feat(server-utils): Add @opentelemetry/instrumentation-koa orchestrion integration#22146
Open
s1gr1d wants to merge 2 commits into
Open
feat(server-utils): Add @opentelemetry/instrumentation-koa orchestrion integration#22146s1gr1d wants to merge 2 commits into
s1gr1d wants to merge 2 commits into
Conversation
Contributor
size-limit report 📦
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds
koaChannelIntegrationin@sentry/server-utilsfor injecting orchestrion channels intokoa.A subscriber wraps each registered layer in a span-creating proxy.
Span-helpers are ported from the vendored instrumentation, preserving span names (but adapting to new conventions - check todo comments).
One thing to know for review: we instrument
koa-compose, notusefrom koa. koa'suselives in koa's main entry (lib/application.js), and transforming a package's main entry forces its top-levelrequirechain through Node'srequire(esm)bridge, which throws on Node < 24.13.uselives in koa's main entry (lib/application.js), so to instrument it we transform that file. But transforming a main entry pulls its whole top-levelrequirechain into the loader's handling --> and that changes how thoserequires are loaded (through the ESM→CommonJS translator, not the normal sync require path).koais CJS (but support ESM). Whenimporting koa, it loads a shim that loads the CJS code:import 'koa'→dist/koa.mjs(a ESM shim) →import '../lib/application.js'(CJS). That CJS entry has a top-levelrequire('is-generator-function').is-generator-function→require('generator-function'), andgenerator-functionpoints at an.mjsfile, which in turn imports./index.js.--> So the top-level
requirein koa'sapplication.js(CJS) becomesrequire(esm)of an ESM file importing a CJS file.require(esm)cache, so it throwsrequest for './index.js' is not in cache.The failing chain:
koa-composeis koa's zero-dependency dispatch engine, so it's safe to transform, andcompose(app.middleware)sees the same layersusewould. Since@koa/routeralso callscomposeper request, the subscriber usesgetActiveSpan()to only wrap at app startup (no active span) and skip the per-request router composition.Closes #20758
Linear: https://linear.app/getsentry/issue/JS-2409/rewrite-opentelemetryinstrumentation-koa-to-orchestrion