From b38f9b218ab84277a8e18ac955dd7ae539692fc2 Mon Sep 17 00:00:00 2001 From: JonasBa Date: Tue, 18 Jun 2024 16:13:28 -0400 Subject: [PATCH 1/2] fix(profiling): continuous profile chunks should be in seconds --- packages/profiling-node/bindings/cpu_profiler.cc | 4 ++-- packages/profiling-node/src/integration.ts | 5 +---- packages/profiling-node/src/utils.ts | 5 ----- packages/types/src/profiling.ts | 1 - 4 files changed, 3 insertions(+), 12 deletions(-) diff --git a/packages/profiling-node/bindings/cpu_profiler.cc b/packages/profiling-node/bindings/cpu_profiler.cc index cbff754623bc..3a00d76f3169 100644 --- a/packages/profiling-node/bindings/cpu_profiler.cc +++ b/packages/profiling-node/bindings/cpu_profiler.cc @@ -759,7 +759,7 @@ static napi_value TranslateMeasurementsDouble( } else if (format == ProfileFormat::kFormatChunk) { napi_value ts; napi_create_double( - env, profile_start_timestamp_ms + (timestamps_ns[i] * 1e-6), &ts); + env, profile_start_timestamp_ms + (timestamps_ns[i] * 1e-9), &ts); napi_set_named_property(env, entry, "timestamp", ts); } @@ -818,7 +818,7 @@ TranslateMeasurements(const napi_env &env, const enum ProfileFormat format, case ProfileFormat::kFormatChunk: { napi_value ts; napi_create_double( - env, profile_start_timestamp_ms + (timestamps_ns[i] * 1e-6), &ts); + env, profile_start_timestamp_ms + (timestamps_ns[i] * 1e-9), &ts); napi_set_named_property(env, entry, "timestamp", ts); } break; default: diff --git a/packages/profiling-node/src/integration.ts b/packages/profiling-node/src/integration.ts index 6cba86fe4f8d..9defabf1913e 100644 --- a/packages/profiling-node/src/integration.ts +++ b/packages/profiling-node/src/integration.ts @@ -146,7 +146,6 @@ function setupAutomatedSpanProfiling(client: NodeClient): void { interface ChunkData { id: string; timer: NodeJS.Timeout | undefined; - startTimestampMS: number; startTraceID: string; } class ContinuousProfiler { @@ -212,7 +211,7 @@ class ContinuousProfiler { return; } const profile = CpuProfilerBindings.stopProfiling(this._chunkData.id, ProfileFormat.CHUNK); - if (!profile || !this._chunkData.startTimestampMS) { + if (!profile) { DEBUG_BUILD && logger.log(`[Profiling] _chunkiledStartTraceID to collect profile for: ${this._chunkData.id}`); return; } @@ -222,7 +221,6 @@ class ContinuousProfiler { DEBUG_BUILD && logger.log(`[Profiling] Profile chunk ${this._chunkData.id} sent to Sentry.`); const chunk = createProfilingChunkEvent( - this._chunkData.startTimestampMS, this._client, this._client.getOptions(), profile, @@ -300,7 +298,6 @@ class ContinuousProfiler { this._chunkData = { id: uuid4(), startTraceID: traceId, - startTimestampMS: timestampInSeconds(), timer: undefined, }; } diff --git a/packages/profiling-node/src/utils.ts b/packages/profiling-node/src/utils.ts index 107debae5c8b..fde5acabf1d5 100644 --- a/packages/profiling-node/src/utils.ts +++ b/packages/profiling-node/src/utils.ts @@ -191,14 +191,12 @@ function createProfileChunkPayload( { release, environment, - start_timestamp, trace_id, profiler_id, chunk_id, }: { release: string; environment: string; - start_timestamp: number; trace_id: string | undefined; chunk_id: string; profiler_id: string; @@ -216,7 +214,6 @@ function createProfileChunkPayload( const profile: ProfileChunk = { chunk_id: chunk_id, profiler_id: profiler_id, - timestamp: new Date(start_timestamp).toISOString(), platform: 'node', version: CONTINUOUS_FORMAT_VERSION, release: release, @@ -235,7 +232,6 @@ function createProfileChunkPayload( * Creates a profiling chunk envelope item, if the profile does not pass validation, returns null. */ export function createProfilingChunkEvent( - start_timestamp: number, client: Client, options: { release?: string; environment?: string }, profile: RawChunkCpuProfile, @@ -248,7 +244,6 @@ export function createProfilingChunkEvent( return createProfileChunkPayload(client, profile, { release: options.release ?? '', environment: options.environment ?? '', - start_timestamp: start_timestamp, trace_id: identifiers.trace_id ?? '', chunk_id: identifiers.chunk_id, profiler_id: identifiers.profiler_id, diff --git a/packages/types/src/profiling.ts b/packages/types/src/profiling.ts index 5161b6b64b2e..48dd797492bf 100644 --- a/packages/types/src/profiling.ts +++ b/packages/types/src/profiling.ts @@ -50,7 +50,6 @@ export interface ContinuousThreadCpuProfile { } interface BaseProfile { - timestamp: string; version: string; release: string; environment: string; From be3bb04081a2d3233729887bece5dc886d088ac0 Mon Sep 17 00:00:00 2001 From: JonasBa Date: Tue, 18 Jun 2024 16:31:56 -0400 Subject: [PATCH 2/2] lint --- packages/profiling-node/src/integration.ts | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/packages/profiling-node/src/integration.ts b/packages/profiling-node/src/integration.ts index 62188e174b18..e6d33d5c4b46 100644 --- a/packages/profiling-node/src/integration.ts +++ b/packages/profiling-node/src/integration.ts @@ -2,7 +2,7 @@ import { defineIntegration, getCurrentScope, getIsolationScope, getRootSpan, spa import type { NodeClient } from '@sentry/node'; import type { Event, Integration, IntegrationFn, Profile, ProfileChunk, Span } from '@sentry/types'; -import { LRUMap, logger, timestampInSeconds, uuid4 } from '@sentry/utils'; +import { LRUMap, logger, uuid4 } from '@sentry/utils'; import { getGlobalScope } from '../../core/src/currentScopes'; import { CpuProfilerBindings } from './cpu_profiler'; @@ -225,16 +225,11 @@ class ContinuousProfiler { } DEBUG_BUILD && logger.log(`[Profiling] Profile chunk ${this._chunkData.id} sent to Sentry.`); - const chunk = createProfilingChunkEvent( - this._client, - this._client.getOptions(), - profile, - { - chunk_id: this._chunkData.id, - trace_id: this._chunkData.startTraceID, - profiler_id: this._profilerId, - }, - ); + const chunk = createProfilingChunkEvent(this._client, this._client.getOptions(), profile, { + chunk_id: this._chunkData.id, + trace_id: this._chunkData.startTraceID, + profiler_id: this._profilerId, + }); if (!chunk) { DEBUG_BUILD && logger.log(`[Profiling] Failed to create profile chunk for: ${this._chunkData.id}`);