UNPKG

enhanced-adot-node-autoinstrumentation

Version:

This package provides Amazon Web Services distribution of the OpenTelemetry Node Instrumentation, which allows for auto-instrumentation of NodeJS applications.

56 lines 2.78 kB
"use strict"; // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 // Modifications Copyright The OpenTelemetry Authors. Licensed under the Apache License 2.0 License. Object.defineProperty(exports, "__esModule", { value: true }); exports.AwsBatchUnsampledSpanProcessor = void 0; const api_1 = require("@opentelemetry/api"); const aws_attribute_keys_1 = require("./aws-attribute-keys"); const BatchSpanProcessorBase_1 = require("@opentelemetry/sdk-trace-base/build/src/export/BatchSpanProcessorBase"); /** * This class is a customized version of the `BatchSpanProcessorBase` from the * OpenTelemetry SDK (`@opentelemetry/sdk-trace-base/build/src/export/BatchSpanProcessorBase`). * It inherits much of the behavior of the `BatchSpanProcessorBase` while adding * specific logic to handle unsampled spans. * * It can't directly be inherited `BatchSpanProcessorBase` as child class because * a few stateful fields are private in `BatchSpanProcessorBase` which need to be accessed * in `AwsBatchUnsampledSpanProcessor` and we don't plan to update upstream code for it. * * In particular, the following methods are modified: * * 1. `onStart`: This method is modified to detect unsampled spans and add an * AWS-specific attribute (`AWS_TRACE_FLAG_SAMPLED`) to denote that the span * is unsampled. This is done by checking the `traceFlags` of the span. * * 2. `onEnd`: The logic here is changed to handle unsampled spans. While the * default behavior of `BatchSpanProcessorBase` is to ignore unsampled spans, * this version adds them to the buffer for export. The unsampled spans are * queued and processed similarly to sampled spans. * * This processor ensures that even unsampled spans are exported, which is a * deviation from the typical span processing behavior in OpenTelemetry. * * The rest of the behavior—batch processing, queuing, and exporting spans in * batches—is inherited from the base class and remains largely the same. */ class AwsBatchUnsampledSpanProcessor extends BatchSpanProcessorBase_1.BatchSpanProcessorBase { onStart(span, _parentContext) { if ((span.spanContext().traceFlags & api_1.TraceFlags.SAMPLED) === 0) { span.setAttribute(aws_attribute_keys_1.AWS_ATTRIBUTE_KEYS.AWS_TRACE_FLAG_SAMPLED, false); return; } } onEnd(span) { if (this._shutdownOnce.isCalled) { return; } if ((span.spanContext().traceFlags & api_1.TraceFlags.SAMPLED) === 1) { return; } this._addToBuffer(span); } onShutdown() { } } exports.AwsBatchUnsampledSpanProcessor = AwsBatchUnsampledSpanProcessor; //# sourceMappingURL=aws-batch-unsampled-span-processor.js.map