From 0bdbb1a2b3aec32e8322055cb8317f9d4edf877e Mon Sep 17 00:00:00 2001 From: Srikanta Date: Wed, 20 Jan 2021 01:36:05 -0800 Subject: [PATCH 1/5] API changes to Azure Monitor exporter --- .../azuremonitor/AzureMonitorExporter.java | 12 +++++++- .../AzureMonitorExporterBuilder.java | 28 +++++++++++++++---- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/sdk/monitor/azure-opentelemetry-exporter-azuremonitor/src/main/java/com/azure/opentelemetry/exporter/azuremonitor/AzureMonitorExporter.java b/sdk/monitor/azure-opentelemetry-exporter-azuremonitor/src/main/java/com/azure/opentelemetry/exporter/azuremonitor/AzureMonitorExporter.java index c16463a32dae8..9a138bb1496b7 100644 --- a/sdk/monitor/azure-opentelemetry-exporter-azuremonitor/src/main/java/com/azure/opentelemetry/exporter/azuremonitor/AzureMonitorExporter.java +++ b/sdk/monitor/azure-opentelemetry-exporter-azuremonitor/src/main/java/com/azure/opentelemetry/exporter/azuremonitor/AzureMonitorExporter.java @@ -75,6 +75,7 @@ public final class AzureMonitorExporter implements SpanExporter { private final ClientLogger logger = new ClientLogger(AzureMonitorExporter.class); private final String instrumentationKey; private final String telemetryItemNamePrefix; + private final String endpoint; /** * Creates an instance of exporter that is configured with given exporter client that sends telemetry events to @@ -83,13 +84,22 @@ public final class AzureMonitorExporter implements SpanExporter { * @param client The client used to send data to Azure Monitor. * @param instrumentationKey The instrumentation key of Application Insights resource. */ - AzureMonitorExporter(MonitorExporterClient client, String instrumentationKey) { + AzureMonitorExporter(MonitorExporterClient client, String instrumentationKey, String endpoint) { this.client = client; this.instrumentationKey = instrumentationKey; + this.endpoint = endpoint; String formattedInstrumentationKey = instrumentationKey.replaceAll("-", ""); this.telemetryItemNamePrefix = "Microsoft.ApplicationInsights." + formattedInstrumentationKey + "."; } + /** + * Returns the endpoint of the Application Insights resource. + * @return The endpoint of the Application Insights resource. + */ + public String getEndpoint() { + return endpoint; + } + /** * {@inheritDoc} */ 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..17114c55c92df 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,8 @@ 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; /** * Creates an instance of {@link AzureMonitorExporterBuilder}. @@ -52,6 +54,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 +139,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 +156,18 @@ public AzureMonitorExporterBuilder connectionString(String connectionString) { if (endpoint != null) { this.endpoint(endpoint); } + this.connectionString = connectionString; + return this; + } + + /** + * Sets the instrumentation key of the Azure Monitor resource. + * @param instrumentationKey The instrumentation key of the Azure Monitor resource. + * @return The update {@link AzureMonitorExporterBuilder} object. + * @throws NullPointerException If the {@code instrumentationKey} is null. + */ + public AzureMonitorExporterBuilder instrumentationKey(String instrumentationKey) { + this.instrumentationKey = Objects.requireNonNull(instrumentationKey, "'instrumentationKey' cannot be null."); return this; } @@ -213,13 +228,14 @@ 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 instrumentation key or endpoint 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"); - return new AzureMonitorExporter(buildClient(), instrumentationKey); + if (connectionString == null && instrumentationKey == null) { + throw logger.logExceptionAsError(new NullPointerException("'connectionString' or 'instrumentationKey' " + + "must be set.")); + } + return new AzureMonitorExporter(buildClient(), instrumentationKey, endpoint); } } From 62b9c53ca714d0a07a3f793ce56342de1b0bb5ba Mon Sep 17 00:00:00 2001 From: Srikanta Date: Wed, 20 Jan 2021 01:51:05 -0800 Subject: [PATCH 2/5] Service version config --- .../AzureMonitorExporterBuilder.java | 12 ++++++++ .../AzureMonitorExporterServiceVersion.java | 29 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 sdk/monitor/azure-opentelemetry-exporter-azuremonitor/src/main/java/com/azure/opentelemetry/exporter/azuremonitor/AzureMonitorExporterServiceVersion.java 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 17114c55c92df..4ff377ebd11a7 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 @@ -34,6 +34,7 @@ public final class AzureMonitorExporterBuilder { private String instrumentationKey; private String endpoint; private String connectionString; + private AzureMonitorExporterServiceVersion serviceVersion; /** * Creates an instance of {@link AzureMonitorExporterBuilder}. @@ -171,6 +172,17 @@ public AzureMonitorExporterBuilder instrumentationKey(String instrumentationKey) 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; + } + private Map extractKeyValuesFromConnectionString(String connectionString) { Objects.requireNonNull(connectionString); Map keyValues = new HashMap<>(); 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..4d44856696bbe --- /dev/null +++ b/sdk/monitor/azure-opentelemetry-exporter-azuremonitor/src/main/java/com/azure/opentelemetry/exporter/azuremonitor/AzureMonitorExporterServiceVersion.java @@ -0,0 +1,29 @@ +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; + } +} From eeb67ecd6899d7b3af79ea3a9ab98292fc179fc1 Mon Sep 17 00:00:00 2001 From: Srikanta Date: Mon, 25 Jan 2021 10:10:53 -0800 Subject: [PATCH 3/5] Fix checkstyle --- .../exporter/azuremonitor/AzureMonitorExporterBuilder.java | 4 ++-- .../azuremonitor/AzureMonitorExporterServiceVersion.java | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) 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 4ff377ebd11a7..3fb0e3b2fb7a2 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 @@ -244,8 +244,8 @@ MonitorExporterAsyncClient buildAsyncClient() { */ public AzureMonitorExporter buildExporter() { if (connectionString == null && instrumentationKey == null) { - throw logger.logExceptionAsError(new NullPointerException("'connectionString' or 'instrumentationKey' " + - "must be set.")); + throw logger.logExceptionAsError(new NullPointerException("'connectionString' or 'instrumentationKey' " + + "must be set.")); } return new AzureMonitorExporter(buildClient(), instrumentationKey, endpoint); } 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 index 4d44856696bbe..78e65768cc00c 100644 --- 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 @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + package com.azure.opentelemetry.exporter.azuremonitor; import com.azure.core.util.ServiceVersion; From b494608d5715789e87f94dce8a9979bc5d375146 Mon Sep 17 00:00:00 2001 From: Srikanta Date: Fri, 5 Feb 2021 01:38:24 -0800 Subject: [PATCH 4/5] Remove endpoint and instrumentation key --- .../azuremonitor/AzureMonitorExporter.java | 12 +----------- .../AzureMonitorExporterBuilder.java | 18 +++--------------- 2 files changed, 4 insertions(+), 26 deletions(-) diff --git a/sdk/monitor/azure-opentelemetry-exporter-azuremonitor/src/main/java/com/azure/opentelemetry/exporter/azuremonitor/AzureMonitorExporter.java b/sdk/monitor/azure-opentelemetry-exporter-azuremonitor/src/main/java/com/azure/opentelemetry/exporter/azuremonitor/AzureMonitorExporter.java index 9a138bb1496b7..c16463a32dae8 100644 --- a/sdk/monitor/azure-opentelemetry-exporter-azuremonitor/src/main/java/com/azure/opentelemetry/exporter/azuremonitor/AzureMonitorExporter.java +++ b/sdk/monitor/azure-opentelemetry-exporter-azuremonitor/src/main/java/com/azure/opentelemetry/exporter/azuremonitor/AzureMonitorExporter.java @@ -75,7 +75,6 @@ public final class AzureMonitorExporter implements SpanExporter { private final ClientLogger logger = new ClientLogger(AzureMonitorExporter.class); private final String instrumentationKey; private final String telemetryItemNamePrefix; - private final String endpoint; /** * Creates an instance of exporter that is configured with given exporter client that sends telemetry events to @@ -84,22 +83,13 @@ public final class AzureMonitorExporter implements SpanExporter { * @param client The client used to send data to Azure Monitor. * @param instrumentationKey The instrumentation key of Application Insights resource. */ - AzureMonitorExporter(MonitorExporterClient client, String instrumentationKey, String endpoint) { + AzureMonitorExporter(MonitorExporterClient client, String instrumentationKey) { this.client = client; this.instrumentationKey = instrumentationKey; - this.endpoint = endpoint; String formattedInstrumentationKey = instrumentationKey.replaceAll("-", ""); this.telemetryItemNamePrefix = "Microsoft.ApplicationInsights." + formattedInstrumentationKey + "."; } - /** - * Returns the endpoint of the Application Insights resource. - * @return The endpoint of the Application Insights resource. - */ - public String getEndpoint() { - return endpoint; - } - /** * {@inheritDoc} */ 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 3fb0e3b2fb7a2..5dffc6c1fddab 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 @@ -161,17 +161,6 @@ public AzureMonitorExporterBuilder connectionString(String connectionString) { return this; } - /** - * Sets the instrumentation key of the Azure Monitor resource. - * @param instrumentationKey The instrumentation key of the Azure Monitor resource. - * @return The update {@link AzureMonitorExporterBuilder} object. - * @throws NullPointerException If the {@code instrumentationKey} is null. - */ - public AzureMonitorExporterBuilder instrumentationKey(String instrumentationKey) { - this.instrumentationKey = Objects.requireNonNull(instrumentationKey, "'instrumentationKey' cannot be null."); - return this; - } - /** * Sets the Azure Monitor service version. * @@ -243,11 +232,10 @@ MonitorExporterAsyncClient buildAsyncClient() { * @throws NullPointerException if the instrumentation key or endpoint is not set. */ public AzureMonitorExporter buildExporter() { - if (connectionString == null && instrumentationKey == null) { - throw logger.logExceptionAsError(new NullPointerException("'connectionString' or 'instrumentationKey' " - + "must be set.")); + if (connectionString == null) { + throw logger.logExceptionAsError(new NullPointerException("'connectionString' cannot be null.")); } - return new AzureMonitorExporter(buildClient(), instrumentationKey, endpoint); + return new AzureMonitorExporter(buildClient(), instrumentationKey); } } From d8cfb2bc5e58b087b508e61427a628daaf183f87 Mon Sep 17 00:00:00 2001 From: Srikanta <51379715+srnagar@users.noreply.github.com> Date: Fri, 5 Feb 2021 11:57:11 -0800 Subject: [PATCH 5/5] Update sdk/monitor/azure-opentelemetry-exporter-azuremonitor/src/main/java/com/azure/opentelemetry/exporter/azuremonitor/AzureMonitorExporterBuilder.java Co-authored-by: Trask Stalnaker --- .../exporter/azuremonitor/AzureMonitorExporterBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 5dffc6c1fddab..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 @@ -229,7 +229,7 @@ MonitorExporterAsyncClient buildAsyncClient() { * implementation of OpenTelemetry {@link SpanExporter}. * * @return An instance of {@link AzureMonitorExporter}. - * @throws NullPointerException if the instrumentation key or endpoint is not set. + * @throws NullPointerException if the connection string is not set. */ public AzureMonitorExporter buildExporter() { if (connectionString == null) {