Skip to content

Commit

Permalink
LibraryTelemetryOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
lmolkova committed Sep 24, 2024
1 parent 7b0f6a2 commit 053d0eb
Show file tree
Hide file tree
Showing 21 changed files with 63 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.azure.core.util.CoreUtils;
import com.azure.core.util.MetricsOptions;
import com.azure.core.util.TelemetryAttributes;
import com.azure.core.util.TelemetryOptions;
import com.azure.core.util.LibraryTelemetryOptions;
import com.azure.core.util.metrics.DoubleHistogram;
import com.azure.core.util.metrics.LongCounter;
import com.azure.core.util.metrics.LongGauge;
Expand All @@ -29,7 +29,7 @@ class OpenTelemetryMeter implements Meter {
private final io.opentelemetry.api.metrics.Meter meter;
private final boolean isEnabled;

OpenTelemetryMeter(TelemetryOptions libraryOptions, MetricsOptions applicationOptions) {
OpenTelemetryMeter(LibraryTelemetryOptions libraryOptions, MetricsOptions applicationOptions) {
MeterProvider otelProvider = GlobalOpenTelemetry.getMeterProvider();
if (applicationOptions != null
&& applicationOptions.isEnabled()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package com.azure.core.metrics.opentelemetry;

import com.azure.core.util.MetricsOptions;
import com.azure.core.util.TelemetryOptions;
import com.azure.core.util.LibraryTelemetryOptions;
import com.azure.core.util.metrics.Meter;
import com.azure.core.util.metrics.MeterProvider;

Expand Down Expand Up @@ -35,9 +35,9 @@ public OpenTelemetryMeterProvider() {
@Override
public Meter createMeter(String libraryName, String libraryVersion, MetricsOptions applicationOptions) {
Objects.requireNonNull(libraryName, "'libraryName' cannot be null.");
final TelemetryOptions telemetryOptions
= new TelemetryOptions().setLibraryName(libraryName).setLibraryVersion(libraryVersion);
return new OpenTelemetryMeter(telemetryOptions, applicationOptions);
final LibraryTelemetryOptions libraryOptions
= new LibraryTelemetryOptions().setLibraryName(libraryName).setLibraryVersion(libraryVersion);
return new OpenTelemetryMeter(libraryOptions, applicationOptions);
}

/**
Expand Down Expand Up @@ -125,7 +125,7 @@ public Meter createMeter(String libraryName, String libraryVersion, MetricsOptio
* @return a meter instance.
*/
@Override
public Meter createMeter(TelemetryOptions libraryOptions, MetricsOptions applicationOptions) {
public Meter createMeter(LibraryTelemetryOptions libraryOptions, MetricsOptions applicationOptions) {
Objects.requireNonNull(libraryOptions, "'libraryOptions' cannot be null.");
return new OpenTelemetryMeter(libraryOptions, applicationOptions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.azure.core.util.Context;
import com.azure.core.util.MetricsOptions;
import com.azure.core.util.TelemetryAttributes;
import com.azure.core.util.TelemetryOptions;
import com.azure.core.util.LibraryTelemetryOptions;
import com.azure.core.util.metrics.DoubleHistogram;
import com.azure.core.util.metrics.Meter;
import com.azure.core.util.metrics.MeterProvider;
Expand Down Expand Up @@ -193,12 +193,12 @@ private static final class AzureClient {
private final DoubleHistogram callDuration;
private final TelemetryAttributes attributes;
AzureClient(String endpoint, ClientOptions options) {
TelemetryOptions telemetryOptions = new TelemetryOptions()
LibraryTelemetryOptions libraryOptions = new LibraryTelemetryOptions()
.setLibraryName("azure-samples")
.setLibraryVersion("1.0.0")
.setResourceProviderNamespace("Microsoft.Sample")
.setSchemaUrl("https://opentelemetry.io/schemas/1.23.1");
meter = DEFAULT_PROVIDER.createMeter(telemetryOptions, options == null ? null : options.getMetricsOptions());
meter = DEFAULT_PROVIDER.createMeter(libraryOptions, options == null ? null : options.getMetricsOptions());
callDuration = meter.createDoubleHistogram("az.sample.method.duration", "Duration of sample method call", "ms");
attributes = meter.createAttributes(Collections.singletonMap("endpoint", endpoint));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.azure.core.util.Context;
import com.azure.core.util.MetricsOptions;
import com.azure.core.util.TelemetryAttributes;
import com.azure.core.util.TelemetryOptions;
import com.azure.core.util.LibraryTelemetryOptions;
import com.azure.core.util.metrics.DoubleHistogram;
import com.azure.core.util.metrics.LongCounter;
import com.azure.core.util.metrics.LongGauge;
Expand Down Expand Up @@ -371,7 +371,7 @@ public void gaugeMultiple() throws Exception {

@Test
public void sdkOptions() {
TelemetryOptions sdkOptions = new TelemetryOptions().setLibraryName("az.sdk-name")
LibraryTelemetryOptions sdkOptions = new LibraryTelemetryOptions().setLibraryName("az.sdk-name")
.setLibraryVersion("1.0.0-beta.1")
.setSchemaUrl("https://aka.ms/az/sdk/schema:1.42.0");
InstrumentationScopeInfo expectedInstrumentationScope = InstrumentationScopeInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import com.azure.core.test.utils.metrics.TestMeter;
import com.azure.core.util.MetricsOptions;
import com.azure.core.util.TelemetryOptions;
import com.azure.core.util.LibraryTelemetryOptions;
import com.azure.core.util.metrics.Meter;
import com.azure.core.util.metrics.MeterProvider;
import org.junit.jupiter.api.Test;
Expand All @@ -31,7 +31,7 @@ public void invalidParams() {
assertThrows(NullPointerException.class, () -> MeterProvider.getDefaultProvider().createMeter(null, null));

assertThrows(NullPointerException.class,
() -> MeterProvider.getDefaultProvider().createMeter(new TelemetryOptions(), null));
() -> MeterProvider.getDefaultProvider().createMeter(new LibraryTelemetryOptions(), null));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.azure.core.tracing.opentelemetry.OpenTelemetryTracingOptions;
import com.azure.core.util.ClientOptions;
import com.azure.core.util.Context;
import com.azure.core.util.TelemetryOptions;
import com.azure.core.util.LibraryTelemetryOptions;
import com.azure.core.util.TracingOptions;
import com.azure.core.util.tracing.TracerProvider;
import io.opentelemetry.api.OpenTelemetry;
Expand Down Expand Up @@ -143,7 +143,7 @@ private static final class AzureClient {
private static final TracerProvider DEFAULT_PROVIDER = TracerProvider.getDefaultProvider();
private final com.azure.core.util.tracing.Tracer tracer;
AzureClient(String endpoint, ClientOptions options) {
TelemetryOptions libraryOptions = new TelemetryOptions()
LibraryTelemetryOptions libraryOptions = new LibraryTelemetryOptions()
.setLibraryName("azure-sample")
.setLibraryVersion("12.20.0")
.setResourceProviderNamespace("Microsoft.Sample")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import com.azure.core.util.Context;
import com.azure.core.util.CoreUtils;
import com.azure.core.util.TelemetryOptions;
import com.azure.core.util.LibraryTelemetryOptions;
import com.azure.core.util.TracingOptions;
import com.azure.core.util.logging.ClientLogger;
import com.azure.core.util.tracing.StartSpanOptions;
Expand Down Expand Up @@ -93,15 +93,15 @@ public class OpenTelemetryTracer implements com.azure.core.util.tracing.Tracer {
*
*/
public OpenTelemetryTracer() {
this(new TelemetryOptions().setLibraryName("azure-core"), null);
this(new LibraryTelemetryOptions().setLibraryName("azure-core"), null);
}

/**
* Creates new {@link OpenTelemetryTracer} using default global tracer -
* {@link GlobalOpenTelemetry#getTracer(String)}
*
*/
OpenTelemetryTracer(TelemetryOptions libraryOptions, TracingOptions applicationOptions) {
OpenTelemetryTracer(LibraryTelemetryOptions libraryOptions, TracingOptions applicationOptions) {

TracerProvider otelProvider = getTracerProvider(applicationOptions);
this.isEnabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package com.azure.core.tracing.opentelemetry;

import com.azure.core.util.TelemetryOptions;
import com.azure.core.util.LibraryTelemetryOptions;
import com.azure.core.util.TracingOptions;
import com.azure.core.util.tracing.Tracer;
import com.azure.core.util.tracing.TracerProvider;
Expand Down Expand Up @@ -38,7 +38,7 @@ public Tracer createTracer(String libraryName, String libraryVersion, String azN
TracingOptions applicationOptions) {
Objects.requireNonNull(libraryName, "'libraryName' cannot be null.");

final TelemetryOptions libraryOptions = new TelemetryOptions().setLibraryName(libraryName)
final LibraryTelemetryOptions libraryOptions = new LibraryTelemetryOptions().setLibraryName(libraryName)
.setLibraryVersion(libraryVersion)
.setResourceProviderNamespace(azNamespace);
return new OpenTelemetryTracer(libraryOptions, applicationOptions);
Expand All @@ -52,7 +52,7 @@ public Tracer createTracer(String libraryName, String libraryVersion, String azN
* @return a tracer instance.
*/
@Override
public Tracer createTracer(TelemetryOptions libraryOptions, TracingOptions applicationOptions) {
public Tracer createTracer(LibraryTelemetryOptions libraryOptions, TracingOptions applicationOptions) {
return new OpenTelemetryTracer(libraryOptions, applicationOptions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package com.azure.core.tracing.opentelemetry;

import com.azure.core.util.Context;
import com.azure.core.util.TelemetryOptions;
import com.azure.core.util.LibraryTelemetryOptions;
import com.azure.core.util.tracing.Tracer;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.trace.Span;
Expand All @@ -27,7 +27,7 @@ public class AmqpPropagationFormatUtilTest {
private static final SdkTracerProvider TRACER_PROVIDER = SdkTracerProvider.builder().build();
private static final OpenTelemetry OPEN_TELEMETRY
= OpenTelemetrySdk.builder().setTracerProvider(TRACER_PROVIDER).build();
private static final Tracer TRACER = new OpenTelemetryTracer(new TelemetryOptions().setLibraryName("test"),
private static final Tracer TRACER = new OpenTelemetryTracer(new LibraryTelemetryOptions().setLibraryName("test"),
new OpenTelemetryTracingOptions().setOpenTelemetry(OPEN_TELEMETRY));

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package com.azure.core.tracing.opentelemetry;

import com.azure.core.util.Context;
import com.azure.core.util.TelemetryOptions;
import com.azure.core.util.LibraryTelemetryOptions;
import com.azure.core.util.tracing.Tracer;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.baggage.Baggage;
Expand Down Expand Up @@ -35,7 +35,7 @@ public class ContextPropagationTests {
private static final SdkTracerProvider TRACER_PROVIDER = SdkTracerProvider.builder().build();
private static final OpenTelemetry OPEN_TELEMETRY
= OpenTelemetrySdk.builder().setTracerProvider(TRACER_PROVIDER).build();
private static final Tracer TRACER = new OpenTelemetryTracer(new TelemetryOptions().setLibraryName("test"),
private static final Tracer TRACER = new OpenTelemetryTracer(new LibraryTelemetryOptions().setLibraryName("test"),
new OpenTelemetryTracingOptions().setOpenTelemetry(OPEN_TELEMETRY));

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package com.azure.core.tracing.opentelemetry;

import com.azure.core.util.Context;
import com.azure.core.util.TelemetryOptions;
import com.azure.core.util.LibraryTelemetryOptions;
import com.azure.core.util.tracing.Tracer;
import com.azure.core.util.tracing.TracerProvider;
import io.opentelemetry.api.OpenTelemetry;
Expand Down Expand Up @@ -100,7 +100,7 @@ public void defaultSchemaVersion() {
OpenTelemetryTracingOptions options = new OpenTelemetryTracingOptions().setOpenTelemetry(openTelemetry);

Tracer tracer
= TracerProvider.getDefaultProvider().createTracer(new TelemetryOptions().setLibraryName("test"), options);
= TracerProvider.getDefaultProvider().createTracer(new LibraryTelemetryOptions().setLibraryName("test"), options);

Context span = tracer.start("test", Context.NONE);
tracer.end(null, null, span);
Expand Down Expand Up @@ -141,7 +141,7 @@ public void instrumentationScopeVersion() {
public void testSdkOptions() {
OpenTelemetryTracingOptions options = new OpenTelemetryTracingOptions().setOpenTelemetry(openTelemetry);

TelemetryOptions libraryOptions = new TelemetryOptions().setLibraryName("test")
LibraryTelemetryOptions libraryOptions = new LibraryTelemetryOptions().setLibraryName("test")
.setLibraryVersion("1.2.3-beta.45")
.setResourceProviderNamespace("namespace")
.setSchemaUrl("https://aka.ms/az/sdk/schema:1.42.0");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.azure.core.util.BinaryData;
import com.azure.core.util.ClientOptions;
import com.azure.core.util.Context;
import com.azure.core.util.TelemetryOptions;
import com.azure.core.util.LibraryTelemetryOptions;
import com.azure.core.util.TracingOptions;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.common.AttributeKey;
Expand Down Expand Up @@ -89,7 +89,7 @@ public class OpenTelemetryHttpPolicyTests {
private static final String EXPECTED_URL_REDACTED = "https://httpbin.org/hello?n=REDACTED&api-version=1.2.3";
private static final String ORIGINAL_URL_NO_QUERY = "https://httpbin.org/hello";
private static final ClientOptions DEFAULT_CLIENT_OPTIONS = new ClientOptions();
private static final TelemetryOptions DEFAULT_TELEMETRY_OPTIONS = new TelemetryOptions().setLibraryName("test");
private static final LibraryTelemetryOptions DEFAULT_TELEMETRY_OPTIONS = new LibraryTelemetryOptions().setLibraryName("test");
private InMemorySpanExporter exporter;
private SdkTracerProvider tracerProvider;
private OpenTelemetry openTelemetry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package com.azure.core.tracing.opentelemetry;

import com.azure.core.util.Context;
import com.azure.core.util.TelemetryOptions;
import com.azure.core.util.LibraryTelemetryOptions;
import com.azure.core.util.tracing.StartSpanOptions;
import com.azure.core.util.tracing.TracingLink;
import io.opentelemetry.api.OpenTelemetry;
Expand Down Expand Up @@ -125,7 +125,7 @@ public void setUp() {
tracingContext
= new Context(PARENT_TRACE_CONTEXT_KEY, io.opentelemetry.context.Context.root().with(parentSpan));
openTelemetryTracer = new OpenTelemetryTracer(
new TelemetryOptions().setLibraryName("test").setResourceProviderNamespace(AZ_NAMESPACE_VALUE),
new LibraryTelemetryOptions().setLibraryName("test").setResourceProviderNamespace(AZ_NAMESPACE_VALUE),
new OpenTelemetryTracingOptions().setOpenTelemetry(openTelemetry));
}

Expand Down Expand Up @@ -224,7 +224,7 @@ public void startWithAttributes() {
@Test
public void fallbackToAzNamespaceFromContext() {
// Arrange
OpenTelemetryTracer noAzTracer = new OpenTelemetryTracer(new TelemetryOptions().setLibraryName("test"),
OpenTelemetryTracer noAzTracer = new OpenTelemetryTracer(new LibraryTelemetryOptions().setLibraryName("test"),
new OpenTelemetryTracingOptions().setOpenTelemetry(openTelemetry));

// Act
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.azure.core.http.policy.HttpPipelinePolicy;
import com.azure.core.http.policy.HttpPolicyProviders;
import com.azure.core.test.http.MockHttpResponse;
import com.azure.core.util.TelemetryOptions;
import com.azure.core.util.LibraryTelemetryOptions;
import com.azure.core.util.tracing.Tracer;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.context.Context;
Expand Down Expand Up @@ -77,7 +77,7 @@ private static HttpPipeline createPipeline(Tracer tracer, boolean addTracingPoli

private static Tracer configureTracer(boolean enabled) {
if (!enabled) {
return new OpenTelemetryTracer(new TelemetryOptions().setLibraryName("benchmark"),
return new OpenTelemetryTracer(new LibraryTelemetryOptions().setLibraryName("benchmark"),
new OpenTelemetryTracingOptions().setEnabled(false));
}

Expand All @@ -87,7 +87,7 @@ private static Tracer configureTracer(boolean enabled) {
.build();

OpenTelemetry openTelemetry = OpenTelemetrySdk.builder().setTracerProvider(provider).build();
return new OpenTelemetryTracer(new TelemetryOptions().setLibraryName("benchmark"),
return new OpenTelemetryTracer(new LibraryTelemetryOptions().setLibraryName("benchmark"),
new OpenTelemetryTracingOptions().setOpenTelemetry(openTelemetry));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@
* The options to configure library-specific information on {@link TracerProvider}
*/
@Fluent
public class TelemetryOptions {
public class LibraryTelemetryOptions {
private String libraryName;
private String libraryVersion;
private String rpNamespace;
private String schemaUrl;

/**
* Creates an instance of {@link TelemetryOptions}.
* Creates an instance of {@link LibraryTelemetryOptions}.
*/
public TelemetryOptions() {
public LibraryTelemetryOptions() {
}

/**
* Sets the client library name.
*
* @param libraryName The client library name.
* @return The updated {@link TelemetryOptions} object.
* @return The updated {@link LibraryTelemetryOptions} object.
*/
public TelemetryOptions setLibraryName(String libraryName) {
public LibraryTelemetryOptions setLibraryName(String libraryName) {
this.libraryName = libraryName;
return this;
}
Expand All @@ -37,9 +37,9 @@ public TelemetryOptions setLibraryName(String libraryName) {
* Sets the client library version.
*
* @param libraryVersion The client library version.
* @return The updated {@link TelemetryOptions} object.
* @return The updated {@link LibraryTelemetryOptions} object.
*/
public TelemetryOptions setLibraryVersion(String libraryVersion) {
public LibraryTelemetryOptions setLibraryVersion(String libraryVersion) {
this.libraryVersion = libraryVersion;
return this;
}
Expand All @@ -48,9 +48,9 @@ public TelemetryOptions setLibraryVersion(String libraryVersion) {
* Sets the Azure namespace.
*
* @param rpNamespace The Azure Resource Provider namespace client library communicates with.
* @return The updated {@link TelemetryOptions} object.
* @return The updated {@link LibraryTelemetryOptions} object.
*/
public TelemetryOptions setResourceProviderNamespace(String rpNamespace) {
public LibraryTelemetryOptions setResourceProviderNamespace(String rpNamespace) {
this.rpNamespace = rpNamespace;
return this;
}
Expand All @@ -60,9 +60,9 @@ public TelemetryOptions setResourceProviderNamespace(String rpNamespace) {
* the library emits.
*
* @param schemaUrl The schema URL.
* @return The updated {@link TelemetryOptions} object.
* @return The updated {@link LibraryTelemetryOptions} object.
*/
public TelemetryOptions setSchemaUrl(String schemaUrl) {
public LibraryTelemetryOptions setSchemaUrl(String schemaUrl) {
this.schemaUrl = schemaUrl;
return this;
}
Expand Down
Loading

0 comments on commit 053d0eb

Please sign in to comment.