Skip to content

Commit e9e862f

Browse files
authored
fix(profiling): continuous profile chunks should be in seconds (#12532)
Timestamps reported in the chunk format need to be in seconds
1 parent 2c12022 commit e9e862f

File tree

4 files changed

+9
-23
lines changed

4 files changed

+9
-23
lines changed

packages/profiling-node/bindings/cpu_profiler.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ static napi_value TranslateMeasurementsDouble(
759759
} else if (format == ProfileFormat::kFormatChunk) {
760760
napi_value ts;
761761
napi_create_double(
762-
env, profile_start_timestamp_ms + (timestamps_ns[i] * 1e-6), &ts);
762+
env, profile_start_timestamp_ms + (timestamps_ns[i] * 1e-9), &ts);
763763
napi_set_named_property(env, entry, "timestamp", ts);
764764
}
765765

@@ -818,7 +818,7 @@ TranslateMeasurements(const napi_env &env, const enum ProfileFormat format,
818818
case ProfileFormat::kFormatChunk: {
819819
napi_value ts;
820820
napi_create_double(
821-
env, profile_start_timestamp_ms + (timestamps_ns[i] * 1e-6), &ts);
821+
env, profile_start_timestamp_ms + (timestamps_ns[i] * 1e-9), &ts);
822822
napi_set_named_property(env, entry, "timestamp", ts);
823823
} break;
824824
default:

packages/profiling-node/src/integration.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { defineIntegration, getCurrentScope, getIsolationScope, getRootSpan, spa
22
import type { NodeClient } from '@sentry/node';
33
import type { Event, Integration, IntegrationFn, Profile, ProfileChunk, Span } from '@sentry/types';
44

5-
import { LRUMap, logger, timestampInSeconds, uuid4 } from '@sentry/utils';
5+
import { LRUMap, logger, uuid4 } from '@sentry/utils';
66

77
import { getGlobalScope } from '../../core/src/currentScopes';
88
import { CpuProfilerBindings } from './cpu_profiler';
@@ -149,7 +149,6 @@ function setupAutomatedSpanProfiling(client: NodeClient): void {
149149
interface ChunkData {
150150
id: string;
151151
timer: NodeJS.Timeout | undefined;
152-
startTimestampMS: number;
153152
startTraceID: string;
154153
}
155154
class ContinuousProfiler {
@@ -217,7 +216,7 @@ class ContinuousProfiler {
217216

218217
const profile = this._stopChunkProfiling(this._chunkData);
219218

220-
if (!profile || !this._chunkData.startTimestampMS) {
219+
if (!profile) {
221220
DEBUG_BUILD && logger.log(`[Profiling] _chunkiledStartTraceID to collect profile for: ${this._chunkData.id}`);
222221
return;
223222
}
@@ -226,17 +225,11 @@ class ContinuousProfiler {
226225
}
227226

228227
DEBUG_BUILD && logger.log(`[Profiling] Profile chunk ${this._chunkData.id} sent to Sentry.`);
229-
const chunk = createProfilingChunkEvent(
230-
this._chunkData.startTimestampMS,
231-
this._client,
232-
this._client.getOptions(),
233-
profile,
234-
{
235-
chunk_id: this._chunkData.id,
236-
trace_id: this._chunkData.startTraceID,
237-
profiler_id: this._profilerId,
238-
},
239-
);
228+
const chunk = createProfilingChunkEvent(this._client, this._client.getOptions(), profile, {
229+
chunk_id: this._chunkData.id,
230+
trace_id: this._chunkData.startTraceID,
231+
profiler_id: this._profilerId,
232+
});
240233

241234
if (!chunk) {
242235
DEBUG_BUILD && logger.log(`[Profiling] Failed to create profile chunk for: ${this._chunkData.id}`);
@@ -341,7 +334,6 @@ class ContinuousProfiler {
341334
this._chunkData = {
342335
id: uuid4(),
343336
startTraceID: traceId,
344-
startTimestampMS: timestampInSeconds(),
345337
timer: undefined,
346338
};
347339
}

packages/profiling-node/src/utils.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,12 @@ function createProfileChunkPayload(
191191
{
192192
release,
193193
environment,
194-
start_timestamp,
195194
trace_id,
196195
profiler_id,
197196
chunk_id,
198197
}: {
199198
release: string;
200199
environment: string;
201-
start_timestamp: number;
202200
trace_id: string | undefined;
203201
chunk_id: string;
204202
profiler_id: string;
@@ -216,7 +214,6 @@ function createProfileChunkPayload(
216214
const profile: ProfileChunk = {
217215
chunk_id: chunk_id,
218216
profiler_id: profiler_id,
219-
timestamp: new Date(start_timestamp).toISOString(),
220217
platform: 'node',
221218
version: CONTINUOUS_FORMAT_VERSION,
222219
release: release,
@@ -235,7 +232,6 @@ function createProfileChunkPayload(
235232
* Creates a profiling chunk envelope item, if the profile does not pass validation, returns null.
236233
*/
237234
export function createProfilingChunkEvent(
238-
start_timestamp: number,
239235
client: Client,
240236
options: { release?: string; environment?: string },
241237
profile: RawChunkCpuProfile,
@@ -248,7 +244,6 @@ export function createProfilingChunkEvent(
248244
return createProfileChunkPayload(client, profile, {
249245
release: options.release ?? '',
250246
environment: options.environment ?? '',
251-
start_timestamp: start_timestamp,
252247
trace_id: identifiers.trace_id ?? '',
253248
chunk_id: identifiers.chunk_id,
254249
profiler_id: identifiers.profiler_id,

packages/types/src/profiling.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ export interface ContinuousThreadCpuProfile {
5050
}
5151

5252
interface BaseProfile<T> {
53-
timestamp: string;
5453
version: string;
5554
release: string;
5655
environment: string;

0 commit comments

Comments
 (0)