Skip to content

Commit

Permalink
make sampling rule matching case insensitive (#4972)
Browse files Browse the repository at this point in the history
  • Loading branch information
ida613 authored Dec 8, 2024
1 parent 9eb1180 commit af176d1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/dd-trace/src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ function isError (value) {

// Matches a glob pattern to a given subject string
function globMatch (pattern, subject) {
if (typeof pattern === 'string') pattern = pattern.toLowerCase()
if (typeof subject === 'string') subject = subject.toLowerCase()
let px = 0 // [p]attern inde[x]
let sx = 0 // [s]ubject inde[x]
let nextPx = 0
Expand Down
24 changes: 24 additions & 0 deletions packages/dd-trace/test/sampling_rule.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,30 @@ describe('sampling rule', () => {
expect(rule.match(spans[10])).to.equal(false)
})

it('should match with case-insensitive strings', () => {
const lowerCaseRule = new SamplingRule({
service: 'test',
name: 'operation'
})

const mixedCaseRule = new SamplingRule({
service: 'teSt',
name: 'oPeration'
})

expect(lowerCaseRule.match(spans[0])).to.equal(mixedCaseRule.match(spans[0]))
expect(lowerCaseRule.match(spans[1])).to.equal(mixedCaseRule.match(spans[1]))
expect(lowerCaseRule.match(spans[2])).to.equal(mixedCaseRule.match(spans[2]))
expect(lowerCaseRule.match(spans[3])).to.equal(mixedCaseRule.match(spans[3]))
expect(lowerCaseRule.match(spans[4])).to.equal(mixedCaseRule.match(spans[4]))
expect(lowerCaseRule.match(spans[5])).to.equal(mixedCaseRule.match(spans[5]))
expect(lowerCaseRule.match(spans[6])).to.equal(mixedCaseRule.match(spans[6]))
expect(lowerCaseRule.match(spans[7])).to.equal(mixedCaseRule.match(spans[7]))
expect(lowerCaseRule.match(spans[8])).to.equal(mixedCaseRule.match(spans[8]))
expect(lowerCaseRule.match(spans[9])).to.equal(mixedCaseRule.match(spans[9]))
expect(lowerCaseRule.match(spans[10])).to.equal(mixedCaseRule.match(spans[10]))
})

it('should match with regexp', () => {
rule = new SamplingRule({
service: /test/,
Expand Down

0 comments on commit af176d1

Please sign in to comment.