Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions packages/nextjs/src/common/utils/dropMiddlewareTunnelRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,35 @@
// eslint-disable-next-line deprecation/deprecation
const httpTarget = spanAttributes[SEMATTRS_HTTP_TARGET];

if (typeof httpTarget === 'string') {
// Extract pathname from the target (e.g., "/tunnel?o=123&p=456" -> "/tunnel")
const pathname = httpTarget.split('?')[0] || '';
if (typeof httpTarget !== 'string') {
return false;
}

// Next.js / OTel can sometimes report `http.target` as a full URL (including scheme/host), e.g.
// "https://example.com/monitoring/tunnel?o=...". In that case, comparing the raw string to the tunnel
// route path would fail.
const pathname = extractPathnameFromHttpTarget(httpTarget);
if (!pathname) {
return false;
}

const normalizedTunnelPath = tunnelPath.startsWith('/') ? tunnelPath : `/${tunnelPath}`;
return pathname === normalizedTunnelPath || pathname.startsWith(normalizedTunnelPath + '/');

Check failure on line 70 in packages/nextjs/src/common/utils/dropMiddlewareTunnelRequests.ts

View workflow job for this annotation

GitHub Actions / Lint

eslint(prefer-template)

Unexpected string concatenation.
}

function extractPathnameFromHttpTarget(httpTarget: string): string {
if (!httpTarget) {
return '';
}

return pathname.startsWith(tunnelPath);
if (httpTarget.startsWith('http://') || httpTarget.startsWith('https://')) {
try {
return new URL(httpTarget).pathname;
} catch {
// Fall back to best-effort parsing below.
}
}

return false;
// Example: "/tunnel?o=123&p=456" -> "/tunnel"
return httpTarget.split('?')[0] || '';
}
Loading