Skip to content

Commit a845a0e

Browse files
authored
feat(profiling-node): Expose nodeProfilingIntegration (#10868)
@JonasBa when you got some time, could you look into actually rewriting this to the new style? Right now a lot of the tests depend on the non-hook based version etc. and I'm not 100% clear on what can/cannot be removed there 😅 The end result should be just having a single `nodeProfilingIntegration` that receives the client in `setup(client)` and sets up hooks etc in there!
1 parent 16ed613 commit a845a0e

File tree

7 files changed

+83
-44
lines changed

7 files changed

+83
-44
lines changed

MIGRATION.md

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -740,46 +740,48 @@ The following list shows how integrations should be migrated:
740740

741741
### List of integrations and their replacements
742742

743-
| Old | New | Packages |
744-
| ---------------------------- | ----------------------------------- | ------------------------------------------------------------------------------------------------------- |
745-
| `new BrowserTracing()` | `browserTracingIntegration()` | `@sentry/browser` |
746-
| `new InboundFilters()` | `inboundFiltersIntegration()` | `@sentry/core`, `@sentry/browser`, `@sentry/node`, `@sentry/deno`, `@sentry/bun`, `@sentry/vercel-edge` |
747-
| `new FunctionToString()` | `functionToStringIntegration()` | `@sentry/core`, `@sentry/browser`, `@sentry/node`, `@sentry/deno`, `@sentry/bun`, `@sentry/vercel-edge` |
748-
| `new LinkedErrors()` | `linkedErrorsIntegration()` | `@sentry/core`, `@sentry/browser`, `@sentry/node`, `@sentry/deno`, `@sentry/bun`, `@sentry/vercel-edge` |
749-
| `new ModuleMetadata()` | `moduleMetadataIntegration()` | `@sentry/core`, `@sentry/browser` |
750-
| `new RequestData()` | `requestDataIntegration()` | `@sentry/core`, `@sentry/node`, `@sentry/deno`, `@sentry/bun`, `@sentry/vercel-edge` |
751-
| `new Wasm() ` | `wasmIntegration()` | `@sentry/wasm` |
752-
| `new Replay()` | `replayIntegration()` | `@sentry/browser` |
753-
| `new ReplayCanvas()` | `replayCanvasIntegration()` | `@sentry/browser` |
754-
| `new Feedback()` | `feedbackIntegration()` | `@sentry/browser` |
755-
| `new CaptureConsole()` | `captureConsoleIntegration()` | `@sentry/integrations` |
756-
| `new Debug()` | `debugIntegration()` | `@sentry/integrations` |
757-
| `new Dedupe()` | `dedupeIntegration()` | `@sentry/browser`, `@sentry/integrations`, `@sentry/deno` |
758-
| `new ExtraErrorData()` | `extraErrorDataIntegration()` | `@sentry/integrations` |
759-
| `new ReportingObserver()` | `reportingObserverIntegration()` | `@sentry/integrations` |
760-
| `new RewriteFrames()` | `rewriteFramesIntegration()` | `@sentry/integrations` |
761-
| `new SessionTiming()` | `sessionTimingIntegration()` | `@sentry/integrations` |
762-
| `new HttpClient()` | `httpClientIntegration()` | `@sentry/integrations` |
763-
| `new ContextLines()` | `contextLinesIntegration()` | `@sentry/integrations`, `@sentry/node`, `@sentry/deno`, `@sentry/bun` |
764-
| `new Breadcrumbs()` | `breadcrumbsIntegration()` | `@sentry/browser`, `@sentry/deno` |
765-
| `new GlobalHandlers()` | `globalHandlersIntegration()` | `@sentry/browser` , `@sentry/deno` |
766-
| `new HttpContext()` | `httpContextIntegration()` | `@sentry/browser` |
767-
| `new TryCatch()` | `browserApiErrorsIntegration()` | `@sentry/browser`, `@sentry/deno` |
768-
| `new VueIntegration()` | `vueIntegration()` | `@sentry/vue` |
769-
| `new DenoContext()` | `denoContextIntegration()` | `@sentry/deno` |
770-
| `new DenoCron()` | `denoCronIntegration()` | `@sentry/deno` |
771-
| `new NormalizePaths()` | `normalizePathsIntegration()` | `@sentry/deno` |
772-
| `new Console()` | `consoleIntegration()` | `@sentry/node` |
773-
| `new Context()` | `nodeContextIntegration()` | `@sentry/node` |
774-
| `new Modules()` | `modulesIntegration()` | `@sentry/node` |
775-
| `new OnUncaughtException()` | `onUncaughtExceptionIntegration()` | `@sentry/node` |
776-
| `new OnUnhandledRejection()` | `onUnhandledRejectionIntegration()` | `@sentry/node` |
777-
| `new LocalVariables()` | `localVariablesIntegration()` | `@sentry/node` |
778-
| `new Spotlight()` | `spotlightIntegration()` | `@sentry/node` |
779-
| `new Anr()` | `anrIntegration()` | `@sentry/node` |
780-
| `new Hapi()` | `hapiIntegration()` | `@sentry/node` |
781-
| `new Undici()` | `nativeNodeFetchIntegration()` | `@sentry/node` |
782-
| `new Http()` | `httpIntegration()` | `@sentry/node` |
743+
| Old | New | Packages |
744+
| ----------------------------------- | ----------------------------------- | ------------------------------------------------------------------------------------------------------- |
745+
| `new BrowserTracing()` | `browserTracingIntegration()` | `@sentry/browser` |
746+
| `new InboundFilters()` | `inboundFiltersIntegration()` | `@sentry/core`, `@sentry/browser`, `@sentry/node`, `@sentry/deno`, `@sentry/bun`, `@sentry/vercel-edge` |
747+
| `new FunctionToString()` | `functionToStringIntegration()` | `@sentry/core`, `@sentry/browser`, `@sentry/node`, `@sentry/deno`, `@sentry/bun`, `@sentry/vercel-edge` |
748+
| `new LinkedErrors()` | `linkedErrorsIntegration()` | `@sentry/core`, `@sentry/browser`, `@sentry/node`, `@sentry/deno`, `@sentry/bun`, `@sentry/vercel-edge` |
749+
| `new ModuleMetadata()` | `moduleMetadataIntegration()` | `@sentry/core`, `@sentry/browser` |
750+
| `new RequestData()` | `requestDataIntegration()` | `@sentry/core`, `@sentry/node`, `@sentry/deno`, `@sentry/bun`, `@sentry/vercel-edge` |
751+
| `new Wasm() ` | `wasmIntegration()` | `@sentry/wasm` |
752+
| `new Replay()` | `replayIntegration()` | `@sentry/browser` |
753+
| `new ReplayCanvas()` | `replayCanvasIntegration()` | `@sentry/browser` |
754+
| `new Feedback()` | `feedbackIntegration()` | `@sentry/browser` |
755+
| `new CaptureConsole()` | `captureConsoleIntegration()` | `@sentry/integrations` |
756+
| `new Debug()` | `debugIntegration()` | `@sentry/integrations` |
757+
| `new Dedupe()` | `dedupeIntegration()` | `@sentry/browser`, `@sentry/integrations`, `@sentry/deno` |
758+
| `new ExtraErrorData()` | `extraErrorDataIntegration()` | `@sentry/integrations` |
759+
| `new ReportingObserver()` | `reportingObserverIntegration()` | `@sentry/integrations` |
760+
| `new RewriteFrames()` | `rewriteFramesIntegration()` | `@sentry/integrations` |
761+
| `new SessionTiming()` | `sessionTimingIntegration()` | `@sentry/integrations` |
762+
| `new HttpClient()` | `httpClientIntegration()` | `@sentry/integrations` |
763+
| `new ContextLines()` | `contextLinesIntegration()` | `@sentry/integrations`, `@sentry/node`, `@sentry/deno`, `@sentry/bun` |
764+
| `new Breadcrumbs()` | `breadcrumbsIntegration()` | `@sentry/browser`, `@sentry/deno` |
765+
| `new GlobalHandlers()` | `globalHandlersIntegration()` | `@sentry/browser` , `@sentry/deno` |
766+
| `new HttpContext()` | `httpContextIntegration()` | `@sentry/browser` |
767+
| `new TryCatch()` | `browserApiErrorsIntegration()` | `@sentry/browser`, `@sentry/deno` |
768+
| `new VueIntegration()` | `vueIntegration()` | `@sentry/vue` |
769+
| `new DenoContext()` | `denoContextIntegration()` | `@sentry/deno` |
770+
| `new DenoCron()` | `denoCronIntegration()` | `@sentry/deno` |
771+
| `new NormalizePaths()` | `normalizePathsIntegration()` | `@sentry/deno` |
772+
| `new Console()` | `consoleIntegration()` | `@sentry/node` |
773+
| `new Context()` | `nodeContextIntegration()` | `@sentry/node` |
774+
| `new Modules()` | `modulesIntegration()` | `@sentry/node` |
775+
| `new OnUncaughtException()` | `onUncaughtExceptionIntegration()` | `@sentry/node` |
776+
| `new OnUnhandledRejection()` | `onUnhandledRejectionIntegration()` | `@sentry/node` |
777+
| `new LocalVariables()` | `localVariablesIntegration()` | `@sentry/node` |
778+
| `new Spotlight()` | `spotlightIntegration()` | `@sentry/node` |
779+
| `new Anr()` | `anrIntegration()` | `@sentry/node` |
780+
| `new Hapi()` | `hapiIntegration()` | `@sentry/node` |
781+
| `new Undici()` | `nativeNodeFetchIntegration()` | `@sentry/node` |
782+
| `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({

0 commit comments

Comments
 (0)