Skip to content

Commit

Permalink
API changes to Azure Monitor exporter (#18702)
Browse files Browse the repository at this point in the history
* API changes to Azure Monitor exporter
  • Loading branch information
srnagar authored Feb 5, 2021
1 parent a3d6ad5 commit b41a7ab
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand All @@ -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(
Expand Down Expand Up @@ -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}.
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit b41a7ab

Please sign in to comment.