-
Notifications
You must be signed in to change notification settings - Fork 619
feat(aws-lambda): disableAwsContextPropagation config option #546
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
46df98d
68012ea
abc4f0b
9832d3a
4f58620
d8a4995
98444de
c01c29f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -151,7 +151,10 @@ export class AwsLambdaInstrumentation extends InstrumentationBase { | |
| ) { | ||
| const httpHeaders = | ||
| typeof event.headers === 'object' ? event.headers : {}; | ||
| const parent = AwsLambdaInstrumentation._determineParent(httpHeaders); | ||
| const parent = AwsLambdaInstrumentation._determineParent( | ||
| httpHeaders, | ||
| Boolean(plugin._config.disableAwsPropagation) | ||
nirsky marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ); | ||
|
|
||
| const name = context.functionName; | ||
| const span = plugin.tracer.startSpan( | ||
|
|
@@ -298,29 +301,34 @@ export class AwsLambdaInstrumentation extends InstrumentationBase { | |
| } | ||
|
|
||
| private static _determineParent( | ||
| httpHeaders: APIGatewayProxyEventHeaders | ||
| httpHeaders: APIGatewayProxyEventHeaders, | ||
| disableAwsPropagation: boolean | ||
| ): OtelContext { | ||
| let parent: OtelContext | undefined = undefined; | ||
| const lambdaTraceHeader = process.env[traceContextEnvironmentKey]; | ||
| if (lambdaTraceHeader) { | ||
| parent = awsPropagator.extract( | ||
| otelContext.active(), | ||
| { [AWSXRAY_TRACE_ID_HEADER]: lambdaTraceHeader }, | ||
| headerGetter | ||
| ); | ||
| } | ||
| if (parent) { | ||
| const spanContext = trace.getSpan(parent)?.spanContext(); | ||
| if ( | ||
| spanContext && | ||
| (spanContext.traceFlags & TraceFlags.SAMPLED) === TraceFlags.SAMPLED | ||
| ) { | ||
| // Trace header provided by Lambda only sampled if a sampled context was propagated from | ||
| // an upstream cloud service such as S3, or the user is using X-Ray. In these cases, we | ||
| // need to use it as the parent. | ||
| return parent; | ||
|
|
||
| if (!disableAwsPropagation) { | ||
| const lambdaTraceHeader = process.env[traceContextEnvironmentKey]; | ||
| if (lambdaTraceHeader) { | ||
| parent = awsPropagator.extract( | ||
| otelContext.active(), | ||
| { [AWSXRAY_TRACE_ID_HEADER]: lambdaTraceHeader }, | ||
| headerGetter | ||
| ); | ||
| } | ||
| if (parent) { | ||
| const spanContext = trace.getSpan(parent)?.spanContext(); | ||
| if ( | ||
| spanContext && | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry to have this idea this late but does it work to add a check that that span context is valid and no need for the option? I just realized that I think in the problematic case the context has sampled = false, but actually doesn't have a valid span ID either and that could be enough of a signal
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you mean by checking that the span context is valid? Doesn't the Consider the following:
We end up only having spans
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think if spanContext is only in the case that there is no span in the context, in practice I don't know if it can actually happen with this code. There is an isSpanContextValid function https://www.github.com/open-telemetry/opentelemetry-js-api/tree/main/src%2Fapi%2Ftrace.ts For that use case, is the idea for the customer to have the trace both in x-ray and another backend via the collector and show the same trace in them?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this use case, the customer is interested only in having
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In that case they can disable x-ray right? Is there a reason to enable it and be charged even without needing y?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some of our customers may have an existing x-ray set-up and may want to use our product in addition to other usages, without integrating x-ray traces into our product. Anyway, IMO it's up for the user to decide, each one has different considerations and it's reasonable to let the user decide how to configure this |
||
| (spanContext.traceFlags & TraceFlags.SAMPLED) === TraceFlags.SAMPLED | ||
| ) { | ||
| // Trace header provided by Lambda only sampled if a sampled context was propagated from | ||
| // an upstream cloud service such as S3, or the user is using X-Ray. In these cases, we | ||
| // need to use it as the parent. | ||
| return parent; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // There was not a sampled trace header from Lambda so try from HTTP headers. | ||
| const httpContext = propagation.extract( | ||
| otelContext.active(), | ||
|
|
||

Uh oh!
There was an error while loading. Please reload this page.