Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ test('Should record exceptions and transactions for faulty route handlers', asyn

expect(routehandlerTransaction.contexts?.trace?.status).toBe('internal_error');
expect(routehandlerTransaction.contexts?.trace?.op).toBe('http.server');
expect(routehandlerTransaction.contexts?.trace?.origin).toContain('auto.http.otel.http');
expect(routehandlerTransaction.contexts?.trace?.origin).toContain('auto');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test keeps coming back 😄


expect(routehandlerError.exception?.values?.[0].value).toBe('route-handler-error');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test('Sends a transaction for a request to app router', async ({ page }) => {
expect(transactionEvent.contexts?.trace).toEqual({
data: expect.objectContaining({
'sentry.op': 'http.server',
'sentry.origin': 'auto.http.otel.http',
'sentry.origin': 'auto',
'sentry.sample_rate': 1,
'sentry.source': 'route',
'http.method': 'GET',
Expand All @@ -27,7 +27,7 @@ test('Sends a transaction for a request to app router', async ({ page }) => {
'otel.kind': 'SERVER',
}),
op: 'http.server',
origin: 'auto.http.otel.http',
origin: 'auto',
span_id: expect.any(String),
status: 'ok',
trace_id: expect.any(String),
Expand Down
30 changes: 26 additions & 4 deletions packages/nextjs/src/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import {
SEMANTIC_ATTRIBUTE_SENTRY_OP,
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
applySdkMetadata,
getClient,
getGlobalScope,
getRootSpan,
spanToJSON,
} from '@sentry/core';
import { getDefaultIntegrations, init as nodeInit } from '@sentry/node';
import { getDefaultIntegrations, httpIntegration, init as nodeInit } from '@sentry/node';
import type { NodeClient, NodeOptions } from '@sentry/node';
import { GLOBAL_OBJ, logger } from '@sentry/utils';
import { GLOBAL_OBJ, logger, stripUrlQueryAndFragment } from '@sentry/utils';

import {
ATTR_HTTP_REQUEST_METHOD,
Expand Down Expand Up @@ -99,7 +100,18 @@ export function init(options: NodeOptions): NodeClient | undefined {
return;
}

const customDefaultIntegrations = getDefaultIntegrations(options);
const customDefaultIntegrations = getDefaultIntegrations(options)
.filter(integration => integration.name !== 'Http')
.concat(
// We are using the HTTP integration without instrumenting incoming HTTP requests because Next.js does that by itself.
httpIntegration({
instrumentation: {
_experimentalConfig: {
disableIncomingRequestInstrumentation: true,
},
},
}),
);

// Turn off Next.js' own fetch instrumentation
// https://github.com/lforst/nextjs-fork/blob/1994fd186defda77ad971c36dc3163db263c993f/packages/next/src/server/lib/patch-fetch.ts#L245
Expand Down Expand Up @@ -319,15 +331,25 @@ export function init(options: NodeOptions): NodeClient | undefined {
}

// Enhance route handler transactions
if (event.type === 'transaction' && event.contexts?.trace?.data?.['sentry.route_handler'] === true) {
if (
event.type === 'transaction' &&
(event.contexts?.trace?.data?.['sentry.route_handler'] === true ||
event.contexts?.trace?.data?.['sentry.rsc'] === true)
) {
event.contexts.trace.data = event.contexts.trace.data || {};
event.contexts.trace.data[SEMANTIC_ATTRIBUTE_SENTRY_OP] = 'http.server';
event.contexts.trace.op = 'http.server';

if (event.transaction) {
event.transaction = stripUrlQueryAndFragment(event.transaction);
}

if (typeof event.contexts.trace.data[ATTR_HTTP_ROUTE] === 'string') {
// eslint-disable-next-line deprecation/deprecation
event.transaction = `${event.contexts.trace.data[SEMATTRS_HTTP_METHOD]} ${event.contexts.trace.data[
ATTR_HTTP_ROUTE
].replace(/\/route$/, '')}`;
event.contexts.trace.data[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] = 'route';
}
}

Expand Down
Loading