@opentelemetry/propagator-aws-xray-lambda
Version:
OpenTelemetry AWS Xray propagator provides context propagation for systems that are using AWS X-Ray format.
51 lines • 2.24 kB
JavaScript
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.AWSXRayLambdaPropagator = exports.AWSXRAY_TRACE_ID_ENV_VAR = void 0;
const api_1 = require("@opentelemetry/api");
const propagator_aws_xray_1 = require("@opentelemetry/propagator-aws-xray");
exports.AWSXRAY_TRACE_ID_ENV_VAR = '_X_AMZN_TRACE_ID';
/**
* Implementation of the AWS X-Ray Trace Header propagation protocol with special
* logic for handling Lambda X-ray environment variable.
*
* An example AWS Xray Tracing Header is shown below:
* X-Amzn-Trace-Id: Root=1-5759e988-bd862e3fe1be46a994272793;Parent=53995c3f42cd8ad8;Sampled=1
*/
class AWSXRayLambdaPropagator {
_awsXrayPropagator = new propagator_aws_xray_1.AWSXRayPropagator();
inject(context, carrier, setter) {
this._awsXrayPropagator.inject(context, carrier, setter);
}
extract(context, carrier, getter) {
const xrayContext = this._awsXrayPropagator.extract(context, carrier, getter);
const spanContext = api_1.trace.getSpanContext(context);
if (spanContext && (0, api_1.isSpanContextValid)(spanContext)) {
return xrayContext;
}
const xrayEnvVar = process.env[exports.AWSXRAY_TRACE_ID_ENV_VAR];
if (!xrayEnvVar) {
return xrayContext;
}
return this._awsXrayPropagator.extract(xrayContext, { [propagator_aws_xray_1.AWSXRAY_TRACE_ID_HEADER]: xrayEnvVar }, api_1.defaultTextMapGetter);
}
fields() {
return this._awsXrayPropagator.fields();
}
}
exports.AWSXRayLambdaPropagator = AWSXRayLambdaPropagator;
//# sourceMappingURL=AWSXRayLambdaPropagator.js.map
;