Skip to content

Commit c0d36fd

Browse files
committed
feat: add trace_id pprof label
1 parent 59e5455 commit c0d36fd

4 files changed

Lines changed: 10 additions & 5 deletions

File tree

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ link traces with the profiling data, and find specific lines of code related to
77
* Because of how sampling profilers work, spans shorter than the sample interval may not be captured. By default pyroscope CPU profiler probes stack traces 100 times per second, meaning that spans shorter than 10ms may not be captured.
88

99

10-
Java code can be easily instrumented with otel-profiling-java package -
11-
a `OpenTelemetry` implementation, that annotates profiling data with span IDs which makes it possible to filter
12-
out profile of a particular trace span in Pyroscope.
10+
Java code can be easily instrumented with the otel-profiling-java package, an `OpenTelemetry` implementation that annotates profiling data with `trace_id` and `span_id` labels, which makes it possible to filter the profile of a particular trace (or trace span) in Pyroscope.
1311

1412
Visit [docs](https://grafana.com/docs/pyroscope/latest/configure-client/trace-span-profiles/java-span-profiles/) page for usage and configuration documentation.
1513

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pyroscope_version=2.5.1
1+
pyroscope_version=2.6.0
22
# x-release-please-start-version
33
otel_profiling_version=2.0.5
44
# x-release-please-end

lib/src/main/java/io/otel/pyroscope/PyroscopeOtelSpanProcessor.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ public void onStart(Context parentContext, ReadWriteSpan span) {
6363

6464
span.setAttribute(ATTRIBUTE_KEY_PROFILE_ID, strProfileId);
6565
asprof.setTracingContext(spanId, spanName);
66+
String traceId = span.getSpanContext().getTraceId();
67+
asprof.setTraceId(Long.parseUnsignedLong(traceId.substring(0, 16), 16),
68+
Long.parseUnsignedLong(traceId.substring(16, 32), 16));
6669
}
6770

6871
@Override
@@ -71,6 +74,7 @@ public void onEnd(ReadableSpan span) {
7174
return;
7275
}
7376
asprof.setTracingContext(0, 0);
77+
asprof.setTraceId(0L, 0L);
7478
}
7579

7680
public static long parseSpanId(String strProfileId) {

otel-extension/src/main/java/io/otel/pyroscope/PyroscopeOtelSpanProcessor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,17 @@ public void onStart(Context parentContext, ReadWriteSpan span) {
5252

5353
span.setAttribute(ATTRIBUTE_KEY_PROFILE_ID, strProfileId);
5454
api.setTracingContext(spanId, spanName);
55+
api.setTraceId(span.getSpanContext().getTraceId());
5556
}
5657

5758
@Override
5859
public void onEnd(ReadableSpan span) {
5960
if (configuration.rootSpanOnly && !isRootSpan(span)) {
6061
return;
6162
}
62-
getProfiler().setTracingContext(0, 0);
63+
ProfilerApi api = getProfiler();
64+
api.setTracingContext(0, 0);
65+
api.clearTraceId();
6366
}
6467

6568
public static long parseSpanId(String strProfileId) {

0 commit comments

Comments
 (0)