Commit 0df7ea0d authored by Evan Kirkiles's avatar Evan Kirkiles Committed by devjiwonchoi

Use route matcher's pathname for app route spans, not manual derivation

parent 6fd885cf
......@@ -22,7 +22,6 @@ import { getImplicitTags, type ImplicitTags } from '../../lib/implicit-tags'
import { patchFetch } from '../../lib/patch-fetch'
import { getTracer } from '../../lib/trace/tracer'
import { AppRouteRouteHandlersSpan } from '../../lib/trace/constants'
import { getPathnameFromAbsolutePath } from './helpers/get-pathname-from-absolute-path'
import * as Log from '../../../build/output/log'
import { autoImplementMethods } from './helpers/auto-implement-methods'
import {
......@@ -765,20 +764,18 @@ export class AppRouteRouteModule extends RouteModule<
this.dynamic satisfies never
}
// TODO: propagate this pathname from route matcher
const route = getPathnameFromAbsolutePath(this.resolvedPagePath)
const tracer = getTracer()
// Update the root span attribute for the route.
tracer.setRootSpanAttribute('next.route', route)
const { pathname } = this.definition
tracer.setRootSpanAttribute('next.route', pathname)
return tracer.trace(
AppRouteRouteHandlersSpan.runHandler,
{
spanName: `executing api route (app) ${route}`,
spanName: `executing api route (app) ${pathname}`,
attributes: {
'next.route': route,
'next.route': pathname,
},
},
async () =>
......
......@@ -13,7 +13,7 @@ const EXTERNAL = {
const COLLECTOR_PORT = 9001
describe('opentelemetry', () => {
const { next, skipped, isNextDev, isNextStart } = nextTestSetup({
const { next, skipped, isNextStart } = nextTestSetup({
files: __dirname,
skipDeployment: true,
dependencies: require('./package.json').dependencies,
......@@ -394,14 +394,14 @@ describe('opentelemetry', () => {
await expectTrace(getCollector(), [
{
name: 'GET /api/app/[param]/data/route',
name: 'GET /api/app/[param]/data',
attributes: {
'http.method': 'GET',
'http.route': '/api/app/[param]/data/route',
'http.route': '/api/app/[param]/data',
'http.status_code': 200,
'http.target': '/api/app/param/data',
'next.route': '/api/app/[param]/data/route',
'next.span_name': 'GET /api/app/[param]/data/route',
'next.route': '/api/app/[param]/data',
'next.span_name': 'GET /api/app/[param]/data',
'next.span_type': 'BaseServer.handleRequest',
},
kind: 1,
......@@ -410,11 +410,11 @@ describe('opentelemetry', () => {
parentId: env.span.rootParentId,
spans: [
{
name: 'executing api route (app) /api/app/[param]/data/route',
name: 'executing api route (app) /api/app/[param]/data',
attributes: {
'next.route': '/api/app/[param]/data/route',
'next.route': '/api/app/[param]/data',
'next.span_name':
'executing api route (app) /api/app/[param]/data/route',
'executing api route (app) /api/app/[param]/data',
'next.span_type': 'AppRouteRouteHandlers.runHandler',
},
kind: 0,
......@@ -452,11 +452,11 @@ describe('opentelemetry', () => {
runtime: 'edge',
traceId: env.span.traceId,
parentId: env.span.rootParentId,
name: 'executing api route (app) /api/app/[param]/data/edge/route',
name: 'executing api route (app) /api/app/[param]/data/edge',
attributes: {
'next.route': '/api/app/[param]/data/edge/route',
'next.route': '/api/app/[param]/data/edge',
'next.span_name':
'executing api route (app) /api/app/[param]/data/edge/route',
'executing api route (app) /api/app/[param]/data/edge',
'next.span_type': 'AppRouteRouteHandlers.runHandler',
},
kind: 0,
......
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