Skip to content

Commit c52f05a

Browse files
committed
fix: warn about ignored OTLP application name and labels
Signed-off-by: Arnab Nandy <arnab_nandy7@yahoo.com>
1 parent eaf9428 commit c52f05a

4 files changed

Lines changed: 39 additions & 1 deletion

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ The agent can export async-profiler recordings using the experimental OpenTeleme
3636
The agent sends protobuf requests to `<server-address>/v1development/profiles`.
3737

3838
OTLP export requires the default `ASYNC` profiler and is not supported by the JFR profiler used on Windows.
39+
The application name and labels configured through `PYROSCOPE_APPLICATION_NAME`, `PYROSCOPE_LABELS`, static labels,
40+
or dynamic labels are not included in OTLP profiles. As a result, profiles may appear under
41+
`service_name="unknown_service"`.
3942
Only one profiling event can run at a time. Allocation and lock thresholds can be configured when their event is
4043
selected, for example with `PYROSCOPE_PROFILER_EVENT=alloc` and `PYROSCOPE_PROFILER_ALLOC=512k`. Multiple events
4144
remain supported in sampling mode because they run sequentially.

agent/src/main/java/io/pyroscope/javaagent/AsyncProfilerDelegate.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ private Snapshot dumpImpl(Instant started, Instant ended) {
147147
started,
148148
ended,
149149
data,
150+
// This also removes closed scoped contexts. Keep draining them even though the
151+
// current OTLP exporter does not include the resulting labels snapshot.
150152
Pyroscope.LabelsWrapper.dump()
151153
);
152154
}

agent/src/main/java/io/pyroscope/javaagent/PyroscopeAgent.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.pyroscope.javaagent;
22

3+
import io.pyroscope.http.Format;
34
import io.pyroscope.javaagent.api.Exporter;
45
import io.pyroscope.javaagent.api.Logger;
56
import io.pyroscope.javaagent.api.ProfilingScheduler;
@@ -59,6 +60,11 @@ public static void start(@NotNull Options options) {
5960
}
6061
sOptions = options;
6162
logger.log(Logger.Level.DEBUG, "Config: %s", options.config);
63+
if (options.config.format == Format.OTLP) {
64+
logger.log(Logger.Level.WARN,
65+
"OTLP export does not include the configured application name or labels; " +
66+
"profiles may appear under service_name=\"unknown_service\"");
67+
}
6268
try {
6369
options.scheduler.start(options.profiler);
6470
ScopedContext.ENABLED.set(true);

agent/src/test/java/io/pyroscope/javaagent/PyroscopeAgentTest.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.pyroscope.javaagent;
22

3+
import io.pyroscope.http.Format;
34
import io.pyroscope.javaagent.api.Logger;
45
import io.pyroscope.javaagent.api.ProfilingScheduler;
56
import io.pyroscope.javaagent.config.Config;
@@ -27,6 +28,9 @@ public class PyroscopeAgentTest {
2728
@Mock
2829
private ProfilingScheduler profilingScheduler;
2930

31+
@Mock
32+
private ProfilerDelegate profiler;
33+
3034
@BeforeEach
3135
void setUp() {
3236
configAgentEnabled = new Config.Builder()
@@ -35,6 +39,7 @@ void setUp() {
3539
optionsAgentEnabled = new PyroscopeAgent.Options.Builder(configAgentEnabled)
3640
.setScheduler(profilingScheduler)
3741
.setLogger(logger)
42+
.setProfiler(profiler)
3843
.build();
3944

4045
configAgentDisabled = new Config.Builder()
@@ -43,6 +48,7 @@ void setUp() {
4348
optionsAgentDisabled = new PyroscopeAgent.Options.Builder(configAgentDisabled)
4449
.setScheduler(profilingScheduler)
4550
.setLogger(logger)
51+
.setProfiler(profiler)
4652
.build();
4753
}
4854

@@ -56,6 +62,7 @@ void startupTestWithEnabledAgent() {
5662
PyroscopeAgent.start(optionsAgentEnabled);
5763

5864
verify(profilingScheduler, times(1)).start(any());
65+
verify(logger, never()).log(eq(Logger.Level.WARN), contains("OTLP export"));
5966
}
6067

6168
@Test
@@ -64,4 +71,24 @@ void startupTestWithDisabledAgent() {
6471

6572
verify(profilingScheduler, never()).start(any());
6673
}
67-
}
74+
75+
@Test
76+
void warnsWhenOtlpDoesNotIncludeApplicationNameOrLabels() {
77+
Config config = new Config.Builder()
78+
.setAgentEnabled(true)
79+
.setFormat(Format.OTLP)
80+
.build();
81+
PyroscopeAgent.Options options = new PyroscopeAgent.Options.Builder(config)
82+
.setScheduler(profilingScheduler)
83+
.setLogger(logger)
84+
.setProfiler(profiler)
85+
.build();
86+
87+
PyroscopeAgent.start(options);
88+
89+
verify(logger).log(
90+
Logger.Level.WARN,
91+
"OTLP export does not include the configured application name or labels; " +
92+
"profiles may appear under service_name=\"unknown_service\"");
93+
}
94+
}

0 commit comments

Comments
 (0)