Skip to content

Commit 282ce32

Browse files
committed
feat(v8/profiling-node): Use OTEL powered node package
1 parent 0caddec commit 282ce32

File tree

6 files changed

+39
-39
lines changed

6 files changed

+39
-39
lines changed

packages/profiling-node/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
},
7979
"devDependencies": {
8080
"@sentry/core": "8.0.0-alpha.2",
81-
"@sentry/node-experimental": "8.0.0-alpha.2",
81+
"@sentry/node": "8.0.0-alpha.2",
8282
"@sentry/types": "8.0.0-alpha.2",
8383
"@sentry/utils": "8.0.0-alpha.2",
8484
"@types/node": "16.18.70",

packages/profiling-node/src/integration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { defineIntegration, getCurrentScope, getRootSpan, spanToJSON } from '@sentry/core';
2-
import type { NodeClient } from '@sentry/node-experimental';
2+
import type { NodeClient } from '@sentry/node';
33
import type { IntegrationFn, Span } from '@sentry/types';
44

55
import { logger } from '@sentry/utils';

packages/profiling-node/src/spanProfileUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { spanIsSampled, spanToJSON } from '@sentry/core';
2-
import type { NodeClient } from '@sentry/node-experimental';
2+
import type { NodeClient } from '@sentry/node';
33
import type { CustomSamplingContext, Span } from '@sentry/types';
44
import { logger, uuid4 } from '@sentry/utils';
55

packages/profiling-node/src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { Context, Envelope, Event, StackFrame, StackParser } from '@sentry/
33
import { env, versions } from 'process';
44
import { isMainThread, threadId } from 'worker_threads';
55

6-
import * as Sentry from '@sentry/node-experimental';
6+
import { getCurrentHub } from '@sentry/node';
77
import { GLOBAL_OBJ, forEachEnvelopeItem, logger } from '@sentry/utils';
88

99
import { DEBUG_BUILD } from './debug-build';
@@ -318,7 +318,7 @@ export function applyDebugMetadata(resource_paths: ReadonlyArray<string>): Debug
318318
}
319319

320320
// eslint-disable-next-line deprecation/deprecation
321-
const hub = Sentry.getCurrentHub();
321+
const hub = getCurrentHub();
322322
// eslint-disable-next-line deprecation/deprecation
323323
const client = hub.getClient();
324324
const options = client && client.getOptions();

packages/profiling-node/test/integration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { EventEmitter } from 'events';
22

33
import type { Transport } from '@sentry/types';
44

5-
import type { NodeClient } from '@sentry/node-experimental';
5+
import type { NodeClient } from '@sentry/node';
66
import { _nodeProfilingIntegration } from '../src/integration';
77

