-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Multiple trace IDs generated in sentry-trace header when using Next.js #13870
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi, thanks for moving this issue here! Before I go and try reproduce this. How are you calling your Next.js app? |
@lforst My application is running in docker const packageInfo = require('./package.json');
const { PHASE_PRODUCTION_SERVER } = require('next/constants');
const withBundleAnalyzer = require('@next/bundle-analyzer')({ enabled: process.env.ANALYZE === 'true' });
const { withSentryConfig } = require('@sentry/nextjs');
const parseEnv = variable =>
variable === undefined ||
variable === null ||
variable === '' ||
variable === 'undefined' ||
variable === 'null' ||
variable === '<nil>'
? undefined
: variable;
const buildId = parseEnv(process.env.NEXT_PUBLIC_BUILD_ID);
const environment = parseEnv(process.env.NODE_ENV) || 'development';
const release = `${packageInfo.name}@${packageInfo.version}+${buildId || environment}`;
const appBaseUrl = new URL(parseEnv(process.env.NEXT_PUBLIC_APP_BASE_URL));
const apiBaseUrl = new URL(parseEnv(process.env.NEXT_PUBLIC_API_BASE_URL));
module.exports = phase => {
const isServer = phase === PHASE_PRODUCTION_SERVER;
/** @type {import('next').NextConfig} */
const nextConfig = {
generateBuildId: () => buildId || environment,
output: buildId ? 'standalone' : undefined,
compress: !buildId,
cacheHandler: isServer && buildId ? require.resolve('./cache-handler.mjs') : undefined,
cacheMaxMemorySize: isServer && buildId ? 0 : undefined,
logging: {
fetches: {
fullUrl: !buildId,
},
},
poweredByHeader: false,
experimental: {
instrumentationHook: true,
serverActions: { allowedOrigins: appBaseUrl ? [appBaseUrl.host] : undefined },
},
transpilePackages: ['next-mdx-remote'],
images: {
minimumCacheTTL: 604800,
formats: ['image/avif', 'image/webp'],
deviceSizes: [375, 640, 768, 828, 1024, 1080, 1280, 1440, 1570, 1920, 2048, 2560],
},
};
/** @type {Parameters<import('@sentry/nextjs').withSentryConfig>[1]} */
const sentryBuildOptions = {
org: parseEnv(process.env.NEXT_PUBLIC_SENTRY_ORG),
project: packageInfo.name,
authToken: parseEnv(process.env.SENTRY_AUTH_TOKEN),
telemetry: false,
silent: !!buildId,
hideSourceMaps: !!buildId,
disableLogger: !!buildId,
tunnelRoute: '/api/monitoring-tunnel',
};
return withBundleAnalyzer(withSentryConfig(nextConfig, sentryBuildOptions));
}; |
Ah sorry, I meant how the middleware is invoked as in how the HTTP request to your Next.js app is made 😄 |
@lforst I have middleware enabled for the following routers. export const config = {
matcher: ['/((?!api|_next|.*\\..*).*)'],
}; I have complex business logic to call middleware depending on URL and user authorization. But I always have at least 1 middleware function that is always called. To implement calling different middlewares we use @nimpl/middleware-chain library. My middleware is similar to the example from the library. Unfortunately I can't provide the exact source code of my middleware due to privacy. |
What I meant is, what causes your server to be hit to generate these traces? 😂 I assume the answer is "People open our website in their browser". |
@lforst To reproduce the error it is enough to have any static page created in |
@lforst Additionally, I can add that inside the middleware the |
@shlyamster Thanks! I have a hunch, but I don't know for sure whether I am right. Maybe this fixes it: #13907 (Side note: None of this is happening in the frontend so you should be in your happy place as a backend dev 😄) |
A PR closing this issue has just been released 🚀This issue was referenced by PR #13907, which was included in the 8.35.0 release. |
Is there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/nextjs
SDK Version
8.33.1
Framework Version
Next 14.2.14
Link to Sentry event
n/a
Reproduction Example/SDK Setup
Dependencies
sentry.client.config.ts
instrumentation.ts
Steps to Reproduce
tracePropagationTargets
and configure it to point to your backend server.fetch
inside middleware or during SSG generation in a Next.js project.Baggage
andSentry-Trace
headers to the outgoing requests.Sentry-Trace
header will contain two trace IDs, for example:0b7da23d63cc4a7d9436abf37ace0e0c-9510fafae5f1c2c5-1,faca5d26f53d660657d9e4b073fb8da2-74dbb120f6aca02a-1
Expected Result
The
Sentry-Trace
header should contain only a single trace ID.Actual Result
The
Sentry-Trace
header contains multiple trace IDs.The text was updated successfully, but these errors were encountered: