diff --git a/packages/profiling-node/src/integration.ts b/packages/profiling-node/src/integration.ts index 5b455f72974d..4e63574c70f2 100644 --- a/packages/profiling-node/src/integration.ts +++ b/packages/profiling-node/src/integration.ts @@ -1,6 +1,5 @@ /* eslint-disable max-lines */ - -import { CpuProfilerBindings } from '@sentry-internal/node-cpu-profiler'; +import { CpuProfilerBindings, ProfileFormat, type RawThreadCpuProfile } from '@sentry-internal/node-cpu-profiler'; import type { Event, IntegrationFn, Profile, ProfileChunk, ProfilingIntegration, Span } from '@sentry/core'; import { LRUMap, @@ -18,8 +17,6 @@ import type { NodeClient } from '@sentry/node'; import { DEBUG_BUILD } from './debug-build'; import { NODE_MAJOR, NODE_VERSION } from './nodeVersion'; import { MAX_PROFILE_DURATION_MS, maybeProfileSpan, stopSpanProfile } from './spanProfileUtils'; -import type { RawThreadCpuProfile } from './types'; -import { ProfileFormat } from './types'; import { PROFILER_THREAD_ID_STRING, PROFILER_THREAD_NAME, diff --git a/packages/profiling-node/src/spanProfileUtils.ts b/packages/profiling-node/src/spanProfileUtils.ts index 342075bde890..9ff20816895c 100644 --- a/packages/profiling-node/src/spanProfileUtils.ts +++ b/packages/profiling-node/src/spanProfileUtils.ts @@ -1,9 +1,8 @@ -import { CpuProfilerBindings } from '@sentry-internal/node-cpu-profiler'; +import { CpuProfilerBindings, type RawThreadCpuProfile } from '@sentry-internal/node-cpu-profiler'; import type { CustomSamplingContext, Span } from '@sentry/core'; import { logger, spanIsSampled, spanToJSON, uuid4 } from '@sentry/core'; import type { NodeClient } from '@sentry/node'; import { DEBUG_BUILD } from './debug-build'; -import type { RawThreadCpuProfile } from './types'; import { isValidSampleRate } from './utils'; export const MAX_PROFILE_DURATION_MS = 30 * 1000; diff --git a/packages/profiling-node/src/types.ts b/packages/profiling-node/src/types.ts deleted file mode 100644 index 9b8f039b3c95..000000000000 --- a/packages/profiling-node/src/types.ts +++ /dev/null @@ -1,84 +0,0 @@ -import type { Event } from '@sentry/core'; - -interface Sample { - stack_id: number; - thread_id: string; - elapsed_since_start_ns: string; -} - -interface ChunkSample { - stack_id: number; - thread_id: string; - timestamp: number; -} - -type Frame = { - function: string; - file: string; - lineno: number; - colno: number; -}; - -interface Measurement { - unit: string; - values: { - elapsed_since_start_ns: number; - value: number; - }[]; -} - -// Profile is marked as optional because it is deleted from the metadata -// by the integration before the event is processed by other integrations. -export interface ProfiledEvent extends Event { - sdkProcessingMetadata: { - profile?: RawThreadCpuProfile; - }; -} - -interface BaseProfile { - profile_id?: string; - stacks: number[][]; - frames: Frame[]; - resources: string[]; - profiler_logging_mode: 'eager' | 'lazy'; - measurements: Record; -} -export interface RawThreadCpuProfile extends BaseProfile { - samples: Sample[]; -} - -export interface RawChunkCpuProfile extends BaseProfile { - samples: ChunkSample[]; -} - -export interface PrivateV8CpuProfilerBindings { - startProfiling?: (name: string) => void; - - stopProfiling?( - name: string, - format: ProfileFormat.THREAD, - threadId: number, - collectResources: boolean, - ): RawThreadCpuProfile | null; - stopProfiling?( - name: string, - format: ProfileFormat.CHUNK, - threadId: number, - collectResources: boolean, - ): RawChunkCpuProfile | null; - - // Helper methods exposed for testing - getFrameModule(abs_path: string): string; -} - -export enum ProfileFormat { - THREAD = 0, - CHUNK = 1, -} - -export interface V8CpuProfilerBindings { - startProfiling(name: string): void; - - stopProfiling(name: string, format: ProfileFormat.THREAD): RawThreadCpuProfile | null; - stopProfiling(name: string, format: ProfileFormat.CHUNK): RawChunkCpuProfile | null; -} diff --git a/packages/profiling-node/src/utils.ts b/packages/profiling-node/src/utils.ts index e6ab3803ebdd..23b05f14f67b 100644 --- a/packages/profiling-node/src/utils.ts +++ b/packages/profiling-node/src/utils.ts @@ -27,8 +27,8 @@ import { import { env, versions } from 'process'; import { isMainThread, threadId } from 'worker_threads'; +import type { RawChunkCpuProfile, RawThreadCpuProfile } from '@sentry-internal/node-cpu-profiler'; import { DEBUG_BUILD } from './debug-build'; -import type { RawChunkCpuProfile, RawThreadCpuProfile } from './types'; // We require the file because if we import it, it will be included in the bundle. // I guess tsc does not check file contents when it's imported. diff --git a/packages/profiling-node/test/utils.test.ts b/packages/profiling-node/test/utils.test.ts index dac0bf16be79..2e5b79e9baee 100644 --- a/packages/profiling-node/test/utils.test.ts +++ b/packages/profiling-node/test/utils.test.ts @@ -1,6 +1,7 @@ import { addItemToEnvelope, createEnvelope, uuid4 } from '@sentry/core'; import type { Event } from '@sentry/core'; +import type { RawThreadCpuProfile } from '@sentry-internal/node-cpu-profiler'; import { addProfilesToEnvelope, findProfiledTransactionsFromEnvelope, @@ -8,7 +9,11 @@ import { isValidSampleRate, } from '../src/utils'; -import type { ProfiledEvent } from '../src/types'; +interface ProfiledEvent extends Event { + sdkProcessingMetadata: { + profile?: RawThreadCpuProfile; + }; +} function makeProfile( props: Partial,