Skip to content

Commit

Permalink
Update distro and extension examples to use AutoConfigurationCustomiz… (
Browse files Browse the repository at this point in the history
#5574)

* Update distro and extension examples to use AutoConfigurationCustomizerProvider

* Rename the SPI file too
  • Loading branch information
Mateusz Rzeszutek authored Mar 15, 2022
1 parent b0d5fc6 commit 3096188
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 31 deletions.
4 changes: 2 additions & 2 deletions examples/distro/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ subprojects {

ext {
versions = [
opentelemetry : "1.9.1",
opentelemetryAlpha : "1.9.1-alpha",
opentelemetry : "1.12.0",
opentelemetryAlpha : "1.12.0-alpha",
opentelemetryJavaagent : "1.13.0-SNAPSHOT",
opentelemetryJavaagentAlpha: "1.13.0-alpha-SNAPSHOT",
bytebuddy : "1.10.18",
Expand Down
2 changes: 1 addition & 1 deletion examples/distro/custom/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def relocatePackages = ext.relocatePackages

dependencies {
compileOnly("io.opentelemetry:opentelemetry-sdk:${versions.opentelemetry}")
compileOnly("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure:${versions.opentelemetryAlpha}")
compileOnly("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi:${versions.opentelemetry}")
compileOnly("io.opentelemetry.javaagent:opentelemetry-javaagent-extension-api:${versions.opentelemetryJavaagentAlpha}")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,34 @@

package com.example.javaagent;

import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizer;
import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizerProvider;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.traces.SdkTracerProviderConfigurer;
import io.opentelemetry.sdk.trace.SdkTracerProviderBuilder;
import io.opentelemetry.sdk.trace.SpanLimits;
import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;

/**
* This is one of the main entry points for Instrumentation Agent's customizations. It allows
* configuring {@link SdkTracerProviderBuilder}. See the {@link
* #configure(SdkTracerProviderBuilder)} method below.
* configuring the {@link AutoConfigurationCustomizer}. See the {@link
* #customize(AutoConfigurationCustomizer)} method below.
*
* <p>Also see https://github.com/open-telemetry/opentelemetry-java/issues/2022
*
* @see SdkTracerProviderConfigurer
* @see AutoConfigurationCustomizerProvider
* @see DemoPropagatorProvider
*/
public class DemoSdkTracerProviderConfigurer implements SdkTracerProviderConfigurer {
public class DemoAutoConfigurationCustomizerProvider
implements AutoConfigurationCustomizerProvider {

@Override
public void configure(SdkTracerProviderBuilder tracerProvider, ConfigProperties config) {
tracerProvider
public void customize(AutoConfigurationCustomizer autoConfiguration) {
autoConfiguration.addTracerProviderCustomizer(this::configureSdkTracerProvider);
}

private SdkTracerProviderBuilder configureSdkTracerProvider(
SdkTracerProviderBuilder tracerProvider, ConfigProperties config) {
return tracerProvider
.setIdGenerator(new DemoIdGenerator())
.setSpanLimits(SpanLimits.builder().setMaxNumberOfAttributes(1024).build())
.setSampler(new DemoSampler())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Custom {@link IdGenerator} which provides span and trace ids.
*
* @see io.opentelemetry.sdk.trace.SdkTracerProvider
* @see DemoSdkTracerProviderConfigurer
* @see DemoAutoConfigurationCustomizerProvider
*/
public class DemoIdGenerator implements IdGenerator {
private static final AtomicLong traceId = new AtomicLong(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* href="https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/sdk.md#sampling">
* OpenTelemetry Specification</a> for more information about span sampling.
*
* @see DemoSdkTracerProviderConfigurer
* @see DemoAutoConfigurationCustomizerProvider
*/
public class DemoSampler implements Sampler {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* href="https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/sdk.md#span-exporter">
* OpenTelemetry Specification</a> for more information about {@link SpanExporter}.
*
* @see DemoSdkTracerProviderConfigurer
* @see DemoAutoConfigurationCustomizerProvider
*/
public class DemoSpanExporter implements SpanExporter {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* href="https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/sdk.md#span-processor">
* OpenTelemetry Specification</a> for more information about {@link SpanProcessor}.
*
* @see DemoSdkTracerProviderConfigurer
* @see DemoAutoConfigurationCustomizerProvider
*/
public class DemoSpanProcessor implements SpanProcessor {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.example.javaagent.DemoAutoConfigurationCustomizerProvider

This file was deleted.

8 changes: 4 additions & 4 deletions examples/extension/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ version '1.0'

ext {
versions = [
opentelemetry : "1.9.1",
opentelemetryAlpha : "1.9.1-alpha",
opentelemetry : "1.12.0",
opentelemetryAlpha : "1.12.0-alpha",
opentelemetryJavaagent : "1.13.0-SNAPSHOT",
opentelemetryJavaagentAlpha: "1.13.0-alpha-SNAPSHOT",
]
Expand Down Expand Up @@ -63,7 +63,7 @@ dependencies {
Interfaces and SPIs that we implement. We use `compileOnly` dependency because during
runtime all necessary classes are provided by javaagent itself.
*/
compileOnly("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure:${versions.opentelemetryAlpha}")
compileOnly("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi:${versions.opentelemetry}")
compileOnly("io.opentelemetry.javaagent:opentelemetry-javaagent-instrumentation-api:${versions.opentelemetryJavaagentAlpha}")
compileOnly("io.opentelemetry.javaagent:opentelemetry-javaagent-extension-api:${versions.opentelemetryJavaagentAlpha}")

Expand Down Expand Up @@ -110,7 +110,7 @@ dependencies {
add("muzzleBootstrap", "io.opentelemetry.javaagent:opentelemetry-javaagent-instrumentation-api:${versions.opentelemetryJavaagentAlpha}")
add("muzzleTooling", "io.opentelemetry.javaagent:opentelemetry-javaagent-extension-api:${versions.opentelemetryJavaagentAlpha}")
add("muzzleTooling", "io.opentelemetry.javaagent:opentelemetry-javaagent-tooling:${versions.opentelemetryJavaagentAlpha}")
add("muzzleTooling", "org.slf4j:slf4j-simple:1.7.30")
add("muzzleTooling", "org.slf4j:slf4j-simple:1.7.36")
}

//Produces a copy of upstream javaagent with this extension jar included inside it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,36 @@
package com.example.javaagent;

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 io.opentelemetry.sdk.autoconfigure.spi.traces.SdkTracerProviderConfigurer;
import io.opentelemetry.sdk.trace.SdkTracerProviderBuilder;
import io.opentelemetry.sdk.trace.SpanLimits;
import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;

/**
* This is one of the main entry points for Instrumentation Agent's customizations. It allows
* configuring {@link SdkTracerProviderBuilder}. See the {@link
* #configure(SdkTracerProviderBuilder)} method below.
* configuring the {@link AutoConfigurationCustomizer}. See the {@link
* #customize(AutoConfigurationCustomizer)} method below.
*
* <p>Also see https://github.com/open-telemetry/opentelemetry-java/issues/2022
*
* @see SdkTracerProviderConfigurer
* @see AutoConfigurationCustomizerProvider
* @see DemoPropagatorProvider
*/
@AutoService(SdkTracerProviderConfigurer.class)
public class DemoSdkTracerProviderConfigurer implements SdkTracerProviderConfigurer {
@AutoService(AutoConfigurationCustomizerProvider.class)
public class DemoAutoConfigurationCustomizerProvider
implements AutoConfigurationCustomizerProvider {

@Override
public void configure(SdkTracerProviderBuilder tracerProvider, ConfigProperties config) {
tracerProvider
public void customize(AutoConfigurationCustomizer autoConfiguration) {
autoConfiguration.addTracerProviderCustomizer(this::configureSdkTracerProvider);
}

private SdkTracerProviderBuilder configureSdkTracerProvider(
SdkTracerProviderBuilder tracerProvider, ConfigProperties config) {

return tracerProvider
.setIdGenerator(new DemoIdGenerator())
.setSpanLimits(SpanLimits.builder().setMaxNumberOfAttributes(1024).build())
.setSampler(new DemoSampler())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Custom {@link IdGenerator} which provides span and trace ids.
*
* @see io.opentelemetry.sdk.trace.SdkTracerProvider
* @see DemoSdkTracerProviderConfigurer
* @see DemoAutoConfigurationCustomizerProvider
*/
public class DemoIdGenerator implements IdGenerator {
private static final AtomicLong traceId = new AtomicLong(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* href="https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/sdk.md#sampling">
* OpenTelemetry Specification</a> for more information about span sampling.
*
* @see DemoSdkTracerProviderConfigurer
* @see DemoAutoConfigurationCustomizerProvider
*/
public class DemoSampler implements Sampler {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* href="https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/sdk.md#span-exporter">
* OpenTelemetry Specification</a> for more information about {@link SpanExporter}.
*
* @see DemoSdkTracerProviderConfigurer
* @see DemoAutoConfigurationCustomizerProvider
*/
public class DemoSpanExporter implements SpanExporter {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* href="https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/sdk.md#span-processor">
* OpenTelemetry Specification</a> for more information about {@link SpanProcessor}.
*
* @see DemoSdkTracerProviderConfigurer
* @see DemoAutoConfigurationCustomizerProvider
*/
public class DemoSpanProcessor implements SpanProcessor {

Expand Down

0 comments on commit 3096188

Please sign in to comment.