router icon indicating copy to clipboard operation
router copied to clipboard

expose the TraceId functionality to rhai

Open garypen opened this issue 3 years ago • 2 comments

issue: #1935 suggested exposing a span's trace id via the Context. I think it's better to avoid further use of the context and provide direct acccess to the traceid from rhai. (Note: In case it isn't obvious the TraceId is the opentelemetry Span Id.)

If you ran code like the docs example, you'd see something like:

2022-10-10T11:37:58.404084Z  INFO apollo_router::plugins::rhai: id: 338600282987103915558890515230971876324

fixes: #1935

also: drive by fix of the log_error in the surrogate example.

garypen avatar Oct 10 '22 13:10 garypen

@garypen, please add a /NEXT_CHANGELOG.md entry for this PR to the appropriate section!

github-actions[bot] avatar Oct 10 '22 13:10 github-actions[bot]

I'm not familiar with OpenTelemetry but this diff seems reasonable.

This exposes apollo_router::tracer::TraceId as Display to Rhai, which is based on u128 as Display in decimal. opentelemetry::trace::TraceId as Display however uses fixed-width hexadecimal. Is this difference (not new in this PR) deliberate?

It's not deliberate. We could change it now to be the same. I don't think that would count as a breaking change.

garypen avatar Oct 10 '22 13:10 garypen