Skip to content

Commit 475d31e

Browse files
isaacsclaude
andcommitted
chore(eslint-plugin-sdk): Check span origin categories
`sdk/valid-span-origin` now requires the category part of a literal origin to be a span op category, as the trace origin spec says. It need not match the op of the same span: `auto.ui.angular` on a `router` span is valid. This replaces the AGENTS.md line about origin categories. `faas` is allowed as a known exception. The `auto.faas.cloudflare.*` origins break the spec, but renaming them would break user queries in a minor release, so a TODO(v12) marks the rename. The runtime metrics integrations disable the rule, because the spec covers span and log origins, not metric origins. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 0e6f42e commit 475d31e

6 files changed

Lines changed: 63 additions & 7 deletions

File tree

‎AGENTS.md‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,6 @@ Uses **Git Flow** (see `docs/gitflow.md`).
7474
- `Sentry.init()` follows one rule for repeated calls: the first call wins. See
7575
`docs/repeated-init.md` before you add or change an `init()`.
7676

77-
- In a span origin, the second part is the span op category (`auto.queue.kafkajs.producer`, not
78-
`auto.kafkajs.producer`). `sdk/valid-span-origin` checks the rest of the format.
79-
8077
## Linting & Formatting
8178

8279
Use `pnpm run lint` (Oxlint) and `pnpm run format` (Oxfmt). Never run ESLint or Prettier, and never add their config

