Skip to content

Commit e253a45

Browse files
committed
feat(profiling-node): Expose nodeProfilingIntegration
1 parent 65d9150 commit e253a45

File tree

7 files changed

+43
-4
lines changed

7 files changed

+43
-4
lines changed

MIGRATION.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,8 @@ The following list shows how integrations should be migrated:
780780
| `new Hapi()` | `hapiIntegration()` | `@sentry/node` |
781781
| `new Undici()` | `nativeNodeFetchIntegration()` | `@sentry/node` |
782782
| `new Http()` | `httpIntegration()` | `@sentry/node` |
783+
| `new ProfilingIntegration()` | `nodeProfilingIntegration()` | `@sentry/profiling-node` |
784+
| `new BrowserProfilingIntegration()` | `browserProfilingIntegration()` | `@sentry/browser` |
783785

784786
## Deprecate `hub.bindClient()` and `makeMain()`
785787

packages/profiling-node/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ npm install --save @sentry/node @sentry/profiling-node
2727

2828
```javascript
2929
import * as Sentry from '@sentry/node';
30-
import { ProfilingIntegration } from '@sentry/profiling-node';
30+
import { nodeProfilingIntegration } from '@sentry/profiling-node';
3131

3232
Sentry.init({
3333
dsn: 'https://[email protected]/6625302',
3434
debug: true,
3535
tracesSampleRate: 1,
3636
profilesSampleRate: 1, // Set profiling sampling rate.
37-
integrations: [new ProfilingIntegration()],
37+
integrations: [nodeProfilingIntegration()],
3838
});
3939
```
4040

packages/profiling-node/src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
export { ProfilingIntegration } from './integration';
1+
export {
2+
// eslint-disable-next-line deprecation/deprecation
3+
ProfilingIntegration,
4+
nodeProfilingIntegration,
5+
} from './integration';

packages/profiling-node/src/integration.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import { spanToJSON } from '@sentry/core';
22
import type { NodeClient } from '@sentry/node-experimental';
3-
import type { Event, EventProcessor, Hub, Integration, Transaction } from '@sentry/types';
3+
import type {
4+
Event,
5+
EventProcessor,
6+
Hub,
7+
Integration,
8+
IntegrationFn,
9+
IntegrationFnResult,
10+
Transaction,
11+
} from '@sentry/types';
412

513
import { logger } from '@sentry/utils';
614

