Skip to content

Commit

Permalink
rename get|setProvider to get|setTelemetryProvider and make it object
Browse files Browse the repository at this point in the history
  • Loading branch information
lmolkova committed Jan 21, 2025
1 parent 1f9a4d3 commit 980021f
Show file tree
Hide file tree
Showing 24 changed files with 133 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
* <pre>
*
* OpenTelemetry openTelemetry = AutoConfiguredOpenTelemetrySdk.initialize&#40;&#41;.getOpenTelemetrySdk&#40;&#41;;
* HttpInstrumentationOptions&lt;OpenTelemetry&gt; instrumentationOptions = new HttpInstrumentationOptions&lt;OpenTelemetry&gt;&#40;&#41;
* .setProvider&#40;openTelemetry&#41;;
* HttpInstrumentationOptions instrumentationOptions = new HttpInstrumentationOptions&#40;&#41;
* .setTelemetryProvider&#40;openTelemetry&#41;;
*
* SampleClient client = new SampleClientBuilder&#40;&#41;.instrumentationOptions&#40;instrumentationOptions&#41;.build&#40;&#41;;
*
Expand All @@ -78,11 +78,8 @@
*
* </pre>
* <!-- end io.clientcore.core.telemetry.useexplicitopentelemetry -->
*
* @param <T> The type of the instrumentation provider. When using OpenTelemetry, this is {@code io.opentelemetry.api.OpenTelemetry}. If not provided
* the {@code io.opentelemetry.api.GlobalOpenTelemetry} instance is used.
*/
public final class HttpInstrumentationOptions<T> extends InstrumentationOptions<T> {
public final class HttpInstrumentationOptions extends InstrumentationOptions {
private boolean isHttpLoggingEnabled;
private boolean isContentLoggingEnabled;
private boolean isRedactedHeaderNamesLoggingEnabled;
Expand Down Expand Up @@ -155,8 +152,7 @@ public boolean isRedactedHeaderNamesLoggingEnabled() {
* Default is true.
* @return The updated {@link HttpInstrumentationOptions} object.
*/
public HttpInstrumentationOptions<T>
setRedactedHeaderNamesLoggingEnabled(boolean redactedHeaderNamesLoggingEnabled) {
public HttpInstrumentationOptions setRedactedHeaderNamesLoggingEnabled(boolean redactedHeaderNamesLoggingEnabled) {
isRedactedHeaderNamesLoggingEnabled = redactedHeaderNamesLoggingEnabled;
return this;
}
Expand Down Expand Up @@ -184,7 +180,7 @@ public boolean isContentLoggingEnabled() {
* @param isHttpLoggingEnabled True to enable detailed HTTP logging, false otherwise.
* @return The updated {@link HttpInstrumentationOptions} object.
*/
public HttpInstrumentationOptions<T> setHttpLoggingEnabled(boolean isHttpLoggingEnabled) {
public HttpInstrumentationOptions setHttpLoggingEnabled(boolean isHttpLoggingEnabled) {
this.isHttpLoggingEnabled = isHttpLoggingEnabled;
return this;
}
Expand All @@ -199,7 +195,7 @@ public HttpInstrumentationOptions<T> setHttpLoggingEnabled(boolean isHttpLogging
* @param isContentLoggingEnabled True to enable content logging, false otherwise.
* @return The updated {@link HttpInstrumentationOptions} object.
*/
public HttpInstrumentationOptions<T> setContentLoggingEnabled(boolean isContentLoggingEnabled) {
public HttpInstrumentationOptions setContentLoggingEnabled(boolean isContentLoggingEnabled) {
this.isHttpLoggingEnabled |= isContentLoggingEnabled;
this.isContentLoggingEnabled = isContentLoggingEnabled;
return this;
Expand Down Expand Up @@ -229,7 +225,7 @@ public Set<HttpHeaderName> getAllowedHeaderNames() {
*
* @return The updated HttpLogOptions object.
*/
public HttpInstrumentationOptions<T> setAllowedHeaderNames(final Set<HttpHeaderName> allowedHeaderNames) {
public HttpInstrumentationOptions setAllowedHeaderNames(final Set<HttpHeaderName> allowedHeaderNames) {
this.allowedHeaderNames = allowedHeaderNames == null ? new HashSet<>() : allowedHeaderNames;

return this;
Expand All @@ -246,7 +242,7 @@ public HttpInstrumentationOptions<T> setAllowedHeaderNames(final Set<HttpHeaderN
*
* @throws NullPointerException If {@code allowedHeaderName} is {@code null}.
*/
public HttpInstrumentationOptions<T> addAllowedHeaderName(final HttpHeaderName allowedHeaderName) {
public HttpInstrumentationOptions addAllowedHeaderName(final HttpHeaderName allowedHeaderName) {
Objects.requireNonNull(allowedHeaderName);
this.allowedHeaderNames.add(allowedHeaderName);

Expand All @@ -269,7 +265,7 @@ public Set<String> getAllowedQueryParamNames() {
*
* @return The updated {@code allowedQueryParamName} object.
*/
public HttpInstrumentationOptions<T> setAllowedQueryParamNames(final Set<String> allowedQueryParamNames) {
public HttpInstrumentationOptions setAllowedQueryParamNames(final Set<String> allowedQueryParamNames) {
this.allowedQueryParamNames = allowedQueryParamNames == null ? new HashSet<>() : allowedQueryParamNames;

return this;
Expand All @@ -284,20 +280,20 @@ public HttpInstrumentationOptions<T> setAllowedQueryParamNames(final Set<String>
*
* @throws NullPointerException If {@code allowedQueryParamName} is {@code null}.
*/
public HttpInstrumentationOptions<T> addAllowedQueryParamName(final String allowedQueryParamName) {
public HttpInstrumentationOptions addAllowedQueryParamName(final String allowedQueryParamName) {
this.allowedQueryParamNames.add(allowedQueryParamName);
return this;
}

@Override
public HttpInstrumentationOptions<T> setTracingEnabled(boolean isTracingEnabled) {
public HttpInstrumentationOptions setTracingEnabled(boolean isTracingEnabled) {
super.setTracingEnabled(isTracingEnabled);
return this;
}

@Override
public HttpInstrumentationOptions<T> setProvider(T provider) {
super.setProvider(provider);
public HttpInstrumentationOptions setTelemetryProvider(Object telemetryProvider) {
super.setTelemetryProvider(telemetryProvider);
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
*
* &#47;&#47; You can configure URL sanitization to include additional query parameters to preserve
* &#47;&#47; in `url.full` attribute.
* HttpInstrumentationOptions&lt;?&gt; instrumentationOptions = new HttpInstrumentationOptions&lt;&gt;&#40;&#41;;
* HttpInstrumentationOptions instrumentationOptions = new HttpInstrumentationOptions&#40;&#41;;
* instrumentationOptions.addAllowedQueryParamName&#40;&quot;documentId&quot;&#41;;
*
* HttpPipeline pipeline = new HttpPipelineBuilder&#40;&#41;
Expand Down Expand Up @@ -135,7 +135,7 @@
*/
public final class HttpInstrumentationPolicy implements HttpPipelinePolicy {
private static final ClientLogger LOGGER = new ClientLogger(HttpInstrumentationPolicy.class);
private static final HttpInstrumentationOptions<?> DEFAULT_OPTIONS = new HttpInstrumentationOptions<>();
private static final HttpInstrumentationOptions DEFAULT_OPTIONS = new HttpInstrumentationOptions();
private static final String LIBRARY_NAME;
private static final String LIBRARY_VERSION;
private static final LibraryInstrumentationOptions LIBRARY_OPTIONS;
Expand Down Expand Up @@ -178,12 +178,12 @@ public final class HttpInstrumentationPolicy implements HttpPipelinePolicy {
* Creates a new instrumentation policy.
* @param instrumentationOptions Application telemetry options.
*/
public HttpInstrumentationPolicy(HttpInstrumentationOptions<?> instrumentationOptions) {
public HttpInstrumentationPolicy(HttpInstrumentationOptions instrumentationOptions) {
Instrumentation instrumentation = Instrumentation.create(instrumentationOptions, LIBRARY_OPTIONS);
this.tracer = instrumentation.getTracer();
this.traceContextPropagator = instrumentation.getW3CTraceContextPropagator();

HttpInstrumentationOptions<?> optionsToUse
HttpInstrumentationOptions optionsToUse
= instrumentationOptions == null ? DEFAULT_OPTIONS : instrumentationOptions;
this.isLoggingEnabled = optionsToUse.isHttpLoggingEnabled();
this.isContentLoggingEnabled = optionsToUse.isContentLoggingEnabled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
public class FallbackInstrumentation implements Instrumentation {
public static final FallbackInstrumentation DEFAULT_INSTANCE = new FallbackInstrumentation(null, null);

private final InstrumentationOptions<?> instrumentationOptions;
private final InstrumentationOptions instrumentationOptions;
private final LibraryInstrumentationOptions libraryOptions;

/**
* Creates a new instance of {@link FallbackInstrumentation}.
* @param instrumentationOptions the application instrumentation options
* @param libraryOptions the library instrumentation options
*/
public FallbackInstrumentation(InstrumentationOptions<?> instrumentationOptions,
public FallbackInstrumentation(InstrumentationOptions instrumentationOptions,
LibraryInstrumentationOptions libraryOptions) {
this.instrumentationOptions = instrumentationOptions;
this.libraryOptions = libraryOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ final class FallbackTracer implements Tracer {
private final boolean isEnabled;
private final ClientLogger logger;

FallbackTracer(InstrumentationOptions<?> instrumentationOptions, LibraryInstrumentationOptions libraryOptions) {
FallbackTracer(InstrumentationOptions instrumentationOptions, LibraryInstrumentationOptions libraryOptions) {
// TODO (limolkova): do we need additional config to enable fallback tracing? Or maybe we enable it only if logs are enabled?
this.isEnabled = instrumentationOptions == null || instrumentationOptions.isTracingEnabled();
this.logger = isEnabled ? getLogger(instrumentationOptions, libraryOptions) : LOGGER;
}

private static ClientLogger getLogger(InstrumentationOptions<?> instrumentationOptions,
private static ClientLogger getLogger(InstrumentationOptions instrumentationOptions,
LibraryInstrumentationOptions libraryOptions) {
Object providedLogger = instrumentationOptions == null ? null : instrumentationOptions.getProvider();
Object providedLogger = instrumentationOptions == null ? null : instrumentationOptions.getTelemetryProvider();
if (providedLogger instanceof ClientLogger) {
return (ClientLogger) providedLogger;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ public class OTelInstrumentation implements Instrumentation {
* @param applicationOptions the application options
* @param libraryOptions the library options
*/
public OTelInstrumentation(InstrumentationOptions<?> applicationOptions,
public OTelInstrumentation(InstrumentationOptions applicationOptions,
LibraryInstrumentationOptions libraryOptions) {
Object explicitOTel = applicationOptions == null ? null : applicationOptions.getProvider();
Object explicitOTel = applicationOptions == null ? null : applicationOptions.getTelemetryProvider();
if (explicitOTel != null && !OTEL_CLASS.isInstance(explicitOTel)) {
throw LOGGER.atError()
.addKeyValue("expectedProvider", OTEL_CLASS.getName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public interface Instrumentation {
* .setLibraryVersion&#40;&quot;1.0.0&quot;&#41;
* .setSchemaUrl&#40;&quot;https:&#47;&#47;opentelemetry.io&#47;schemas&#47;1.29.0&quot;&#41;;
*
* InstrumentationOptions&lt;?&gt; instrumentationOptions = new InstrumentationOptions&lt;&gt;&#40;&#41;;
* InstrumentationOptions instrumentationOptions = new InstrumentationOptions&#40;&#41;;
*
* Tracer tracer = Instrumentation.create&#40;instrumentationOptions, libraryOptions&#41;.getTracer&#40;&#41;;
*
Expand Down Expand Up @@ -61,7 +61,7 @@ public interface Instrumentation {
* @param libraryOptions Library-specific telemetry collection options.
* @return The instance of telemetry provider implementation.
*/
static Instrumentation create(InstrumentationOptions<?> applicationOptions,
static Instrumentation create(InstrumentationOptions applicationOptions,
LibraryInstrumentationOptions libraryOptions) {
Objects.requireNonNull(libraryOptions, "'libraryOptions' cannot be null");
if (OTelInitializer.isInitialized()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@
* Library should use them on all instance of {@link io.clientcore.core.instrumentation.tracing.Tracer}
* it creates and, if it sets up {@link HttpInstrumentationPolicy}, it should pass
* {@link InstrumentationOptions} to the policy.
*
* @param <T> The type of the provider. Only {@code io.opentelemetry.api.OpenTelemetry} is supported.
*/
public class InstrumentationOptions<T> {
public class InstrumentationOptions {
private boolean isTracingEnabled = true;
private T provider = null;
private Object telemetryProvider = null;

/**
* Enables or disables distributed tracing. Distributed tracing is enabled by default when
Expand All @@ -29,7 +27,7 @@ public class InstrumentationOptions<T> {
* <!-- src_embed io.clientcore.core.telemetry.disabledistributedtracing -->
* <pre>
*
* HttpInstrumentationOptions&lt;?&gt; instrumentationOptions = new HttpInstrumentationOptions&lt;&gt;&#40;&#41;
* HttpInstrumentationOptions instrumentationOptions = new HttpInstrumentationOptions&#40;&#41;
* .setTracingEnabled&#40;false&#41;;
*
* SampleClient client = new SampleClientBuilder&#40;&#41;.instrumentationOptions&#40;instrumentationOptions&#41;.build&#40;&#41;;
Expand All @@ -41,14 +39,14 @@ public class InstrumentationOptions<T> {
* @param isTracingEnabled true to enable distributed tracing, false to disable.
* @return The updated {@link InstrumentationOptions} object.
*/
public InstrumentationOptions<T> setTracingEnabled(boolean isTracingEnabled) {
public InstrumentationOptions setTracingEnabled(boolean isTracingEnabled) {
this.isTracingEnabled = isTracingEnabled;
return this;
}

/**
* Sets the provider to use for telemetry. Only {@code io.opentelemetry.api.OpenTelemetry} and
* derived classes are supported.
* Sets the telemetry provider. Only {@code io.opentelemetry.api.OpenTelemetry} and
* derived classes are currently supported.
* <p>
*
* When provider is not passed explicitly, clients will attempt to use global OpenTelemetry instance.
Expand All @@ -59,8 +57,8 @@ public InstrumentationOptions<T> setTracingEnabled(boolean isTracingEnabled) {
* <pre>
*
* OpenTelemetry openTelemetry = AutoConfiguredOpenTelemetrySdk.initialize&#40;&#41;.getOpenTelemetrySdk&#40;&#41;;
* HttpInstrumentationOptions&lt;OpenTelemetry&gt; instrumentationOptions = new HttpInstrumentationOptions&lt;OpenTelemetry&gt;&#40;&#41;
* .setProvider&#40;openTelemetry&#41;;
* HttpInstrumentationOptions instrumentationOptions = new HttpInstrumentationOptions&#40;&#41;
* .setTelemetryProvider&#40;openTelemetry&#41;;
*
* SampleClient client = new SampleClientBuilder&#40;&#41;.instrumentationOptions&#40;instrumentationOptions&#41;.build&#40;&#41;;
*
Expand All @@ -70,11 +68,11 @@ public InstrumentationOptions<T> setTracingEnabled(boolean isTracingEnabled) {
* </pre>
* <!-- end io.clientcore.core.telemetry.useexplicitopentelemetry -->
*
* @param provider The provider to use for telemetry.
* @param telemetryProvider The provider to use for telemetry.
* @return The updated {@link InstrumentationOptions} object.
*/
public InstrumentationOptions<T> setProvider(T provider) {
this.provider = provider;
public InstrumentationOptions setTelemetryProvider(Object telemetryProvider) {
this.telemetryProvider = telemetryProvider;
return this;
}

Expand All @@ -92,8 +90,8 @@ public boolean isTracingEnabled() {
*
* @return The telemetry provider instance.
*/
public T getProvider() {
return provider;
public Object getTelemetryProvider() {
return telemetryProvider;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
* <pre>
*
* OpenTelemetry openTelemetry = AutoConfiguredOpenTelemetrySdk.initialize&#40;&#41;.getOpenTelemetrySdk&#40;&#41;;
* HttpInstrumentationOptions&lt;OpenTelemetry&gt; instrumentationOptions = new HttpInstrumentationOptions&lt;OpenTelemetry&gt;&#40;&#41;
* .setProvider&#40;openTelemetry&#41;;
* HttpInstrumentationOptions instrumentationOptions = new HttpInstrumentationOptions&#40;&#41;
* .setTelemetryProvider&#40;openTelemetry&#41;;
*
* SampleClient client = new SampleClientBuilder&#40;&#41;.instrumentationOptions&#40;instrumentationOptions&#41;.build&#40;&#41;;
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public interface HttpTrait<T extends HttpTrait<T>> {
* @return Returns the same concrete type with the appropriate properties updated, to allow for fluent chaining of
* operations.
*/
T httpInstrumentationOptions(HttpInstrumentationOptions<T> instrumentationOptions);
T httpInstrumentationOptions(HttpInstrumentationOptions instrumentationOptions);

/**
* Sets the {@link HttpRedirectOptions} for all the requests made through the client.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public void useCustomLogger() {

ClientLogger logger = new ClientLogger("sample-client-traces");

HttpInstrumentationOptions<ClientLogger> instrumentationOptions = new HttpInstrumentationOptions<ClientLogger>()
.setProvider(logger);
HttpInstrumentationOptions instrumentationOptions = new HttpInstrumentationOptions()
.setTelemetryProvider(logger);

SampleClient client = new SampleClientBuilder().instrumentationOptions(instrumentationOptions).build();
client.clientCall();
Expand All @@ -76,7 +76,7 @@ public void useCustomLogger() {
public void disableDistributedTracing() {
// BEGIN: io.clientcore.core.telemetry.fallback.disabledistributedtracing

HttpInstrumentationOptions<?> instrumentationOptions = new HttpInstrumentationOptions<>()
HttpInstrumentationOptions instrumentationOptions = new HttpInstrumentationOptions()
.setTracingEnabled(false);

SampleClient client = new SampleClientBuilder().instrumentationOptions(instrumentationOptions).build();
Expand Down Expand Up @@ -138,8 +138,8 @@ public Span getSpan() {
}

static class SampleClientBuilder {
private HttpInstrumentationOptions<?> instrumentationOptions;
public SampleClientBuilder instrumentationOptions(HttpInstrumentationOptions<?> instrumentationOptions) {
private HttpInstrumentationOptions instrumentationOptions;
public SampleClientBuilder instrumentationOptions(HttpInstrumentationOptions instrumentationOptions) {
this.instrumentationOptions = instrumentationOptions;
return this;
}
Expand All @@ -156,7 +156,7 @@ static class SampleClient {
private final HttpPipeline httpPipeline;
private final io.clientcore.core.instrumentation.tracing.Tracer tracer;

SampleClient(InstrumentationOptions<?> instrumentationOptions, HttpPipeline httpPipeline) {
SampleClient(InstrumentationOptions instrumentationOptions, HttpPipeline httpPipeline) {
this.httpPipeline = httpPipeline;
this.tracer = Instrumentation.create(instrumentationOptions, LIBRARY_OPTIONS).getTracer();
}
Expand Down
Loading

0 comments on commit 980021f

Please sign in to comment.