Skip to content

Commit f2129aa

Browse files
committed
test(opentelemetry): read native exports in next span naming spec
Native mode passes DatadogSpan instances to the exporter instead of preformatted payload spans. Normalize the captured export in the Next OTel span-naming regression spec so it asserts the same name/resource contract on both exporter shapes.
1 parent e02d720 commit f2129aa

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

packages/dd-trace/test/opentelemetry/next-otel-span-naming.spec.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ const TracerProvider = require('../../src/opentelemetry/tracer_provider')
2020
const NEXT_HANDLE_REQUEST = 'BaseServer.handleRequest'
2121

2222
// Capture the span as the exporter receives it, i.e. after the trace has been
23-
// formatted and is about to be written. The Next root span is the only span in
24-
// its trace, so `Span.end()` -> `_ddSpan.finish()` builds and exports the
25-
// payload synchronously; asserting here proves the correction reached the wire
26-
// rather than a post-finish re-format that no exported trace ever sees.
23+
// formatted on the JS path or passed to the native exporter. The Next root span
24+
// is the only span in its trace, so `Span.end()` -> `_ddSpan.finish()` builds and
25+
// exports synchronously; asserting here proves the correction reached the export
26+
// boundary rather than a post-finish re-format that no exported trace ever sees.
2727
function captureExportedRootSpan (run) {
2828
const exporter = tracer._tracer._exporter
2929
const originalExport = exporter.export
@@ -36,7 +36,15 @@ function captureExportedRootSpan (run) {
3636
} finally {
3737
exporter.export = originalExport
3838
}
39-
return exported
39+
return normalizeExportedSpan(exported)
40+
}
41+
42+
function normalizeExportedSpan (span) {
43+
const context = span.context?.()
44+
return {
45+
name: span.name ?? context?._name,
46+
resource: span.resource ?? context?.getTag('resource.name'),
47+
}
4048
}
4149

4250
function startNextRootSpan ({ method = 'GET', initialName } = {}) {

0 commit comments

Comments
 (0)