Skip to content

Commit

Permalink
fix: NoSuchMethod error on pre 1.15 otel (honeycomb is 1.14)
Browse files Browse the repository at this point in the history
  • Loading branch information
korniltsev committed Sep 21, 2022
1 parent 14f2261 commit 3d3ce08
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
25 changes: 25 additions & 0 deletions src/main/java/io/otel/pyroscope/OtelCompat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.otel.pyroscope;

import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;

public class OtelCompat {
// For compat reasons
// io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties.getBoolean(java.lang.String, boolean) is only since 1.15
static boolean getBoolean(ConfigProperties cfg, String name, boolean defaultValue) {
Boolean v = cfg.getBoolean(name);
if (v == null) {
return defaultValue;
}
return v;
}

// For compat reasons
// io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties.getString(java.lang.String, java.lang.String) is only since 1.15
static String getString(ConfigProperties cfg, String name, String defaultValue) {
String v = cfg.getString(name);
if (v == null) {
return defaultValue;
}
return v;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizerProvider;
import io.pyroscope.javaagent.PyroscopeAgent;
import io.pyroscope.javaagent.config.Config;
import io.pyroscope.javaagent.impl.DefaultConfigurationProvider;

import java.util.Map;

import static io.otel.pyroscope.OtelCompat.getBoolean;
import static io.otel.pyroscope.OtelCompat.getString;
import static io.pyroscope.javaagent.config.AppName.*;


Expand All @@ -25,7 +26,7 @@ public class PyroscopeOtelAutoConfigurationCustomizerProvider
@Override
public void customize(AutoConfigurationCustomizer autoConfiguration) {
autoConfiguration.addTracerProviderCustomizer((tpBuilder, cfg) -> {
boolean startProfiling = cfg.getBoolean("otel.pyroscope.start.profiling", true);
boolean startProfiling = getBoolean(cfg, "otel.pyroscope.start.profiling", true);

String appName = cfg.getString(CONFIG_APP_NAME);
String endpoint = cfg.getString(CONFIG_ENDPOINT);
Expand Down Expand Up @@ -54,17 +55,16 @@ public void customize(AutoConfigurationCustomizer autoConfiguration) {
}
}
}
System.out.println(endpoint + " endpoint");
Map<String, String> labels = parseLabels(cfg.getString(CONFIG_BASELINE_LABELS, ""));
Map<String, String> labels = parseLabels(getString(cfg, CONFIG_BASELINE_LABELS, ""));
PyroscopeOtelConfiguration pyroOtelConfig = new PyroscopeOtelConfiguration.Builder()
.setAppName(appName)
.setPyroscopeEndpoint(endpoint)
.setProfileBaselineLabels(labels)
.setRootSpanOnly(cfg.getBoolean("otel.pyroscope.root.span.only", true))
.setAddSpanName(cfg.getBoolean("otel.pyroscope.add.span.name", true))
.setAddProfileURL(cfg.getBoolean("otel.pyroscope.add.profile.url", true))
.setAddProfileBaselineURLs(cfg.getBoolean("otel.pyroscope.add.profile.baseline.url", true))
.setOptimisticTimestamps(cfg.getBoolean("otel.pyroscope.optimistic.timestamps", true))
.setRootSpanOnly(getBoolean(cfg, "otel.pyroscope.root.span.only", true))
.setAddSpanName(getBoolean(cfg, "otel.pyroscope.add.span.name", true))
.setAddProfileURL(getBoolean(cfg, "otel.pyroscope.add.profile.url", true))
.setAddProfileBaselineURLs(getBoolean(cfg, "otel.pyroscope.add.profile.baseline.url", true))
.setOptimisticTimestamps(getBoolean(cfg, "otel.pyroscope.optimistic.timestamps", true))
.build();
return tpBuilder.addSpanProcessor(
new PyroscopeOtelSpanProcessor(
Expand Down

0 comments on commit 3d3ce08

Please sign in to comment.