UNPKG

@dynatrace/opentelemetry-core

Version:

Dynatrace OpenTelemetry core package

58 lines (55 loc) 2.4 kB
"use strict"; /* Copyright 2022 Dynatrace LLC 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 http://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.DtSampler = exports.DtFw4TagSampler = void 0; const api_1 = require("@opentelemetry/api"); const sdk_trace_base_1 = require("@opentelemetry/sdk-trace-base"); const SpanEmbedder_1 = require("../../export/SpanEmbedder"); // ============================================================================ /* eslint-disable @typescript-eslint/no-deprecated */ /** * Sampler that respects the ignore flag of the FW4 tag. If no FW4 tag exists the span * is sampled. */ class DtFw4TagSampler { shouldSample(context) { const parentSpanContext = api_1.trace.getSpanContext(context); const fw4Tag = (0, SpanEmbedder_1.getFw4Tag)(parentSpanContext === null || parentSpanContext === void 0 ? void 0 : parentSpanContext.traceState); return { decision: (fw4Tag === null || fw4Tag === void 0 ? void 0 : fw4Tag.isIgnored) ? api_1.SamplingDecision.NOT_RECORD : api_1.SamplingDecision.RECORD_AND_SAMPLED }; } toString() { return "DtFw4TagSampler"; } } exports.DtFw4TagSampler = DtFw4TagSampler; // ---------------------------------------------------------------------------- class DtSampler extends sdk_trace_base_1.ParentBasedSampler { constructor() { const fw4TagSampler = new DtFw4TagSampler(); super({ root: new sdk_trace_base_1.AlwaysOnSampler(), remoteParentNotSampled: fw4TagSampler, remoteParentSampled: fw4TagSampler, localParentNotSampled: new sdk_trace_base_1.AlwaysOffSampler(), localParentSampled: new sdk_trace_base_1.AlwaysOnSampler() }); } toString() { return "DtSampler"; } } exports.DtSampler = DtSampler; //# sourceMappingURL=DtSampler.js.map