Skip to content

Commit 30a6688

Browse files
committed
Better bundling?
1 parent 40bf557 commit 30a6688

File tree

5 files changed

+27
-42
lines changed

5 files changed

+27
-42
lines changed

dev-packages/node-integration-tests/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"node-schedule": "^2.1.1",
6363
"openai": "5.18.1",
6464
"pg": "8.16.0",
65-
"pino": "^9.9.4",
65+
"pino": "9.9.4",
6666
"postgres": "^3.4.7",
6767
"prisma": "6.15.0",
6868
"proxy": "^2.1.1",

packages/core/src/utils/worldwide.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export type InternalGlobal = {
4848
*/
4949
_sentryModuleMetadata?: Record<string, any>;
5050
_sentryEsmLoaderHookRegistered?: boolean;
51+
_sentryInjectLoaderHookRegister?: () => void;
5152
_sentryInjectLoaderHookRegistered?: boolean;
5253
} & Carrier;
5354

packages/node-core/src/integrations/pino.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,16 @@ export const pinoIntegration = ((options: Options = { eventLevels: ['error', 'fa
6363
setup: () => {
6464
addInstrumentationConfig({
6565
channelName: 'pino-log',
66-
module: { name: 'pino', versionRange: '>=8.0.0 < 9.19.0', filePath: 'lib/tools.js' },
66+
// From Pino v9.10.0 a tracing channel is available directly from Pino:
67+
// https://github.com/pinojs/pino/pull/2281
68+
module: { name: 'pino', versionRange: '>=8.0.0 < 9.10.0', filePath: 'lib/tools.js' },
6769
functionQuery: {
6870
functionName: 'asJson',
6971
kind: 'Sync',
7072
},
7173
});
7274

7375
const injectedChannel = tracingChannel('orchestrion:pino:pino-log');
74-
// From Pino v9.19.0 a tracing channel is available directly from Pino:
75-
// https://github.com/pinojs/pino/pull/2281
7676
const integratedChannel = tracingChannel('pino_asJson');
7777

7878
const onPinoStart = (data: unknown): void => {

packages/node-core/src/sdk/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
functionToStringIntegration,
88
getCurrentScope,
99
getIntegrationsToSetup,
10+
GLOBAL_OBJ,
1011
hasSpansEnabled,
1112
inboundFiltersIntegration,
1213
linkedErrorsIntegration,
@@ -40,7 +41,6 @@ import { envToBool } from '../utils/envToBool';
4041
import { defaultStackParser, getSentryRelease } from './api';
4142
import { NodeClient } from './client';
4243
import { initializeEsmLoader } from './esmLoader';
43-
import { initializeInjectionLoader } from './injectLoader';
4444

4545
/**
4646
* Get default integrations for the Node-Core SDK.
@@ -132,7 +132,7 @@ function _init(
132132

133133
client.init();
134134

135-
initializeInjectionLoader();
135+
GLOBAL_OBJ._sentryInjectLoaderHookRegister?.();
136136

137137
debug.log(`SDK initialized from ${isCjs() ? 'CommonJS' : 'ESM'}`);
138138

packages/node-core/src/sdk/injectLoader.ts

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,26 @@ import * as moduleModule from 'module';
55
import { supportsEsmLoaderHooks } from '../utils/detection';
66

77
let instrumentationConfigs: InstrumentationConfig[] | undefined;
8-
let setupHookFn: (() => void) | undefined;
98

10-
function setupHook(): void {
11-
if (!GLOBAL_OBJ._sentryInjectLoaderHookRegistered) {
9+
/**
10+
* Add an instrumentation config to be used by the injection loader.
11+
*/
12+
export function addInstrumentationConfig(config: InstrumentationConfig): void {
13+
if (!supportsEsmLoaderHooks()) {
14+
return;
15+
}
16+
17+
if (!instrumentationConfigs) {
18+
instrumentationConfigs = [];
19+
}
20+
21+
instrumentationConfigs.push(config);
22+
23+
GLOBAL_OBJ._sentryInjectLoaderHookRegister = () => {
24+
if (GLOBAL_OBJ._sentryInjectLoaderHookRegistered) {
25+
return;
26+
}
27+
1228
GLOBAL_OBJ._sentryInjectLoaderHookRegistered = true;
1329

1430
const instrumentations = instrumentationConfigs || [];
@@ -29,37 +45,5 @@ function setupHook(): void {
2945
} catch (error) {
3046
debug.warn("Failed to register '@apm-js-collab/tracing-hooks' hook", error);
3147
}
32-
}
33-
}
34-
35-
/**
36-
* Add an instrumentation config to be used by the injection loader.
37-
*
38-
* This should be called before `initializeInjectionLoader` is called.
39-
*/
40-
export function addInstrumentationConfig(config: InstrumentationConfig): void {
41-
if (!instrumentationConfigs) {
42-
instrumentationConfigs = [];
43-
}
44-
45-
instrumentationConfigs.push(config);
46-
47-
setupHookFn = setupHook;
48-
}
49-
50-
/**
51-
* Initialize the injection loader - This method is private and not part of the public
52-
* API.
53-
*
54-
* @ignore
55-
*/
56-
export function initializeInjectionLoader(): void {
57-
if (!supportsEsmLoaderHooks()) {
58-
return;
59-
}
60-
61-
if (setupHookFn) {
62-
setupHookFn();
63-
setupHookFn = undefined;
64-
}
48+
};
6549
}

0 commit comments

Comments
 (0)