forked from getsentry/sentry-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(nextjs): Remove Http integration from Next.js (getsentry#11304)
Next.js provides their own OTel http integration, which conflicts with ours ref getsentry#11016 added commit from this PR: getsentry#11319 --------- Co-authored-by: Luca Forstner <luca.forstner@sentry.io> Co-authored-by: Francesco Novy <francesco.novy@sentry.io>
- Loading branch information
1 parent
a5b1c21
commit 4e8d20b
Showing
7 changed files
with
147 additions
and
70 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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
44 changes: 44 additions & 0 deletions
44
packages/nextjs/src/server/requestIsolationScopeIntegration.ts
This file contains 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,44 @@ | ||
import { SpanKind } from '@opentelemetry/api'; | ||
import { | ||
defineIntegration, | ||
getCapturedScopesOnSpan, | ||
getCurrentScope, | ||
getIsolationScope, | ||
getRootSpan, | ||
setCapturedScopesOnSpan, | ||
spanToJSON, | ||
} from '@sentry/core'; | ||
import { getSpanKind } from '@sentry/opentelemetry'; | ||
|
||
/** | ||
* This integration is responsible for creating isolation scopes for incoming Http requests. | ||
* We do so by waiting for http spans to be created and then forking the isolation scope. | ||
* | ||
* Normally the isolation scopes would be created by our Http instrumentation, however Next.js brings it's own Http | ||
* instrumentation so we had to disable ours. | ||
*/ | ||
export const requestIsolationScopeIntegration = defineIntegration(() => { | ||
return { | ||
name: 'RequestIsolationScope', | ||
setup(client) { | ||
client.on('spanStart', span => { | ||
const spanJson = spanToJSON(span); | ||
const data = spanJson.data || {}; | ||
|
||
// The following check is a heuristic to determine whether the started span is a span that tracks an incoming HTTP request | ||
if ( | ||
(getSpanKind(span) === SpanKind.SERVER && data['http.method']) || | ||
(span === getRootSpan(span) && data['next.route']) | ||
) { | ||
const scopes = getCapturedScopesOnSpan(span); | ||
|
||
// Update the isolation scope, isolate this request | ||
const isolationScope = (scopes.isolationScope || getIsolationScope()).clone(); | ||
const scope = scopes.scope || getCurrentScope(); | ||
|
||
setCapturedScopesOnSpan(span, scope, isolationScope); | ||
} | ||
}); | ||
}, | ||
}; | ||
}); |
This file contains 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