diff --git a/AGENTS.md b/AGENTS.md index ed059f1ca9d8..a22a16e74cf2 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -74,9 +74,6 @@ Uses **Git Flow** (see `docs/gitflow.md`). - `Sentry.init()` follows one rule for repeated calls: the first call wins. See `docs/repeated-init.md` before you add or change an `init()`. -- In a span origin, the second part is the span op category (`auto.queue.kafkajs.producer`, not - `auto.kafkajs.producer`). `sdk/valid-span-origin` checks the rest of the format. - ## Linting & Formatting Use `pnpm run lint` (Oxlint) and `pnpm run format` (Oxfmt). Never run ESLint or Prettier, and never add their config diff --git a/packages/bun/src/integrations/bunRuntimeMetrics.ts b/packages/bun/src/integrations/bunRuntimeMetrics.ts index 9be65ffd3b9e..d7cc3715f775 100644 --- a/packages/bun/src/integrations/bunRuntimeMetrics.ts +++ b/packages/bun/src/integrations/bunRuntimeMetrics.ts @@ -93,9 +93,11 @@ export const bunRuntimeMetricsIntegration = defineIntegration((options: BunRunti let prevFlushTime: number = 0; let eluAvailable = false; + /* oxlint-disable sdk/valid-span-origin -- a metric origin; trace origin categories apply to spans and logs */ const METRIC_ATTRIBUTES = { attributes: { [SENTRY_ORIGIN]: 'auto.bun.runtime_metrics' } }; const METRIC_ATTRIBUTES_BYTE = { unit: 'byte', attributes: { [SENTRY_ORIGIN]: 'auto.bun.runtime_metrics' } }; const METRIC_ATTRIBUTES_SECOND = { unit: 'second', attributes: { [SENTRY_ORIGIN]: 'auto.bun.runtime_metrics' } }; + /* oxlint-enable sdk/valid-span-origin */ function collectMetrics(): void { const now = _INTERNAL_safeDateNow(); diff --git a/packages/deno/src/integrations/denoRuntimeMetrics.ts b/packages/deno/src/integrations/denoRuntimeMetrics.ts index 283f0615be52..3b4a3648f556 100644 --- a/packages/deno/src/integrations/denoRuntimeMetrics.ts +++ b/packages/deno/src/integrations/denoRuntimeMetrics.ts @@ -80,8 +80,10 @@ export const denoRuntimeMetricsIntegration = defineIntegration((options: DenoRun let intervalId: number | undefined; let prevFlushTime: number = 0; + /* oxlint-disable sdk/valid-span-origin -- a metric origin; trace origin categories apply to spans and logs */ const METRIC_ATTRIBUTES_BYTE = { unit: 'byte', attributes: { [SENTRY_ORIGIN]: 'auto.deno.runtime_metrics' } }; const METRIC_ATTRIBUTES_SECOND = { unit: 'second', attributes: { [SENTRY_ORIGIN]: 'auto.deno.runtime_metrics' } }; + /* oxlint-enable sdk/valid-span-origin */ function collectMetrics(): void { const now = _INTERNAL_safeDateNow(); diff --git a/packages/eslint-plugin-sdk/src/rules/valid-span-origin.js b/packages/eslint-plugin-sdk/src/rules/valid-span-origin.js index dcd7b73e26a2..c2161908a0be 100644 --- a/packages/eslint-plugin-sdk/src/rules/valid-span-origin.js +++ b/packages/eslint-plugin-sdk/src/rules/valid-span-origin.js @@ -7,9 +7,9 @@ * It checks string literals written to an origin attribute, and string * literals assigned to a constant whose name ends in `ORIGIN`. Origins * built with a template literal or imported from elsewhere are not - * checked. Whether the `category` part is the span op category - * (`auto.queue.kafkajs.producer`, not `auto.kafkajs.producer`) needs a - * human. + * checked. The category must be a span op category + * (`auto.queue.kafkajs.producer`, not `auto.kafkajs.producer`), but it + * need not match the op of the same span. */ const ORIGIN_KEYS = new Set(['SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN', 'SENTRY_ORIGIN', 'sentry.origin']); @@ -17,6 +17,45 @@ const ORIGIN_FORMAT = /^(auto|manual)(\.[a-zA-Z0-9_]+){0,3}$/; const TOOLING_PARTS = new Set(['otel', 'orchestrion']); const ORIGIN_CONSTANT = /(^|_)ORIGIN$/; +// Span op categories from https://develop.sentry.dev/sdk/telemetry/traces/span-operations/ +const CATEGORIES = new Set([ + 'ai', + 'app', + 'browser', + 'cache', + 'console', + 'db', + 'event', + 'file', + 'function', + 'graphql', + 'grpc', + 'http', + 'log', + 'mark', + 'measure', + 'middleware', + 'navigation', + 'object', + 'pageload', + 'queue', + 'resource', + 'rpc', + 'serialize', + 'socket', + 'subprocess', + 'template', + 'topic', + 'ui', + 'view', + 'websocket', + // TODO(v12): Rename the `auto.faas.cloudflare.*` origins to + // `auto.function.cloudflare.*`, as AWS and GCP use, and drop this entry. + // `faas` is not a span op category, but renaming an origin breaks user + // queries that match it, so it waits for a major. + 'faas', +]); + function getKeyName(node, computed) { if (computed && node.type === 'Identifier') { return node.name; @@ -39,6 +78,8 @@ module.exports = { "Span origin '{{origin}}' must be '...': 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/", toolingPart: "Span origin '{{origin}}' names tooling ('{{part}}'). The origin identifies the integration, not how it is built.", + badCategory: + "Span origin '{{origin}}' has category '{{category}}', which is not a span op category. See https://develop.sentry.dev/sdk/telemetry/traces/span-operations/", }, }, create(context) { @@ -51,7 +92,13 @@ module.exports = { context.report({ node: valueNode, messageId: 'badFormat', data: { origin } }); return; } - const part = origin.split('.').find(p => TOOLING_PARTS.has(p)); + const parts = origin.split('.'); + const category = parts[1]; + if (category !== undefined && !CATEGORIES.has(category)) { + context.report({ node: valueNode, messageId: 'badCategory', data: { origin, category } }); + return; + } + const part = parts.find(p => TOOLING_PARTS.has(p)); if (part) { context.report({ node: valueNode, messageId: 'toolingPart', data: { origin, part } }); } diff --git a/packages/eslint-plugin-sdk/test/lib/rules/valid-span-origin.test.ts b/packages/eslint-plugin-sdk/test/lib/rules/valid-span-origin.test.ts index 157f4ae3d4d4..7eedd8431d91 100644 --- a/packages/eslint-plugin-sdk/test/lib/rules/valid-span-origin.test.ts +++ b/packages/eslint-plugin-sdk/test/lib/rules/valid-span-origin.test.ts @@ -25,6 +25,8 @@ describe('valid-span-origin', () => { { code: "const SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN = 'sentry.origin';" }, { code: "const ORIGINAL_ENTRY_QUERY = '?sentry-cloudflare-original';" }, { code: 'const ORIGIN = `auto.${op}.angular`;' }, + { code: "({ [SENTRY_ORIGIN]: 'auto.ui.angular' });" }, + { code: "({ [SENTRY_ORIGIN]: 'auto' });" }, ], invalid: [ { @@ -39,6 +41,10 @@ describe('valid-span-origin', () => { code: "({ 'sentry.origin': 'node.http' });", errors: [{ messageId: 'badFormat' }], }, + { + code: "({ [SENTRY_ORIGIN]: 'auto.kafkajs.producer' });", + errors: [{ messageId: 'badCategory', data: { origin: 'auto.kafkajs.producer', category: 'kafkajs' } }], + }, { code: "span.setAttribute('sentry.origin', 'auto.http..node');", errors: [{ messageId: 'badFormat' }], diff --git a/packages/node/src/integrations/nodeRuntimeMetrics.ts b/packages/node/src/integrations/nodeRuntimeMetrics.ts index cb028e40686a..afe5f287ea48 100644 --- a/packages/node/src/integrations/nodeRuntimeMetrics.ts +++ b/packages/node/src/integrations/nodeRuntimeMetrics.ts @@ -139,9 +139,11 @@ export const nodeRuntimeMetricsIntegration = defineIntegration((options: NodeRun const resolutionNs = EVENT_LOOP_DELAY_RESOLUTION_MS * 1e6; const nsToS = (ns: number): number => Math.max(0, (ns - resolutionNs) / 1e9); + /* oxlint-disable sdk/valid-span-origin -- a metric origin; trace origin categories apply to spans and logs */ const METRIC_ATTRIBUTES = { attributes: { [SENTRY_ORIGIN]: 'auto.node.runtime_metrics' } }; const METRIC_ATTRIBUTES_BYTE = { unit: 'byte', attributes: { [SENTRY_ORIGIN]: 'auto.node.runtime_metrics' } }; const METRIC_ATTRIBUTES_SECOND = { unit: 'second', attributes: { [SENTRY_ORIGIN]: 'auto.node.runtime_metrics' } }; + /* oxlint-enable sdk/valid-span-origin */ function collectMetrics(): void { const now = _INTERNAL_safeDateNow();