UNPKG

@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.

45 lines 1.78 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NextJsSpanProcessor = void 0; // Workaround for high cardinality span names in Next.js // https://github.com/vercel/next.js/issues/54694 class NextJsSpanProcessor { onStart(span, _parentContext) { var _a; if (span.attributes['next.span_type'] === 'BaseServer.handleRequest') { this.handleRequestSpan = span; const queryIndex = this.handleRequestSpan.name.indexOf('?'); if (queryIndex === -1) { return; } const name = this.handleRequestSpan.name.slice(0, queryIndex); this.handleRequestSpan.updateName(name); return; } if (this.handleRequestSpan === undefined) { return; } if (span.attributes['next.span_name'] === 'resolve page components' && ((_a = span.parentSpanContext) === null || _a === void 0 ? void 0 : _a.spanId) === this.handleRequestSpan.spanContext().spanId && typeof span.attributes['next.route'] === 'string') { const rsc = this.handleRequestSpan.attributes['next.rsc'] === true ? 'rsc ' : ''; const method = this.handleRequestSpan.attributes['http.method'] || ''; const name = `${rsc}${method} ${span.attributes['next.route']}`; this.handleRequestSpan.updateName(name); } } onEnd(span) { if (span === this.handleRequestSpan) { this.handleRequestSpan = undefined; } } forceFlush() { return Promise.resolve(); } shutdown() { return Promise.resolve(); } } exports.NextJsSpanProcessor = NextJsSpanProcessor; //# sourceMappingURL=NextJsSpanProcessor.js.map