88
describe('ProfilingIntegration', () => {

packages/profiling-node/test/spanProfileUtils.test.ts

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
import * as Sentry from '@sentry/node-experimental';
1+
import { NodeClient, defaultStackParser, flush, makeNodeTransport, setCurrentClient, startInactiveSpan } from '@sentry/node';
22

3-
import { getMainCarrier } from '@sentry/core';
3+
import { getMainCarrier, } from '@sentry/core';
44
import type { Transport } from '@sentry/types';
55
import { GLOBAL_OBJ, createEnvelope, logger } from '@sentry/utils';
66
import { CpuProfilerBindings } from '../src/cpu_profiler';
77
import { _nodeProfilingIntegration } from '../src/integration';
88

9-
function makeClientWithHooks(): [Sentry.NodeClient, Transport] {
9+
function makeClientWithHooks(): [NodeClient, Transport] {
1010
const integration = _nodeProfilingIntegration();
11-
const client = new Sentry.NodeClient({
12-
stackParser: Sentry.defaultStackParser,
11+
const client = new NodeClient({
12+
stackParser: defaultStackParser,
1313
tracesSampleRate: 1,
1414
profilesSampleRate: 1,
1515
debug: true,
1616
environment: 'test-environment',
1717
dsn: 'https://[email protected]/6625302',
1818
integrations: [integration],
1919
transport: _opts =>
20-
Sentry.makeNodeTransport({
20+
makeNodeTransport({
2121
url: 'https://[email protected]/6625302',
2222
recordDroppedEvent: () => {
2323
return undefined;
@@ -45,24 +45,24 @@ describe('spanProfileUtils', () => {
4545

4646
it('pulls environment from sdk init', async () => {
4747
const [client, transport] = makeClientWithHooks();
48-
Sentry.setCurrentClient(client);
48+
setCurrentClient(client);
4949
client.init();
5050

5151
const transportSpy = jest.spyOn(transport, 'send').mockReturnValue(Promise.resolve({}));
5252

53-
const transaction = Sentry.startInactiveSpan({ forceTransaction: true, name: 'profile_hub' });
53+
const transaction = startInactiveSpan({ forceTransaction: true, name: 'profile_hub' });
5454
await wait(500);
5555
transaction.end();
5656

57-
await Sentry.flush(1000);
57+
await flush(1000);
5858
expect(transportSpy.mock.calls?.[0]?.[0]?.[1]?.[0]?.[1]).toMatchObject({ environment: 'test-environment' });
5959
});
6060

6161
it('logger warns user if there are insufficient samples and discards the profile', async () => {
6262
const logSpy = jest.spyOn(logger, 'log');
6363

6464
const [client, transport] = makeClientWithHooks();
65-
Sentry.setCurrentClient(client);
65+
setCurrentClient(client);
6666
client.init();
6767

6868
jest.spyOn(CpuProfilerBindings, 'stopProfiling').mockImplementation(() => {
@@ -84,10 +84,10 @@ describe('spanProfileUtils', () => {
8484

8585
jest.spyOn(transport, 'send').mockReturnValue(Promise.resolve({}));
8686

87-
const transaction = Sentry.startInactiveSpan({ forceTransaction: true, name: 'profile_hub' });
87+
const transaction = startInactiveSpan({ forceTransaction: true, name: 'profile_hub' });
8888
transaction.end();
8989

90-
await Sentry.flush(1000);
90+
await flush(1000);
9191

9292
expect(logSpy).toHaveBeenCalledWith('[Profiling] Discarding profile because it contains less than 2 samples');
9393

@@ -100,7 +100,7 @@ describe('spanProfileUtils', () => {
100100
const logSpy = jest.spyOn(logger, 'log');
101101

102102
const [client, transport] = makeClientWithHooks();
103-
Sentry.setCurrentClient(client);
103+
setCurrentClient(client);
104104
client.init();
105105

106106
jest.spyOn(CpuProfilerBindings, 'stopProfiling').mockImplementation(() => {
@@ -127,48 +127,48 @@ describe('spanProfileUtils', () => {
127127

128128
jest.spyOn(transport, 'send').mockReturnValue(Promise.resolve({}));
129129

130-
const transaction = Sentry.startInactiveSpan({ forceTransaction: true, name: 'profile_hub', traceId: 'boop' });
130+
const transaction = startInactiveSpan({ forceTransaction: true, name: 'profile_hub', traceId: 'boop' });
131131
await wait(500);
132132
transaction.end();
133133

134-
await Sentry.flush(1000);
134+
await flush(1000);
135135

136136
expect(logSpy).toHaveBeenCalledWith('[Profiling] Invalid traceId: ' + 'boop' + ' on profiled event');
137137
});
138138

139139
describe('with hooks', () => {
140140
it('calls profiler when transaction is started/stopped', async () => {
141141
const [client, transport] = makeClientWithHooks();
142-
Sentry.setCurrentClient(client);
142+
setCurrentClient(client);
143143
client.init();
144144

145145
const startProfilingSpy = jest.spyOn(CpuProfilerBindings, 'startProfiling');
146146
const stopProfilingSpy = jest.spyOn(CpuProfilerBindings, 'stopProfiling');
147147

148148
jest.spyOn(transport, 'send').mockReturnValue(Promise.resolve({}));
149149

150-
const transaction = Sentry.startInactiveSpan({ forceTransaction: true, name: 'profile_hub' });
150+
const transaction = startInactiveSpan({ forceTransaction: true, name: 'profile_hub' });
151151
await wait(500);
152152
transaction.end();
153153

154-
await Sentry.flush(1000);
154+
await flush(1000);
155155

156156
expect(startProfilingSpy).toHaveBeenCalledTimes(1);
157157
expect((stopProfilingSpy.mock.calls[stopProfilingSpy.mock.calls.length - 1]?.[0] as string).length).toBe(32);
158158
});
159159

160160
it('sends profile in the same envelope as transaction', async () => {
161161
const [client, transport] = makeClientWithHooks();
162-
Sentry.setCurrentClient(client);
162+
setCurrentClient(client);
163163
client.init();
164164

165165
const transportSpy = jest.spyOn(transport, 'send').mockReturnValue(Promise.resolve({}));
166166

167-
const transaction = Sentry.startInactiveSpan({ forceTransaction: true, name: 'profile_hub' });
167+
const transaction = startInactiveSpan({ forceTransaction: true, name: 'profile_hub' });
168168
await wait(500);
169169
transaction.end();
170170

171-
await Sentry.flush(1000);
171+
await flush(1000);
172172

173173
// One for profile, the other for transaction
174174
expect(transportSpy).toHaveBeenCalledTimes(1);
@@ -177,7 +177,7 @@ describe('spanProfileUtils', () => {
177177

178178
it('does not crash if transaction has no profile context or it is invalid', async () => {
179179
const [client] = makeClientWithHooks();
180-
Sentry.setCurrentClient(client);
180+
setCurrentClient(client);
181181
client.init();
182182

183183
// @ts-expect-error transaction is partial
@@ -201,7 +201,7 @@ describe('spanProfileUtils', () => {
201201

202202
it('if transaction was profiled, but profiler returned null', async () => {
203203
const [client, transport] = makeClientWithHooks();
204-
Sentry.setCurrentClient(client);
204+
setCurrentClient(client);
205205
client.init();
206206

207207
jest.spyOn(CpuProfilerBindings, 'stopProfiling').mockReturnValue(null);
@@ -211,11 +211,11 @@ describe('spanProfileUtils', () => {
211211
return Promise.resolve({});
212212
});
213213

214-
const transaction = Sentry.startInactiveSpan({ forceTransaction: true, name: 'profile_hub' });
214+
const transaction = startInactiveSpan({ forceTransaction: true, name: 'profile_hub' });
215215
await wait(500);
216216
transaction.end();
217217

218-
await Sentry.flush(1000);
218+
await flush(1000);
219219

220220
// Only transaction is sent
221221
expect(transportSpy.mock.calls?.[0]?.[0]?.[1]?.[0]?.[0]).toMatchObject({ type: 'transaction' });
@@ -224,18 +224,18 @@ describe('spanProfileUtils', () => {
224224

225225
it('emits preprocessEvent for profile', async () => {
226226
const [client] = makeClientWithHooks();
227-
Sentry.setCurrentClient(client);
227+
setCurrentClient(client);
228228
client.init();
229229

230230
const onPreprocessEvent = jest.fn();
231231

232232
client.on('preprocessEvent', onPreprocessEvent);
233233

234-
const transaction = Sentry.startInactiveSpan({ forceTransaction: true, name: 'profile_hub' });
234+
const transaction = startInactiveSpan({ forceTransaction: true, name: 'profile_hub' });
235235
await wait(500);
236236
transaction.end();
237237

238-
await Sentry.flush(1000);
238+
await flush(1000);
239239

240240
expect(onPreprocessEvent.mock.calls[1][0]).toMatchObject({
241241
profile: {
@@ -250,10 +250,10 @@ describe('spanProfileUtils', () => {
250250
const stopProfilingSpy = jest.spyOn(CpuProfilerBindings, 'stopProfiling');
251251

252252
const [client] = makeClientWithHooks();
253-
Sentry.setCurrentClient(client);
253+
setCurrentClient(client);
254254
client.init();
255255

256-
const transaction = Sentry.startInactiveSpan({ forceTransaction: true, name: 'txn' });
256+
const transaction = startInactiveSpan({ forceTransaction: true, name: 'txn' });
257257
transaction.end();
258258
transaction.end();
259259
expect(stopProfilingSpy).toHaveBeenCalledTimes(1);
@@ -289,16 +289,16 @@ describe('spanProfileUtils', () => {
289289
});
290290

291291
const [client, transport] = makeClientWithHooks();
292-
Sentry.setCurrentClient(client);
292+
setCurrentClient(client);
293293
client.init();
294294

295295
const transportSpy = jest.spyOn(transport, 'send').mockReturnValue(Promise.resolve({}));
296296

297-
const transaction = Sentry.startInactiveSpan({ forceTransaction: true, name: 'profile_hub' });
297+
const transaction = startInactiveSpan({ forceTransaction: true, name: 'profile_hub' });
298298
await wait(500);
299299
transaction.end();
300300

301-
await Sentry.flush(1000);
301+
await flush(1000);
302302

303303
expect(transportSpy.mock.calls?.[0]?.[0]?.[1]?.[1]?.[1]).toMatchObject({
304304
debug_meta: {

0 commit comments

Comments
 (0)