-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: Add span creators to @sentry/tracing package #2736
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
AbhiPrasad
merged 13 commits into
abhi/ref/add-sentry-tracing
from
abhi/feat/tracing-span-creators
Jul 14, 2020
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2647f18
feat: errors
AbhiPrasad 64d1efc
feat: Max Transaction Duration
AbhiPrasad 644fb78
feat: Background tab detection
AbhiPrasad 51ec856
feat: Request instrumentation
AbhiPrasad a9b91c5
feat: metrics
AbhiPrasad bede869
add more logging
AbhiPrasad a55c8be
trim transactions
AbhiPrasad ea0686e
test for request
AbhiPrasad 3e55bf6
remove comment
AbhiPrasad 0a5e72a
ref: Make sure tracingOrigins is set properly
AbhiPrasad ee5b4c4
ref: Address PR review
AbhiPrasad e8c5d00
address PR review 2
AbhiPrasad da4b39a
entryScriptStartTimestamp
AbhiPrasad 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,32 @@ | ||
import { getGlobalObject, logger } from '@sentry/utils'; | ||
|
||
import { IdleTransaction } from '../idletransaction'; | ||
import { SpanStatus } from '../spanstatus'; | ||
|
||
import { getActiveTransaction } from './utils'; | ||
|
||
const global = getGlobalObject<Window>(); | ||
|
||
/** | ||
* Add a listener that cancels and finishes a transaction when the global | ||
* document is hidden. | ||
*/ | ||
export function registerBackgroundTabDetection(): void { | ||
if (global && global.document) { | ||
global.document.addEventListener('visibilitychange', () => { | ||
const activeTransaction = getActiveTransaction() as IdleTransaction; | ||
if (global.document.hidden && activeTransaction) { | ||
logger.log( | ||
`[Tracing] Transaction: ${SpanStatus.Cancelled} -> since tab moved to the background, op: ${ | ||
activeTransaction.op | ||
}`, | ||
); | ||
activeTransaction.setStatus(SpanStatus.Cancelled); | ||
activeTransaction.setTag('visibilitychange', 'document.hidden'); | ||
activeTransaction.finish(); | ||
} | ||
}); | ||
} else { | ||
logger.warn('[Tracing] Could not set up background tab detection due to lack of global document'); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { addInstrumentationHandler, logger } from '@sentry/utils'; | ||
|
||
import { SpanStatus } from '../spanstatus'; | ||
|
||
import { getActiveTransaction } from './utils'; | ||
|
||
/** | ||
* Configures global error listeners | ||
*/ | ||
export function registerErrorInstrumentation(): void { | ||
addInstrumentationHandler({ | ||
callback: errorCallback, | ||
type: 'error', | ||
}); | ||
addInstrumentationHandler({ | ||
callback: errorCallback, | ||
type: 'unhandledrejection', | ||
}); | ||
} | ||
|
||
/** | ||
* If an error or unhandled promise occurs, we mark the active transaction as failed | ||
*/ | ||
function errorCallback(): void { | ||
const activeTransaction = getActiveTransaction(); | ||
if (activeTransaction) { | ||
logger.log(`[Tracing] Transaction: ${SpanStatus.InternalError} -> Global error occured`); | ||
activeTransaction.setStatus(SpanStatus.InternalError); | ||
} | ||
} |
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.
_emitOptionsWarning
is based ontracingOrigins
only, which we have access to here. Not sure if it's necessary to store it in the class.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.
Good point, I will refactor the logic here.
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.
Also, this is here because we cannot call it in the constructor, and we want to warn the user if they haven't manually set the
_option
themselves.