-
I am trying to modernize a circa-2016 micro-services NodeJS stack. We have a poor mans version of distributed tracing in that:
But, the correlationid is a mongo object hash and the span id is a "tree like counter" - e.g. first span is 1, that makes a call it gets 1.1, then the parent makes another call, 1.2, and if it calls something else, it's 1.2.1, etc. SO, obviously I don't want to have to replace all services at once and I'd like tools to mostly keep working while we enable new tools. (We're using Sumo now if that ends up mattering). Is it possible to take our correlation id header Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
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))
}
}
extract (context: Context, carrier: unknown, getter: GetterFunction): Context {
const customContext = getter(carrier, X_CUSTOM_CONTEXT)
if (typeof customContext !== 'string') return context
return trace.setSpan(context.setValue(CUSTOM_COMTEXT_SYMBOL, JSON.parse(customContext)), trace.wrapSpanContext({
traceId: hash(customContext) // here we create a traceId from your header, should be consistent across your services,
spanId: 0, // you may want to do the same thing with your header that contains span "counter" to link remote span
isRemote: true
}))
}
} |
Beta Was this translation helpful? Give feedback.
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: