Skip to content

Commit

Permalink
enable experimental runtime metrics (#327)
Browse files Browse the repository at this point in the history
* enable experimental runtime metrics
  • Loading branch information
SylvainJuge authored Jul 12, 2024
1 parent ab61c64 commit 1c32ecb
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 17 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ The stacktrace is stored in the [`code.stacktrace`](https://opentelemetry.io/doc

The minimum span duration can be configured with `elastic.otel.span.stack.trace.min.duration` (in milliseconds, defaults to 5ms).

### Runtime metrics

Experimental runtime metrics are enabled by default.
Set `otel.instrumentation.runtime-telemetry.emit-experimental-telemetry` to `false` to disable them.

### Breakdown metrics

Breakdown metrics currently require a custom Elasticsearch ingest pipeline.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,19 @@
import com.google.auto.service.AutoService;
import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizer;
import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizerProvider;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

@AutoService(AutoConfigurationCustomizerProvider.class)
public class ElasticAutoConfigurationCustomizerprovider
public class ElasticAutoConfigurationCustomizerProvider
implements AutoConfigurationCustomizerProvider {

private static final String DISABLED_RESOURCE_PROVIDERS = "otel.java.disabled.resource.providers";
private static final String RUNTIME_EXPERIMENTAL_TELEMETRY =
"otel.instrumentation.runtime-telemetry.emit-experimental-telemetry";

@Override
public void customize(AutoConfigurationCustomizer autoConfiguration) {
Expand All @@ -41,26 +44,31 @@ public void customize(AutoConfigurationCustomizer autoConfiguration) {
// span processor registration
sdkTracerProviderBuilder.addSpanProcessor(
ElasticExtension.INSTANCE.getSpanProcessor()))
.addPropertiesCustomizer(
configProperties -> {
Set<String> disabledConfig =
new HashSet<>(configProperties.getList(DISABLED_RESOURCE_PROVIDERS));

// disabling embedded resource providers

// disable upstream distro name & version provider
disabledConfig.add(
"io.opentelemetry.javaagent.tooling.DistroVersionResourceProvider");

Map<String, String> config = new HashMap<>();
config.put(DISABLED_RESOURCE_PROVIDERS, String.join(",", disabledConfig));

return config;
})
.addPropertiesCustomizer(ElasticAutoConfigurationCustomizerProvider::propertiesCustomizer)
.addSpanExporterCustomizer(
(spanExporter, configProperties) ->
// wrap the original span exporter
ElasticExtension.INSTANCE.wrapSpanExporter(spanExporter))
.addMetricExporterCustomizer((exporter, config) -> new ElasticMetricExporter(exporter));
}

static Map<String, String> propertiesCustomizer(ConfigProperties configProperties) {
Set<String> disabledResourceProviders =
new HashSet<>(configProperties.getList(DISABLED_RESOURCE_PROVIDERS));

// disable upstream distro name & version provider
disabledResourceProviders.add(
"io.opentelemetry.javaagent.tooling.DistroVersionResourceProvider");

Map<String, String> config = new HashMap<>();

// enable experimental telemetry metrics by default if not explicitly disabled
boolean experimentalTelemetry =
configProperties.getBoolean(RUNTIME_EXPERIMENTAL_TELEMETRY, true);
config.put(RUNTIME_EXPERIMENTAL_TELEMETRY, Boolean.toString(experimentalTelemetry));

config.put(DISABLED_RESOURCE_PROVIDERS, String.join(",", disabledResourceProviders));

return config;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package co.elastic.otel;

import static co.elastic.otel.ElasticAutoConfigurationCustomizerProvider.propertiesCustomizer;
import static org.assertj.core.api.Assertions.assertThat;

import io.opentelemetry.javaagent.tooling.EmptyConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Test;

class ElasticAutoConfigurationCustomizerProviderTest {

@Test
void defaultConfiguration() {
Map<String, String> config = propertiesCustomizer(EmptyConfigProperties.INSTANCE);
assertThat(config)
.describedAs("upstream distro version resource provider must be disabled")
.containsEntry(
"otel.java.disabled.resource.providers",
"io.opentelemetry.javaagent.tooling.DistroVersionResourceProvider");

assertThat(config)
.describedAs("runtime experimental metrics must be enabled")
.containsEntry(
"otel.instrumentation.runtime-telemetry.emit-experimental-telemetry", "true");
}

@Test
void disableCustomResourceProvider() {
Map<String, String> userConfig = new HashMap<>();
userConfig.put("otel.java.disabled.resource.providers", "my.disabled.provider.Provider");
Map<String, String> config = propertiesCustomizer(DefaultConfigProperties.create(userConfig));
String value = config.get("otel.java.disabled.resource.providers");
assertThat(value)
.satisfies(
v ->
assertThat(v.split(","))
.containsExactly(
"io.opentelemetry.javaagent.tooling.DistroVersionResourceProvider",
"my.disabled.provider.Provider"));
}

@Test
void disableExperimentalRuntimeMetrics() {
Map<String, String> userConfig = new HashMap<>();
userConfig.put("otel.instrumentation.runtime-telemetry.emit-experimental-telemetry", "false");
Map<String, String> config = propertiesCustomizer(DefaultConfigProperties.create(userConfig));
String value = config.get("otel.instrumentation.runtime-telemetry.emit-experimental-telemetry");
assertThat(value).isEqualTo("false");
}
}

0 comments on commit 1c32ecb

Please sign in to comment.