Skip to content

Commit 086a5da

Browse files
committed
added context propagation documentation and examples
1 parent 6abcf5e commit 086a5da

File tree

1 file changed

+32
-4
lines changed
  • plugins/node/opentelemetry-instrumentation-aws-lambda

1 file changed

+32
-4
lines changed

plugins/node/opentelemetry-instrumentation-aws-lambda/README.md

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,23 @@ The `lambdaHandler` should be specified as a string in the format `<file>.<handl
8585

8686
One way to determine if the `lambdaHandler` option should be used is to check the handler defined on your Lambda. This can be done by determining the value of the `_HANDLER` environment variable or by viewing the **Runtime Settings** of your Lambda in AWS Console. If the handler is what you expect, then the instrumentation should work without the `lambdaHandler` option. If the handler points to something else, then the `lambdaHandler` option should be used to explicitly specify the handler that should be instrumented.
8787

88-
### Active Tracing Context Propagation
88+
### Context Propagation
8989

90-
AWS Active Tracing can provide a parent context for the span generated by this instrumentation. In order to use this context, please use the [xray-lambda](https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/propagator-aws-xray-lambda) propagator.
90+
AWS Active Tracing can provide a parent context for the span generated by this instrumentation. Note that the span generated by Active Tracing is always reported only to AWS X-Ray. Therefore, if the OpenTelemetry SDK is configured to export traces to a backend other than AWS X-Ray, this will result in a broken trace.
9191

92-
Example usage:
92+
If you use version `<=0.45.0` of this package, then the Active Tracing context is used as the parent context by default if present. In this case, in order to prevent broken traces, set the `disableAwsContextPropagation` option to `false`.
93+
Additional propagators can be added in the TracerProvider configuration.
94+
95+
If you use version `>0.45.0`, the Active Tracing context is no longer used by default. In order to enable it, include the [AWSXRayLambdaPropagator](https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/propagator-aws-xray-lambda) propagator in the list of propagators provided to the TracerProvider via its configuration, or by including `xray-lambda` in the OTEL_PROPAGATORS environment variable (see the example below on using the env variable).
96+
97+
Note that there are two AWS-related propagators: [AWSXRayPropagator](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/propagators/propagator-aws-xray) and [AWSXRayLambdaPropagator](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/propagators/propagator-aws-xray-lambda). Here is a guideline for when to use one or the other:
98+
99+
- If you export traces to AWS X-Ray, then use the `AWSXRayLambdaPropagator` or the `xray-lambda` value in the OTEL_PROPAGATORS environment variable. This will handle the active tracing lambda context as well as X-Ray HTTP headers.
100+
- If you export traces to a backend other than AWS X-Ray, then use the `AWSXrayPropagator` or `xray` in the environment variable. This propagator only handles the X-Ray HTTP headers.
101+
102+
Examples:
103+
104+
1. Active Tracing is enabled and the OpenTelemetry SDK is configured to export traces to AWS X-Ray. In this case, configure the SDK to use the `AWSXRayLambdaPropagator`.
93105

94106
```js
95107
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
@@ -101,7 +113,7 @@ provider.register({
101113
});
102114
```
103115

104-
Alternatively, you can use the [auto-configuration-propagators](https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/metapackages/auto-configuration-propagators/README.md) package, which makes it possible to configure propagators via the `OTEL_PROPAGATORS` environment variable. In order to use the `AWSXRayLambdaPropagator`, set the env variable value to `xray-lambda`.
116+
Alternatively, use the `getPropagators()` function from the [auto-configuration-propagators](https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/metapackages/auto-configuration-propagators/README.md) package, and set the OTEL_PROPAGATORS environment variable to `xray-lambda`.
105117

106118
```js
107119
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
@@ -113,6 +125,22 @@ provider.register({
113125
});
114126
```
115127

128+
2. The OpenTelemetry SDK is configured to export traces to a backend other than AWX X-Ray, but the lambda function is invoked by other AWS services which send the context using the X-Ray HTTP headers. In this case, include the `AWSXRayPropagator`, which extracts context from the HTTP header but not the Lambda Active Tracing context.
129+
130+
```js
131+
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
132+
const { AWSXRayLambdaPropagator } = require('@opentelemetry/propagator-aws-xray-lambda');
133+
134+
const provider = new NodeTracerProvider();
135+
provider.register({
136+
propagator: new AWSXRayPropagator()
137+
});
138+
```
139+
140+
Alternatively, use the `auto-configuration-package` as in example #1 and set the OTEL_PROPAGATORS environment variable to `xray`.
141+
142+
For additional information, see the semantic conventions for lambda.
143+
116144
## Semantic Conventions
117145

118146
This package uses `@opentelemetry/semantic-conventions` version `1.22+`, which implements Semantic Convention [Version 1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md)

0 commit comments

Comments
 (0)