Problem Statement
Currently, in order not to go with sentry.gethub.getscope.getspan and the same for scope all over the application, we use a couple of utility methods:
export function setTransactionName(name: string): void {
Sentry.getCurrentHub().getStack()[0]?.scope?.setTransactionName(name);
}
export function dropTransaction() {
Sentry.getCurrentHub().getStack()[0]?.scope?.setTag('dropTransaction', true);
}
export function startSpan(
name: string,
spanContext?: Parameters<Sentry.Span['startChild']>[0],
pushScope = true
): Sentry.Span | undefined {
const span = Sentry.getCurrentHub()
.getScope()
?.getSpan()
?.startChild({
op: name,
...spanContext,
});
if (pushScope) {
Sentry.getCurrentHub().pushScope().setSpan(span);
}
return span;
}
export function endSpan(span: Sentry.Span | undefined, popScope = true): void {
if (!span) {
return;
}
span.finish();
if (popScope) {
Sentry.getCurrentHub().popScope();
}
}
especially the Sentry.getCurrentHub().getStack()[0]?.scope part is tricky.
Solution Brainstorm
Are those methods even correct? If they are, the sdk should export something similar itself
Problem Statement
Currently, in order not to go with
sentry.gethub.getscope.getspanand the same for scope all over the application, we use a couple of utility methods:especially the
Sentry.getCurrentHub().getStack()[0]?.scopepart is tricky.Solution Brainstorm
Are those methods even correct? If they are, the sdk should export something similar itself