Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion observability-kit-agent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<properties>
<extension.name>opentelemetry-vaadin-observability-instrumentation-extension</extension.name>
<google.auto-service.version>1.1.1</google.auto-service.version>
<byte-buddy.version>1.17.7</byte-buddy.version>
<byte-buddy.version>1.18.7</byte-buddy.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {

@Override
public boolean isHelperClass(String className) {
// TODO: check if helper classes can be included by convention
return className != null
&& className.startsWith("com.vaadin.extension");
&& className.startsWith("com.vaadin.extension")
&& !className.startsWith("com.vaadin.extension.conf.ConfigurationDefaults");
}

private boolean classExists(String className) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
package com.vaadin.extension.conf;

import com.vaadin.extension.Constants;

import io.opentelemetry.javaagent.bootstrap.internal.AgentInstrumentationConfig;
import java.util.function.Function;

/**
* Provides the effective configuration for the Vaadin observability extension.
* Initialized by {@code ConfigurationDefaults} from the agent classloader
* during auto-configuration, before any instrumentation is applied.
*/
public class Configuration {
public static final TraceLevel TRACE_LEVEL = determineTraceLevel();

private static TraceLevel determineTraceLevel() {
String traceLevelString = AgentInstrumentationConfig.get().getString(
Constants.CONFIG_TRACE_LEVEL, TraceLevel.DEFAULT.name());
private static TraceLevel traceLevel = TraceLevel.DEFAULT;
private static Function<String, String> propertyLookup = key -> null;

/**
* Called by {@code ConfigurationDefaults} during agent initialization to
* provide resolved configuration values. Uses only standard Java types to
* avoid references to OTel SDK classes in this helper class.
*/
static void initialize(String traceLevelValue,
Function<String, String> lookup) {
try {
return TraceLevel.valueOf(traceLevelString.toUpperCase());
traceLevel = TraceLevel.valueOf(traceLevelValue.toUpperCase());
} catch (IllegalArgumentException ignored) {
return TraceLevel.DEFAULT;
traceLevel = TraceLevel.DEFAULT;
}
propertyLookup = lookup;
}

/**
Expand All @@ -29,6 +36,17 @@ private static TraceLevel determineTraceLevel() {
* @return true if the trace level is enabled, false if not
*/
public static boolean isEnabled(TraceLevel traceLevel) {
return TRACE_LEVEL.includes(traceLevel);
return Configuration.traceLevel.includes(traceLevel);
}

/**
* Looks up a configuration property by key.
*
* @param key
* the property key
* @return the property value, or null if not set
*/
public static String getProperty(String key) {
return propertyLookup.apply(key);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class ConfigurationDefaults

static final String CONFIGURATION_FILE_PROPERTY = "otel.javaagent.configuration-file";

public static ConfigProperties configProperties;
static ConfigProperties configProperties;
public static SpanExporter spanExporter;

@Override
Expand All @@ -77,6 +77,10 @@ private SpanExporter setSpanExporter(SpanExporter spanExporter,
ConfigProperties configProperties) {
ConfigurationDefaults.configProperties = configProperties;
ConfigurationDefaults.spanExporter = spanExporter;
Configuration.initialize(
configProperties.getString(Constants.CONFIG_TRACE_LEVEL,
TraceLevel.DEFAULT.name()),
configProperties::getString);
return spanExporter;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;

import com.vaadin.extension.conf.ConfigurationDefaults;
import com.vaadin.extension.conf.Configuration;

import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed;
import static net.bytebuddy.matcher.ElementMatchers.isConstructor;
Expand Down Expand Up @@ -80,8 +80,7 @@ public void transform(TypeTransformer transformer) {
Field functionField = helperClazz.getField("configHolder");
AtomicReference<Function<String,String>> functionHolder =
(AtomicReference<Function<String,String>>) functionField.get(null);
functionHolder.set((key) ->
ConfigurationDefaults.configProperties.getString(key));
functionHolder.set(Configuration::getProperty);

Field consumerField = helperClazz.getField("exportHolder");
AtomicReference<BiConsumer<String,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.vaadin.extension.VaadinObservabilityInstrumentationModule
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.vaadin.extension.conf.ConfigurationDefaults
1 change: 1 addition & 0 deletions observability-kit-test/observability-kit-agent-it/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
-javaagent:${basedir}/../../observability-kit-agent/target/observability-kit-agent-${project.version}.jar
</jvmArgs>
<env>
<OTEL_EXPORTER_OTLP_ENDPOINT>http://127.0.0.1:4318</OTEL_EXPORTER_OTLP_ENDPOINT>
<OTEL_EXPORTER_OTLP_PROTOCOL>http/protobuf</OTEL_EXPORTER_OTLP_PROTOCOL>
<OTEL_METRIC_EXPORT_INTERVAL>5000</OTEL_METRIC_EXPORT_INTERVAL>
<OTEL_METRICS_EXPORTER>${otel.exporter}</OTEL_METRICS_EXPORTER>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<servlet.api.version>6.0.0</servlet.api.version>
<annotation.api.version>2.1.1</annotation.api.version>
<opentelemetry.version>1.54.1</opentelemetry.version>
<opentelemetry.javaagent.version>2.20.1</opentelemetry.javaagent.version>
<opentelemetry.version>1.60.1</opentelemetry.version>
<opentelemetry.javaagent.version>2.26.1</opentelemetry.javaagent.version>
<jetty.version>11.0.26</jetty.version>
<junit.version>5.9.2</junit.version>
<mockito.version>5.20.0</mockito.version>
Expand Down
Loading