Skip to content

feat(attribute): Add koa.type and (deprecated) koa.name - #472

Merged
Lms24 merged 5 commits into
mainfrom
sig/attr-koa
Jul 13, 2026
Merged

feat(attribute): Add koa.type and (deprecated) koa.name#472
Lms24 merged 5 commits into
mainfrom
sig/attr-koa

Conversation

@s1gr1d

@s1gr1d s1gr1d commented Jul 9, 2026

Copy link
Copy Markdown
Member

Description

Adds koa.type which is used in the koa instrumentation: https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/packages/instrumentation-koa/src/enums/AttributeNames.ts

koa.name can be substituted with either http.route (for routes) or code.function.name (for middleware) as middleware is named after the function name: https://github.com/koajs/koa/blob/master/docs/guide.md#named-middleware

PR Checklist

  • I have run yarn test and verified that the tests pass.
  • I have run yarn generate to generate and format code and docs.

If an attribute was added:

  • The attribute is in a namespace (e.g. nextjs.function_id, not function_id)
  • I have used the correct value for apply_scrubbing (i.e. manual or auto. Use never only for values that should never be scrubbed such as IDs)

If an attribute was deprecated:

@s1gr1d
s1gr1d requested review from a team, Lms24, cleptric, mjq and nsdeschenes as code owners July 9, 2026 12:49
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

Attributes

  • Add navigation.origin attribute and deprecate SvelteKit routing attributes by Lms24 in #467
  • Add AWS service instrumentation attributes by andreiborza in #480
  • Add messaging, rpc and gen_ai attributes by andreiborza in #482
  • Add faas.invoked_* attributes by andreiborza in #481
  • Add AWS DynamoDB instrumentation attributes by andreiborza in #479
  • Add sentry.metric.source by klochek in #476
  • Add faas.id (deprecated) in favor of cloud.resource_id by andreiborza in #475
  • Add faas.execution (deprecated) in favor of faas.invocation_id by andreiborza in #473
  • Add messaging attributes by s1gr1d in #469
  • Add url.same_origin (deprecated) and http.request.same_origin (replacement) attributes by Lms24 in #456
  • Add db.response.status_code by s1gr1d in #462

Other

  • (ai) Add granular cost attributes for cache and reasoning by vgrozdanic in #461
  • (attribute) Add koa.type and (deprecated) koa.name by s1gr1d in #472
  • (js) Add _BASE attribute key exports for dynamic attribute keys by Lms24 in #471
  • (queues) Add Python sentry.op values for queues by alexander-alderman-webb in #470

Internal Changes 🔧

  • (ci) Stop inheriting secrets for changelog-preview by tobias-wilfert in #463

🤖 This preview updates automatically when you update the PR.

@Lms24 Lms24 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding!

RE: koa.name: We can still add it to conventions and mark it as deprecated. Add _status: null to the deprecation since there's no direct replacement. In this case, the SDK will decide which attributes replace it in which case. The benefit is still that the attribute is documented and that it's gonna be deprecated (i.e. signaling conventions consumers that it shouldn't be set anymore). But feel free to tackle later

@s1gr1d
s1gr1d enabled auto-merge (squash) July 13, 2026 08:27
@s1gr1d
s1gr1d disabled auto-merge July 13, 2026 08:28
@s1gr1d s1gr1d changed the title feat(attribute): Add koa.type feat(attribute): Add koa.type and koa.name Jul 13, 2026
@s1gr1d s1gr1d changed the title feat(attribute): Add koa.type and koa.name feat(attribute): Add koa.type and (deprecated) koa.name Jul 13, 2026
@Lms24
Lms24 enabled auto-merge (squash) July 13, 2026 08:55
@Lms24
Lms24 disabled auto-merge July 13, 2026 08:55
@Lms24
Lms24 enabled auto-merge (squash) July 13, 2026 08:55
@Lms24
Lms24 merged commit 7cb6a6c into main Jul 13, 2026
17 checks passed
@Lms24
Lms24 deleted the sig/attr-koa branch July 13, 2026 08:58
s1gr1d added a commit to getsentry/sentry-javascript that referenced this pull request Jul 16, 2026
…n integration (#22146)

Adds `koaChannelIntegration` in `@sentry/server-utils` for injecting
orchestrion channels into `koa`.

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](getsentry/sentry-conventions#472)).

Also upgraded `@apm-js-collab/tracing-hooks` to get this:
apm-js-collab/tracing-hooks#45 to be released
(lets us actually patch `koa` - see 1. iteration below).



<details>
<summary>1. iteration</summary>

One thing to know for review: **we instrument `koa-compose`, not `use`
from koa.** koa's `use` lives in koa's main entry
(`lib/application.js`), and transforming a package's main entry forces
its top-level `require` chain through Node's `require(esm)` bridge,
which throws on Node < 24.13.

1. Orchestrion instruments by rewriting a module's source at load time
(via the ESM load hook).
2. `use` lives 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-level `require` chain into the loader's handling -->
and that changes how those `require`s are loaded (through the
ESM→CommonJS translator, not the normal sync require path).
3. `koa` is CJS (but support ESM). When `import`ing 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-level
`require('is-generator-function')`.
4. `is-generator-function` → `require('generator-function')`, and
`generator-function` points at an `.mjs` file, which in turn imports
`./index.js`.
--> So the top-level `require` in koa's `application.js` (CJS) becomes
`require(esm)` of an ESM file importing a CJS file.
5. On Node < 24.13 (we pin 20.19.5), the loader can't pre-link this
dual-package shape into the `require(esm)` cache, so it throws `request
for './index.js' is not in cache`.

The failing chain:
```
koa/lib/application.js (CJS)
  └─ require('is-generator-function')        (CJS)
       └─ require('generator-function')      → require(esm) → require.mjs (ESM)
            └─ import './index.js'            (ESM importing CJS)
```

`koa-compose` is koa's zero-dependency dispatch engine, so it's safe to
transform, and `compose(app.middleware)` sees the same layers `use`
would. Since `@koa/router` also calls `compose` per request, the
subscriber uses `getActiveSpan()` to only wrap at app startup (no active
span) and skip the per-request router composition.</details>





Closes #20758

Linear:
https://linear.app/getsentry/issue/JS-2409/rewrite-opentelemetryinstrumentation-koa-to-orchestrion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants