Skip to content

Commit 649f2a0

Browse files
committed
leave profiler disabled in test
1 parent 671f9b2 commit 649f2a0

File tree

5 files changed

+20
-0
lines changed

5 files changed

+20
-0
lines changed

inferred-spans/src/main/java/io/opentelemetry/contrib/inferredspans/InferredSpansAutoConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ static SpanProcessor create(ConfigProperties properties) {
6060

6161
PropertiesApplier applier = new PropertiesApplier(properties);
6262

63+
applier.applyBool(ENABLED_OPTION, builder::profilerEnabled);
6364
applier.applyBool(LOGGING_OPTION, builder::profilerLoggingEnabled);
6465
applier.applyBool(DIAGNOSTIC_FILES_OPTION, builder::backupDiagnosticFiles);
6566
applier.applyInt(SAFEMODE_OPTION, builder::asyncProfilerSafeMode);

inferred-spans/src/main/java/io/opentelemetry/contrib/inferredspans/InferredSpansProcessorBuilder.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
@SuppressWarnings("CanIgnoreReturnValueSuggester")
2121
public class InferredSpansProcessorBuilder {
22+
private boolean enabled = true;
2223
private boolean profilerLoggingEnabled = true;
2324
private boolean backupDiagnosticFiles = false;
2425
private int asyncProfilerSafeMode = 0;
@@ -60,6 +61,7 @@ public class InferredSpansProcessorBuilder {
6061
public InferredSpansProcessor build() {
6162
InferredSpansConfiguration config =
6263
new InferredSpansConfiguration(
64+
enabled,
6365
profilerLoggingEnabled,
6466
backupDiagnosticFiles,
6567
asyncProfilerSafeMode,
@@ -76,6 +78,11 @@ public InferredSpansProcessor build() {
7678
config, clock, startScheduledProfiling, activationEventsFile, jfrFile);
7779
}
7880

81+
public InferredSpansProcessorBuilder profilerEnabled(boolean profilerEnabled) {
82+
this.enabled = profilerEnabled;
83+
return this;
84+
}
85+
7986
/**
8087
* By default, async profiler prints warning messages about missing JVM symbols to standard
8188
* output. Set this option to {@code false} to suppress such messages.

inferred-spans/src/main/java/io/opentelemetry/contrib/inferredspans/internal/InferredSpansConfiguration.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
public class InferredSpansConfiguration {
1717

18+
private final boolean enabled;
1819
private final boolean profilerLoggingEnabled;
1920
private final boolean backupDiagnosticFiles;
2021
private final int asyncProfilerSafeMode;
@@ -30,6 +31,7 @@ public class InferredSpansConfiguration {
3031

3132
@SuppressWarnings("TooManyParameters")
3233
public InferredSpansConfiguration(
34+
boolean enabled,
3335
boolean profilerLoggingEnabled,
3436
boolean backupDiagnosticFiles,
3537
int asyncProfilerSafeMode,
@@ -42,6 +44,7 @@ public InferredSpansConfiguration(
4244
Duration profilingDuration,
4345
@Nullable String profilerLibDirectory,
4446
BiConsumer<SpanBuilder, SpanContext> parentOverrideHandler) {
47+
this.enabled = enabled;
4548
this.profilerLoggingEnabled = profilerLoggingEnabled;
4649
this.backupDiagnosticFiles = backupDiagnosticFiles;
4750
this.asyncProfilerSafeMode = asyncProfilerSafeMode;
@@ -56,6 +59,10 @@ public InferredSpansConfiguration(
5659
this.parentOverrideHandler = parentOverrideHandler;
5760
}
5861

62+
public boolean isEnabled() {
63+
return enabled;
64+
}
65+
5966
public boolean isProfilingLoggingEnabled() {
6067
return profilerLoggingEnabled;
6168
}

inferred-spans/src/main/java/io/opentelemetry/contrib/inferredspans/internal/SamplingProfiler.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,10 @@ public boolean onDeactivation(Span deactivatedSpan, @Nullable Span previouslyAct
354354
@Override
355355
@SuppressWarnings("FutureReturnValueIgnored")
356356
public void run() {
357+
if (!config.isEnabled()) {
358+
logger.fine("Profiling is disabled, not starting profiling session");
359+
return;
360+
}
357361

358362
// lazily create temporary files
359363
try {

inferred-spans/src/test/java/io/opentelemetry/contrib/inferredspans/InferredSpansCustomizerProviderTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ void declarativeConfig() {
3333
+ "tracer_provider:\n"
3434
+ " processors:\n"
3535
+ " - inferred_spans:\n"
36+
+ " enabled: false\n"
3637
+ " backup:\n"
3738
+ " diagnostic:\n"
3839
+ " files: true\n";

0 commit comments

Comments
 (0)