-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(tracing): Clean up sampling decision inheritance #2921
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
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4240557
make explicit sampling decision win
lobsterkatie 8168f83
always return the active transaction, even if sampled = false
lobsterkatie d9fe8c6
make beforeNavigate always return transaction
lobsterkatie 436deb1
stop using <meta> tag data for navigation transactions
lobsterkatie fafce5b
add tracing enablement check to xhr and fetch callbacks
lobsterkatie ba7c51c
add tests for sampling decision propagation for XHR requests
lobsterkatie 01efccf
remove plan to deprecate beforeNavigate returning undefined
lobsterkatie 62e1701
revert getTransaction() change, skip tests that that change breaks
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
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 |
---|---|---|
|
@@ -7,6 +7,7 @@ import { | |
BrowserTracing, | ||
BrowserTracingOptions, | ||
DEFAULT_MAX_TRANSACTION_DURATION_SECONDS, | ||
getHeaderContext, | ||
getMetaContent, | ||
} from '../../src/browser/browsertracing'; | ||
import { defaultRequestInstrumentionOptions } from '../../src/browser/request'; | ||
|
@@ -177,14 +178,15 @@ describe('BrowserTracing', () => { | |
expect(mockBeforeNavigation).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('does not create a transaction if it returns undefined', () => { | ||
// TODO add this back in once getTransaction() returns sampled = false transactions, too | ||
it.skip('creates a transaction with sampled = false if it returns undefined', () => { | ||
const mockBeforeNavigation = jest.fn().mockReturnValue(undefined); | ||
createBrowserTracing(true, { | ||
beforeNavigate: mockBeforeNavigation, | ||
routingInstrumentation: customRoutingInstrumentation, | ||
}); | ||
const transaction = getActiveTransaction(hub) as IdleTransaction; | ||
expect(transaction).not.toBeDefined(); | ||
expect(transaction.sampled).toBe(false); | ||
|
||
expect(mockBeforeNavigation).toHaveBeenCalledTimes(1); | ||
}); | ||
|
@@ -379,5 +381,67 @@ describe('BrowserTracing', () => { | |
expect(metaTagValue).toBe(content); | ||
}); | ||
}); | ||
lobsterkatie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
describe('getHeaderContext', () => { | ||
it('correctly parses a valid sentry-trace meta header', () => { | ||
document.head.innerHTML = `<meta name="sentry-trace" content="12312012123120121231201212312012-1121201211212012-0">`; | ||
|
||
const headerContext = getHeaderContext(); | ||
|
||
expect(headerContext).toBeDefined(); | ||
expect(headerContext!.traceId).toEqual('12312012123120121231201212312012'); | ||
expect(headerContext!.parentSpanId).toEqual('1121201211212012'); | ||
expect(headerContext!.parentSampled).toEqual(false); | ||
}); | ||
|
||
it('returns undefined if the header is malformed', () => { | ||
document.head.innerHTML = `<meta name="sentry-trace" content="12312012-112120121-0">`; | ||
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. L: 💡 If we see a meta tag that is half-way there, Such invalid tags are most likely coming from a wrong setup in the backend. |
||
|
||
const headerContext = getHeaderContext(); | ||
|
||
expect(headerContext).toBeUndefined(); | ||
}); | ||
|
||
it("returns undefined if the header isn't there", () => { | ||
document.head.innerHTML = `<meta name="dogs" content="12312012123120121231201212312012-1121201211212012-0">`; | ||
|
||
const headerContext = getHeaderContext(); | ||
|
||
expect(headerContext).toBeUndefined(); | ||
}); | ||
}); | ||
|
||
describe('using the data', () => { | ||
// TODO add this back in once getTransaction() returns sampled = false transactions, too | ||
it.skip('uses the data for pageload transactions', () => { | ||
// make sampled false here, so we can see that it's being used rather than the tracesSampleRate-dictated one | ||
document.head.innerHTML = `<meta name="sentry-trace" content="12312012123120121231201212312012-1121201211212012-0">`; | ||
|
||
// pageload transactions are created as part of the BrowserTracing integration's initialization | ||
createBrowserTracing(true); | ||
const transaction = getActiveTransaction(hub) as IdleTransaction; | ||
|
||
expect(transaction).toBeDefined(); | ||
expect(transaction.op).toBe('pageload'); | ||
expect(transaction.traceId).toEqual('12312012123120121231201212312012'); | ||
expect(transaction.parentSpanId).toEqual('1121201211212012'); | ||
expect(transaction.sampled).toBe(false); | ||
}); | ||
|
||
it('ignores the data for navigation transactions', () => { | ||
mockChangeHistory = () => undefined; | ||
document.head.innerHTML = `<meta name="sentry-trace" content="12312012123120121231201212312012-1121201211212012-0">`; | ||
|
||
createBrowserTracing(true); | ||
|
||
mockChangeHistory({ to: 'here', from: 'there' }); | ||
const transaction = getActiveTransaction(hub) as IdleTransaction; | ||
|
||
expect(transaction).toBeDefined(); | ||
expect(transaction.op).toBe('navigation'); | ||
expect(transaction.traceId).not.toEqual('12312012123120121231201212312012'); | ||
expect(transaction.parentSpanId).toBeUndefined(); | ||
}); | ||
}); | ||
}); | ||
}); |
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
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.
Uh oh!
There was an error while loading. Please reload this page.