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.

49 lines 2.29 kB
"use strict"; // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 Object.defineProperty(exports, "__esModule", { value: true }); exports.AlwaysRecordSampler = void 0; const sdk_trace_base_1 = require("@opentelemetry/sdk-trace-base"); /** * This sampler will return the sampling result of the provided {@link #rootSampler}, unless the * sampling result contains the sampling decision {@link SamplingDecision.NOT_RECORD}, in which case, a * new sampling result will be returned that is functionally equivalent to the original, except that * it contains the sampling decision {@link SamplingDecision.RECORD}. This ensures that all * spans are recorded, with no change to sampling. * * <p>The intended use case of this sampler is to provide a means of sending all spans to a * processor without having an impact on the sampling rate. This may be desirable if a user wishes * to count or otherwise measure all spans produced in a service, without incurring the cost of 100% * sampling. */ class AlwaysRecordSampler { constructor(rootSampler) { if (rootSampler == null) { throw new Error('rootSampler is null/undefined. It must be provided'); } this.rootSampler = rootSampler; } static create(rootSampler) { return new AlwaysRecordSampler(rootSampler); } shouldSample(context, traceId, spanName, spanKind, attributes, links) { const rootSamplerSamplingResult = this.rootSampler.shouldSample(context, traceId, spanName, spanKind, attributes, links); if (rootSamplerSamplingResult.decision === sdk_trace_base_1.SamplingDecision.NOT_RECORD) { return this.wrapResultWithRecordOnlyResult(rootSamplerSamplingResult); } return rootSamplerSamplingResult; } toString() { return `AlwaysRecordSampler{${this.rootSampler.toString()}}`; } wrapResultWithRecordOnlyResult(result) { const wrappedResult = { decision: sdk_trace_base_1.SamplingDecision.RECORD, attributes: result.attributes, traceState: result.traceState, }; return wrappedResult; } } exports.AlwaysRecordSampler = AlwaysRecordSampler; //# sourceMappingURL=always-record-sampler.js.map