@splunk/otel
Version:
The Splunk distribution of OpenTelemetry Node Instrumentation provides a Node agent that automatically instruments your Node application to capture and report distributed traces to Splunk APM.
67 lines • 2.57 kB
JavaScript
;
/*
* Copyright Splunk Inc.
*
* 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.SnapshotSpanProcessor = void 0;
const api_1 = require("@opentelemetry/api");
function shouldProcessContext(context) {
const parentSpan = api_1.trace.getSpan(context);
return parentSpan === undefined || parentSpan.spanContext().isRemote === true;
}
class SnapshotSpanProcessor {
constructor(options) {
// Mapping of span ID to trace ID.
// We can't reconstruct the parent span context in processors onEnd,
// so we store the trace ID for the span that started the snapshot.
this.snapshotSpans = new Map();
this.traceSnapshotBegin = options.traceSnapshotBegin;
this.traceSnapshotEnd = options.traceSnapshotEnd;
}
onStart(span, parentContext) {
var _a;
if (!shouldProcessContext(parentContext)) {
return;
}
const baggage = api_1.propagation.getBaggage(parentContext);
if (baggage === undefined) {
return;
}
const volumeFromBaggage = (_a = baggage.getEntry('splunk.trace.snapshot.volume')) === null || _a === void 0 ? void 0 : _a.value;
if (volumeFromBaggage === 'highest') {
span.setAttribute('splunk.snapshot.profiling', true);
const spanCtx = span.spanContext();
this.snapshotSpans.set(spanCtx.spanId, spanCtx.traceId);
this.traceSnapshotBegin(span.spanContext().traceId);
}
}
onEnd(span) {
const spanId = span.spanContext().spanId;
const traceId = this.snapshotSpans.get(spanId);
if (traceId === undefined) {
return;
}
this.traceSnapshotEnd(traceId);
this.snapshotSpans.delete(spanId);
}
forceFlush() {
return Promise.resolve();
}
shutdown() {
return Promise.resolve();
}
}
exports.SnapshotSpanProcessor = SnapshotSpanProcessor;
//# sourceMappingURL=SnapshotSpanProcessor.js.map