Skip to content

Commit

Permalink
fix: use url.path || http.target for sampling decision
Browse files Browse the repository at this point in the history
  • Loading branch information
sjvans committed Nov 28, 2024
1 parent 062151d commit 95d7723
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/tracing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ function _getSampler() {
else {
// eslint-disable-next-line no-unused-vars
_shouldSample = (_context, _traceId, _name, _spanKind, attributes, _links) => {
const originalUrl = attributes?.['http.originalUrl']
if (!originalUrl) return true
return !ignoreIncomingPaths.some(p => originalUrl.startsWith(p))
const url_path = attributes?.['url.path'] || attributes?.['http.target'] //> http.target is deprecated
if (!url_path) return true
return !ignoreIncomingPaths.some(p => url_path.startsWith(p))
}
}

Expand Down
8 changes: 7 additions & 1 deletion lib/tracing/trace.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,13 @@ function trace(name, fn, targetObj, args, options = {}) {
kind: _determineKind(targetObj, name?.phase, isAsync, options)
}
// needed for sampling decision (cf. shouldSample)
if (cds.context?.http?.req) spanOptions.attributes = { 'http.originalUrl': cds.context.http?.req.originalUrl }
if (cds.context?.http?.req) {
const url_path = cds.context.http.req.baseUrl + cds.context.http.req.path
spanOptions.attributes = {
'url.path': url_path,
'http.target': url_path //> http.target is deprecated
}
}
if (HRTIME) spanOptions.startTime = _hrnow()
if (isAsync) {
spanOptions.links = [{ context: parentSpan.spanContext() }]
Expand Down

0 comments on commit 95d7723

Please sign in to comment.