-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vercel-edge): Use opentelemetry for
@sentry/vercel-edge
(#13742)
**This PR is part of a stacked PR sequence as we need to do many changes at once for #8105. Merging this PR as is will create inconsistent data.** --- This PR will make the `@sentry/vercel-edge` SDK use OpenTelemetry performance under the hood. We need to employ a few hacks so that OpenTelemetry works on a worker runtime: - We are vendoring the OTEL `AsyncLocalStorageContextManage` because the original implementation depends on `AsyncLocalStorage` as exported from `async_hooks` which is not available in workers. In our vendored version we are taking it from `globalThis.AsyncLocalStorage`. - We are polyfilling `performance` with `Date.now()` as that API is not available in worker runtimes. Resolves #13740
- Loading branch information
Showing
18 changed files
with
605 additions
and
145 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,60 @@ | ||
import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollup-utils'; | ||
import replace from '@rollup/plugin-replace'; | ||
import { makeBaseNPMConfig, makeNPMConfigVariants, plugins } from '@sentry-internal/rollup-utils'; | ||
|
||
export default makeNPMConfigVariants(makeBaseNPMConfig()); | ||
export default makeNPMConfigVariants( | ||
makeBaseNPMConfig({ | ||
entrypoints: ['src/index.ts'], | ||
bundledBuiltins: ['perf_hooks'], | ||
packageSpecificConfig: { | ||
context: 'globalThis', | ||
output: { | ||
preserveModules: false, | ||
}, | ||
plugins: [ | ||
plugins.makeCommonJSPlugin({ transformMixedEsModules: true }), // Needed because various modules in the OTEL toolchain use CJS (require-in-the-middle, shimmer, etc..) | ||
plugins.makeJsonPlugin(), // Needed because `require-in-the-middle` imports json via require | ||
replace({ | ||
preventAssignment: true, | ||
values: { | ||
'process.argv0': JSON.stringify(''), // needed because otel relies on process.argv0 for the default service name, but that api is not available in the edge runtime. | ||
}, | ||
}), | ||
{ | ||
// This plugin is needed because otel imports `performance` from `perf_hooks` and also uses it via the `performance` global. | ||
// Both of these APIs are not available in the edge runtime so we need to define a polyfill. | ||
// Vercel does something similar in the `@vercel/otel` package: https://github.com/vercel/otel/blob/087601ae585cb116bb2b46c211d014520de76c71/packages/otel/build.ts#L62 | ||
name: 'perf-hooks-performance-polyfill', | ||
banner: ` | ||
{ | ||
if (globalThis.performance === undefined) { | ||
globalThis.performance = { | ||
timeOrigin: 0, | ||
now: () => Date.now() | ||
}; | ||
} | ||
} | ||
`, | ||
resolveId: source => { | ||
if (source === 'perf_hooks') { | ||
return '\0perf_hooks_sentry_shim'; | ||
} else { | ||
return null; | ||
} | ||
}, | ||
load: id => { | ||
if (id === '\0perf_hooks_sentry_shim') { | ||
return ` | ||
export const performance = { | ||
timeOrigin: 0, | ||
now: () => Date.now() | ||
} | ||
`; | ||
} else { | ||
return null; | ||
} | ||
}, | ||
}, | ||
], | ||
}, | ||
}), | ||
); |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.