Skip to content

Commit

Permalink
fix: reported profiling stack frame count (#886)
Browse files Browse the repository at this point in the history
  • Loading branch information
seemk authored Feb 22, 2024
1 parent ee90b71 commit 6bed434
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
21 changes: 19 additions & 2 deletions src/profiling/OTLPProfilingExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@
import * as protoLoader from '@grpc/proto-loader';
import type * as grpc from '@grpc/grpc-js';
import * as path from 'path';
import { CpuProfile, HeapProfile, ProfilingExporter } from './types';
import {
CpuProfile,
HeapProfile,
ProfilingExporter,
ProfilingStacktrace,
} from './types';
import { diag } from '@opentelemetry/api';
import { Resource } from '@opentelemetry/resources';
import { VERSION } from '@opentelemetry/core';
Expand Down Expand Up @@ -68,6 +73,16 @@ function commonAttributes(
];
}

function countSamples(stacktraces: ProfilingStacktrace[]) {
let sampleCount = 0;

for (const profilingStacktrace of stacktraces) {
sampleCount += profilingStacktrace.stacktrace.length;
}

return sampleCount;
}

export class OTLPProfilingExporter implements ProfilingExporter {
protected _client: LogsClient;
protected _options: OTLPExporterOptions;
Expand Down Expand Up @@ -140,7 +155,9 @@ export class OTLPProfilingExporter implements ProfilingExporter {

send(profile: CpuProfile) {
const { stacktraces } = profile;
const sampleCount = stacktraces?.length || 0;

const sampleCount = countSamples(stacktraces);

diag.debug(`profiling: Exporting ${sampleCount} CPU samples`);
const { callstackInterval } = this._options;
const attributes = commonAttributes('cpu', sampleCount);
Expand Down
2 changes: 1 addition & 1 deletion test/profiling/exporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe('profiling OTLP exporter', () => {
key: 'com.splunk.sourcetype',
value: { stringValue: 'otel.profiling' },
},
{ key: 'profiling.data.total.frame.count', value: { intValue: 1 } },
{ key: 'profiling.data.total.frame.count', value: { intValue: 2 } },
]);

done();
Expand Down

0 comments on commit 6bed434

Please sign in to comment.