Unverified Commit 40296fe5 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Fix remaining OTEL issues in adapter (#94817)

**View diff without whitespace**

1. RSC requests weren't properly handled
2. The mismatch on getServerSideProps is actually fine (depends on
whatever invokes the handler)
parent b08fb8d9
...@@ -222,6 +222,12 @@ export async function handler( ...@@ -222,6 +222,12 @@ export async function handler(
} }
const isMinimalMode = Boolean(getRequestMeta(req, 'minimalMode')) const isMinimalMode = Boolean(getRequestMeta(req, 'minimalMode'))
// Capture the request target before `prepare()` runs, since route
// normalization (e.g. `normalizeCdnUrl`) rewrites `req.url` and would
// otherwise change the `http.target` span attribute. This mirrors
// `BaseServer.handleRequest`, which records the target before normalization.
const httpTarget = req.url
const multiZoneDraftMode = process.env const multiZoneDraftMode = process.env
.__NEXT_MULTI_ZONE_DRAFT_MODE as any as boolean .__NEXT_MULTI_ZONE_DRAFT_MODE as any as boolean
...@@ -722,7 +728,7 @@ export async function handler( ...@@ -722,7 +728,7 @@ export async function handler(
span.setAttributes({ span.setAttributes({
'http.status_code': res.statusCode, 'http.status_code': res.statusCode,
'next.rsc': false, 'next.rsc': isRSCRequest,
}) })
if (res.statusCode && res.statusCode >= 500) { if (res.statusCode && res.statusCode >= 500) {
...@@ -754,7 +760,9 @@ export async function handler( ...@@ -754,7 +760,9 @@ export async function handler(
} }
const route = rootSpanAttributes.get('next.route') || normalizedSrcPage const route = rootSpanAttributes.get('next.route') || normalizedSrcPage
const name = `${method} ${route}` const name = isRSCRequest
? `RSC ${method} ${route}`
: `${method} ${route}`
span.setAttributes({ span.setAttributes({
'next.route': route, 'next.route': route,
...@@ -2009,7 +2017,7 @@ export async function handler( ...@@ -2009,7 +2017,7 @@ export async function handler(
kind: SpanKind.SERVER, kind: SpanKind.SERVER,
attributes: { attributes: {
'http.method': method, 'http.method': method,
'http.target': req.url, 'http.target': httpTarget,
}, },
}, },
handleResponse handleResponse
......
...@@ -69,7 +69,6 @@ describe.each( ...@@ -69,7 +69,6 @@ describe.each(
// Edge runtime is currently not implemented in custom-entrypoint-server.ts // Edge runtime is currently not implemented in custom-entrypoint-server.ts
const itEdge = useDirectEntrypointHandler ? it.skip : it const itEdge = useDirectEntrypointHandler ? it.skip : it
const itNoDirect = useDirectEntrypointHandler ? it.skip : it
for (const env of [ for (const env of [
{ {
...@@ -371,8 +370,7 @@ describe.each( ...@@ -371,8 +370,7 @@ describe.each(
) )
}) })
// TODO why is this failing it('should handle RSC with fetch in RSC mode', async () => {
itNoDirect('should handle RSC with fetch in RSC mode', async () => {
await next.fetch(`/app/param/rsc-fetch?${NEXT_RSC_UNION_QUERY}`, { await next.fetch(`/app/param/rsc-fetch?${NEXT_RSC_UNION_QUERY}`, {
...env.fetchInit, ...env.fetchInit,
headers: { headers: {
...@@ -1033,10 +1031,7 @@ describe.each( ...@@ -1033,10 +1031,7 @@ describe.each(
) )
}) })
// TODO why is this failing it('should handle getServerSideProps exceptions', async () => {
itNoDirect(
'should handle getServerSideProps exceptions',
async () => {
await next.fetch( await next.fetch(
'/pages/param/getServerSidePropsError', '/pages/param/getServerSidePropsError',
env.fetchInit env.fetchInit
...@@ -1048,13 +1043,23 @@ describe.each( ...@@ -1048,13 +1043,23 @@ describe.each(
attributes: { attributes: {
'http.method': 'GET', 'http.method': 'GET',
'http.route': '/pages/[param]/getServerSidePropsError', 'http.route': '/pages/[param]/getServerSidePropsError',
'http.status_code': 500,
'http.target': '/pages/param/getServerSidePropsError', 'http.target': '/pages/param/getServerSidePropsError',
'next.route': '/pages/[param]/getServerSidePropsError', 'next.route': '/pages/[param]/getServerSidePropsError',
'next.span_name': 'next.span_name':
'GET /pages/[param]/getServerSidePropsError', 'GET /pages/[param]/getServerSidePropsError',
'next.span_type': 'BaseServer.handleRequest', 'next.span_type': 'BaseServer.handleRequest',
...(useDirectEntrypointHandler
? {
// With direct entrypoints, this 500 error has to be handled by whatever is
// invoking the handler. And that same invoker is then also responsible for
// setting OTEL correctly.
'error.type': 'Error',
'http.status_code': 200,
}
: {
'error.type': '500', 'error.type': '500',
'http.status_code': 500,
}),
}, },
kind: 1, kind: 1,
status: { code: 2 }, status: { code: 2 },
...@@ -1156,8 +1161,7 @@ describe.each( ...@@ -1156,8 +1161,7 @@ describe.each(
], ],
}, },
]) ])
} })
)
it('should handle getServerSideProps returning notFound', async () => { it('should handle getServerSideProps returning notFound', async () => {
await next.fetch( await next.fetch(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment