This is a basic implementation of the W3C trace context header spec.
npm install elastic-apm-trace-context
const crypto =const TraceContext =const version = Bufferconst traceId = cryptoconst id = cryptoconst flags = '01'const header = `---`const context = TraceContext
Construct a new
TraceContext instance from an existing buffer. The contents are binary data that corresponds to the structure of the W3C traceparent header format, with separators removed.
TraceContext instance from a formatted W3C traceparent header string.
settings object with a
transactionSampleRate value from 0.0 to 1.0 to generate a sampling decision for the context. This will only be applied when starting a new context. When continuing an existing context, the sampling decision will be propagated into all child contexts.
true if this
TraceContext is sampled.
traceId property will propagate through all children in the tree to link them all together.
id property is used to uniquely identify a given
TraceContext instance within the tree.
parentId property links this context to its direct parent in the tree.
flags property is used to store metadata such as the sampling decision.
version property corresponds to the version segment of the W3C traceparent header.
Create a new
TraceContext instance that is a child of this one.
TraceContext instance as a W3C traceparent header.
Return the parent ID, if there is none, generate one. This is useful in browser instrumentation to produce a starting span around a browser request which was not instrumented prior to page load.