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
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import com.splunk.opentelemetry.instrumentation.jvmmetrics.otel.OtelAllocatedMemoryMetrics;
import com.splunk.opentelemetry.instrumentation.jvmmetrics.otel.OtelGcMemoryMetrics;
import com.splunk.opentelemetry.profiler.ProfilerConfiguration;
import com.splunk.opentelemetry.profiler.ProfilerDeclarativeConfiguration;
import com.splunk.opentelemetry.profiler.ProfilerEnvVarsConfiguration;
import io.opentelemetry.javaagent.extension.AgentListener;
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
Expand All @@ -33,7 +31,7 @@ public class JvmMetricsInstaller implements AgentListener {
@Override
public void afterAgent(AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemetrySdk) {
ConfigProperties config = getConfig(autoConfiguredOpenTelemetrySdk);
boolean metricsEnabled = isProfilerMemoryEnabled(config);
boolean metricsEnabled = isProfilerMemoryEnabled();

if (!config.getBoolean("otel.instrumentation.jvm-metrics-splunk.enabled", metricsEnabled)) {
return;
Expand All @@ -43,12 +41,7 @@ public void afterAgent(AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemetr
new OtelGcMemoryMetrics().install();
}

private boolean isProfilerMemoryEnabled(ConfigProperties config) {
ProfilerConfiguration profilerConfiguration =
ProfilerDeclarativeConfiguration.SUPPLIER.isConfigured()
? ProfilerDeclarativeConfiguration.SUPPLIER.get()
: new ProfilerEnvVarsConfiguration(config);

return profilerConfiguration.getMemoryEnabled();
private boolean isProfilerMemoryEnabled() {
return ProfilerConfiguration.SUPPLIER.get().getMemoryEnabled();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,27 @@
import static org.mockito.Mockito.verify;

import com.splunk.opentelemetry.instrumentation.jvmmetrics.otel.OtelAllocatedMemoryMetrics;
import com.splunk.opentelemetry.profiler.ProfilerConfiguration;
import com.splunk.opentelemetry.profiler.ProfilerEnvVarsConfigurationFactory;
import com.splunk.opentelemetry.testing.declarativeconfig.DeclarativeConfigTestUtil;
import io.opentelemetry.instrumentation.config.bridge.DeclarativeConfigPropertiesBridgeBuilder;
import io.opentelemetry.sdk.autoconfigure.AutoConfigureUtil;
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
import java.util.Map;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.mockito.MockedConstruction;
import org.mockito.MockedStatic;

class JvmMetricsInstallerTest {

@AfterEach
void tearDown() {
ProfilerConfiguration.SUPPLIER.reset();
}

@Test
void shouldInstallJvmMetrics_declarativeConfig() {
// given
Expand All @@ -53,6 +61,7 @@ void shouldInstallJvmMetrics_declarativeConfig() {
new DeclarativeConfigPropertiesBridgeBuilder()
.build(
AutoConfigureUtil.getInstrumentationConfig(DeclarativeConfigTestUtil.parse(yaml)));
ProfilerConfiguration.SUPPLIER.configure(ProfilerEnvVarsConfigurationFactory.create(config));

try (MockedStatic<AutoConfigureUtil> autoConfigureUtil = mockStatic(AutoConfigureUtil.class);
MockedConstruction<OtelAllocatedMemoryMetrics> allocatedMetrics =
Expand All @@ -78,6 +87,7 @@ void shouldInstallJvmMetrics_envVarsConfig() {
ConfigProperties config =
DefaultConfigProperties.createFromMap(
Map.of("otel.instrumentation.jvm-metrics-splunk.enabled", "true"));
ProfilerConfiguration.SUPPLIER.configure(ProfilerEnvVarsConfigurationFactory.create(config));

try (MockedStatic<AutoConfigureUtil> autoConfigureUtil = mockStatic(AutoConfigureUtil.class);
MockedConstruction<OtelAllocatedMemoryMetrics> allocatedMetrics =
Expand Down
8 changes: 4 additions & 4 deletions licenses/licenses.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# splunk-otel-javaagent
## Dependency License Report
_2026-06-20 10:34:26 EEST_
_2026-06-24 14:18:04 CEST_
## Apache License, Version 2.0

**1** **Group:** `com.squareup.okhttp3` **Name:** `okhttp` **Version:** `5.4.0`
Expand Down Expand Up @@ -92,12 +92,12 @@ _2026-06-20 10:34:26 EEST_
> - **POM Project URL**: [https://github.com/open-telemetry/opentelemetry-java-instrumentation](https://github.com/open-telemetry/opentelemetry-java-instrumentation)
> - **POM License**: Apache License, Version 2.0 - [https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)

**23** **Group:** `org.apache.commons` **Name:** `commons-jexl3` **Version:** `3.6.2`
**23** **Group:** `org.apache.commons` **Name:** `commons-jexl3` **Version:** `3.6.3`
> - **Project URL**: [https://commons.apache.org/proper/commons-jexl/](https://commons.apache.org/proper/commons-jexl/)
> - **Manifest License**: [https://www.apache.org/licenses/LICENSE-2.0](Apache License, Version 2.0)
> - **POM License**: Apache License, Version 2.0 - [https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)
> - **Embedded license files**: [commons-jexl3-3.6.2.jar/META-INF/LICENSE.txt](commons-jexl3-3.6.2.jar/META-INF/LICENSE.txt)
- [commons-jexl3-3.6.2.jar/META-INF/NOTICE.txt](commons-jexl3-3.6.2.jar/META-INF/NOTICE.txt)
> - **Embedded license files**: [commons-jexl3-3.6.3.jar/META-INF/LICENSE.txt](commons-jexl3-3.6.3.jar/META-INF/LICENSE.txt)
- [commons-jexl3-3.6.3.jar/META-INF/NOTICE.txt](commons-jexl3-3.6.3.jar/META-INF/NOTICE.txt)

**24** **Group:** `org.jetbrains` **Name:** `annotations` **Version:** `13.0`
> - **POM Project URL**: [http://www.jetbrains.org](http://www.jetbrains.org)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import com.google.common.annotations.VisibleForTesting;
import com.splunk.opentelemetry.profiler.ProfilerConfiguration;
import com.splunk.opentelemetry.profiler.ProfilerDeclarativeConfiguration;
import com.splunk.opentelemetry.profiler.snapshot.SnapshotProfilingConfiguration;
import com.splunk.opentelemetry.profiler.snapshot.SnapshotProfilingDeclarativeConfiguration;
import io.opentelemetry.sdk.autoconfigure.declarativeconfig.model.LogRecordExporterModel;
Expand Down Expand Up @@ -69,7 +68,7 @@ public String createEffectiveConfigContent() {
if (model == null) {
return "";
}
ProfilerConfiguration profilerConfiguration = ProfilerDeclarativeConfiguration.SUPPLIER.get();
ProfilerConfiguration profilerConfiguration = ProfilerConfiguration.SUPPLIER.get();
SnapshotProfilingConfiguration snapshotConfiguration =
SnapshotProfilingDeclarativeConfiguration.SUPPLIER.get();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.splunk.opentelemetry.opamp;

import com.splunk.opentelemetry.profiler.ProfilerConfiguration;
import com.splunk.opentelemetry.profiler.ProfilerEnvVarsConfiguration;
import com.splunk.opentelemetry.profiler.ProfilerEnvVarsConfigurationFactory;
import com.splunk.opentelemetry.profiler.snapshot.SnapshotProfilingConfiguration;
import com.splunk.opentelemetry.profiler.snapshot.SnapshotProfilingEnvVarsConfiguration;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
Expand Down Expand Up @@ -49,7 +49,8 @@ public String createEffectiveConfigContent() {
}

private void addSplunkEnvVars(EffectiveConfigBuilder builder) {
ProfilerConfiguration profilerConfiguration = new ProfilerEnvVarsConfiguration(config);
ProfilerConfiguration profilerConfiguration =
ProfilerEnvVarsConfigurationFactory.create(config);
SnapshotProfilingConfiguration snapshotConfiguration =
new SnapshotProfilingEnvVarsConfiguration(config);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
import static io.opentelemetry.api.incubator.config.DeclarativeConfigProperties.empty;

import com.google.common.annotations.VisibleForTesting;
import com.splunk.opentelemetry.profiler.ProfilerDeclarativeConfiguration;
import com.splunk.opentelemetry.profiler.ProfilerConfiguration;
import com.splunk.opentelemetry.profiler.ProfilerDeclarativeConfigurationFactory;
import com.splunk.opentelemetry.profiler.ProfilingSupervisor;
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties;
import io.opentelemetry.opamp.client.OpampClient;
Expand Down Expand Up @@ -69,8 +70,8 @@ public void applyConfig(AgentRemoteConfig remoteConfig, OpampClient opampClient)
if (splunkDistributionConfigProperties.getPropertyKeys().contains(PROFILING_NODE_NAME)) {
DeclarativeConfigProperties profilingConfigProperties =
splunkDistributionConfigProperties.getStructured(PROFILING_NODE_NAME, empty());
ProfilerDeclarativeConfiguration profilingConfig =
new ProfilerDeclarativeConfiguration(profilingConfigProperties);
ProfilerConfiguration profilingConfig =
ProfilerDeclarativeConfigurationFactory.create(profilingConfigProperties);
// TODO: should be merged with current profiling config. Probably we will need profiler
// configuration refactoring and some listeners implemented for profiler configuration
// changes. For POC use this temporary solution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import static org.mockito.Mockito.when;

import com.splunk.opentelemetry.profiler.ProfilerConfiguration;
import com.splunk.opentelemetry.profiler.ProfilerDeclarativeConfiguration;
import com.splunk.opentelemetry.profiler.ProfilerDeclarativeConfigurationFactory;
import com.splunk.opentelemetry.profiler.snapshot.SnapshotProfilingConfiguration;
import com.splunk.opentelemetry.profiler.snapshot.SnapshotProfilingDeclarativeConfiguration;
import com.splunk.opentelemetry.testing.declarativeconfig.DeclarativeConfigTestUtil;
Expand Down Expand Up @@ -56,7 +56,7 @@ class DeclarativeEffectiveConfigFileFactoryTest {
@AfterEach
void afterEach() {
DeclarativeConfigurationInterceptor.reset();
ProfilerDeclarativeConfiguration.SUPPLIER.reset();
ProfilerConfiguration.SUPPLIER.reset();
SnapshotProfilingDeclarativeConfiguration.SUPPLIER.reset();
}

Expand Down Expand Up @@ -396,8 +396,8 @@ public static void main(String[] args) throws Exception {

DeclarativeConfigProperties profilingConfig =
getDistributionConfig(model).getStructured("profiling", empty());
ProfilerDeclarativeConfiguration.SUPPLIER.configure(
new ProfilerDeclarativeConfiguration(profilingConfig));
ProfilerConfiguration.SUPPLIER.configure(
ProfilerDeclarativeConfigurationFactory.create(profilingConfig));
SnapshotProfilingDeclarativeConfiguration.SUPPLIER.configure(
new SnapshotProfilingDeclarativeConfiguration(profilingConfig));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
import com.google.auto.service.AutoService;
import com.google.common.annotations.VisibleForTesting;
import io.opentelemetry.javaagent.extension.AgentListener;
import io.opentelemetry.sdk.autoconfigure.AutoConfigureUtil;
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import java.util.logging.Logger;

@AutoService(AgentListener.class)
Expand All @@ -40,12 +38,14 @@ public JfrAgentListener() {

@Override
public void afterAgent(AutoConfiguredOpenTelemetrySdk sdk) {
ProfilingSupervisor.setupJfrContextStorage();
if (jfr.isAvailable()) {
ProfilingSupervisor.setupJfrContextStorage();
}

ProfilerConfiguration config = getProfilerConfiguration(sdk);
// Always start the supervisor, so it can start profiling later elsewhere.
ProfilingSupervisor supervisor = makeProfilingSupervisor(sdk, config);
ProfilingSupervisor supervisor = makeProfilingSupervisor(sdk);

ProfilerConfiguration config = ProfilerConfiguration.SUPPLIER.get();
if (notClearForTakeoff(config)) {
return;
}
Expand All @@ -60,19 +60,8 @@ public int order() {
}

// Exists for testing
ProfilingSupervisor makeProfilingSupervisor(
AutoConfiguredOpenTelemetrySdk sdk, ProfilerConfiguration config) {
return ProfilingSupervisor.createAndStart(sdk, config);
}

private static ProfilerConfiguration getProfilerConfiguration(
AutoConfiguredOpenTelemetrySdk sdk) {
if (ProfilerDeclarativeConfiguration.SUPPLIER.isConfigured()) {
return ProfilerDeclarativeConfiguration.SUPPLIER.get();
} else {
ConfigProperties configProperties = AutoConfigureUtil.getConfig(sdk);
return new ProfilerEnvVarsConfiguration(configProperties);
}
ProfilingSupervisor makeProfilingSupervisor(AutoConfiguredOpenTelemetrySdk sdk) {
return ProfilingSupervisor.createAndStart(sdk);
}

private boolean notClearForTakeoff(ProfilerConfiguration config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class LogExporterBuilder {
static final String EXTRA_CONTENT_TYPE = "Extra-Content-Type";
static final String STACKTRACES_HEADER_VALUE = "otel-profiling-stacktraces";

static LogRecordExporter fromConfig(DeclarativeConfigProperties exporterConfigProperties) {
static LogRecordExporter fromDeclarativeConfig(
DeclarativeConfigProperties exporterConfigProperties) {
if (exporterConfigProperties != null) {
Set<String> propertyKeys = exporterConfigProperties.getPropertyKeys();

Expand All @@ -68,11 +69,8 @@ static LogRecordExporter fromConfig(DeclarativeConfigProperties exporterConfigPr
throw new ConfigurationException("Profiler exporter configuration is invalid");
}

static LogRecordExporter fromConfig(ConfigProperties config) {
return fromConfig(new ProfilerEnvVarsConfiguration(config));
}

static LogRecordExporter fromConfig(ProfilerEnvVarsConfiguration config) {
static LogRecordExporter fromEnvironmentConfig() {
ProfilerConfiguration config = ProfilerConfiguration.SUPPLIER.get();
String protocol = config.getOtlpProtocol();
if ("http/protobuf".equals(protocol)) {
return buildHttpExporter(config, OtlpHttpLogRecordExporter::builder);
Expand All @@ -84,7 +82,7 @@ static LogRecordExporter fromConfig(ProfilerEnvVarsConfiguration config) {

@VisibleForTesting
static LogRecordExporter buildGrpcExporter(
ProfilerEnvVarsConfiguration config, Supplier<OtlpGrpcLogRecordExporterBuilder> makeBuilder) {
ProfilerConfiguration config, Supplier<OtlpGrpcLogRecordExporterBuilder> makeBuilder) {
OtlpGrpcLogRecordExporterBuilder builder = makeBuilder.get();
String ingestUrl = config.getIngestUrl();
builder.setEndpoint(ingestUrl);
Expand All @@ -94,13 +92,13 @@ static LogRecordExporter buildGrpcExporter(

@VisibleForTesting
static LogRecordExporter buildHttpExporter(
ProfilerEnvVarsConfiguration config, Supplier<OtlpHttpLogRecordExporterBuilder> makeBuilder) {
ProfilerConfiguration config, Supplier<OtlpHttpLogRecordExporterBuilder> makeBuilder) {
OtlpHttpLogRecordExporterBuilder builder = makeBuilder.get();
String ingestUrl = config.getIngestUrl();

OtlpConfigUtil.configureOtlpExporterBuilder(
DATA_TYPE_LOGS,
config.getConfigProperties(),
(ConfigProperties) config.getConfigProperties(),
builder::setComponentLoader,
builder::setEndpoint,
builder::addHeader,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,27 @@
import io.opentelemetry.sdk.logs.export.SimpleLogRecordProcessor;
import io.opentelemetry.sdk.resources.Resource;
import java.util.function.Function;
import java.util.function.Supplier;

public class OtelLoggerFactory {
private final Function<ConfigProperties, LogRecordExporter> logRecordExporter;
private final Supplier<LogRecordExporter> logRecordExporter;
private final Function<DeclarativeConfigProperties, LogRecordExporter>
declarativeLogRecordExporter;

public OtelLoggerFactory() {
this(LogExporterBuilder::fromConfig, LogExporterBuilder::fromConfig);
this(LogExporterBuilder::fromEnvironmentConfig, LogExporterBuilder::fromDeclarativeConfig);
}

@VisibleForTesting
public OtelLoggerFactory(
Function<ConfigProperties, LogRecordExporter> logRecordExporter,
Supplier<LogRecordExporter> logRecordExporter,
Function<DeclarativeConfigProperties, LogRecordExporter> declarativeLogRecordExporter) {
this.logRecordExporter = logRecordExporter;
this.declarativeLogRecordExporter = declarativeLogRecordExporter;
}

public Logger build(ConfigProperties properties, Resource resource) {
LogRecordExporter exporter = createLogRecordExporter(properties);
LogRecordExporter exporter = createLogRecordExporter();
LogRecordProcessor processor = SimpleLogRecordProcessor.create(exporter);
return buildOtelLogger(processor, resource);
}
Expand All @@ -56,8 +57,8 @@ public Logger build(DeclarativeConfigProperties properties, Resource resource) {
return buildOtelLogger(processor, resource);
}

private LogRecordExporter createLogRecordExporter(ConfigProperties properties) {
return logRecordExporter.apply(properties);
private LogRecordExporter createLogRecordExporter() {
return logRecordExporter.get();
}

private LogRecordExporter createLogRecordExporter(DeclarativeConfigProperties properties) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.splunk.opentelemetry.profiler.exporter.CpuEventExporter;
import com.splunk.opentelemetry.profiler.exporter.PprofCpuEventExporter;
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.logs.LogRecordProcessor;
import io.opentelemetry.sdk.logs.SdkLoggerProvider;
import io.opentelemetry.sdk.logs.export.LogRecordExporter;
Expand Down Expand Up @@ -162,13 +161,9 @@ private static LogRecordExporter createLogRecordExporter(Object configProperties
if (configProperties instanceof DeclarativeConfigProperties) {
DeclarativeConfigProperties exporterConfig =
((DeclarativeConfigProperties) configProperties).getStructured("exporter", empty());
return LogExporterBuilder.fromConfig(exporterConfig);
return LogExporterBuilder.fromDeclarativeConfig(exporterConfig);
}
if (configProperties instanceof ConfigProperties) {
return LogExporterBuilder.fromConfig((ConfigProperties) configProperties);
}
throw new IllegalArgumentException(
"Unsupported config properties type: " + configProperties.getClass().getName());
return LogExporterBuilder.fromEnvironmentConfig();
}

private boolean checkOutputDir(Path outputDir) {
Expand Down
Loading
Loading