From 3d3ce08f93441f23400f8d0e942569e7cbc492dc Mon Sep 17 00:00:00 2001 From: Tolya Korniltsev Date: Wed, 21 Sep 2022 21:24:24 +0700 Subject: [PATCH] fix: NoSuchMethod error on pre 1.15 otel (honeycomb is 1.14) --- .../java/io/otel/pyroscope/OtelCompat.java | 25 +++++++++++++++++++ ...elAutoConfigurationCustomizerProvider.java | 18 ++++++------- 2 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 src/main/java/io/otel/pyroscope/OtelCompat.java diff --git a/src/main/java/io/otel/pyroscope/OtelCompat.java b/src/main/java/io/otel/pyroscope/OtelCompat.java new file mode 100644 index 0000000..0e7355b --- /dev/null +++ b/src/main/java/io/otel/pyroscope/OtelCompat.java @@ -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; + } +} diff --git a/src/main/java/io/otel/pyroscope/PyroscopeOtelAutoConfigurationCustomizerProvider.java b/src/main/java/io/otel/pyroscope/PyroscopeOtelAutoConfigurationCustomizerProvider.java index b1a3440..e20ec09 100644 --- a/src/main/java/io/otel/pyroscope/PyroscopeOtelAutoConfigurationCustomizerProvider.java +++ b/src/main/java/io/otel/pyroscope/PyroscopeOtelAutoConfigurationCustomizerProvider.java @@ -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.*; @@ -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); @@ -54,17 +55,16 @@ public void customize(AutoConfigurationCustomizer autoConfiguration) { } } } - System.out.println(endpoint + " endpoint"); - Map labels = parseLabels(cfg.getString(CONFIG_BASELINE_LABELS, "")); + Map 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(