Skip to content

Export more utility functions #7152

Description

@jeengbe

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:

exportfunctionsetTransactionName(name: string): void{Sentry.getCurrentHub().getStack()[0]?.scope?.setTransactionName(name);}exportfunctiondropTransaction(){Sentry.getCurrentHub().getStack()[0]?.scope?.setTag('dropTransaction',true);}exportfunctionstartSpan(name: string,spanContext?: Parameters<Sentry.Span['startChild']>[0],pushScope=true): Sentry.Span|undefined{constspan=Sentry.getCurrentHub().getScope()?.getSpan()?.startChild({op: name,
...spanContext,});if(pushScope){Sentry.getCurrentHub().pushScope().setSpan(span);}returnspan;}exportfunctionendSpan(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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions