getsentry / getsentry/sentry-javascript

Rework span start and end lifecycle hook emission

Open
#21,368 1 comment 0 reactions 1 assignee Claimed by @Lms24 View on GitHub
Core javascript Spans
Dominant language
TypeScript
Stars
8.7k
Forks
1.8k
Avg merge
1d 17h
Merged PRs (30d)
515

Description

Currently, the behaviour for `spanStart` and `spanEnd`/`afterSpanEnd` client hook event emissions is a bit inconsistent across SDKs and span types

### Sentry Spans (non-OTel path)

| Case | Span class | `spanStart` | `spanEnd` | Notes |
|---|---|---|---|---|
| **Sampled root** | `SentrySpan` | Yes | Yes (via `_onSpanEnded`) | |
| **Negatively sampled root** | `SentrySpan` (`sampled: false`) | **Yes** | **Yes** (via `_onSpanEnded`) | Hooks fire, listeners must guard themselves |
| **Sampled child** | `SentrySpan` | **Yes** | **Yes** (via `_onSpanEnded`) | |
| **Negatively sampled child** | `SentryNonRecordingSpan` | **Yes** | **No** (`end()` is no-op) | **Unpaired!** `spanStart` fires, `spanEnd` never does |
| **Ignored span** | `SentryNonRecordingSpan` | **No** (returns before `_startChildSpan`) | **No** | |
| **`onlyIfParent`**, no parent | `SentryNonRecordingSpan` | **No** (created before `createChildOrRootSpan`) | **No** | |
| **Tracing disabled** | `SentryNonRecordingSpan` | **No** (`hasSpansEnabled()` = false) | **No** | |

### OTel Spans

| Case | OTel `SamplingDecision` | Reaches processor? | `spanStart` | `spanEnd` |
|---|---|---|---|---|
| **Sampled root** | `RECORD_AND_SAMPLED` | Yes | Yes | Yes |
| **Negatively sampled root** | `NOT_RECORD` | No | No | No |
| **Sampled child** | `RECORD_AND_SAMPLED` | Yes | Yes | Yes |
| **Negatively sampled child** | `NOT_RECORD` | No | No | No |
| **Ignored span** | `NOT_RECORD` | No | No | No |

### Goals

- We need to align on the behaviour and at the very least fix the unpaired occurance of the negatively sampled child span scenario
- We simplify which actor emits the events. Ideally, only the span classes (Sentry) and span processor (OTel) emit the hooks. Though this can be challenging with the cases where we early return for ignored/no_parent_span cases.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.