tagssentry

How to get custom tags that was set in Sentry


I'm using Sentry to track errors on my app and I set custom tags when I initialize Sentry.

Sentry.setTag('custom', 'custom tag value');

Later on in the app, I need this custom tag value, is there a way for me to retrieve it back? I've tried Sentry.getTag('custom') and it doesn't work. I've been looking at their documentation and I can't find any.


Solution

  • Sentry.getIsolationScope() gets you an object similar to this:

    const a = Sentry.getIsolationScope()
    console.log({a})
    
    {
      a: Scope {
      _notifyingListeners: false,
      _scopeListeners: [],
      _eventProcessors: [],
      _breadcrumbs: [],
      _attachments: [],
      _user: {},
      _tags: { custom: 'custom-value' },
      _extra: {},
      _contexts: {},
      _sdkProcessingMetadata: {},
      _propagationContext: {
      traceId: 'some_id',
      spanId: 'another_id'
      },
        _level: undefined,
        _span: undefined,
        _session: undefined,
        _transactionName: undefined,
        _fingerprint: undefined,
        _requestSession: undefined,
        _client: undefined
      }
    }
    

    https://docs.sentry.io/platforms/javascript/guides/nextjs/enriching-events/scopes/#isolation-scope