Skip to content

Commit fe8e34d

Browse files
committed
fix: forward tracing headers in link gateway analytics fetch
1 parent e1a03e3 commit fe8e34d

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/middleware.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { ErrorSource, handleError } from '@/lib/errorHandler.edge';
1010
import { getUserLogId, sanitizeHeaderValue } from '@/utils/logging';
1111
import { mapPathToDisciplineParam } from '@/utils/appMode';
1212
import { isFromLegacyApp } from '@/utils/legacyAppDetection';
13+
import { pickTracingHeadersEdge } from '@/utils/tracing.edge';
1314

1415
const log = edgeLogger.child({}, { msgPrefix: '[middleware] ' });
1516

@@ -264,7 +265,10 @@ const emitAnalytics = async (req: NextRequest): Promise<void> => {
264265

265266
try {
266267
const startTime = Date.now();
267-
const response = await fetch(url, { method: 'GET' });
268+
const response = await fetch(url, {
269+
method: 'GET',
270+
headers: pickTracingHeadersEdge(req.headers),
271+
});
268272
const duration = Date.now() - startTime;
269273

270274
if (response.ok) {

src/middlewares/__tests__/middleware.routes.integration.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ describe('middleware route integration', () => {
281281
await middleware(req);
282282
expect(fetchSpy).toHaveBeenCalledWith('https://base.example.com/link_gateway/123%2F456/abstract', {
283283
method: 'GET',
284+
headers: expect.any(Object),
284285
});
285286
fetchSpy.mockRestore();
286287
});

0 commit comments

Comments
 (0)