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