-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(opentelemetry): Add conditional browser export to avoid node deps #20556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
dev-packages/browser-integration-tests/suites/opentelemetry/node-exports/init.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import * as Sentry from '@sentry/browser'; | ||
|
|
||
| window.Sentry = Sentry; | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| }); |
13 changes: 13 additions & 0 deletions
13
dev-packages/browser-integration-tests/suites/opentelemetry/node-exports/subject.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import * as SentryOpenTelemetry from '@sentry/opentelemetry'; | ||
| import * as Sentry from '@sentry/browser'; | ||
|
|
||
| // Verify that generally all imports can be resolved | ||
| // oxlint-disable-next-line no-console | ||
| for (const key in SentryOpenTelemetry) { | ||
| console.log(key, SentryOpenTelemetry[key]); | ||
| } | ||
|
|
||
| // Verify that it console.errors if calling node-only thing | ||
| new SentryOpenTelemetry.SentryAsyncLocalStorageContextManager(); | ||
|
|
||
| Sentry.captureException(new Error('test')); |
26 changes: 26 additions & 0 deletions
26
dev-packages/browser-integration-tests/suites/opentelemetry/node-exports/test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { expect } from '@playwright/test'; | ||
| import { sentryTest } from '../../../utils/fixtures'; | ||
| import { envelopeRequestParser, waitForErrorRequestOnUrl } from '../../../utils/helpers'; | ||
|
|
||
| sentryTest('Should allow importing from @sentry/opentelemetry package', async ({ getLocalTestUrl, page }) => { | ||
| const bundle = process.env.PW_BUNDLE; | ||
|
|
||
| if (bundle && bundle.includes('bundle')) { | ||
| sentryTest.skip(); | ||
| return; | ||
| } | ||
|
|
||
| const consoleMessages: string[] = []; | ||
| page.on('console', msg => { | ||
| consoleMessages.push(msg.text()); | ||
| }); | ||
|
|
||
| const url = await getLocalTestUrl({ testDir: __dirname }); | ||
| const req = await waitForErrorRequestOnUrl(page, url); | ||
| const eventData = envelopeRequestParser(req); | ||
|
|
||
| expect(eventData.exception?.values).toHaveLength(1); | ||
| expect(eventData.exception?.values?.[0].value).toBe('test'); | ||
|
|
||
| expect(consoleMessages).toContainEqual('SentryAsyncLocalStorageContextManager is not supported in the browser'); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| export { SEMANTIC_ATTRIBUTE_SENTRY_GRAPHQL_OPERATION } from './semanticAttributes'; | ||
|
|
||
| export { getRequestSpanData } from './utils/getRequestSpanData'; | ||
|
|
||
| export type { OpenTelemetryClient } from './types'; | ||
| export { wrapClientClass } from './custom/client'; | ||
|
|
||
| export { getSpanKind } from './utils/getSpanKind'; | ||
|
|
||
| export { getScopesFromContext } from './utils/contextData'; | ||
|
|
||
| export { | ||
| spanHasAttributes, | ||
| spanHasEvents, | ||
| spanHasKind, | ||
| spanHasName, | ||
| spanHasParentId, | ||
| spanHasStatus, | ||
| } from './utils/spanTypes'; | ||
|
|
||
| // Re-export this for backwards compatibility (this used to be a different implementation) | ||
| export { getDynamicSamplingContextFromSpan } from '@sentry/core'; | ||
|
|
||
| export { isSentryRequestSpan } from './utils/isSentryRequest'; | ||
|
|
||
| export { enhanceDscWithOpenTelemetryRootSpanName } from './utils/enhanceDscWithOpenTelemetryRootSpanName'; | ||
|
|
||
| export { getActiveSpan } from './utils/getActiveSpan'; | ||
| export { | ||
| startSpan, | ||
| startSpanManual, | ||
| startInactiveSpan, | ||
| withActiveSpan, | ||
| continueTrace, | ||
| getTraceContextForScope, | ||
| } from './trace'; | ||
|
|
||
| export { suppressTracing } from './utils/suppressTracing'; | ||
|
|
||
| export { setupEventContextTrace } from './setupEventContextTrace'; | ||
|
|
||
| export { setOpenTelemetryContextAsyncContextStrategy } from './asyncContextStrategy'; | ||
| export { wrapContextManagerClass } from './contextManager'; | ||
|
|
||
| export { SentryPropagator, shouldPropagateTraceForUrl } from './propagator'; | ||
| export { SentrySpanProcessor } from './spanProcessor'; | ||
| export { SentrySampler, wrapSamplingDecision } from './sampler'; | ||
|
|
||
| export { openTelemetrySetupCheck } from './utils/setupCheck'; | ||
|
|
||
| export { getSentryResource } from './resource'; | ||
|
|
||
| export { withStreamedSpan } from '@sentry/core'; | ||
|
|
||
| // Legacy | ||
| export { getClient } from '@sentry/core'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { consoleSandbox } from '@sentry/core'; | ||
|
|
||
| export * from './exports'; | ||
|
|
||
| // Stubs for node-specific exports | ||
| export class SentryAsyncLocalStorageContextManager { | ||
| public constructor() { | ||
| consoleSandbox(() => { | ||
| // oxlint-disable-next-line no-console | ||
| console.error('SentryAsyncLocalStorageContextManager is not supported in the browser'); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| export type AsyncLocalStorageLookup = { | ||
| asyncLocalStorage: unknown; | ||
| contextSymbol: symbol; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,57 +1,5 @@ | ||
| export { SEMANTIC_ATTRIBUTE_SENTRY_GRAPHQL_OPERATION } from './semanticAttributes'; | ||
| export * from './exports'; | ||
|
|
||
| export { getRequestSpanData } from './utils/getRequestSpanData'; | ||
|
|
||
| export type { OpenTelemetryClient } from './types'; | ||
| export { wrapClientClass } from './custom/client'; | ||
|
|
||
| export { getSpanKind } from './utils/getSpanKind'; | ||
|
|
||
| export { getScopesFromContext } from './utils/contextData'; | ||
|
|
||
| export { | ||
| spanHasAttributes, | ||
| spanHasEvents, | ||
| spanHasKind, | ||
| spanHasName, | ||
| spanHasParentId, | ||
| spanHasStatus, | ||
| } from './utils/spanTypes'; | ||
|
|
||
| // Re-export this for backwards compatibility (this used to be a different implementation) | ||
| export { getDynamicSamplingContextFromSpan } from '@sentry/core'; | ||
|
|
||
| export { isSentryRequestSpan } from './utils/isSentryRequest'; | ||
|
|
||
| export { enhanceDscWithOpenTelemetryRootSpanName } from './utils/enhanceDscWithOpenTelemetryRootSpanName'; | ||
|
|
||
| export { getActiveSpan } from './utils/getActiveSpan'; | ||
| export { | ||
| startSpan, | ||
| startSpanManual, | ||
| startInactiveSpan, | ||
| withActiveSpan, | ||
| continueTrace, | ||
| getTraceContextForScope, | ||
| } from './trace'; | ||
|
|
||
| export { suppressTracing } from './utils/suppressTracing'; | ||
|
|
||
| export { setupEventContextTrace } from './setupEventContextTrace'; | ||
|
|
||
| export { setOpenTelemetryContextAsyncContextStrategy } from './asyncContextStrategy'; | ||
| export { wrapContextManagerClass } from './contextManager'; | ||
| // Node-specific exports | ||
| export { SentryAsyncLocalStorageContextManager } from './asyncLocalStorageContextManager'; | ||
| export type { AsyncLocalStorageLookup } from './contextManager'; | ||
| export { SentryPropagator, shouldPropagateTraceForUrl } from './propagator'; | ||
| export { SentrySpanProcessor } from './spanProcessor'; | ||
| export { SentrySampler, wrapSamplingDecision } from './sampler'; | ||
|
|
||
| export { openTelemetrySetupCheck } from './utils/setupCheck'; | ||
|
|
||
| export { getSentryResource } from './resource'; | ||
|
|
||
| export { withStreamedSpan } from '@sentry/core'; | ||
|
|
||
| // Legacy | ||
| export { getClient } from '@sentry/core'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're specifying
browserhere, it might be safer to put it abovenode, just to ensure that anything that claims to support this (even if it does so with weird shims etc) can pick up thebrowserone first.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't 100% sure about this (and still am not 🤔 ) my thinking for this was that node is def. the main target here, and I want to avoid somebody who has a node target not getting this. IMHO that's more important than somebody who has node & browser targets not getting the node stuff - I'd say it's reasonable that if your targets include node, you get the variant with the node import 😅 but we can always revisit the order if this turns out to be problematic!