Skip to content
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

fix(node): Do not manually finish / update root Hapi spans. #12287

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
import { expect, test } from '@playwright/test';
import { waitForError } from '@sentry-internal/event-proxy-server';
import { waitForError, waitForTransaction } from '@sentry-internal/event-proxy-server';

test('Sends thrown error to Sentry', async ({ baseURL }) => {
const errorEventPromise = waitForError('node-hapi', errorEvent => {
return errorEvent?.exception?.values?.[0]?.value === 'This is an error';
});

const transactionEventPromise = waitForTransaction('node-hapi', transactionEvent => {
return transactionEvent?.transaction === 'GET /test-failure';
});

await fetch(`${baseURL}/test-failure`);

const errorEvent = await errorEventPromise;
const errorEventId = errorEvent.event_id;
const transactionEvent = await transactionEventPromise;

expect(transactionEvent.transaction).toBe('GET /test-failure');
expect(transactionEvent.contexts?.trace).toMatchObject({
trace_id: expect.any(String),
span_id: expect.any(String),
});

expect(errorEvent.exception?.values).toHaveLength(1);
expect(errorEvent.exception?.values?.[0]?.value).toBe('This is an error');
Expand All @@ -27,6 +37,9 @@ test('Sends thrown error to Sentry', async ({ baseURL }) => {
trace_id: expect.any(String),
span_id: expect.any(String),
});

expect(errorEvent.contexts?.trace?.trace_id).toBe(transactionEvent.contexts?.trace?.trace_id);
expect(errorEvent.contexts?.trace?.span_id).toBe(transactionEvent.contexts?.trace?.span_id);
});

test('sends error with parameterized transaction name', async ({ baseURL }) => {
Expand Down
11 changes: 0 additions & 11 deletions packages/node/src/integrations/tracing/hapi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ import {
SDK_VERSION,
SEMANTIC_ATTRIBUTE_SENTRY_OP,
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
SPAN_STATUS_ERROR,
captureException,
defineIntegration,
getActiveSpan,
getClient,
getDefaultIsolationScope,
getIsolationScope,
getRootSpan,
spanToJSON,
} from '@sentry/core';
import type { IntegrationFn, Span } from '@sentry/types';
Expand Down Expand Up @@ -79,19 +76,11 @@ export const hapiErrorPlugin = {
logger.warn('Isolation scope is still the default isolation scope - skipping setting transactionName');
}

const activeSpan = getActiveSpan();
const rootSpan = activeSpan ? getRootSpan(activeSpan) : undefined;

if (request.response && isBoomObject(request.response)) {
sendErrorToSentry(request.response);
} else if (isErrorEvent(event)) {
sendErrorToSentry(event.error);
}

if (rootSpan) {
rootSpan.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });
rootSpan.end();
}
});
},
};
Expand Down
Loading