envoy
envoy copied to clipboard
tracing: expose trace info in dynamic metadata
Commit Message: tracing: expose trace info in dynamic metadata
Additional Description: Expose trace information in dynamic metadata so filters in other languages can create child spans of the same trace, or so the logging system can record per-request trace info. The issue only calls out trace ID, but in practice I found we must also expose the span ID to create proper parent/child span relationship. Also, report whether it was sampled, so we can set trace flags appropriately. Trace and sampled info was readily available, but span ID was not, so plumb that through all the tracers.
I put this under a new envoy.tracing metadata domain as it felt warranted, but I'm not sure whether this is the "right" place. I wanted to avoid touching docs until I can get some feedback on the naming/placement.
This is only implemented for the HTTP flow.
Risk Level: Low Testing: A unit test is modified to verify population of the dynamic metadata. An HTTP Golang filter was used to verify the workings end-to-end using the OpenTelemetry tracer. Docs Changes: The new dynamic metadata fields should be documented (TODO). Release Notes: Platform Specific Features: [Optional Runtime guard:] [Optional Fixes #Issue] https://github.com/envoyproxy/envoy/issues/32894 [Optional Fixes commit #PR or SHA] [Optional Deprecated:] [Optional API Considerations:]
To use this from Go, for example:
sampled := <dynamic metadata fetch/cast>
traceID := <dynamic metadata fetch/cast, convert to bytes>
spanID := <dynamic metadata fetch/cast, convert to bytes>
var traceFlags oteltrace.TraceFlags
if sampled {
traceFlags = oteltrace.FlagsSampled
}
// Establish the parent span context manually. If this is in DecodeHeaders, it will be the ingress span.
ctx = oteltrace.ContextWithSpanContext(
ctx,
oteltrace.NewSpanContext(oteltrace.SpanContextConfig{
TraceID: oteltrace.TraceID(traceID),
SpanID: oteltrace.SpanID(spanID),
TraceFlags: traceFlags,
}),
)
trace.Start(ctx, ...)
Hi @gdvalle, welcome and thank you for your contribution.
We will try to review your Pull Request as quickly as possible.
In the meantime, please take a look at the contribution guidelines if you have not done so already.
This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!
I haven't had time to rework this yet, but still plan to.
@wbpcode PTAL.
Thanks for the contribution. There are two main changes here. One adds getSpanId method to the tracer. One change to the contrib go.
Could you split them to two independent PRs? The first one is LGTM but it would be better to do it in an independent PR. Thanks.
Could you split them to two independent PRs? The first one is LGTM but it would be better to do it in an independent PR. Thanks.
Done. I've turned this PR into the span ID API changes. Given the Go changes depend on this, I'll open that after merge. I don't see a way to chain the branches together in a PR against this repo.
LGTM. Thanks.
Funny, 2 hours ago https://github.com/envoyproxy/envoy/pull/33909 was merged, which also implemented getSpanId.
@wbpcode would you be okay with me altering this PR yet again to target the Go filter work, or just open a new one?
Funny, 2 hours ago #33909 was merged, which also implemented
getSpanId.@wbpcode would you be okay with me altering this PR yet again to target the Go filter work, or just open a new one?
It's complete up to you. Both are OK for me. :)
/wait on main merge
This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!
This pull request has been automatically closed because it has not had activity in the last 37 days. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!