Unverified Commit 370ba8d0 authored by Povilas Versockas's avatar Povilas Versockas Committed by GitHub

[OTel] fix: Root span name should not include high cardinality URL (#75416)

> HTTP span names SHOULD be {method} {target} if there is a
(low-cardinality) target available. If there is no (low-cardinality)
{target} available, HTTP span names SHOULD be {method}.

Some root spans don't have the `next.route` name available. In that
case, we used the `req.url` in the name. However, the OTel docs
recommend using only the method if the target is high cardinality.
Therefore, removed the usage of `req.url` in the name of root spans.

x-ref: [OTel
docs](https://opentelemetry.io/docs/specs/semconv/http/http-spans/#:~:text=HTTP%20span%20names%20SHOULD%20be%20%7Bmethod%7D%20%7Btarget%7D%20if%20there%20is%20a%20(low%2Dcardinality)%20target%20available.%20If%20there%20is%20no%20(low%2Dcardinality)%20%7Btarget%7D%20available%2C%20HTTP%20span%20names%20SHOULD%20be%20%7Bmethod%7D.)
Related: https://github.com/vercel/next.js/discussions/59645

---------
Co-authored-by: 's avatarJiwon Choi <devjiwonchoi@gmail.com>
Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
parent fc307c4f
......@@ -459,7 +459,7 @@ export async function handler(
})
span.updateName(name)
} else {
span.updateName(`${method} ${req.url}`)
span.updateName(`${method}`)
}
})
}
......@@ -1396,7 +1396,7 @@ export async function handler(
tracer.trace(
BaseServerSpan.handleRequest,
{
spanName: `${method} ${req.url}`,
spanName: `${method}`,
kind: SpanKind.SERVER,
attributes: {
'http.method': method,
......
......@@ -258,7 +258,7 @@ export async function handler(
})
span.updateName(name)
} else {
span.updateName(`${method} ${req.url}`)
span.updateName(`${method}`)
}
})
}
......@@ -454,7 +454,7 @@ export async function handler(
tracer.trace(
BaseServerSpan.handleRequest,
{
spanName: `${method} ${req.url}`,
spanName: `${method}`,
kind: SpanKind.SERVER,
attributes: {
'http.method': method,
......
......@@ -317,7 +317,7 @@ async function requestHandler(
})
span.updateName(name)
} else {
span.updateName(`${req.method} ${relativeUrl}`)
span.updateName(`${req.method}`)
}
})
......@@ -340,7 +340,7 @@ async function requestHandler(
tracer.trace(
BaseServerSpan.handleRequest,
{
spanName: `${req.method} ${relativeUrl}`,
spanName: `${req.method}`,
kind: SpanKind.SERVER,
attributes: {
'http.method': req.method,
......
......@@ -296,7 +296,7 @@ async function requestHandler(
})
span.updateName(name)
} else {
span.updateName(`${req.method} ${relativeUrl}`)
span.updateName(`${req.method}`)
}
})
......@@ -343,7 +343,7 @@ async function requestHandler(
tracer.trace(
BaseServerSpan.handleRequest,
{
spanName: `${req.method} ${relativeUrl}`,
spanName: `${req.method}`,
kind: SpanKind.SERVER,
attributes: {
'http.method': req.method,
......
......@@ -133,7 +133,7 @@ export async function handler(
})
span.updateName(name)
} else {
span.updateName(`${method} ${req.url}`)
span.updateName(`${method}`)
}
})
......@@ -146,7 +146,7 @@ export async function handler(
tracer.trace(
BaseServerSpan.handleRequest,
{
spanName: `${method} ${req.url}`,
spanName: `${method}`,
kind: SpanKind.SERVER,
attributes: {
'http.method': method,
......
......@@ -882,13 +882,13 @@ export default abstract class Server<
): Promise<void> {
await this.prepare()
const method = req.method.toUpperCase()
const tracer = getTracer()
return tracer.withPropagatedContext(req.headers, () => {
return tracer.trace(
BaseServerSpan.handleRequest,
{
spanName: `${method} ${req.url}`,
spanName: `${method}`,
kind: SpanKind.SERVER,
attributes: {
'http.method': method,
......@@ -944,11 +944,7 @@ export default abstract class Server<
})
span.updateName(name)
} else {
span.updateName(
isRSCRequest
? `RSC ${method} ${req.url}`
: `${method} ${req.url}`
)
span.updateName(isRSCRequest ? `RSC ${method}` : `${method}`)
}
})
)
......
......@@ -333,10 +333,10 @@ describe('opentelemetry', () => {
traceId: env.span.traceId,
parentId: env.span.rootParentId,
runtime: 'nodejs',
name: 'GET /app/param/rsc-fetch/edge',
name: 'GET',
kind: 1,
attributes: {
'next.span_name': 'GET /app/param/rsc-fetch/edge',
'next.span_name': 'GET',
'next.span_type': 'BaseServer.handleRequest',
'http.method': 'GET',
'http.target': '/app/param/rsc-fetch/edge',
......@@ -468,10 +468,10 @@ describe('opentelemetry', () => {
runtime: 'nodejs',
traceId: env.span.traceId,
parentId: env.span.rootParentId,
name: 'GET /api/app/param/data/edge',
name: 'GET',
kind: 1,
attributes: {
'next.span_name': 'GET /api/app/param/data/edge',
'next.span_name': 'GET',
'next.span_type': 'BaseServer.handleRequest',
'http.method': 'GET',
'http.target': '/api/app/param/data/edge',
......@@ -831,10 +831,10 @@ describe('opentelemetry', () => {
runtime: 'nodejs',
traceId: env.span.traceId,
parentId: env.span.rootParentId,
name: 'GET /pages/param/edge/getServerSideProps',
name: 'GET',
kind: 1,
attributes: {
'next.span_name': 'GET /pages/param/edge/getServerSideProps',
'next.span_name': 'GET',
'next.span_type': 'BaseServer.handleRequest',
'http.method': 'GET',
'http.target': '/pages/param/edge/getServerSideProps',
......@@ -1100,10 +1100,10 @@ describe('opentelemetry', () => {
runtime: 'nodejs',
traceId: env.span.traceId,
parentId: env.span.rootParentId,
name: 'GET /api/pages/param/edge',
name: 'GET',
kind: 1,
attributes: {
'next.span_name': 'GET /api/pages/param/edge',
'next.span_name': 'GET',
'next.span_type': 'BaseServer.handleRequest',
'http.method': 'GET',
'http.target': '/api/pages/param/edge',
......
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