Skip to content

Latest commit

 

History

History

trace-context

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

HTTP Server with trace context propagation

Running the example

  1. Run the docker compose file in the root of the repo, which will boot the OTLP collector: docker compose up

  2. Run the http server by preloading the instrumentation code.

node -r "./trace-instrumentation.js" http-server.js
  1. Access the app at http://localhost:8080

Explanation

The request handler function in http-server will create a log entry. Since pino is instrumented with @opentelemetry/instrumentation-pino in trace-instrumentation.js, it will also add the span context values as attributes (trace_id, span_id, trace_flags).

pino-opentelemetry-transport will read those attributes and add them to the current context. The resulting LogRecord will have those fields populated. Fields trace_id, span_id, trace_flags will not be visible in the LogRecord attributes.

Observe the logs with:

tail -f /tmp/test-logs/otlp-logs.log