Skip to content

How to migrate from home-grown tracing to OpenTelemetry (aka header munging) #3326

Answered by vmarchaud
djMax asked this question in Q&A
Discussion options

You must be logged in to vote

I think i would have a custom propagator that take the correlation id, hash it and use that as traceId for otel. Here is an example (pretty much in pseudo code) that you could start from:

// name of your header
const X_CUSTOM_CONTEXT = 'correlation-id'
// store the original correlation id in the context
export const CUSTOM_COMTEXT_SYMBOL = Symbol.for(X_CUSTOM_CONTEXT)

export class CustomContextPropagator implements TextMapPropagator {
  inject (context: Context, carrier: unknown, setter: SetterFunction) {
    const customContext = context.getValue(CUSTOM_COMTEXT_SYMBOL)
    if (typeof customContext !== 'undefined') {
      setter(carrier, X_CUSTOM_CONTEXT, JSON.stringify(customContext))

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@djMax
Comment options

@vmarchaud
Comment options

Answer selected by djMax
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants