-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(tracing): Add initial tracestate
header handling
#3909
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
lobsterkatie
merged 28 commits into
kmclb-add-tracestate-header-handling
from
kmclb-rebase-tracestate-proof-of-concept
Aug 24, 2021
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
9cfe4c7
add TextEncoder and TextDecoder to jsdom test environment
lobsterkatie 37b4944
add TransactionMetadata to DebugMeta type
lobsterkatie 2ec4722
add segment to user type
lobsterkatie f9ba96c
add TraceHeaders and SpanContext.getTraceHeaders() to types
lobsterkatie bbf472d
add base64 string functions
lobsterkatie 9474a4e
fix circular dependency
lobsterkatie 6728b26
move setting default environment to SDK initialization rather than ev…
lobsterkatie 0af6717
remove unused traceHeaders function
lobsterkatie 5e57193
polyfill Object.fromEntries for tracing tests
lobsterkatie 5d53567
s/TRACEPARENT_REGEXP/SENTRY_TRACE_REGEX
lobsterkatie 2a50338
s/extractTraceparentData/extractSentrytraceData
lobsterkatie 54ac0d6
s/traceparent/sentrytrace in various spots
lobsterkatie 58eeda9
add functions for computing tracestate and combined tracing headers
lobsterkatie a758e16
add tracestate header to outgoing requests
lobsterkatie a007a83
deprecate toTraceparent
lobsterkatie 1a4336e
add extractTracestateData() function
lobsterkatie fcb41b3
make transactions accept metadata in their incoming transaction context
lobsterkatie f0f7ed6
propagate incoming tracestate headers
lobsterkatie 9ab5a8f
extract and propagate tracestate data from <meta> tags
lobsterkatie 08d9ba4
add missing tracestate when capturing transaction, if necessary
lobsterkatie 5c6070e
only deal with envelope header data if we're using an envelope
lobsterkatie 50819b6
add tracestate to envelope header
lobsterkatie 756e855
clean up comments
lobsterkatie a0b5caf
add http header tests
lobsterkatie f1a0dbf
random cleanup
lobsterkatie 6415a5a
don't stringify event data until the end
lobsterkatie 15a2e85
rework and add request tests
lobsterkatie dd76840
remove redundant string test, add browser test for non-base64 string
lobsterkatie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,17 @@ | ||
const JSDOMEnvironment = require('jest-environment-jsdom'); | ||
|
||
// TODO Node >= 8.3 includes the same TextEncoder and TextDecoder as exist in the browser, but they haven't yet been | ||
// added to jsdom. Until they are, we can do it ourselves. Once they do, this file can go away. | ||
|
||
// see https://github.com/jsdom/jsdom/issues/2524 and https://nodejs.org/api/util.html#util_class_util_textencoder | ||
|
||
module.exports = class DOMEnvironment extends JSDOMEnvironment { | ||
async setup() { | ||
await super.setup(); | ||
if (typeof this.global.TextEncoder === 'undefined') { | ||
const { TextEncoder, TextDecoder } = require('util'); | ||
this.global.TextEncoder = TextEncoder; | ||
this.global.TextDecoder = TextDecoder; | ||
} | ||
} | ||
}; |
This file contains hidden or 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,59 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { base64ToUnicode, unicodeToBase64 } from '@sentry/utils'; | ||
import { expect } from 'chai'; | ||
|
||
// See https://tools.ietf.org/html/rfc4648#section-4 for base64 spec | ||
// eslint-disable-next-line no-useless-escape | ||
const BASE64_REGEX = /([a-zA-Z0-9+/]{4})*(|([a-zA-Z0-9+/]{3}=)|([a-zA-Z0-9+/]{2}==))/; | ||
|
||
// NOTE: These tests are copied (and adapted for chai syntax) from `string.test.ts` in `@sentry/utils`. The | ||
// base64-conversion functions have a different implementation in browser and node, so they're copied here to prove they | ||
// work in a real live browser. If you make changes here, make sure to also port them over to that copy. | ||
describe('base64ToUnicode/unicodeToBase64', () => { | ||
const unicodeString = 'Dogs are great!'; | ||
const base64String = 'RG9ncyBhcmUgZ3JlYXQh'; | ||
|
||
it('converts to valid base64', () => { | ||
expect(BASE64_REGEX.test(unicodeToBase64(unicodeString))).to.be.true; | ||
}); | ||
|
||
it('works as expected (and conversion functions are inverses)', () => { | ||
expect(unicodeToBase64(unicodeString)).to.equal(base64String); | ||
expect(base64ToUnicode(base64String)).to.equal(unicodeString); | ||
}); | ||
|
||
it('can handle and preserve multi-byte characters in original string', () => { | ||
['🐶', 'Καλό κορίτσι, Μάιζεϊ!', 'Of margir hundar! Ég geri ráð fyrir að ég þurfi stærra rúm.'].forEach(orig => { | ||
expect(() => { | ||
unicodeToBase64(orig); | ||
}).not.to.throw; | ||
expect(base64ToUnicode(unicodeToBase64(orig))).to.equal(orig); | ||
}); | ||
}); | ||
|
||
it('throws an error when given invalid input', () => { | ||
expect(() => { | ||
unicodeToBase64(null as any); | ||
}).to.throw('Unable to convert to base64'); | ||
expect(() => { | ||
unicodeToBase64(undefined as any); | ||
}).to.throw('Unable to convert to base64'); | ||
expect(() => { | ||
unicodeToBase64({} as any); | ||
}).to.throw('Unable to convert to base64'); | ||
|
||
expect(() => { | ||
base64ToUnicode(null as any); | ||
}).to.throw('Unable to convert from base64'); | ||
expect(() => { | ||
base64ToUnicode(undefined as any); | ||
}).to.throw('Unable to convert from base64'); | ||
expect(() => { | ||
base64ToUnicode({} as any); | ||
}).to.throw('Unable to convert from base64'); | ||
expect(() => { | ||
// the exclamation point makes this invalid base64 | ||
base64ToUnicode('Dogs are great!'); | ||
}).to.throw('Unable to convert from base64'); | ||
}); | ||
}); |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -177,7 +177,6 @@ describe('BaseClient', () => { | |
const client = new TestClient({ dsn: PUBLIC_DSN }); | ||
client.captureException(new Error('test exception')); | ||
expect(TestBackend.instance!.event).toEqual({ | ||
environment: 'production', | ||
event_id: '42', | ||
exception: { | ||
values: [ | ||
|
@@ -246,7 +245,6 @@ describe('BaseClient', () => { | |
const client = new TestClient({ dsn: PUBLIC_DSN }); | ||
client.captureMessage('test message'); | ||
expect(TestBackend.instance!.event).toEqual({ | ||
environment: 'production', | ||
event_id: '42', | ||
level: 'info', | ||
message: 'test message', | ||
|
@@ -322,7 +320,6 @@ describe('BaseClient', () => { | |
client.captureEvent({ message: 'message' }, undefined, scope); | ||
expect(TestBackend.instance!.event!.message).toBe('message'); | ||
expect(TestBackend.instance!.event).toEqual({ | ||
environment: 'production', | ||
event_id: '42', | ||
message: 'message', | ||
timestamp: 2020, | ||
|
@@ -336,7 +333,6 @@ describe('BaseClient', () => { | |
client.captureEvent({ message: 'message', timestamp: 1234 }, undefined, scope); | ||
expect(TestBackend.instance!.event!.message).toBe('message'); | ||
expect(TestBackend.instance!.event).toEqual({ | ||
environment: 'production', | ||
event_id: '42', | ||
message: 'message', | ||
timestamp: 1234, | ||
|
@@ -349,28 +345,12 @@ describe('BaseClient', () => { | |
const scope = new Scope(); | ||
client.captureEvent({ message: 'message' }, { event_id: 'wat' }, scope); | ||
expect(TestBackend.instance!.event!).toEqual({ | ||
environment: 'production', | ||
event_id: 'wat', | ||
message: 'message', | ||
timestamp: 2020, | ||
}); | ||
}); | ||
|
||
test('sets default environment to `production` it none provided', () => { | ||
expect.assertions(1); | ||
const client = new TestClient({ | ||
dsn: PUBLIC_DSN, | ||
}); | ||
const scope = new Scope(); | ||
client.captureEvent({ message: 'message' }, undefined, scope); | ||
expect(TestBackend.instance!.event!).toEqual({ | ||
environment: 'production', | ||
event_id: '42', | ||
message: 'message', | ||
timestamp: 2020, | ||
}); | ||
}); | ||
|
||
test('adds the configured environment', () => { | ||
expect.assertions(1); | ||
const client = new TestClient({ | ||
|
@@ -412,7 +392,6 @@ describe('BaseClient', () => { | |
const scope = new Scope(); | ||
client.captureEvent({ message: 'message' }, undefined, scope); | ||
expect(TestBackend.instance!.event!).toEqual({ | ||
environment: 'production', | ||
event_id: '42', | ||
message: 'message', | ||
release: 'v1.0.0', | ||
|
@@ -453,7 +432,6 @@ describe('BaseClient', () => { | |
scope.setUser({ id: 'user' }); | ||
client.captureEvent({ message: 'message' }, undefined, scope); | ||
expect(TestBackend.instance!.event!).toEqual({ | ||
environment: 'production', | ||
event_id: '42', | ||
extra: { b: 'b' }, | ||
message: 'message', | ||
|
@@ -470,7 +448,6 @@ describe('BaseClient', () => { | |
scope.setFingerprint(['abcd']); | ||
client.captureEvent({ message: 'message' }, undefined, scope); | ||
expect(TestBackend.instance!.event!).toEqual({ | ||
environment: 'production', | ||
event_id: '42', | ||
fingerprint: ['abcd'], | ||
message: 'message', | ||
|
@@ -525,7 +502,6 @@ describe('BaseClient', () => { | |
expect(TestBackend.instance!.event!).toEqual({ | ||
breadcrumbs: [normalizedBreadcrumb, normalizedBreadcrumb, normalizedBreadcrumb], | ||
contexts: normalizedObject, | ||
environment: 'production', | ||
event_id: '42', | ||
extra: normalizedObject, | ||
timestamp: 2020, | ||
|
@@ -571,7 +547,6 @@ describe('BaseClient', () => { | |
expect(TestBackend.instance!.event!).toEqual({ | ||
breadcrumbs: [normalizedBreadcrumb, normalizedBreadcrumb, normalizedBreadcrumb], | ||
contexts: normalizedObject, | ||
environment: 'production', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These test changes seen unrelated to tracestate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my comment above re: setting default environment earlier. |
||
event_id: '42', | ||
extra: normalizedObject, | ||
timestamp: 2020, | ||
|
@@ -622,7 +597,6 @@ describe('BaseClient', () => { | |
expect(TestBackend.instance!.event!).toEqual({ | ||
breadcrumbs: [normalizedBreadcrumb, normalizedBreadcrumb, normalizedBreadcrumb], | ||
contexts: normalizedObject, | ||
environment: 'production', | ||
event_id: '42', | ||
extra: normalizedObject, | ||
timestamp: 2020, | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this related to tracestate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Environment is part of the data that goes into tracestate, so it needs to be set in time for that to happen. If the user provides an environment, we're already good, but if we need to use the default, at the moment that's not getting added until we're sending the event. This moves it earlier so that it's available when we compute the
tracestate
value.See #3242.