Skip to content

Commit b41a7ab

Browse files
authored
API changes to Azure Monitor exporter (Azure#18702)
* API changes to Azure Monitor exporter
1 parent a3d6ad5 commit b41a7ab

File tree

2 files changed

+53
-5
lines changed

2 files changed

+53
-5
lines changed

sdk/monitor/azure-opentelemetry-exporter-azuremonitor/src/main/java/com/azure/opentelemetry/exporter/azuremonitor/AzureMonitorExporterBuilder.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public final class AzureMonitorExporterBuilder {
3232
private final ClientLogger logger = new ClientLogger(AzureMonitorExporterBuilder.class);
3333
private final ApplicationInsightsClientImplBuilder restServiceClientBuilder;
3434
private String instrumentationKey;
35+
private String endpoint;
36+
private String connectionString;
37+
private AzureMonitorExporterServiceVersion serviceVersion;
3538

3639
/**
3740
* Creates an instance of {@link AzureMonitorExporterBuilder}.
@@ -52,6 +55,7 @@ AzureMonitorExporterBuilder endpoint(String endpoint) {
5255

5356
try {
5457
URL url = new URL(endpoint);
58+
this.endpoint = endpoint;
5559
restServiceClientBuilder.host(url.getProtocol() + "://" + url.getHost());
5660
} catch (MalformedURLException ex) {
5761
throw logger.logExceptionAsWarning(
@@ -136,7 +140,7 @@ public AzureMonitorExporterBuilder configuration(Configuration configuration) {
136140
}
137141

138142
/**
139-
* The connection string to use for exporting telemetry events to Azure Monitor.
143+
* Sets the connection string to use for exporting telemetry events to Azure Monitor.
140144
* @param connectionString The connection string for the Azure Monitor resource.
141145
* @return The updated {@link AzureMonitorExporterBuilder} object.
142146
* @throws NullPointerException If the connection string is {@code null}.
@@ -153,6 +157,18 @@ public AzureMonitorExporterBuilder connectionString(String connectionString) {
153157
if (endpoint != null) {
154158
this.endpoint(endpoint);
155159
}
160+
this.connectionString = connectionString;
161+
return this;
162+
}
163+
164+
/**
165+
* Sets the Azure Monitor service version.
166+
*
167+
* @param serviceVersion The Azure Monitor service version.
168+
* @return The update {@link AzureMonitorExporterBuilder} object.
169+
*/
170+
public AzureMonitorExporterBuilder serviceVersion(AzureMonitorExporterServiceVersion serviceVersion) {
171+
this.serviceVersion = serviceVersion;
156172
return this;
157173
}
158174

@@ -213,12 +229,12 @@ MonitorExporterAsyncClient buildAsyncClient() {
213229
* implementation of OpenTelemetry {@link SpanExporter}.
214230
*
215231
* @return An instance of {@link AzureMonitorExporter}.
216-
* @throws NullPointerException if the instrumentation key is not set.
232+
* @throws NullPointerException if the connection string is not set.
217233
*/
218234
public AzureMonitorExporter buildExporter() {
219-
// instrumentationKey is extracted from connectionString, so, if instrumentationKey is null
220-
// then the error message should read "connectionString cannot be null".
221-
Objects.requireNonNull(instrumentationKey, "'connectionString' cannot be null");
235+
if (connectionString == null) {
236+
throw logger.logExceptionAsError(new NullPointerException("'connectionString' cannot be null."));
237+
}
222238
return new AzureMonitorExporter(buildClient(), instrumentationKey);
223239
}
224240

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.opentelemetry.exporter.azuremonitor;
5+
6+
import com.azure.core.util.ServiceVersion;
7+
8+
/**
9+
* The versions of Azure Monitor service supported by this client library.
10+
*/
11+
public enum AzureMonitorExporterServiceVersion implements ServiceVersion {
12+
V2("2");
13+
14+
private final String version;
15+
16+
AzureMonitorExporterServiceVersion(String version) {
17+
this.version = version;
18+
}
19+
20+
@Override
21+
public String getVersion() {
22+
return version;
23+
}
24+
25+
/**
26+
* Gets the latest service version supported by this client library.
27+
* @return the latest service version.
28+
*/
29+
public static AzureMonitorExporterServiceVersion getLatest() {
30+
return V2;
31+
}
32+
}

0 commit comments

Comments
 (0)