Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenTelemetry Propagator AWS X-Ray does not work with @opentelemetry/core and api >=0.12.x #35

Closed
mickdekkers opened this issue Nov 27, 2020 · 1 comment

Comments

@mickdekkers
Copy link
Contributor

mickdekkers commented Nov 27, 2020

This one had me scratching my head for a while 馃槄

When using @aws/otel-aws-xray-propagator@0.12.1 with @opentelemetry/core@0.12.0 and @opentelemetry/api@0.12.0, doing this:

const headers = {
    'X-Amzn-Trace-Id': 'Root=1-5759e988-bd862e3fe1be46a994272793;Parent=53995c3f42cd8ad8;Sampled=1'
};

const tracer = api.trace.getTracer(name);
const context = api.propagation.extract(headers);
const span = tracer.startSpan(spanName, {}, context);

Results in a span like this:
Screen Shot 2020-11-27 at 12 50 29
With a different traceId and no parentSpanId.

This despite the context correctly being extracted by @aws/otel-aws-xray-propagator:
Screen Shot 2020-11-27 at 12 40 39

Note the EXTRACTED_SPAN_CONTEXT Symbol. I couldn't find this anywhere in the opentelemetry-js source code, but it turns out this was removed in open-telemetry/opentelemetry-js#1589. Those changes were released as part of 0.12.0.

It turns out this is happening because when @aws/otel-aws-xray-propagator calls setExtractedSpanContext, it's calling @opentelemetry/core@0.10.2's version of that function, which still uses the EXTRACTED_SPAN_CONTEXT Symbol
Screen Shot 2020-11-27 at 13 06 22

When tracer.startSpan then tries to read the context, it's using our app's version of the core and api (0.12.0) and goes through this flow:

Screen Shot 2020-11-27 at 13 16 32

Screen Shot 2020-11-27 at 13 16 54

Screen Shot 2020-11-27 at 13 17 25

Screen Shot 2020-11-27 at 13 17 56

getActiveSpan tries to read the value using the ACTIVE_SPAN_KEY key, but there's nothing there so it returns undefined. This then bubbles back up the stack to become the return value of getParent in startSpan. startSpan then creates the span as a new root span with a new trace ID and no parent.

Screen Shot 2020-11-27 at 13 43 07

@aws/otel-aws-xray-propagator depends on "@opentelemetry/core": "^0.10.2". Because the version is specified using a caret (^), it accepts newer versions that do not modify the left-most non-zero digit. Since opentelemetry-js is still in the 0.x.x version range, this means that e.g. 0.10.3 would be accepted but 0.11.0 would not. In my case it results in @aws/otel-aws-xray-propagator having its own version of @opentelemetry/core@0.10.2 in its node_modules folder and it using that over the version we use in our app. Ditto for @opentelemetry/api.

Fixing the issue is probably a matter of upgrading @aws/otel-aws-xray-propagator's dependencies to 0.12.0 and adapting to any potential breaking changes in the propagator API.

@mickdekkers mickdekkers changed the title OpenTelemetry Propagator AWS X-Ray does not work with @opentelemetry/core >=0.12.x OpenTelemetry Propagator AWS X-Ray does not work with @opentelemetry/core and api >=0.12.x Nov 27, 2020
@mickdekkers
Copy link
Contributor Author

I've got a fairly good idea of which changes are required to upgrade the propagator to opentelemetry 0.12.x now. I'll whip up a PR shortly 馃殌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants