Node.js tracing installation
- 1
Install OpenTelemetry packages
RequiredFor the complete SDK reference, see the OpenTelemetry JavaScript docs.
Terminal@opentelemetry/exporter-trace-otlp-protois the OTLP HTTP/protobuf trace exporter. The similarly named-otlp-httppackage sends HTTP/JSON and-otlp-grpcsends gRPC, so pick-prototo match this guide. - 2
Get your project token
RequiredYou'll need your PostHog project token to authenticate trace requests. This is the same token you use for capturing events with the PostHog SDK.
Important: Use your project token which starts with
phc_. Do not use a personal API key (which starts withphx_).You can find your project token in Project settings.
- 3
Configure the SDK
RequiredSet up the OpenTelemetry SDK to export spans to PostHog over OTLP HTTP.
JavaScriptAlternatively, configure the exporter with environment variables:
TerminalNote: Pass the full
/i/v1/tracespath to the traces endpoint. Don't use the baseOTEL_EXPORTER_OTLP_ENDPOINTvariable, which appends its own/v1/traces. - 4
Create spans
RequiredWrap the operations you want to measure in spans, and attach attributes for context.
JavaScript - 5
Next steps
CheckpointWhat you can do with your tracesAction Description Why you need distributed tracing What a trace shows you that nothing else does Explore traces Read a trace as a waterfall to see where time goes Filter spans Narrow down by service, status, duration, and attributes Propagate context Pass trace context across services so spans join the same trace