#Adding events to inactive spans

1 messages · Page 1 of 1 (latest)

magic ravine
#

Hi everyone 👋

I have span created with Sentry.startInactiveSpan function and somewhere while this span is live I'm adding events to it via span.addEvent. Unfortunately I don't see these events in Sentry's dashboard. Is there something I'm missing? LLM is telling me that inactive spans do not support events but no trace of this info in documentation. Can someone help me?

granite stag
#

do you have a code example of what you are doing?

magic ravine
#

Yeah,

I have hook in React Native application:

    useEffect(() => {
        const span = getSpan(spanId);
        if (!span || !reasonAttributes) {
            return;
        }

        const namespacedAttributes = Object.fromEntries(Object.entries(reasonAttributes).map(([key, value]) => [`${CONST.TELEMETRY.ATTRIBUTE_SKELETON_PREFIX}${key}`, value]));
        span.setAttributes(namespacedAttributes);
        span.addEvent(CONST.TELEMETRY.EVENT_SKELETON_ATTRIBUTES_UPDATE, namespacedAttributes);
    }, [reasonAttributes, spanId]);

On every props change this should find a related span and add Event to it. getSpan returns span created with this such function:

function startSpan(spanId: string, options: StartSpanOptions, extraOptions: StartSpanExtraOptions = {}) {
    // End any existing span for this name
    cancelSpan(spanId);
    const span = Sentry.startInactiveSpan(options);

    if (extraOptions.minDuration) {
        span.setAttribute(CONST.TELEMETRY.ATTRIBUTE_MIN_DURATION, extraOptions.minDuration);
    }
    activeSpans.set(spanId, span);

    return span;
}

SpanID is arbitrary name to be stored in applications memory. Unrelated to Sentry's ID convention.

Events added via span.addEvent are not visible in Sentry

worn plover
#

@magic ravine
I checked your code
startInactiveSpan() can return a non-recording span when tracing is disabled, or when the trace/span isn’t sampled.
In that case, setAttributes() / addEvent() are effectively no-ops and nothing will ever be sent to Sentry

magic ravine
#

Hi, thanks for the answer. We have tracing enabled with tracesSampleRate: 1.0, (but profilesSampleRate: Platform.OS === 'android' ? 0 : 0.3,).

Span is indeed sent to Sentry

charred yoke
#

Bumping!

granite stag
charred yoke
#

I'm in the same team as Hubert actually, we'd like to see the span showing all attribute values throughout its lifecyle