Skip to content

Commit d1402cc

Browse files
Lms24JPeer264
authored andcommitted
feat(core): Add low cardinality span name fallbacks (#23516)
Adds and exports fallback span name constants from `@sentry/core` which we can use to migrate span names to be low-cardinality when span streaming is enabled. Doing this upfront to avoid merge/rebase conflicts when we split up the name migration. Thanks @nicohrubec for the suggestion! All fallbacks taken from: https://getsentry.github.io/sentry-conventions/attributes/ ref #22350
1 parent fa26541 commit d1402cc

4 files changed

Lines changed: 86 additions & 13 deletions

File tree

.agents/skills/port-span-names/SKILL.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Span names must be low cardinality, per the [Sentry span name conventions](https
1111
This only applies when span streaming is enabled. With `traceLifecycle: 'static'` every span name must stay byte-identical to before.
1212

1313
`pageload` was ported first. Read it as the reference implementation before starting:
14-
`packages/core/src/spanNames.ts` (the constant), `packages/browser/src/tracing/browserTracingIntegration.ts`
14+
`packages/core/src/tracing/spans/spanNames.ts` (the constant), `packages/browser/src/tracing/browserTracingIntegration.ts`
1515
(a start site plus the scope guard in `startBrowserTracingPageLoadSpan`), and
1616
`grep -rn PAGELOAD_SPAN_NAME_FALLBACK packages/*/src` for the full set of call sites.
1717

@@ -32,14 +32,14 @@ These are non-negotiable. Every one of them was arrived at by rejecting the alte
3232
4. **Only the name changes.** Do not touch `sentry.source`, `url.template`, `http.route`, or any other attribute. They keep describing where the name came from.
3333
5. **Do not derive the name from attributes in code.** The conventions describe names as attribute templates, but you implement them by reusing the value the site _already_ has for `url.template` / `http.route`. No attribute lookups, no generic template resolver.
3434
6. **No helpers, no abstraction.** An inline ternary at each site. A shared `const` for the fallback string is fine (and required, see rule 6); a function that sets names or attributes is not.
35-
7. **The fallback must never reach `scope.setTransactionName`.** The scope's transaction name is what error events are grouped by, so it keeps the raw URL or the parameterized route — never `Pageload`/`Navigation`/etc. Export the fallback as a constant from `packages/core/src/spanNames.ts` so the guard cannot drift.
35+
7. **The fallback must never reach `scope.setTransactionName`.** The scope's transaction name is what error events are grouped by, so it keeps the raw URL or the parameterized route — never `Pageload`/`Navigation`/etc. Export the fallback as a constant from `packages/core/src/tracing/spans/spanNames.ts` so the guard cannot drift.
3636
8. **`sentry.segment.name` must never diverge from the segment span's name.** Any code that stamps it on a child span has to read it off the segment span, not off the scope.
3737

3838
## 1. Look up the convention
3939

4040
Read <https://getsentry.github.io/sentry-conventions/names/> and find the op. Each op lists attribute templates in priority order, ending in a static fallback — that fallback is your name. Examples: `pageload``Pageload`, `navigation``Navigation`, database ops → `Database operation`.
4141

42-
Add it next to `PAGELOAD_SPAN_NAME_FALLBACK` in `packages/core/src/spanNames.ts` and export it from `shared-exports.ts`. Every package imports it from `@sentry/core` directly — no re-export from `@sentry/browser` is needed.
42+
Add it next to `PAGELOAD_SPAN_NAME_FALLBACK` in `packages/core/src/tracing/spans/spanNames.ts` and export it from `shared-exports.ts`. Every package imports it from `@sentry/core` directly — no re-export from `@sentry/browser` is needed.
4343

4444
## 2. Find every site that names a span with this op
4545

packages/core/src/constants.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,2 @@
11
export const DEFAULT_ENVIRONMENT = 'production';
22
export const DEV_ENVIRONMENT = 'development';
3-
4-
/**
5-
* The name of a pageload span when span streaming is enabled and no parameterized route is
6-
* available. Span names have to be low cardinality, so a raw URL must never be used instead.
7-
*
8-
* This is a span name only: it must never be set as the scope's transaction name, which is what
9-
* error events are grouped by.
10-
*/
11-
export const PAGELOAD_SPAN_NAME_FALLBACK = 'Pageload';

packages/core/src/shared-exports.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export type { OfflineStore, OfflineTransportOptions } from './transports/offline
1010
export type { IntegrationIndex } from './integration';
1111
export * from './tracing';
1212
export * from './semanticAttributes';
13+
export * from './tracing/spans/spanNames';
1314
export type { RawAttributes } from './attributes';
1415
export { createEventEnvelope, createSessionEnvelope } from './envelope';
1516
export {
@@ -136,7 +137,7 @@ export {
136137
MAX_BODY_BYTE_LENGTH,
137138
} from './utils/request';
138139
export type { MaxRequestBodySize } from './utils/request';
139-
export { DEFAULT_ENVIRONMENT, DEV_ENVIRONMENT, PAGELOAD_SPAN_NAME_FALLBACK } from './constants';
140+
export { DEFAULT_ENVIRONMENT, DEV_ENVIRONMENT } from './constants';
140141
export { spanKindToName } from './spanKind';
141142
export type { SpanKind, SpanKindNumber } from './spanKind';
142143
export { addBreadcrumb } from './breadcrumbs';
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// This file contains constants for fallback span names to be used, when no
2+
// better-suited, low-cardinality span name is available.
3+
// Only relevant when span streaming is enabled.
4+
5+
/**
6+
* Fallback name for pageload spans when no better-suited span name is available.
7+
* @see https://getsentry.github.io/sentry-conventions/names/#browser-pageload
8+
*/
9+
export const PAGELOAD_SPAN_NAME_FALLBACK = 'Pageload';
10+
11+
/**
12+
* Fallback name for navigation spans when no better-suited span name is available.
13+
* @see https://getsentry.github.io/sentry-conventions/names/#browser-navigation
14+
*/
15+
export const NAVIGATION_SPAN_NAME_FALLBACK = 'Navigation';
16+
17+
/**
18+
* Fallback name for db spans when no better-suited span name is available.
19+
* @see https://getsentry.github.io/sentry-conventions/names/#db-queries
20+
*/
21+
export const DB_SPAN_NAME_FALLBACK = 'Database operation';
22+
23+
/**
24+
* Fallback name for gen_ai agent spans when no better-suited span name is available.
25+
* @see https://getsentry.github.io/sentry-conventions/names/#gen_ai-agent
26+
*/
27+
export const GEN_AI_AGENT_SPAN_NAME_FALLBACK = 'Generative AI agent operation';
28+
29+
/**
30+
* Fallback name for gen_ai model spans when no better-suited span name is available.
31+
* @see https://getsentry.github.io/sentry-conventions/names/#gen_ai-inference
32+
*/
33+
export const GEN_AI_INFERENCE_SPAN_NAME_FALLBACK = 'Generative AI model operation';
34+
35+
/**
36+
* Fallback name for graphql spans when no better-suited span name is available.
37+
* @see https://getsentry.github.io/sentry-conventions/names/#graphql-graphql
38+
*/
39+
export const GRAPHQL_SPAN_NAME_FALLBACK = 'GraphQL Operation';
40+
41+
/**
42+
* Fallback name for http.(client|server) spans when no better-suited span name is available.
43+
* @see https://getsentry.github.io/sentry-conventions/names/#http
44+
*/
45+
export const HTTP_SPAN_NAME_FALLBACK = 'HTTP';
46+
47+
/**
48+
* Fallback name for messaging spans when no better-suited span name is available.
49+
* @see https://getsentry.github.io/sentry-conventions/names/#messaging
50+
*/
51+
export const MESSAGING_SPAN_NAME_FALLBACK = 'Messaging';
52+
53+
/**
54+
* Fallback name for mcp server spans when no better-suited span name is available.
55+
* @see https://getsentry.github.io/sentry-conventions/names/#mcp-server
56+
*/
57+
export const MCP_SERVER_SPAN_NAME_FALLBACK = 'MCP server operation';
58+
59+
/**
60+
* Fallback name for mcp notification spans when no better-suited span name is available.
61+
* @see https://getsentry.github.io/sentry-conventions/names/#mcp-notification
62+
*/
63+
export const MCP_NOTIFICATION_SPAN_NAME_FALLBACK = 'MCP notification';
64+
65+
/**
66+
* Fallback name for resource spans when no better-suited span name is available.
67+
* @see https://getsentry.github.io/sentry-conventions/names/#resource-resources
68+
*/
69+
export const RESOURCE_SPAN_NAME_FALLBACK = 'Resource';
70+
71+
/**
72+
* Fallback name for router spans when no better-suited span name is available.
73+
* @see https://getsentry.github.io/sentry-conventions/names/#routing-router
74+
*/
75+
export const ROUTER_SPAN_NAME_FALLBACK = 'Router';
76+
77+
/**
78+
* Fallback name for request handler spans when no better-suited span name is available.
79+
* @see https://getsentry.github.io/sentry-conventions/names/#resource-resources
80+
*/
81+
export const REQUEST_HANDLER_SPAN_NAME_FALLBACK = 'Request Handler';

0 commit comments

Comments
 (0)