Docs
Lookup for Stalker, the SlopKit Sensors that watch running software and send every Signal to rat. Source: https://gitlab.techtailors.net/slopkit/stalker. Family site: https://slopkit.dev.
This page matches slopkit/stalker main at commit be099e2: @slopkit/stalker 0.1.0 and stalker-rust 0.1.0. A first run is on Getting started at https://stalker.slopkit.dev/start/.
Stalker has no database and no query API. It collects and sends. rat stores and queries.
Terms
- Sensor
- A Stalker component that watches one kind of running software (a Node or Bun process, a Rust binary, every process on a node) and produces Signals from it without code changes.
- Kernel Sensor
- A Sensor that watches every process on a machine from the kernel (eBPF). It works for any language and needs no change to the product or its build. It sees requests only as bytes, so it cannot read a product's own context.
- Signal
- One kind of observability data Stalker produces: traces, logs, metrics, continuous profiles, or Function Coverage.
- Function Coverage
- The set of functions (with their files) that ran while serving one request or a group of requests that share a Request Key.
- Request Key
- The identity that Stalker files a request's Signals under, taken from the request's trace context and baggage (for example, a Hunt Scenario and Step). A Kernel Sensor can read it only from the first request that carries it. The rest of that trace is found by trace id.
- Profile
- Samples of which stacks the CPU was running in a service over a time window, with a count per stack. It says where time went, not which functions ran for a Request Key.
- Isolated Process
- A product process that serves requests from one Request Key at a time, so that its Function Coverage cannot mix with anything else.
- Instrumented Build
- A binary compiled so it counts which functions run (Rust
-C instrument-coverage). The Rust Sensor works only on one, and only for the Request Keys that reach it one at a time. - rat
- The SlopKit collector and store that Stalker sends every Signal to.
Sensors
| Sensor | Watches | Code change | Signals |
|---|---|---|---|
Node and Bun Sensor, @slopkit/stalker | A Node or Bun process | None, a preload flag | Traces, logs, Function Coverage |
Rust Sensor, stalker-rust | A Rust service built as an Instrumented Build | One line, a tower layer | Function Coverage |
| Kernel Sensors, OBI and the eBPF profiler | Every process on a node | None | Traces, Profiles |
Metrics are off in the Node and Bun Sensor.
Node and Bun Sensor
Package @slopkit/stalker, version 0.1.0. It needs Node 22.12 or newer. It has one entry point, @slopkit/stalker/register, which resolves to register.cjs for require and to register.mjs for import and the bun condition.
Synopsis
node --require @slopkit/stalker/register app.js node --import @slopkit/stalker/register app.mjs bun --preload @slopkit/stalker/register app.ts NODE_OPTIONS="--require @slopkit/stalker/register" node app.js
Use the NODE_OPTIONS form when you cannot change the command. For Bun, preload = [...] in bunfig.toml also works.
Behavior
- Starts OpenTelemetry auto-instrumentation with
@opentelemetry/auto-instrumentations-node.fs,dnsandnetare off. - Propagates W3C
traceparentandbaggage. What comes in on a request goes out on every outgoing HTTP call made while serving it. The propagators are fixed totracecontext,baggage, andOTEL_PROPAGATORSis ignored. - Copies baggage entries onto every span and log record as attributes. This is how a Request Key reaches rat.
- Forwards
console.debug,console.log,console.info,console.warnandconsole.erroras log records inside the active trace. Console output itself is unchanged. - Sends traces to rat at
POST /v1/tracesand logs toPOST /v1/logsas OTLP JSON, uncompressed. Spans and log records also carryservice.nameas an attribute, because rat does not keep the OTLP resource. - Flushes every second, on
beforeExit, and on SIGTERM and SIGINT. If the product has no signal handler of its own, Stalker exits after the flush with the usual code. - Does not break the product. If rat is down, export errors are printed once to stderr and dropped.
- Never follows
HTTP_PROXY,HTTPS_PROXYorNO_PROXYfor its export to rat, unlessSTALKER_USE_PROXY=1.
Configuration
Environment variables. STALKER_* wins over the OpenTelemetry variable with the same meaning.
| Variable | Default | Meaning |
|---|---|---|
STALKER_ENDPOINT | http://127.0.0.1:7410 | Base URL of rat. Traces go to <base>/v1/traces, logs to <base>/v1/logs. |
STALKER_WRITE_KEY | none | rat write key, sent as HTTP Basic auth. Needed only when rat has COLLECTOR_WRITE_KEYS. |
STALKER_BAGGAGE_KEYS | * | Which baggage entries become attributes: comma-separated names or prefix*. Propagation is not affected. |
STALKER_CAPTURE_CONSOLE | 1 | 0 stops console capture. |
STALKER_BUN_WRAP | 1 | 0 stops the Bun.serve and fetch wrappers. |
STALKER_FLUSH_INTERVAL_MS | 1000 | Export interval in milliseconds. |
STALKER_MAX_BODY_BYTES | 30000 | Largest request body sent to rat, in bytes. rat refuses bodies over 32 KiB. Batches are split to fit. |
STALKER_COVERAGE | 0 | 1 turns on Function Coverage. |
STALKER_COVERAGE_KEYS | hunt.scenario,hunt.step | The baggage entries that make up a Request Key. |
STALKER_COVERAGE_IDLE_MS | 1000 | Files the last Request Key after this many milliseconds without a keyed request. |
STALKER_COVERAGE_DEPS | 0 | 1 includes node_modules code. |
STALKER_USE_PROXY | 0 | 1 lets the exporter follow HTTP_PROXY and HTTPS_PROXY. |
STALKER_DISABLED | 0 | 1 turns the Sensor off. |
OTEL_SERVICE_NAME | file name of the entry script | Service name. OTEL_RESOURCE_ATTRIBUTES=service.name=... also works. |
OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, OTEL_EXPORTER_OTLP_LOGS_ENDPOINT, OTEL_EXPORTER_OTLP_HEADERS | none | Used when STALKER_ENDPOINT is not set. Always JSON, never gzip. |
OTEL_NODE_ENABLED_INSTRUMENTATIONS, OTEL_NODE_DISABLED_INSTRUMENTATIONS, OTEL_TRACES_SAMPLER, OTEL_LOG_LEVEL, OTEL_SDK_DISABLED | none | Passed through to the OpenTelemetry SDK. |
Coverage by runtime
| Node CommonJS | Node ES modules | Bun | |
|---|---|---|---|
Incoming HTTP server span, parented on traceparent | yes | yes | yes, through the Bun.serve wrapper (fetch handler and routes function handlers, also after server.reload) |
Outgoing fetch span and header propagation | yes | yes | yes, through the fetch wrapper |
Outgoing node:http client | yes | yes | not covered; use fetch |
| Libraries (express, pg, redis and others) | yes | yes, through the import-in-the-middle loader hook | only what works through Bun's Node compatibility; untested |
| Baggage on spans and logs | yes | yes | yes |
console.* logs | yes | yes | yes |
Not covered: Bun.serve WebSocket messages, static routes responses, the time spent streaming a response body (the server span ends when the handler returns the Response), Bun.sql and bun:sqlite calls, metrics, profiles, and function-level Function Coverage under Bun.
A Bun server span is named <METHOD>, or <METHOD> <route pattern> for routes. It carries url.path, http.request.method, http.response.status_code and the client address. The wrapper replaces Bun.serve and globalThis.fetch, so the preload must run first. --preload does.
Function Coverage on Node and Bun
Set STALKER_COVERAGE=1. The Sensor uses V8 precise coverage (node:inspector, Profiler.takePreciseCoverage). Its counters reset on every take, so each take is the delta since the previous one.
- A Request Key is the values of
STALKER_COVERAGE_KEYSin the request's baggage. Requests without any of them are ignored. - A delta is taken when the first request of a different Request Key starts (it is filed under the previous key), when no keyed request has been active for
STALKER_COVERAGE_IDLE_MS, and at shutdown. - The result is exact only on an Isolated Process, or when requests run one at a time. Overlapping requests of two keys are still recorded, with
stalker.coverage.exact=false. - Work that ran with no keyed request in flight (timers, startup) is dropped. Node internals, Stalker itself and, by default,
node_modulesare left out. - The Node Sensor files by Request Key only. It sets no trace id on coverage.
Each delta is sent to rat as OTLP logs, one log record per source file, with at most 120 functions per record.
| Field | Value |
|---|---|
| body | {"functions":[{"name":"onlyInA","line":8,"column":1,"count":2}]}. Line and column are 1-based. Anonymous functions are (anonymous). |
stalker.signal | function_coverage |
stalker.request_key | for example hunt.scenario=signup,hunt.step=1 |
hunt.scenario, hunt.step | the key's baggage entries, as on spans |
code.filepath | absolute path of the file |
stalker.coverage.granularity | function; script for a file reported whole |
stalker.coverage.exact | true unless requests of two keys overlapped in the window |
service.name | as on every record |
Under Bun, the Sensor counts function entries itself: it adds a counter at the start of every function body when Bun loads a file of your product, without changing line numbers. JSX and TSX files, and files loaded before the preload, are reported whole: granularity=script and an empty functions list.
Measured overhead on Node, with a no-op handler on loopback: about 0.04 ms per request without Stalker, 0.11 ms with Stalker, and 0.27 ms with Stalker and coverage. The source does not measure a real product.
Proxies
Decoy sets HTTP_PROXY and HTTPS_PROXY so a product's calls to third-party hosts reach it. Node honours them only with NODE_USE_ENV_PROXY=1. Bun reads them natively.
Stalker's export to rat uses node:http and node:https with a dedicated agent, so it is not proxied in Node or Bun. If rat is reachable only through a proxy, set STALKER_USE_PROXY=1 and keep NO_PROXY=127.0.0.1,localhost yourself.
Rust Sensor
Crate stalker-rust, version 0.1.0, in packages/rust of the Stalker repo. It is not published. Use it as a path dependency. It measures Function Coverage only.
A compiled binary has no preload hook, so this Sensor needs one line in the product and an Instrumented Build.
Synopsis
# Cargo.toml
stalker-rust = { path = "../stalker/packages/rust" }
let coverage = stalker_rust::Coverage::from_env();
let app = Router::new().route("/path-a", get(handler)).layer(coverage.layer());
coverage.layer() is a tower::Layer over http::Request services, such as axum, hyper and tonic. For a framework without tower, wrap the work in coverage.measure(key, async { ... }), with RequestKey::from_headers(&headers, &keys). coverage.flush().await waits for records sent in the background.
Build helper
packages/rust/scripts/stalker-rust-build [CARGO_BUILD_ARGS...]
Runs cargo build with RUSTFLAGS extended by -C instrument-coverage, into its own target directory, so the normal build is untouched. Arguments are passed to cargo build. For example, -p my-service or --release --bin api. The binary is in <target>/debug, or <target>/release.
STALKER_COVERAGE_TARGET_DIR- Target directory. Default
target/coverage.
Without -C instrument-coverage, the crate compiles to a no-op and STALKER_COVERAGE=1 prints a warning. stalker_rust::INSTRUMENTED tells whether the binary was built with it. Instrumented binaries are bigger and slower. Do not ship them.
Behavior
- A request whose
baggagehas a configured entry is a measured request. Other requests pass through untouched. - The layer takes a process-wide lock, resets the profile counters, runs the handler, copies the counters, and releases the lock.
llvm-profdata merge -sparse -textgives the executed functions and their entry counts.llvm-cov exporton the binary gives each function's file and span. It is read once at startup in a background thread and cached. Only your own code is kept. The standard library,~/.cargo,/nix/storeandvendor/are dropped unlessSTALKER_COVERAGE_DEPS=1. The source measures about 25 ms per request on the example.- The functions are sent to rat at
POST /v1/coverage, one record per file.
Each record has service, traceId (from traceparent), requestKey, scenario, step, file, functions, exact and language: "rust". Each function has name (demangled), line, column, endLine, endColumn and count.
By default the response is returned after the records are sent, so rat can already answer for that Request Key when the caller sees the response. STALKER_COVERAGE_ASYNC=1 sends in the background.
Failures, such as rat down or missing tools, are printed to stderr and dropped. The request is never failed.
Concurrency
The profile counters belong to the process and cannot be read per task or per thread. Function Coverage is exact only when one measured request runs at a time.
- By default (
STALKER_COVERAGE_SERIALIZE=1) the layer queues measured requests behind a lock, so concurrent keyed requests never mix, at the cost of throughput. - Requests with no Request Key are not queued. If one overlaps a measured request, its work is in the counters and the record is sent with
exact=false. Health checks are the usual cause. STALKER_COVERAGE_SERIALIZE=0removes the lock. Overlapping measured requests then reset each other's counters, and every record isexact=false.- Work done with no measured request in flight is dropped. Work a handler spawns that outlives the response lands in whichever request is measured next. The response body is not covered if it streams after the handler returns.
- Run the service as an Isolated Process and keep other callers off it while it is measured.
Configuration
| Variable | Default | Meaning |
|---|---|---|
STALKER_COVERAGE | 0 | 1 turns on measuring. |
STALKER_ENDPOINT | http://127.0.0.1:7410 | rat. Only http://, with no TLS and no proxy. |
STALKER_WRITE_KEY | none | Sent as Basic auth. |
STALKER_COVERAGE_KEYS | hunt.scenario,hunt.step | Baggage entries that make up a Request Key. |
STALKER_COVERAGE_SERIALIZE | 1 | Measured requests run one at a time. |
STALKER_COVERAGE_ASYNC | 0 | 1 answers before the records are sent. |
STALKER_COVERAGE_DEPS | 0 | 1 keeps dependency and standard library functions. |
STALKER_COVERAGE_DEBUG | unset | Print timings to stderr. |
OTEL_SERVICE_NAME | executable file name | The service of each record. |
LLVM_PROFDATA, LLVM_COV | llvm-profdata and llvm-cov from PATH | The LLVM tools. |
The two LLVM tools must come from the same LLVM as rustc (rustc -vV shows it). A tool older than rustc's LLVM cannot read the profile. The Stalker dev shell adds llvmPackages_latest.llvm.
Kernel Sensors
Two eBPF Sensors that watch every process on a node, with no change to the product or its build:
- OBI (OpenTelemetry eBPF Instrumentation, formerly Grafana Beyla) produces spans for HTTP, gRPC, SQL, Redis, Kafka and more, and injects
traceparentinto outgoing requests. - The eBPF profiler (
opentelemetry-ebpf-profiler, shipped as theotelcol-ebpf-profilerCollector distribution) samples the CPU stacks of every process on the node.
OBI sends OTLP protobuf to an OpenTelemetry Collector sidecar in the same pod. The sidecar parses the Request Key, copies service.name, and sends OTLP JSON to rat at /v1/traces. The profiler's Collector sends OTLP profiles JSON to rat at /v1development/profiles.
The source states that the eBPF runtime has not been run on a real node. Configs were validated with the real binaries. See docs/ebpf.md in the Stalker repo for what was and was not checked.
Kubernetes
kubectl kustomize deploy/kubernetes kubectl apply -k deploy/kubernetes
The first command prints what will be applied. Paths are relative to the Stalker repo.
- Namespace:
stalker. It carries the labelpod-security.kubernetes.io/enforce: privileged. - rat location: the
stalker-envConfigMap, literalSTALKER_ENDPOINT. Defaulthttp://rat.hunt.svc.cluster.local:7410. Change the literal in an overlay. - Write key: when rat has
COLLECTOR_WRITE_KEYS, create the Secretstalker-ratin thestalkernamespace with the keybasicset to base64 of<write key>:. Both agents read it when it exists and run without it otherwise. - OBI opt-in: OBI instruments pods labelled
slopkit.dev/stalker: "true"in the pod template. Editdiscovery.instrumentindeploy/kubernetes/config/obi.yamlto select by namespace or deployment instead. The profiler samples everything on the node. - Privileged overlay:
kubectl apply -k deploy/kubernetes-privilegedsetsprivileged: trueon both agents. Use it if your runtime strips capabilities. - Pinned versions: OBI
v1.0.0(otel/ebpf-instrument), Collector distributions0.166.0. OBI config is v1.
Privileges and kernel
Both agents run as root in the container with hostPID: true and an explicit capability list instead of privileged.
| Agent | Capabilities |
|---|---|
| OBI | CAP_BPF, CAP_PERFMON, CAP_NET_RAW, CAP_NET_ADMIN, CAP_DAC_READ_SEARCH, CAP_CHECKPOINT_RESTORE, CAP_SYS_PTRACE, CAP_SYS_ADMIN, CAP_SYS_RESOURCE |
| Profiler | CAP_BPF, CAP_PERFMON, CAP_SYS_ADMIN, CAP_SYS_PTRACE, CAP_SYSLOG, CAP_SYS_RESOURCE |
- OBI needs kernel 5.8 or newer with BTF (
/sys/kernel/btf/vmlinux).traceparentheader propagation needs 5.17 or newer. - On kernels 6.6.128+, 6.12.75+, 6.18.14+ and 6.19+, context propagation needs a
/sys/kernel/tracinghost mount. Without it OBI turns propagation off. - The profiler needs kernel 5.10 or newer. Without
CAP_SYSLOGand withkptr_restrictset, it stops withfailed to read kernel symbols: unable to read kallsyms addresses - check capabilities. OTEL_EBPF_ENFORCE_SYS_CAPS=truemakes OBI exit with the list of missing capabilities instead of half working.- The capability sets come from upstream documentation. They were not run on a cluster.
Run without Kubernetes
scripts/ebpf-local.sh fetch scripts/ebpf-local.sh check sudo -E STALKER_TARGET_PORT=4100 scripts/ebpf-local.sh up scripts/ebpf-local.sh status scripts/ebpf-local.sh down
fetch- Downloads pinned, sha256-checked binaries into
.stalker/bin. linux/amd64 only. On another architecture setSTALKER_OBI_BIN,STALKER_OTELCOL_BINandSTALKER_PROFILER_BIN. check- Validates every config with the real binaries and reports kernel prerequisites.
up- Starts the Collector, OBI and the profiler against rat. Needs root. It refuses to run unprivileged and prints the
sudocommand. status,down- Report on and stop the processes. Logs and pids are under
.stalker/run/.
fetch and check need no privileges.
| Variable | Meaning |
|---|---|
STALKER_ENDPOINT | rat base URL. Default http://127.0.0.1:7410. |
STALKER_WRITE_KEY | rat write key, when rat has COLLECTOR_WRITE_KEYS. |
STALKER_TARGET_PORT | OBI instruments the process that listens on this port. |
STALKER_TARGET_EXE | Or the executables matching this glob, for example */api. One of the two is required for OBI. |
STALKER_ONLY | obi or profiler starts only that one. |
STALKER_OBI_BIN, STALKER_OTELCOL_BIN, STALKER_PROFILER_BIN | Use these binaries instead of .stalker/bin. |
Request Keys on Kernel Sensor spans
- OBI records the incoming request's
baggageheader and the Collector sidecar parseshunt.scenarioandhunt.stepout of it into span attributes. It addsstalker.request_key=hunt.scenario=..,hunt.step=.., the same shape the other Sensors use. The raw header is not stored. - OBI does not forward
baggage. Only the span whose request carried the header has the Request Key. Downstream spans share the trace id but have nohunt.*attributes. To find every span of a Step, take thetrace_idof the spans with that Request Key, then every span with that trace id. - A request with only one of
hunt.scenarioandhunt.stepgets that attribute but nostalker.request_key. service.name,k8s.namespace.name,k8s.pod.nameandk8s.node.nameare copied from the OTLP resource onto each span, because rat does not keep the resource.
Profiles in rat
rat writes one profile_samples row per distinct stack.
- Frames are leaf first. Native code is not symbolized by the profiler, so a Rust or C frame is
<binary>+0x<address>. serviceisservice.nameif present, else the Deployment, StatefulSet or DaemonSet name, else the executable name.- Profile rows have no Request Key, because the profiler samples the node and not requests. Relate profiles to a Step by service and time window.
trace_idis expected to be empty. - The profiler sends one request per 10 seconds per node, unbatched. rat accepts up to 16 MiB for profile routes.
rat endpoints Stalker uses
All are POST on rat's collector, default http://127.0.0.1:7410. Bodies are OTLP JSON, except /v1/coverage, which takes the flat Rust record.
| Path | Body | Sent by |
|---|---|---|
/v1/traces | {"resourceSpans":[{"scopeSpans":[{"spans":[...]}]}]} | Node and Bun Sensor, OBI through the Collector |
/v1/logs | {"resourceLogs":[{"scopeLogs":[{"logRecords":[...]}]}]} | Node and Bun Sensor, including Function Coverage |
/v1/coverage | flat Function Coverage record | Rust Sensor |
/v1development/profiles | OTLP profiles signal as JSON | The eBPF profiler through its Collector |
A success is HTTP 200 with {"success":true}. /v1/metrics also exists in rat, but the Node and Bun Sensor does not send metrics.
Constraints from rat:
- JSON only.
application/x-protobufandContent-Encoding: gzipbodies get 400. - Body limit 32 KiB on every route except
/v1/batchand the profile routes. Larger bodies get 413. Stalker's own exporter splits batches under 30 000 bytes. A stock exporter with its default batch of 512 spans hits 413. - With no
COLLECTOR_WRITE_KEYS, nothing is checked and data goes to instancelocal. With keys set, every request needsAuthorization: Basic base64("<write key>:"), or it gets 401. The key picks the instance. - OTLP resource attributes are dropped, so Stalker writes
service.nameonto every span and log record. - A span is keyed by
traceIdandspanId, so a retried batch is idempotent. A log record is keyed by a fresh UUID unless it has amessageIdfield, so a retried log batch can store a record twice.
Read Function Coverage back
GET /v1/coverage?trace_id=&request_key=&scenario=&step=&service=&file=
All query parameters are optional. Use the same Authorization as for ingest. The response is:
{"files":[{"service":"","file":"","granularity":"","functions":[{"name":"","line":0,"column":0,"endLine":0,"endColumn":0,"count":0}]}]}
Counts are summed over deltas. The values above are placeholders for types, not output.
Read other Signals back
rat has no query API on port 7410 for spans and logs. Read them over Quack, DuckDB's remote protocol, from any DuckDB client. Spans are in otel_spans, logs in otel_logs, Function Coverage in function_coverage, profiles in profile_samples. Baggage attributes are inside payload.
Run the Node and Bun examples
From the Stalker repo, inside devenv shell:
npm install
PORT=8080 node --require ./packages/node/register.cjs examples/node-server.cjs
PORT=8080 node --import ./packages/node/register.mjs examples/node-server.mjs
PORT=8080 bun --preload ./packages/node/register.mjs examples/bun-server.ts
curl -H 'traceparent: 00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01' \
-H 'baggage: hunt.scenario=signup,hunt.step=3' localhost:8080/work
/work calls the server's own /echo and returns the traceparent and baggage it received. Start rat first to see the data arrive.
Tests
npm test npm run test:rat npm run test:ebpf npm run test:ebpf:rat
npm test: unit tests plus integration tests against a fake receiver that behaves like rat.npm run test:rat: the same scenario against the real rat in../analytics. Needs network once for DuckDB's quack extension.RAT_DIRoverrides the path.npm run test:ebpf: renders the Kubernetes manifests and, afterscripts/ebpf-local.sh fetch, checks the real Collector and profiler configs.npm run test:ebpf:rat: adds the real Collector to real rat, and an OTLP profiles request intoprofile_samples.
packages/rust/test/e2e.sh, inside devenv shell, builds the Rust example with coverage, starts rat, sends requests with different Request Keys and reads each key back. cargo test in packages/rust runs the Rust unit tests.
Related
- Source and architecture decisions: https://gitlab.techtailors.net/slopkit/stalker
- Getting started: https://stalker.slopkit.dev/start/
- SlopKit: https://slopkit.dev