diff --git a/.changeset/sentry-v11-segment-source.md b/.changeset/sentry-v11-segment-source.md new file mode 100644 index 000000000..4aab535ea --- /dev/null +++ b/.changeset/sentry-v11-segment-source.md @@ -0,0 +1,5 @@ +--- +"@stackflow/plugin-sentry": patch +--- + +Support Sentry 11. `@sentry/core` 11 removed `SEMANTIC_ATTRIBUTE_SENTRY_SOURCE`, so importing the plugin failed. The plugin now sets the span name source on `sentry.segment.name.source` with Sentry 11 and on `sentry.source` with Sentry 8-10. diff --git a/extensions/plugin-sentry/src/attributes.ts b/extensions/plugin-sentry/src/attributes.ts new file mode 100644 index 000000000..0bf977178 --- /dev/null +++ b/extensions/plugin-sentry/src/attributes.ts @@ -0,0 +1,13 @@ +import { SDK_VERSION } from "@sentry/browser"; + +/** + * Span attribute holding the transaction (segment) name source. + * Sentry 8-10 read `sentry.source`. Sentry 11 reads `sentry.segment.name.source` + * and no longer exports `SEMANTIC_ATTRIBUTE_SENTRY_SOURCE`, so the key is chosen + * from the `@sentry/browser` version instead of importing the constant. The spans + * are started through `@sentry/browser`, so its version decides which key is read. + */ +export const SEMANTIC_ATTRIBUTE_SENTRY_SOURCE = + Number.parseInt(SDK_VERSION, 10) >= 11 + ? "sentry.segment.name.source" + : "sentry.source"; diff --git a/extensions/plugin-sentry/src/integration.ts b/extensions/plugin-sentry/src/integration.ts index 9f4a2f3e9..4477209ac 100644 --- a/extensions/plugin-sentry/src/integration.ts +++ b/extensions/plugin-sentry/src/integration.ts @@ -5,8 +5,8 @@ import { import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, - SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, } from "@sentry/core"; +import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from "./attributes"; export function stackflowBrowserTracingIntegration( options: Parameters[0] = {}, diff --git a/extensions/plugin-sentry/src/sentryPlugin.ts b/extensions/plugin-sentry/src/sentryPlugin.ts index 67a9bcd72..3a02eed5b 100644 --- a/extensions/plugin-sentry/src/sentryPlugin.ts +++ b/extensions/plugin-sentry/src/sentryPlugin.ts @@ -2,9 +2,9 @@ import * as Sentry from "@sentry/browser"; import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, - SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, } from "@sentry/core"; import type { StackflowPlugin } from "@stackflow/core"; +import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from "./attributes"; type NavigationAction = | "push"