Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
9cfe4c737b49442ec4722f9ba96cbbf472d9474a4e6728b260af67175e571935d535672a5033854ac0d658eeda9a758e16a007a831a4336efcb41b3f0f7ed69ab5a8f08d9ba45c6070e50819b6756e855a0b5caff1a0dbf6415a5a15a2e85dd76840File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| 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; | ||
| } | ||
| } | ||
| }; |
| 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'); | ||
| }); | ||
| }); |
| 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', | ||
Contributor 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 MemberAuthor 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, | ||
Uh oh!
There was an error while loading. Please reload this page.
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
tracestatevalue.See #3242.