Skip to content

Commit 5403018

Browse files
authored
feat: Assign all attributes on internal spans to segment (#3000)
1 parent b808e00 commit 5403018

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

lib/otel/segments/internal.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
'use strict'
7-
const customRecorder = require('../../metrics/recorders/custom')
7+
const genericRecorder = require('../../metrics/recorders/generic')
88

99
module.exports = function createInternalSegment(agent, otelSpan) {
1010
const context = agent.tracer.getContext()
@@ -13,7 +13,7 @@ module.exports = function createInternalSegment(agent, otelSpan) {
1313
id: otelSpan?.spanContext()?.spanId,
1414
name,
1515
parent: context.segment,
16-
recorder: customRecorder,
16+
recorder: genericRecorder,
1717
transaction: context.transaction
1818
})
1919
return { segment, transaction: context.transaction }

lib/otel/span-processor.js

+2
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ module.exports = class NrSpanProcessor {
113113
this.reconcileProducerAttributes({ segment, span })
114114
} else if (span.kind === SpanKind.CLIENT && (span.attributes[ATTR_HTTP_METHOD] || span.attributes[ATTR_HTTP_REQUEST_METHOD])) {
115115
this.reconcileHttpExternalAttributes({ segment, span })
116+
} else {
117+
this.#reconciler.reconcile({ segment, otelSpan: span })
116118
}
117119

118120
this.addAWSLinkingAttributes({ segment, span })

test/versioned/otel-bridge/span.test.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,13 @@ test('mix internal and NR span tests', (t, end) => {
108108
helper.runInTransaction(agent, (tx) => {
109109
tx.name = 'otel-example-tx'
110110
tracer.startActiveSpan('main', (span) => {
111+
span.setAttribute('custom-key', 'custom-value')
111112
const segment = agent.tracer.getSegment()
112113
assert.equal(tx.traceId, span.spanContext().traceId)
113114
main(segment, tx)
114115
span.end()
116+
const attrs = segment.getAttributes()
117+
assert.equal(attrs['custom-key'], 'custom-value')
115118
assert.equal(span[otelSynthesis], undefined)
116119
assert.equal(segment.name, span.name)
117120
assert.equal(segment.parentId, tx.trace.root.id)
@@ -128,13 +131,13 @@ test('mix internal and NR span tests', (t, end) => {
128131
]
129132
})
130133
const metrics = tx.metrics.scoped[tx.name]
131-
assert.equal(metrics['Custom/main'].callCount, 1)
132-
assert.equal(metrics['Custom/hi'].callCount, 1)
133-
assert.equal(metrics['Custom/bye'].callCount, 1)
134+
assert.equal(metrics['main'].callCount, 1)
135+
assert.equal(metrics['hi'].callCount, 1)
136+
assert.equal(metrics['bye'].callCount, 1)
134137
const unscopedMetrics = tx.metrics.unscoped
135-
assert.equal(unscopedMetrics['Custom/main'].callCount, 1)
136-
assert.equal(unscopedMetrics['Custom/hi'].callCount, 1)
137-
assert.equal(unscopedMetrics['Custom/bye'].callCount, 1)
138+
assert.equal(unscopedMetrics['main'].callCount, 1)
139+
assert.equal(unscopedMetrics['hi'].callCount, 1)
140+
assert.equal(unscopedMetrics['bye'].callCount, 1)
138141
end()
139142
})
140143
})

0 commit comments

Comments
 (0)