Skip to content

Commit

Permalink
feat: convert duration properties to otel
Browse files Browse the repository at this point in the history
  • Loading branch information
mcruzdev committed Jun 8, 2023
1 parent adcaefc commit 7df8580
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.List;
import java.util.Map;
import java.util.function.BiFunction;
import java.util.function.Function;

import jakarta.enterprise.inject.Any;
import jakarta.enterprise.inject.Instance;
Expand Down Expand Up @@ -154,10 +155,20 @@ 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());
String propertyValue = getConfigPropertyValue(propertyName, configValue);
oTelConfigs.put(name.getName().substring(name.getPosition() + 1), propertyValue);
}
}
}
return oTelConfigs;
}

private static String getConfigPropertyValue(String propertyName, ConfigValue smallRyeConfig) {
Function<String, String> converter = OpenTelemetryUtil.OTEL_CONFIGURATION_AS_DURATION.get(propertyName);
if (converter == null) {
return smallRyeConfig.getValue();
} else {
return converter.apply(smallRyeConfig.getValue());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
package io.quarkus.opentelemetry.runtime;

import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.time.Duration;
import java.util.*;
import java.util.function.Function;

import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanContext;
import io.opentelemetry.context.Context;
import io.opentelemetry.sdk.trace.ReadableSpan;
import io.quarkus.runtime.configuration.DurationConverter;
import io.quarkus.vertx.core.runtime.VertxMDC;

public final class OpenTelemetryUtil {
public static final String TRACE_ID = "traceId";
public static final String SPAN_ID = "spanId";
public static final String SAMPLED = "sampled";
public static final String PARENT_ID = "parentId";
public static final Map<String, Function<String, String>> OTEL_CONFIGURATION_AS_DURATION = Map.of(
"quarkus.otel.bsp.schedule.delay",
OpenTelemetryUtil::convertDuration,
"quarkus.otel.bsp.export.timeout",
OpenTelemetryUtil::convertDuration,
"quarkus.otel.exporter.otlp.traces.timeout",
OpenTelemetryUtil::convertDuration
);

static String convertDuration(String propertyValue) {
Duration duration = DurationConverter.parseDuration(propertyValue);
return Long.toString(duration.toMillis()).concat("ms");
};

private OpenTelemetryUtil() {
}
Expand Down

0 comments on commit 7df8580

Please sign in to comment.