@@ -40,6 +48,8 @@ function addToProfileQueue(profile: RawThreadCpuProfile): void {
4048
* and inspect each event to see if it is a transaction event and if that transaction event
4149
* contains a profile on it's metadata. If that is the case, we create a profiling event envelope
4250
* and delete the profile from the transaction metadata.
51+
*
52+
* @deprecated Use `nodeProfilingIntegration` instead.
4353
*/
4454
export class ProfilingIntegration implements Integration {
4555
/**
@@ -245,3 +255,14 @@ export class ProfilingIntegration implements Integration {
245255
return maybeRemoveProfileFromSdkMetadata(event);
246256
}
247257
}
258+
259+
/**
260+
* We need this integration in order to send data to Sentry. We hook into the event processor
261+
* and inspect each event to see if it is a transaction event and if that transaction event
262+
* contains a profile on it's metadata. If that is the case, we create a profiling event envelope
263+
* and delete the profile from the transaction metadata.
264+
*/
265+
export const nodeProfilingIntegration = (() => {
266+
// eslint-disable-next-line deprecation/deprecation
267+
return new ProfilingIntegration() as unknown as IntegrationFnResult;
268+
}) satisfies IntegrationFn;

packages/profiling-node/test/hubextensions.hub.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { CpuProfilerBindings } from '../src/cpu_profiler';
77
import { ProfilingIntegration } from '../src/index';
88

99
function makeClientWithoutHooks(): [Sentry.NodeClient, Transport] {
10+
// eslint-disable-next-line deprecation/deprecation
1011
const integration = new ProfilingIntegration();
1112
const transport = Sentry.makeNodeTransport({
1213
url: 'https://[email protected]/6625302',
@@ -41,6 +42,7 @@ function makeClientWithoutHooks(): [Sentry.NodeClient, Transport] {
4142
}
4243

4344
function makeClientWithHooks(): [Sentry.NodeClient, Transport] {
45+
// eslint-disable-next-line deprecation/deprecation
4446
const integration = new ProfilingIntegration();
4547
const client = new Sentry.NodeClient({
4648
stackParser: Sentry.defaultStackParser,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ function makeStaticTransport(): MockTransport {
2323
}
2424

2525
function makeClientWithoutHooks(): [Sentry.NodeClient, MockTransport] {
26+
// eslint-disable-next-line deprecation/deprecation
2627
const integration = new ProfilingIntegration();
2728
const transport = makeStaticTransport();
2829
const client = new Sentry.NodeClient({

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ describe('ProfilingIntegration', () => {
4343
jest.clearAllMocks();
4444
});
4545
it('has a name', () => {
46+
// eslint-disable-next-line deprecation/deprecation
4647
expect(new ProfilingIntegration().name).toBe('ProfilingIntegration');
4748
});
4849

4950
it('stores a reference to getCurrentHub', () => {
51+
// eslint-disable-next-line deprecation/deprecation
5052
const integration = new ProfilingIntegration();
5153

5254
const getCurrentHub = jest.fn().mockImplementation(() => {
@@ -66,6 +68,7 @@ describe('ProfilingIntegration', () => {
6668
send: jest.fn().mockImplementation(() => Promise.resolve()),
6769
flush: jest.fn().mockImplementation(() => Promise.resolve()),
6870
};
71+
// eslint-disable-next-line deprecation/deprecation
6972
const integration = new ProfilingIntegration();
7073

7174
const getCurrentHub = jest.fn((): Hub => {
@@ -100,6 +103,7 @@ describe('ProfilingIntegration', () => {
100103

101104
it('when Hub.getClient returns undefined', async () => {
102105
const logSpy = jest.spyOn(logger, 'log');
106+
// eslint-disable-next-line deprecation/deprecation
103107
const integration = new ProfilingIntegration();
104108

105109
const getCurrentHub = jest.fn((): Hub => {
@@ -115,6 +119,7 @@ describe('ProfilingIntegration', () => {
115119
});
116120
it('when getDsn returns undefined', async () => {
117121
const logSpy = jest.spyOn(logger, 'log');
122+
// eslint-disable-next-line deprecation/deprecation
118123
const integration = new ProfilingIntegration();
119124

120125
const getCurrentHub = jest.fn((): Hub => {
@@ -136,6 +141,7 @@ describe('ProfilingIntegration', () => {
136141
});
137142
it('when getTransport returns undefined', async () => {
138143
const logSpy = jest.spyOn(logger, 'log');
144+
// eslint-disable-next-line deprecation/deprecation
139145
const integration = new ProfilingIntegration();
140146

141147
const getCurrentHub = jest.fn((): Hub => {
@@ -165,6 +171,7 @@ describe('ProfilingIntegration', () => {
165171
send: jest.fn().mockImplementation(() => Promise.resolve()),
166172
flush: jest.fn().mockImplementation(() => Promise.resolve()),
167173
};
174+
// eslint-disable-next-line deprecation/deprecation
168175
const integration = new ProfilingIntegration();
169176

170177
const getCurrentHub = jest.fn((): Hub => {
@@ -198,6 +205,7 @@ describe('ProfilingIntegration', () => {
198205
send: jest.fn().mockImplementation(() => Promise.resolve()),
199206
flush: jest.fn().mockImplementation(() => Promise.resolve()),
200207
};
208+
// eslint-disable-next-line deprecation/deprecation
201209
const integration = new ProfilingIntegration();
202210
const emitter = new EventEmitter();
203211

@@ -233,6 +241,7 @@ describe('ProfilingIntegration', () => {
233241
send: jest.fn().mockImplementation(() => Promise.resolve()),
234242
flush: jest.fn().mockImplementation(() => Promise.resolve()),
235243
};
244+
// eslint-disable-next-line deprecation/deprecation
236245
const integration = new ProfilingIntegration();
237246
const emitter = new EventEmitter();
238247

0 commit comments

Comments
 (0)