Stalker Getting started Docs GitLab Hub

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

SensorWatchesCode changeSignals
Node and Bun Sensor, @slopkit/stalkerA Node or Bun processNone, a preload flagTraces, logs, Function Coverage
Rust Sensor, stalker-rustA Rust service built as an Instrumented BuildOne line, a tower layerFunction Coverage
Kernel Sensors, OBI and the eBPF profilerEvery process on a nodeNoneTraces, 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

Configuration

Environment variables. STALKER_* wins over the OpenTelemetry variable with the same meaning.

VariableDefaultMeaning
STALKER_ENDPOINThttp://127.0.0.1:7410Base URL of rat. Traces go to <base>/v1/traces, logs to <base>/v1/logs.
STALKER_WRITE_KEYnonerat 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_CONSOLE10 stops console capture.
STALKER_BUN_WRAP10 stops the Bun.serve and fetch wrappers.
STALKER_FLUSH_INTERVAL_MS1000Export interval in milliseconds.
STALKER_MAX_BODY_BYTES30000Largest request body sent to rat, in bytes. rat refuses bodies over 32 KiB. Batches are split to fit.
STALKER_COVERAGE01 turns on Function Coverage.
STALKER_COVERAGE_KEYShunt.scenario,hunt.stepThe baggage entries that make up a Request Key.
STALKER_COVERAGE_IDLE_MS1000Files the last Request Key after this many milliseconds without a keyed request.
STALKER_COVERAGE_DEPS01 includes node_modules code.
STALKER_USE_PROXY01 lets the exporter follow HTTP_PROXY and HTTPS_PROXY.
STALKER_DISABLED01 turns the Sensor off.
OTEL_SERVICE_NAMEfile name of the entry scriptService 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_HEADERSnoneUsed 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_DISABLEDnonePassed through to the OpenTelemetry SDK.

Coverage by runtime

Node CommonJSNode ES modulesBun
Incoming HTTP server span, parented on traceparentyesyesyes, through the Bun.serve wrapper (fetch handler and routes function handlers, also after server.reload)
Outgoing fetch span and header propagationyesyesyes, through the fetch wrapper
Outgoing node:http clientyesyesnot covered; use fetch
Libraries (express, pg, redis and others)yesyes, through the import-in-the-middle loader hookonly what works through Bun's Node compatibility; untested
Baggage on spans and logsyesyesyes
console.* logsyesyesyes

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.

Each delta is sent to rat as OTLP logs, one log record per source file, with at most 120 functions per record.

FieldValue
body{"functions":[{"name":"onlyInA","line":8,"column":1,"count":2}]}. Line and column are 1-based. Anonymous functions are (anonymous).
stalker.signalfunction_coverage
stalker.request_keyfor example hunt.scenario=signup,hunt.step=1
hunt.scenario, hunt.stepthe key's baggage entries, as on spans
code.filepathabsolute path of the file
stalker.coverage.granularityfunction; script for a file reported whole
stalker.coverage.exacttrue unless requests of two keys overlapped in the window
service.nameas 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

  1. A request whose baggage has a configured entry is a measured request. Other requests pass through untouched.
  2. The layer takes a process-wide lock, resets the profile counters, runs the handler, copies the counters, and releases the lock.
  3. llvm-profdata merge -sparse -text gives the executed functions and their entry counts. llvm-cov export on 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/store and vendor/ are dropped unless STALKER_COVERAGE_DEPS=1. The source measures about 25 ms per request on the example.
  4. 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.

Configuration

VariableDefaultMeaning
STALKER_COVERAGE01 turns on measuring.
STALKER_ENDPOINThttp://127.0.0.1:7410rat. Only http://, with no TLS and no proxy.
STALKER_WRITE_KEYnoneSent as Basic auth.
STALKER_COVERAGE_KEYShunt.scenario,hunt.stepBaggage entries that make up a Request Key.
STALKER_COVERAGE_SERIALIZE1Measured requests run one at a time.
STALKER_COVERAGE_ASYNC01 answers before the records are sent.
STALKER_COVERAGE_DEPS01 keeps dependency and standard library functions.
STALKER_COVERAGE_DEBUGunsetPrint timings to stderr.
OTEL_SERVICE_NAMEexecutable file nameThe service of each record.
LLVM_PROFDATA, LLVM_COVllvm-profdata and llvm-cov from PATHThe 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 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.

Privileges and kernel

Both agents run as root in the container with hostPID: true and an explicit capability list instead of privileged.

AgentCapabilities
OBICAP_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
ProfilerCAP_BPF, CAP_PERFMON, CAP_SYS_ADMIN, CAP_SYS_PTRACE, CAP_SYSLOG, CAP_SYS_RESOURCE

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 set STALKER_OBI_BIN, STALKER_OTELCOL_BIN and STALKER_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 sudo command.
status, down
Report on and stop the processes. Logs and pids are under .stalker/run/.

fetch and check need no privileges.

VariableMeaning
STALKER_ENDPOINTrat base URL. Default http://127.0.0.1:7410.
STALKER_WRITE_KEYrat write key, when rat has COLLECTOR_WRITE_KEYS.
STALKER_TARGET_PORTOBI instruments the process that listens on this port.
STALKER_TARGET_EXEOr the executables matching this glob, for example */api. One of the two is required for OBI.
STALKER_ONLYobi or profiler starts only that one.
STALKER_OBI_BIN, STALKER_OTELCOL_BIN, STALKER_PROFILER_BINUse these binaries instead of .stalker/bin.

Request Keys on Kernel Sensor spans

Profiles in rat

rat writes one profile_samples row per distinct stack.

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.

PathBodySent 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/coverageflat Function Coverage recordRust Sensor
/v1development/profilesOTLP profiles signal as JSONThe 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:

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

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.