open-telemetry / opentelemetry-java-contrib

https://opentelemetry.io
Apache License 2.0
162 stars 129 forks source link

[aws-xray] Provide methods to convert between OtelTraceID <---> Xray trace id #681

Open rapphil opened 1 year ago

rapphil commented 1 year ago

Is your feature request related to a problem? Please describe.

The Otel TraceId is defined as 16-byte array with at least one non-zero byte. https://opentelemetry.io/docs/reference/specification/trace/api/#retrieving-the-traceid-and-spanid The Xray TraceID has the same size, but with some constraints in the construction of it: https://docs.aws.amazon.com/xray/latest/devguide/xray-api-sendingdata.html#xray-api-traceids

Sometimes is useful to present a trace id in the xray format, specially if you are going to dump this information in a log.

Describe the solution you'd like Add methods that provide conversion from/to Otel TraceId to/from Xray trace id.

rapphil commented 1 year ago

@willarmiros Does this make sense?

willarmiros commented 1 year ago

Thanks for raising this! X-Ray will eventually fully support W3C IDs (e.g. no more timestamp requirement) for ingested traces. Part of that work is that we will support searching for W3C-formatted IDs in the console. So even though IDs will still be stored in X-Ray format in the X-Ray backend (e.g. 1-12345678-123456789123456789), ServiceLens will be able to search their logs/traces storage for using W3C format (e.g. 12345678123456789123456789) and it will also work.

I’m definitely all for this proposal, since for backwards compatibility injecting X-Ray-formatted IDs is best. Just providing context on how IDs will work + the fact that AWS services like ServiceLens should support searching W3C-formatted IDs in the future.