Skip to content

Commit

Permalink
Make DD_TRACE_SAMPLING_RULES consistent (#5232)
Browse files Browse the repository at this point in the history
* Make DD_TRACE_SAMPLING_RULES consistent
  • Loading branch information
khanayan123 authored Feb 19, 2025
1 parent 3582be4 commit 4733649
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/dd-trace/src/sampling_rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ function matcher (pattern, locator) {
return new RegExpMatcher(pattern, locator)
}

if (typeof pattern === 'string' && pattern !== '*') {
if (typeof pattern === 'string' && pattern !== '*' && pattern !== '**' && pattern !== '***') {
return new GlobMatcher(pattern, locator)
}

return new AlwaysMatcher()
}

Expand All @@ -63,6 +62,12 @@ function serviceLocator (span) {
span.tracer()._service
}

function resourceLocator (span) {
const { _tags: tags } = span.context()
return tags.resource ||
tags['resource.name']
}

class SamplingRule {
constructor ({ name, service, resource, tags, sampleRate = 1.0, provenance = undefined, maxPerSecond } = {}) {
this.matchers = []
Expand All @@ -74,7 +79,7 @@ class SamplingRule {
this.matchers.push(matcher(service, serviceLocator))
}
if (resource) {
this.matchers.push(matcher(resource, makeTagLocator('resource.name')))
this.matchers.push(matcher(resource, resourceLocator))
}
for (const [key, value] of Object.entries(tags || {})) {
this.matchers.push(matcher(value, makeTagLocator(key)))
Expand Down
2 changes: 2 additions & 0 deletions packages/dd-trace/src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ function isError (value) {
function globMatch (pattern, subject) {
if (typeof pattern === 'string') pattern = pattern.toLowerCase()
if (typeof subject === 'string') subject = subject.toLowerCase()
if (typeof subject === 'number' && Number.isInteger(subject)) subject = String(subject)

let px = 0 // [p]attern inde[x]
let sx = 0 // [s]ubject inde[x]
let nextPx = 0
Expand Down

0 comments on commit 4733649

Please sign in to comment.