‎packages/bun/src/integrations/bunRuntimeMetrics.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,11 @@ export const bunRuntimeMetricsIntegration = defineIntegration((options: BunRunti
9393
let prevFlushTime: number = 0;
9494
let eluAvailable = false;
9595

96+
/* oxlint-disable sdk/valid-span-origin -- a metric origin; trace origin categories apply to spans and logs */
9697
const METRIC_ATTRIBUTES = { attributes: { [SENTRY_ORIGIN]: 'auto.bun.runtime_metrics' } };
9798
const METRIC_ATTRIBUTES_BYTE = { unit: 'byte', attributes: { [SENTRY_ORIGIN]: 'auto.bun.runtime_metrics' } };
9899
const METRIC_ATTRIBUTES_SECOND = { unit: 'second', attributes: { [SENTRY_ORIGIN]: 'auto.bun.runtime_metrics' } };
100+
/* oxlint-enable sdk/valid-span-origin */
99101

100102
function collectMetrics(): void {
101103
const now = _INTERNAL_safeDateNow();

‎packages/deno/src/integrations/denoRuntimeMetrics.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,10 @@ export const denoRuntimeMetricsIntegration = defineIntegration((options: DenoRun
8080
let intervalId: number | undefined;
8181
let prevFlushTime: number = 0;
8282

83+
/* oxlint-disable sdk/valid-span-origin -- a metric origin; trace origin categories apply to spans and logs */
8384
const METRIC_ATTRIBUTES_BYTE = { unit: 'byte', attributes: { [SENTRY_ORIGIN]: 'auto.deno.runtime_metrics' } };
8485
const METRIC_ATTRIBUTES_SECOND = { unit: 'second', attributes: { [SENTRY_ORIGIN]: 'auto.deno.runtime_metrics' } };
86+
/* oxlint-enable sdk/valid-span-origin */
8587

8688
function collectMetrics(): void {
8789
const now = _INTERNAL_safeDateNow();

‎packages/eslint-plugin-sdk/src/rules/valid-span-origin.js‎

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,55 @@
77
* It checks string literals written to an origin attribute, and string
88
* literals assigned to a constant whose name ends in `ORIGIN`. Origins
99
* built with a template literal or imported from elsewhere are not
10-
* checked. Whether the `category` part is the span op category
11-
* (`auto.queue.kafkajs.producer`, not `auto.kafkajs.producer`) needs a
12-
* human.
10+
* checked. The category must be a span op category
11+
* (`auto.queue.kafkajs.producer`, not `auto.kafkajs.producer`), but it
12+
* need not match the op of the same span.
1313
*/
1414

1515
const ORIGIN_KEYS = new Set(['SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN', 'SENTRY_ORIGIN', 'sentry.origin']);
1616
const ORIGIN_FORMAT = /^(auto|manual)(\.[a-zA-Z0-9_]+){0,3}$/;
1717
const TOOLING_PARTS = new Set(['otel', 'orchestrion']);
1818
const ORIGIN_CONSTANT = /(^|_)ORIGIN$/;
1919

20+
// Span op categories from https://develop.sentry.dev/sdk/telemetry/traces/span-operations/
21+
const CATEGORIES = new Set([
22+
'ai',
23+
'app',
24+
'browser',
25+
'cache',
26+
'console',
27+
'db',
28+
'event',
29+
'file',
30+
'function',
31+
'graphql',
32+
'grpc',
33+
'http',
34+
'log',
35+
'mark',
36+
'measure',
37+
'middleware',
38+
'navigation',
39+
'object',
40+
'pageload',
41+
'queue',
42+
'resource',
43+
'rpc',
44+
'serialize',
45+
'socket',
46+
'subprocess',
47+
'template',
48+
'topic',
49+
'ui',
50+
'view',
51+
'websocket',
52+
// TODO(v12): Rename the `auto.faas.cloudflare.*` origins to
53+
// `auto.function.cloudflare.*`, as AWS and GCP use, and drop this entry.
54+
// `faas` is not a span op category, but renaming an origin breaks user
55+
// queries that match it, so it waits for a major.
56+
'faas',
57+
]);
58+
2059
function getKeyName(node, computed) {
2160
if (computed && node.type === 'Identifier') {
2261
return node.name;
@@ -39,6 +78,8 @@ module.exports = {
3978
"Span origin '{{origin}}' must be '<type>.<category>.<integration_name>.<integration_part>': type 'auto' or 'manual', at most four parts, only [a-zA-Z0-9_] in a part. See https://develop.sentry.dev/sdk/telemetry/traces/trace-origin/",
4079
toolingPart:
4180
"Span origin '{{origin}}' names tooling ('{{part}}'). The origin identifies the integration, not how it is built.",
81+
badCategory:
82+
"Span origin '{{origin}}' has category '{{category}}', which is not a span op category. See https://develop.sentry.dev/sdk/telemetry/traces/span-operations/",
4283
},
4384
},
4485
create(context) {
@@ -51,7 +92,13 @@ module.exports = {
5192
context.report({ node: valueNode, messageId: 'badFormat', data: { origin } });
5293
return;
5394
}
54-
const part = origin.split('.').find(p => TOOLING_PARTS.has(p));
95+
const parts = origin.split('.');
96+
const category = parts[1];
97+
if (category !== undefined && !CATEGORIES.has(category)) {
98+
context.report({ node: valueNode, messageId: 'badCategory', data: { origin, category } });
99+
return;
100+
}
101+
const part = parts.find(p => TOOLING_PARTS.has(p));
55102
if (part) {
56103
context.report({ node: valueNode, messageId: 'toolingPart', data: { origin, part } });
57104
}

‎packages/eslint-plugin-sdk/test/lib/rules/valid-span-origin.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ describe('valid-span-origin', () => {
2525
{ code: "const SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN = 'sentry.origin';" },
2626
{ code: "const ORIGINAL_ENTRY_QUERY = '?sentry-cloudflare-original';" },
2727
{ code: 'const ORIGIN = `auto.${op}.angular`;' },
28+
{ code: "({ [SENTRY_ORIGIN]: 'auto.ui.angular' });" },
29+
{ code: "({ [SENTRY_ORIGIN]: 'auto' });" },
2830
],
2931
invalid: [
3032
{
@@ -39,6 +41,10 @@ describe('valid-span-origin', () => {
3941
code: "({ 'sentry.origin': 'node.http' });",
4042
errors: [{ messageId: 'badFormat' }],
4143
},
44+
{
45+
code: "({ [SENTRY_ORIGIN]: 'auto.kafkajs.producer' });",
46+
errors: [{ messageId: 'badCategory', data: { origin: 'auto.kafkajs.producer', category: 'kafkajs' } }],
47+
},
4248
{
4349
code: "span.setAttribute('sentry.origin', 'auto.http..node');",
4450
errors: [{ messageId: 'badFormat' }],

‎packages/node/src/integrations/nodeRuntimeMetrics.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,11 @@ export const nodeRuntimeMetricsIntegration = defineIntegration((options: NodeRun
139139
const resolutionNs = EVENT_LOOP_DELAY_RESOLUTION_MS * 1e6;
140140
const nsToS = (ns: number): number => Math.max(0, (ns - resolutionNs) / 1e9);
141141

142+
/* oxlint-disable sdk/valid-span-origin -- a metric origin; trace origin categories apply to spans and logs */
142143
const METRIC_ATTRIBUTES = { attributes: { [SENTRY_ORIGIN]: 'auto.node.runtime_metrics' } };
143144
const METRIC_ATTRIBUTES_BYTE = { unit: 'byte', attributes: { [SENTRY_ORIGIN]: 'auto.node.runtime_metrics' } };
144145
const METRIC_ATTRIBUTES_SECOND = { unit: 'second', attributes: { [SENTRY_ORIGIN]: 'auto.node.runtime_metrics' } };
146+
/* oxlint-enable sdk/valid-span-origin */
145147

146148
function collectMetrics(): void {
147149
const now = _INTERNAL_safeDateNow();

0 commit comments

Comments
 (0)