-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor toTraceparent into extractTraceparentData
- Loading branch information
1 parent
9824fd2
commit b707cfc
Showing
10 changed files
with
126 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { extractTraceparentData } from '../src/utils'; | ||
|
||
describe('extractTraceparentData', () => { | ||
test('no sample', () => { | ||
const data = extractTraceparentData('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bbbbbbbbbbbbbbbb') as any; | ||
|
||
expect(data).toBeDefined(); | ||
expect(data.parentSpanId).toEqual('bbbbbbbbbbbbbbbb'); | ||
expect(data.traceId).toEqual('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'); | ||
expect(data?.parentSampled).toBeUndefined(); | ||
}); | ||
|
||
test('sample true', () => { | ||
const data = extractTraceparentData('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bbbbbbbbbbbbbbbb-1') as any; | ||
|
||
expect(data).toBeDefined(); | ||
expect(data.parentSampled).toBeTruthy(); | ||
}); | ||
|
||
test('sample false', () => { | ||
const data = extractTraceparentData('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bbbbbbbbbbbbbbbb-0') as any; | ||
|
||
expect(data).toBeDefined(); | ||
expect(data.parentSampled).toBeFalsy(); | ||
}); | ||
|
||
test('just sample decision - false', () => { | ||
const data = extractTraceparentData('0') as any; | ||
|
||
expect(data).toBeDefined(); | ||
expect(data.traceId).toBeUndefined(); | ||
expect(data.spanId).toBeUndefined(); | ||
expect(data.parentSampled).toBeFalsy(); | ||
}); | ||
|
||
test('just sample decision - true', () => { | ||
const data = extractTraceparentData('1') as any; | ||
|
||
expect(data).toBeDefined(); | ||
expect(data.traceId).toBeUndefined(); | ||
expect(data.spanId).toBeUndefined(); | ||
expect(data.parentSampled).toBeTruthy(); | ||
}); | ||
|
||
test('invalid', () => { | ||
// trace id wrong length | ||
expect(extractTraceparentData('a-bbbbbbbbbbbbbbbb-1')).toBeUndefined(); | ||
|
||
// parent span id wrong length | ||
expect(extractTraceparentData('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-b-1')).toBeUndefined(); | ||
|
||
// parent sampling decision wrong length | ||
expect(extractTraceparentData('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bbbbbbbbbbbbbbbb-11')).toBeUndefined(); | ||
|
||
// trace id invalid hex value | ||
expect(extractTraceparentData('someStuffHereWhichIsNotAtAllHexy-bbbbbbbbbbbbbbbb-1')).toBeUndefined(); | ||
|
||
// parent span id invalid hex value | ||
expect(extractTraceparentData('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-alsoNotSuperHexy-1')).toBeUndefined(); | ||
|
||
// bogus sampling decision | ||
expect(extractTraceparentData('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bbbbbbbbbbbbbbbb-x')).toBeUndefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters