Skip to content

Commit 1dccf2b

Browse files
committed
fixup! fixup! fixup! fixup! fixup! feat(core, node): portable Express integration
1 parent 70aa4e5 commit 1dccf2b

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

packages/node-core/src/utils/ensureIsWrapped.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import { isWrapped } from '@opentelemetry/instrumentation';
2-
import { consoleSandbox, getClient, getGlobalScope, hasSpansEnabled, isEnabled } from '@sentry/core';
2+
import {
3+
consoleSandbox,
4+
getClient,
5+
getOriginalFunction,
6+
getGlobalScope,
7+
hasSpansEnabled,
8+
isEnabled,
9+
type WrappedFunction,
10+
} from '@sentry/core';
311
import type { NodeClient } from '../sdk/client';
412
import { createMissingInstrumentationContext } from './createMissingInstrumentationContext';
513
import { isCjs } from './detection';
@@ -14,7 +22,10 @@ export function ensureIsWrapped(
1422
const clientOptions = getClient<NodeClient>()?.getOptions();
1523
if (
1624
!clientOptions?.disableInstrumentationWarnings &&
17-
!isWrapped(maybeWrappedFunction) &&
25+
!(
26+
isWrapped(maybeWrappedFunction) ||
27+
typeof getOriginalFunction(maybeWrappedFunction as WrappedFunction) === 'function'
28+
) &&
1829
isEnabled() &&
1930
hasSpansEnabled(clientOptions)
2031
) {

packages/node-core/test/utils/ensureIsWrapped.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { afterEach, describe, expect, it, vi } from 'vitest';
22
import { ensureIsWrapped } from '../../src/utils/ensureIsWrapped';
33
import { cleanupOtel, mockSdkInit, resetGlobals } from '../helpers/mockSdkInit';
4+
import { markFunctionWrapped } from '@sentry/core';
45

56
const unwrappedFunction = () => {};
67

@@ -69,4 +70,24 @@ describe('ensureIsWrapped', () => {
6970

7071
expect(spyWarn).toHaveBeenCalledTimes(0);
7172
});
73+
74+
it('does not warn when the method is wrapped by @sentry/core', () => {
75+
const spyWarn = vi.spyOn(console, 'warn').mockImplementation(() => {});
76+
77+
mockSdkInit({ tracesSampleRate: 1 });
78+
79+
function originalFunction() {
80+
return 'i am original';
81+
}
82+
83+
function wrappedFunction() {
84+
return originalFunction();
85+
}
86+
87+
markFunctionWrapped(wrappedFunction, originalFunction);
88+
89+
ensureIsWrapped(wrappedfunction, 'express');
90+
91+
expect(spyWarn).toHaveBeenCalledTimes(0);
92+
});
7293
});

0 commit comments

Comments
 (0)