@dcl/tracer-component
v1.0.0
Published
Trace execution spans all across your application for core components library
Readme
@dcl/tracer-component
Creates trace spans over an execution, providing context to the code being run
so it can be traced and the W3C Trace Context (traceparent / tracestate)
propagated.
Installation
npm install @dcl/tracer-componentUsage
Import the component, initialize it and wrap your traceable code into a trace span:
import { createTracerComponent } from '@dcl/tracer-component'
const tracer = createTracerComponent()
tracer.span('my span', () => {
// Do some work here
})While inside the span, the traced code is able to access the trace context. This is especially useful for adding traced logs:
const tracer = createTracerComponent()
tracer.span('my span', () => {
console.log(`[${tracer.getTraceString()}] Starting some work`)
// Do some work here
console.log(`[${tracer.getTraceString()}] Finishing some work`)
})The logs output a trace alongside the message using the
traceparent format
(version-traceId-parentId-flags):
[00-7970d1a8361cc811ee59dc3ee1c8134e-0000000000000000-00] Starting some work
[00-7970d1a8361cc811ee59dc3ee1c8134e-0000000000000000-00] Finishing some workThe traceId is unique throughout the span execution and makes it easy to track
which run of the span a log belongs to. The parentId identifies the span the
current span was created from, making it possible to follow the chain of spans.
See the W3C Trace Context spec for the
meaning of the version and flags values.
