Skip to content

Commit 770bf6f

Browse files
authored
feat: Added server span transaction naming fallback to the url.path (#2966)
1 parent ef697a5 commit 770bf6f

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

lib/otel/segments/server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function rpcSegment({ agent, otelSpan, transaction, rpcSystem }) {
6262
}
6363

6464
function httpSegment({ agent, otelSpan, transaction, httpMethod }) {
65-
const httpUrl = otelSpan.attributes[ATTR_HTTP_URL] || '/Unknown'
65+
const httpUrl = otelSpan.attributes[ATTR_HTTP_URL] || '/unknown'
6666
transaction.nameState.setVerb(httpMethod)
6767
const requestUrl = url.parse(httpUrl, true)
6868
transaction.parsedUrl = requestUrl

lib/otel/span-processor.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,18 @@ module.exports = class NrSpanProcessor {
159159
this.reconcileHttpAttributes({ segment, span, transaction })
160160
}
161161

162-
// End the corresponding transaction for the entry point server span.
163-
// We do then when the span ends to ensure all data has been processed
164-
// for the corresponding server span.
162+
// If `http.route` was not emitted on server span, name the transaction from the path
163+
// to avoid transactions being named `*`
164+
if (transaction.parsedUrl) {
165+
transaction.nameState.appendPathIfEmpty(transaction.parsedUrl?.path)
166+
}
167+
// Add the status code to transaction name
165168
if (transaction.statusCode) {
166169
transaction.finalizeNameFromUri(transaction.parsedUrl, transaction.statusCode)
167170
}
171+
// End the corresponding transaction for the entry point server span.
172+
// We do then when the span ends to ensure all data has been processed
173+
// for the corresponding server span.
168174
transaction.end()
169175
}
170176

test/unit/lib/otel/segment-synthesizer.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -232,15 +232,15 @@ test('should create base http server segment', (t) => {
232232
}
233233
const span = createBaseHttpSpan({ tracer, spanContext })
234234
const { segment, transaction } = synthesizer.synthesize(span)
235-
assert.equal(segment.name, '/Unknown')
235+
assert.equal(segment.name, '/unknown')
236236
assert.equal(segment.id, span.spanContext().spanId)
237237
assert.equal(segment.parentId, segment.root.id)
238238
assert.ok(transaction)
239239
assert.equal(transaction.traceId, span.spanContext().traceId)
240-
assert.equal(transaction.url, '/Unknown')
240+
assert.equal(transaction.url, '/unknown')
241241
assert.equal(transaction.baseSegment.name, segment.name)
242242
const attrs = transaction.trace.attributes.get(DESTINATIONS.TRANS_TRACE)
243-
assert.equal(attrs['request.uri'], '/Unknown')
243+
assert.equal(attrs['request.uri'], '/unknown')
244244
assert.ok(!attrs['request.method'])
245245
assert.ok(transaction)
246246
})

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ test('server span(fallback) is bridged accordingly', (t, end) => {
443443

444444
const duration = hrTimeToMilliseconds(span.duration)
445445
assert.equal(duration, segment.getDurationInMillis())
446-
assert.equal(segment.name, 'WebTransaction/NormalizedUri/*')
446+
assert.equal(segment.name, 'WebTransaction/WebFrameworkUri//unknown')
447447

448448
const attrs = segment.getAttributes()
449449
assert.equal(attrs.host, expectedHost)
@@ -457,14 +457,14 @@ test('server span(fallback) is bridged accordingly', (t, end) => {
457457
'HttpDispatcher',
458458
'WebTransaction',
459459
'WebTransactionTotalTime',
460-
'WebTransactionTotalTime/NormalizedUri/*',
460+
'WebTransactionTotalTime/WebFrameworkUri//unknown',
461461
segment.name
462462
]
463463
for (const expectedMetric of expectedMetrics) {
464464
assert.equal(unscopedMetrics[expectedMetric].callCount, 1, `${expectedMetric} has correct callCount`)
465465
}
466466
assert.equal(unscopedMetrics.Apdex.apdexT, 0.1)
467-
assert.equal(unscopedMetrics['Apdex/NormalizedUri/*'].apdexT, 0.1)
467+
assert.equal(unscopedMetrics['Apdex/WebFrameworkUri//unknown'].apdexT, 0.1)
468468

469469
end()
470470
})

0 commit comments

Comments
 (0)