Skip to content

Commit

Permalink
fix: use url.path || http.target for sampling decision (#258)
Browse files Browse the repository at this point in the history
closes #255
  • Loading branch information
sjvans authored Nov 28, 2024
1 parent 062151d commit 86474f8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
The format is based on [Keep a Changelog](http://keepachangelog.com/).

## Version 1.1.1 - 2024-11-28

### Fixed

- Use attribute `url.path` (with fallback to deprecated `http.target`) for sampling decision

## Version 1.1.0 - 2024-11-27

### Added
Expand Down
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cap-js/telemetry",
"version": "1.1.0",
"version": "1.1.1",
"description": "CDS plugin providing observability features, incl. automatic OpenTelemetry instrumentation.",
"repository": {
"type": "git",
Expand Down

0 comments on commit 86474f8

Please sign in to comment.