-
Notifications
You must be signed in to change notification settings - Fork 0
Add basic Sentry tracing instrumentation #4
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import * as Sentry from "@sentry/browser"; | ||
import { | ||
Integrations as ApmIntegrations, | ||
Span, | ||
Transaction, | ||
} from "@sentry/apm"; | ||
import { CaptureConsole as CaptureConsoleIntegration } from "@sentry/integrations"; | ||
|
||
const Tracing = ApmIntegrations.Tracing; | ||
|
||
export const setupSentry = (options: { [key: string]: any }) => { | ||
console.log(`[sentry] Initialized with DSN: ${options.dsn}`); | ||
Sentry.init({ | ||
tracesSampleRate: 1.0, | ||
...options, | ||
integrations: [ | ||
new CaptureConsoleIntegration({ | ||
levels: ["error"], | ||
}), | ||
new ApmIntegrations.Tracing(), | ||
], | ||
}); | ||
}; | ||
|
||
export const startSpan = (options: { | ||
description?: string; | ||
op?: string; | ||
}): Span | undefined => { | ||
const tracingIntegration = Sentry.getCurrentHub().getIntegration(Tracing); | ||
if (!tracingIntegration) { | ||
console.warn("startSpan called without tracing integration"); | ||
return undefined; | ||
} | ||
const transaction = (tracingIntegration as any).constructor.getTransaction(); | ||
if (!transaction) { | ||
console.info("startSpan called without transaction"); | ||
return undefined; | ||
} | ||
return transaction.startChild(options); | ||
}; | ||
|
||
export const startTransaction = (options: { | ||
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. this doesnt actually seem to work well.. to some degree i wanted to manually bind a transaction but the tracing integration couples them to itself, and theres no real APIs afaik to manage them without the idle helper 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. Can't you just use 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. damn - didnt find that one :( |
||
name: string; | ||
op?: string; | ||
description?: string; | ||
}): Transaction | undefined => { | ||
const hub = Sentry.getCurrentHub(); | ||
const tracingIntegration = hub.getIntegration(Tracing); | ||
if (!tracingIntegration) { | ||
console.warn("startTransaction called without tracing integration"); | ||
return undefined; | ||
} | ||
return Tracing.startIdleTransaction(options); | ||
}; |
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.
its not ideal that we have to attach a span to a transaction (aka we cant always return a span)