Skip to content

Properly set response-based OTEL attributes with adapters #94603

Open
mischnic wants to merge 8 commits into
canaryfrom
mischnic/adpater-otel-response-code
Open

Properly set response-based OTEL attributes with adapters #94603
mischnic wants to merge 8 commits into
canaryfrom
mischnic/adpater-otel-response-code

Conversation

@mischnic

@mischnic mischnic commented Jun 9, 2026

Copy link
Copy Markdown
Member

This fixes some of the failures (particularly the ones where a 500 returned from an App API route showed up as status:200 in OTEL).
But the newly added tests have more failures that I skipped for now

const invokeRouteModule = async (span?: Span) => {
return routeModule.handle(nextReq, context).finally(() => {
if (!span) return
span.setAttributes({
'http.status_code': res.statusCode,
'next.rsc': false,
})

  return routeModule.handle(nextReq, context).finally(() => { // <-- handle() returns the response object from the user code
        if (!span) return
        span.setAttributes({
          'http.status_code': res.statusCode,          // <---------- this is using some default response object, not what handle() returned
          'next.rsc': false,
        })

mischnic commented Jun 9, 2026

Copy link
Copy Markdown
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Failing test suites

Commit: 915b465 | About building and testing Next.js

pnpm test-start test/production/app-dir/metadata-static-route-cache/metadata-static-route-cache.test.ts (job)

  • app dir - metadata static routes cache > should generate different content after replace the static metadata file (DD)
Expand output

● app dir - metadata static routes cache › should generate different content after replace the static metadata file

next already started

  65 |   ) {
  66 |     if (this.childProcess) {
> 67 |       throw new Error('next already started')
     |             ^
  68 |     }
  69 |
  70 |     this._cliOutput = ''

  at NextStartInstance.start (lib/next-modes/next-start.ts:67:13)
  at Object.start (production/app-dir/metadata-static-route-cache/metadata-static-route-cache.test.ts:17:16)

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Stats cancelled

Commit: 915b465
View workflow run

@mischnic mischnic changed the title cover app router int est as well Properly set http.status_code in OTEL with adapters Jun 9, 2026
Comment thread test/e2e/opentelemetry/instrumentation/custom-entrypoint-server.ts
@mischnic mischnic force-pushed the mischnic/adpater-otel-response-code branch from a562389 to 3feec27 Compare June 9, 2026 16:55
@mischnic mischnic changed the title Properly set http.status_code in OTEL with adapters Properly set response-based OTEL attributes with adapters Jun 9, 2026
@mischnic mischnic force-pushed the mischnic/adpater-otel-response-code branch from 3feec27 to 915b465 Compare June 9, 2026 17:12
@mischnic mischnic requested a review from timneutkens June 9, 2026 18:07
@mischnic mischnic marked this pull request as ready for review June 9, 2026 18:07
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.

1 participant