Skip to content

Commit 5fa62e7

Browse files
committed
Use nativeNodeFetchIntegration for ESM too
1 parent d2cdd1d commit 5fa62e7

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

packages/node-experimental/src/integrations/node-fetch.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,29 @@ const _nativeNodeFetchIntegration = ((options: NodeFetchOptions = {}) => {
2727
const _breadcrumbs = typeof options.breadcrumbs === 'undefined' ? true : options.breadcrumbs;
2828
const _ignoreOutgoingRequests = options.ignoreOutgoingRequests;
2929

30-
function getInstrumentation(): [Instrumentation] | void {
30+
async function getInstrumentation(): Promise<[Instrumentation] | void> {
3131
// Only add NodeFetch if Node >= 16, as previous versions do not support it
3232
if (NODE_MAJOR < 16) {
3333
return;
3434
}
3535

3636
try {
37-
// eslint-disable-next-line @typescript-eslint/no-var-requires
38-
const { FetchInstrumentation } = require('opentelemetry-instrumentation-fetch-node');
37+
const pkg = await import('opentelemetry-instrumentation-fetch-node');
3938
return [
40-
new FetchInstrumentation({
39+
new pkg.FetchInstrumentation({
4140
ignoreRequestHook: (request: { origin?: string }) => {
4241
const url = request.origin;
4342
return _ignoreOutgoingRequests && url && _ignoreOutgoingRequests(url);
4443
},
45-
4644
onRequest: ({ span }: { span: Span }) => {
4745
_updateSpan(span);
4846

4947
if (_breadcrumbs) {
5048
_addRequestBreadcrumb(span);
5149
}
5250
},
53-
}),
51+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
52+
} as any),
5453
];
5554
} catch (error) {
5655
// Could not load instrumentation
@@ -60,13 +59,14 @@ const _nativeNodeFetchIntegration = ((options: NodeFetchOptions = {}) => {
6059
return {
6160
name: 'NodeFetch',
6261
setupOnce() {
63-
const instrumentations = getInstrumentation();
64-
65-
if (instrumentations) {
66-
registerInstrumentations({
67-
instrumentations,
68-
});
69-
}
62+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
63+
getInstrumentation().then(instrumentations => {
64+
if (instrumentations) {
65+
registerInstrumentations({
66+
instrumentations,
67+
});
68+
}
69+
});
7070
},
7171
};
7272
}) satisfies IntegrationFn;

packages/node-experimental/src/integrations/tracing/prisma.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { registerInstrumentations } from '@opentelemetry/instrumentation';
2-
// When importing CommonJs modules into an ESM module, we import the named exports directly.
2+
// When importing CJS modules into an ESM module, we cannot import the named exports directly.
33
import * as prismaInstrumentation from '@prisma/instrumentation';
44
import { defineIntegration } from '@sentry/core';
55
import type { IntegrationFn } from '@sentry/types';

packages/node-experimental/src/sdk/init.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import { NodeClient } from './client';
4040
import { initOtel } from './initOtel';
4141

4242
function getCjsOnlyIntegrations(isCjs = typeof require !== 'undefined'): Integration[] {
43-
return isCjs ? [nativeNodeFetchIntegration(), modulesIntegration()] : [];
43+
return isCjs ? [modulesIntegration()] : [];
4444
}
4545

4646
/** Get the default integrations for the Node Experimental SDK. */
@@ -55,6 +55,7 @@ export function getDefaultIntegrations(options: Options): Integration[] {
5555
// Native Wrappers
5656
consoleIntegration(),
5757
httpIntegration(),
58+
nativeNodeFetchIntegration(),
5859
// Global Handlers
5960
onUncaughtExceptionIntegration(),
6061
onUnhandledRejectionIntegration(),

packages/node-experimental/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"include": ["src/**/*"],
55

66
"compilerOptions": {
7-
"lib": ["es6"]
7+
"lib": ["es6"],
8+
"module": "Node16",
89
}
910
}

0 commit comments

Comments
 (0)