Skip to content

Commit

Permalink
Convert duration properties into a format OTel can parse
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Aug 1, 2023
1 parent 591eed0 commit afbbace
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class OtlpExporterConfigTest {
.overrideConfigKey("otel.exporter.otlp.traces.protocol", "http/protobuf")
.overrideConfigKey("quarkus.opentelemetry.tracer.exporter.otlp.endpoint", "http://localhost ")
.overrideConfigKey("quarkus.otel.bsp.schedule.delay", "50")
.overrideConfigKey("quarkus.otel.bsp.export.timeout", "1s");
.overrideConfigKey("quarkus.otel.bsp.export.timeout", "PT1S");

@Inject
OtlpExporterRuntimeConfig config;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.quarkus.opentelemetry.runtime;

import java.time.Duration;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
Expand All @@ -19,6 +20,7 @@
import io.quarkus.arc.SyntheticCreationalContext;
import io.quarkus.opentelemetry.runtime.config.runtime.OTelRuntimeConfig;
import io.quarkus.runtime.annotations.Recorder;
import io.quarkus.runtime.configuration.DurationConverter;
import io.smallrye.config.ConfigValue;
import io.smallrye.config.NameIterator;
import io.smallrye.config.SmallRyeConfig;
Expand Down Expand Up @@ -93,12 +95,35 @@ private Map<String, String> getOtelConfigs() {
if (configValue.getValue() != null) {
NameIterator name = new NameIterator(propertyName);
name.next();
oTelConfigs.put(name.getName().substring(name.getPosition() + 1), configValue.getValue());
oTelConfigs.put(name.getName().substring(name.getPosition() + 1), getValue(configValue));
}
}
}
return oTelConfigs;
}

/**
* Transforms the value to what OTel expects
* TODO: this is super simplistic, and should be more modular if needed
*/
private String getValue(ConfigValue configValue) {
String name = configValue.getName();
if (name.endsWith("timeout") || name.endsWith("delay")) {
Duration duration;
try {
duration = DurationConverter.parseDuration(configValue.getValue());
} catch (Exception ignored) {
// it's not a Duration, so we can't do much
return configValue.getValue();
}
try {
return duration.toMillis() + "ms";
} catch (Exception ignored) {
return duration.toSeconds() + "s";
}
}
return configValue.getValue();
}
};
}

Expand Down

0 comments on commit afbbace

Please sign in to comment.