Integration with Sentry's `Sentry-Trace` header?
# support
y
Hi there! We're using Sentry as part of our observability toolkit, and part of what they offer is distributed tracing. Soon, we'll integrate with their browser tracing feature, which will attach a trace ID as
Sentry-Trace
on every single XHR request (including ones to Medplum). We saw that there are docs showing that Medplum supports an
X-Trace-Id
header. Is it possible for Medplum to check for a
Sentry-Trace
header and use that as the trace ID? That would give Medplum support for Sentry's distributed tracing out-of-the-box, which would be pretty rad. Otherwise, we'll have to do some extra work to grab the sentry trace ID and add that to medplum requests as an
X-Trace-Id
header. Definitely doable, but a bit of a pain.
Digging a little deeper, it looks like the
Sentry-Trace
is actually a
traceparent
value, e.g.:
79078f4ef8da4c7982c61184b7e20f94-89d3679edd366475-1
n
It seems that even if
X-Trace-Id
were set to the
Sentry-Trace
value by the client, the Medplum server would currently ignore it because it is not a UUID. https://github.com/medplum/medplum/blob/f86debc144a6bb73169bec8b0bf12bebaadeb6b0/packages/server/src/context.ts#L106 https://github.com/getsentry/sentry-javascript/blob/6dfddc2dfc4b74cbb70dc325b4af165e25904ed4/packages/utils/src/tracing.ts#L117-L130 I've opened this PR to have the Medplum server directly support the
Sentry-Trace
header https://github.com/medplum/medplum/pull/3877
r
Hi @node @yaaaaale - We really appreciate the contribution, but unfortunately, we don't plan to support vendor-specific logic in our servers.
@node - that is a good note that we are only allowing UUIDs right now. I think it would be reasonable to update our
traceparent
validation to be inline with the spec: https://luizlelis.com/blog/tracecontext#:~:text=The%20traceparent%20field&text=version%20(8%2Dbit)%3A%20trace,trace%20globally%20through%20a%20system.
I would recommend the following: * Could you open a GH issue about supporting the sentry trace format? I can't speak for the whole team, but we'll have to find a balance between following the spec and allowing a practical array of traceid formats
n
Agreed that properly aligning with the
traceparent
spec unblocks distributed tracing for at least Sentry, though it would require additional client configuration.
r
yeah, it seems like the sentry header is just the traceparent format, minus the flags and preceding
00
. There might be a middle ground here where we can consider those optional when we parse the
traceparent
header
152 Views