Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API changes to Azure Monitor exporter #18702

Merged
merged 6 commits into from
Feb 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}