diff --git a/sdk/monitor/azure-opentelemetry-exporter-azuremonitor/src/main/java/com/azure/opentelemetry/exporter/azuremonitor/AzureMonitorExporterBuilder.java b/sdk/monitor/azure-opentelemetry-exporter-azuremonitor/src/main/java/com/azure/opentelemetry/exporter/azuremonitor/AzureMonitorExporterBuilder.java index 6a94e8325765d..24e668dbc9545 100644 --- a/sdk/monitor/azure-opentelemetry-exporter-azuremonitor/src/main/java/com/azure/opentelemetry/exporter/azuremonitor/AzureMonitorExporterBuilder.java +++ b/sdk/monitor/azure-opentelemetry-exporter-azuremonitor/src/main/java/com/azure/opentelemetry/exporter/azuremonitor/AzureMonitorExporterBuilder.java @@ -32,6 +32,9 @@ public final class AzureMonitorExporterBuilder { private final ClientLogger logger = new ClientLogger(AzureMonitorExporterBuilder.class); private final ApplicationInsightsClientImplBuilder restServiceClientBuilder; private String instrumentationKey; + private String endpoint; + private String connectionString; + private AzureMonitorExporterServiceVersion serviceVersion; /** * Creates an instance of {@link AzureMonitorExporterBuilder}. @@ -52,6 +55,7 @@ AzureMonitorExporterBuilder endpoint(String endpoint) { try { URL url = new URL(endpoint); + this.endpoint = endpoint; restServiceClientBuilder.host(url.getProtocol() + "://" + url.getHost()); } catch (MalformedURLException ex) { throw logger.logExceptionAsWarning( @@ -136,7 +140,7 @@ public AzureMonitorExporterBuilder configuration(Configuration configuration) { } /** - * The connection string to use for exporting telemetry events to Azure Monitor. + * Sets the connection string to use for exporting telemetry events to Azure Monitor. * @param connectionString The connection string for the Azure Monitor resource. * @return The updated {@link AzureMonitorExporterBuilder} object. * @throws NullPointerException If the connection string is {@code null}. @@ -153,6 +157,18 @@ public AzureMonitorExporterBuilder connectionString(String connectionString) { if (endpoint != null) { this.endpoint(endpoint); } + this.connectionString = connectionString; + return this; + } + + /** + * Sets the Azure Monitor service version. + * + * @param serviceVersion The Azure Monitor service version. + * @return The update {@link AzureMonitorExporterBuilder} object. + */ + public AzureMonitorExporterBuilder serviceVersion(AzureMonitorExporterServiceVersion serviceVersion) { + this.serviceVersion = serviceVersion; return this; } @@ -213,12 +229,12 @@ MonitorExporterAsyncClient buildAsyncClient() { * implementation of OpenTelemetry {@link SpanExporter}. * * @return An instance of {@link AzureMonitorExporter}. - * @throws NullPointerException if the instrumentation key is not set. + * @throws NullPointerException if the connection string is not set. */ public AzureMonitorExporter buildExporter() { - // instrumentationKey is extracted from connectionString, so, if instrumentationKey is null - // then the error message should read "connectionString cannot be null". - Objects.requireNonNull(instrumentationKey, "'connectionString' cannot be null"); + if (connectionString == null) { + throw logger.logExceptionAsError(new NullPointerException("'connectionString' cannot be null.")); + } return new AzureMonitorExporter(buildClient(), instrumentationKey); } diff --git a/sdk/monitor/azure-opentelemetry-exporter-azuremonitor/src/main/java/com/azure/opentelemetry/exporter/azuremonitor/AzureMonitorExporterServiceVersion.java b/sdk/monitor/azure-opentelemetry-exporter-azuremonitor/src/main/java/com/azure/opentelemetry/exporter/azuremonitor/AzureMonitorExporterServiceVersion.java new file mode 100644 index 0000000000000..78e65768cc00c --- /dev/null +++ b/sdk/monitor/azure-opentelemetry-exporter-azuremonitor/src/main/java/com/azure/opentelemetry/exporter/azuremonitor/AzureMonitorExporterServiceVersion.java @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.opentelemetry.exporter.azuremonitor; + +import com.azure.core.util.ServiceVersion; + +/** + * The versions of Azure Monitor service supported by this client library. + */ +public enum AzureMonitorExporterServiceVersion implements ServiceVersion { + V2("2"); + + private final String version; + + AzureMonitorExporterServiceVersion(String version) { + this.version = version; + } + + @Override + public String getVersion() { + return version; + } + + /** + * Gets the latest service version supported by this client library. + * @return the latest service version. + */ + public static AzureMonitorExporterServiceVersion getLatest() { + return V2; + } +}