Skip to content

Commit

Permalink
fix(profiling): continuous profile chunks should be in seconds (#12532)
Browse files Browse the repository at this point in the history
Timestamps reported in the chunk format need to be in seconds
  • Loading branch information
JonasBa authored Jun 18, 2024
1 parent 2c12022 commit e9e862f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 23 deletions.
4 changes: 2 additions & 2 deletions packages/profiling-node/bindings/cpu_profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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:
Expand Down
22 changes: 7 additions & 15 deletions packages/profiling-node/src/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -149,7 +149,6 @@ function setupAutomatedSpanProfiling(client: NodeClient): void {
interface ChunkData {
id: string;
timer: NodeJS.Timeout | undefined;
startTimestampMS: number;
startTraceID: string;
}
class ContinuousProfiler {
Expand Down Expand Up @@ -217,7 +216,7 @@ class ContinuousProfiler {

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

if (!profile || !this._chunkData.startTimestampMS) {
if (!profile) {
DEBUG_BUILD && logger.log(`[Profiling] _chunkiledStartTraceID to collect profile for: ${this._chunkData.id}`);
return;
}
Expand All @@ -226,17 +225,11 @@ 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,
{
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}`);
Expand Down Expand Up @@ -341,7 +334,6 @@ class ContinuousProfiler {
this._chunkData = {
id: uuid4(),
startTraceID: traceId,
startTimestampMS: timestampInSeconds(),
timer: undefined,
};
}
Expand Down
5 changes: 0 additions & 5 deletions packages/profiling-node/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
1 change: 0 additions & 1 deletion packages/types/src/profiling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export interface ContinuousThreadCpuProfile {
}

interface BaseProfile<T> {
timestamp: string;
version: string;
release: string;
environment: string;
Expand Down

0 comments on commit e9e862f

Please sign in to comment.