@xeonr/telemetry
v0.2.0
Published
Node telemetry for Xeonr services: node --import @xeonr/telemetry/register starts OpenTelemetry (through @lntrn/otel) with OTLP gRPC to the cluster collector, AlwaysOn sampling and a fixed instrumentation list, and adds the fleet's identity vocabulary, in
Readme
@xeonr/telemetry
Telemetry for Xeonr's Node services: the Node mirror of go-platform's
telemetry package, and the way a Node service meets Plumb's
obs.node-telemetry.
node --import @xeonr/telemetry/register dist/server.js # ES modules
node --require @xeonr/telemetry/register dist/server.cjs # CommonJSregister starts OpenTelemetry before the app loads. The SDK itself is
@lntrn/otel, Lantern's add-on
for the stock NodeSDK. This package makes the Xeonr choices on top:
- OTLP gRPC to the cluster collector, from
OTEL_EXPORTER_OTLP_ENDPOINT(Go-stylehost:portor a URL). In-cluster hosts andOTEL_EXPORTER_OTLP_INSECURE=trueare cleartext. With no endpoint nothing is sent: onetelemetry export disabledline, and spans still get ids so log lines still carry them. - Resource from
OTEL_SERVICE_NAME,OTEL_SERVICE_NAMESPACE,OTEL_SERVICE_VERSION,ENV(elseNODE_ENV, asprod/dev) asdeployment.environment, and the pod name asservice.instance.id. - AlwaysOn sampling. W3C trace context is the only propagator: baggage is sent only by this package's in-cluster helpers.
- A fixed instrumentation list, never
auto-instrumentations-node: http, undici (fetch), ioredis, mysql2 (statements masked), pg, aws-sdk, runtime-node, and pino (trace ids on lines, never log export)./healthzis not traced. Client spans need a parent: one without becomes nothing rather than a root (xeonr_telemetry_rootless_client_spans_totalcounts the ones dropped). - Runtime metrics: runtime-node's event loop, heap and GC, and
host-metrics'
process.cpu.*andprocess.memory.*(the pod, not the node). - No log export: logs go to stdout for the Lantern agent. No HTTP RED histograms: spanmetrics derives RED from the spans.
- Identity on every span, from the request or job it belongs to; URL queries and credentials stripped from URL attributes.
Identity (§4.2)
import { setIdentity, setTeam, setResource } from "@xeonr/telemetry";
// where the service verifies a Xeonr caller itself (its auth interceptor)
setIdentity({ subject: principal.sub, orgId, clientId, authMethod: "bearer", scopes });
// in a handler acting on an owned resource
setTeam(bucket.teamUrn);
setResource("bucket", bucket.id, bucket.urn);The keys are generated from go-platform's telemetry/keys.json
(src/keys.json, copied byte for byte; pnpm gen-keys).
Connect
import { clientInterceptor, peerContextValues, serverInterceptor } from "@xeonr/telemetry/connect";
app.register(fastifyConnectPlugin, {
routes,
interceptors: [serverInterceptor(), authInterceptor], // telemetry first
contextValues: peerContextValues, // the TCP peer, for trust
});
const transport = createConnectTransport({ baseUrl, interceptors: [clientInterceptor({ peer: "upl-im-api" })] });The server continues a caller's traceparent and honours its origin baggage
only from a trusted peer (TRUSTED_PROXY_CIDR, default 10.0.0.0/8, as
go-platform); anyone else's trace becomes a link. Status follows otelconnect:
only a server-class code is an error.
Jobs
import { runJob, startJob, detach } from "@xeonr/telemetry";
await runJob("upl.trace.reconcile", () => reconcile(), { trigger: "cron" });
const job = startJob("upl.parse_upload", { trigger: "queue", links });
// … context.with(job.ctx, …) …
job.end(err);
void runJob("upl.index", () => index(id), { ctx: detach(), trigger: "request" }); // from a handlerA job is a root span with xeonr.job.* and system identity (or the caller's,
when started from a request), and counts xeonr_job_runs_total and
xeonr_job_duration_seconds.
Outbound HTTP
import { fetchWith, withPeer, baggageFor } from "@xeonr/telemetry";
const discord = fetchWith({ peer: "discord" }); // fetch with peer.service, no baggage
const api = fetchWith({ peer: "upl-im-api" }); // in-cluster: origin baggage too
await withPeer("s3", () => s3.send(cmd)); // any other clientLogging
import { logger, withContext } from "@xeonr/telemetry/log";
logger.info({ upload_id }, "parsed");pino, JSON on stdout as logrus writes it (level, time, msg), with
trace_id, span_id, trace_flags, the §4.2 fields, procedure and ip
from the active context; credentials redacted by key; errors as
{type, message, stack, code} with tokens, emails and URL queries removed.
An Error line inside a span is mirrored as a span event.
Shutting down
register flushes when the event loop empties. A service that handles
SIGTERM itself calls shutdown() last, after its servers and workers have
drained; one that does not gets a flush and the signal re-raised.
Run-time span processors
addSpanProcessor(p) adds a processor after boot (the upl-im pipeline's
run-trace store). It sees the spans started after it. A span event made with
localEvent(attrs) reaches those processors but is never exported: for
payloads a product shows its own users, which must not reach Lantern.
Releasing
Bump "version" and merge to main: CI (.xeonr-ci.yaml, app telemetry)
tests, builds and publishes any version the registry hasn't got, and tags it
telemetry-vX.Y.Z.
