Skip to content

Commit 5eb96fe

Browse files
authored
Sync back from azure sdk repo (#2793)
1 parent d4136a8 commit 5eb96fe

File tree

4 files changed

+71
-81
lines changed

4 files changed

+71
-81
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,14 @@ public LogRecordExporter buildLogRecordExporter() {
256256
}
257257

258258
private TelemetryItemExporter initExporterBuilder() {
259-
String connectionStringOverride = configuration.get(APPLICATIONINSIGHTS_CONNECTION_STRING);
260-
if (connectionStringOverride != null) {
261-
// APPLICATIONINSIGHTS_CONNECTION_STRING environment variable should take precedence over
262-
// programmatically calling connectionString()
263-
connectionString = ConnectionString.parse(connectionStringOverride);
259+
if (connectionString == null) {
260+
// if connection string is not set, try loading from configuration
261+
Configuration configuration = Configuration.getGlobalConfiguration();
262+
connectionString(configuration.get(APPLICATIONINSIGHTS_CONNECTION_STRING));
264263
}
265264

265+
Objects.requireNonNull(connectionString, "'connectionString' cannot be null");
266+
266267
if (this.credential != null) {
267268
// Add authentication policy to HttpPipeline
268269
BearerTokenAuthenticationPolicy authenticationPolicy =

agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/README.md

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ For more information, please read [introduction to Application Insights][applica
2323
<dependency>
2424
<groupId>com.azure</groupId>
2525
<artifactId>azure-monitor-opentelemetry-exporter</artifactId>
26-
<version>1.0.0-beta.5</version>
26+
<version>1.0.0-beta.6</version>
2727
</dependency>
2828
```
2929
[//]: # ({x-version-update-end})
@@ -39,21 +39,21 @@ right corner.
3939

4040
### Creating exporter for Azure Monitor
4141
```java readme-sample-createExporter
42-
AzureMonitorTraceExporter azureMonitorTraceExporter = new AzureMonitorExporterBuilder()
42+
SpanExporter azureMonitorTraceExporter = new AzureMonitorExporterBuilder()
4343
.connectionString("{connection-string}")
4444
.buildTraceExporter();
4545
```
4646

4747
#### Exporting span data
4848

4949
The following example shows how to export a trace data to Azure Monitor through the
50-
`AzureMonitorExporter`
50+
`AzureMonitorTraceExporter`
5151

5252
##### Setup OpenTelemetry Tracer to work with Azure Monitor exporter
5353
```java readme-sample-setupExporter
5454
// Create Azure Monitor exporter and configure OpenTelemetry tracer to use this exporter
5555
// This should be done just once when application starts up
56-
AzureMonitorTraceExporter exporter = new AzureMonitorExporterBuilder()
56+
SpanExporter exporter = new AzureMonitorExporterBuilder()
5757
.connectionString("{connection-string}")
5858
.buildTraceExporter();
5959

@@ -87,24 +87,6 @@ try {
8787
}
8888
```
8989

90-
### Setup OpenTelemetry Tracer to generate spans with better operation names
91-
92-
93-
```
94-
AzureMonitorTraceExporter exporter = new AzureMonitorExporterBuilder()
95-
.connectionString("{connection-string}")
96-
.buildTraceExporter();
97-
SdkTracerProvider tracerProvider = SdkTracerProvider.builder()
98-
.addSpanProcessor(new AiOperationNameSpanProcessor())
99-
.addSpanProcessor(SimpleSpanProcessor.create(exporter))
100-
.build();
101-
OpenTelemetrySdk openTelemetrySdk = OpenTelemetrySdk.builder()
102-
.setTracerProvider(tracerProvider)
103-
.buildAndRegisterGlobal();
104-
Tracer tracer = openTelemetrySdk.getTracer("Sample");
105-
106-
```
107-
10890
## Key concepts
10991

11092
Some key concepts for the Azure Monitor exporter include:
@@ -182,4 +164,8 @@ This project has adopted the [Microsoft Open Source Code of Conduct][coc]. For m
182164
[sampler_ref]: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/sdk.md#sampling
183165
[trace_concept]: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/overview.md#trace
184166
[samples_code]: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/monitor/azure-monitor-opentelemetry-exporter/src/samples
167+
[cla]: https://cla.microsoft.com
168+
[coc]: https://opensource.microsoft.com/codeofconduct/
169+
[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/
170+
[coc_contact]: mailto:[email protected]
185171
![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-java%2Fsdk%monitor%2Fazure-monitor-opentelemetry-exporter%2FREADME.png)

agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/configuration/StatsbeatConnectionString.java

Lines changed: 54 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
package com.azure.monitor.opentelemetry.exporter.implementation.configuration;
55

6+
import static java.util.Arrays.asList;
7+
68
import java.net.MalformedURLException;
79
import java.net.URL;
810
import java.util.HashSet;
@@ -26,57 +28,58 @@ public final class StatsbeatConnectionString {
2628

2729
private static final Pattern pattern = Pattern.compile("^https?://(?:www\\.)?([^/.-]+)");
2830

29-
private static final Set<String> EU_REGION_GEO_SET = new HashSet<>(12);
30-
private static final Set<String> NON_EU_REGION_GEO_SET = new HashSet<>(33);
31-
32-
static {
33-
EU_REGION_GEO_SET.add("westeurope");
34-
EU_REGION_GEO_SET.add("northeurope");
35-
EU_REGION_GEO_SET.add("francecentral");
36-
EU_REGION_GEO_SET.add("francesouth");
37-
EU_REGION_GEO_SET.add("germanywestcentral");
38-
EU_REGION_GEO_SET.add("norwayeast");
39-
EU_REGION_GEO_SET.add("norwaywest");
40-
EU_REGION_GEO_SET.add("swedencentral");
41-
EU_REGION_GEO_SET.add("switzerlandnorth");
42-
EU_REGION_GEO_SET.add("switzerlandwest");
43-
EU_REGION_GEO_SET.add("uksouth");
44-
EU_REGION_GEO_SET.add("ukwest");
45-
46-
NON_EU_REGION_GEO_SET.add("eastasia");
47-
NON_EU_REGION_GEO_SET.add("southeastasia");
48-
NON_EU_REGION_GEO_SET.add("chinaeast2");
49-
NON_EU_REGION_GEO_SET.add("chinaeast3");
50-
NON_EU_REGION_GEO_SET.add("chinanorth3");
51-
NON_EU_REGION_GEO_SET.add("centralindia");
52-
NON_EU_REGION_GEO_SET.add("southindia");
53-
NON_EU_REGION_GEO_SET.add("jioindiacentral");
54-
NON_EU_REGION_GEO_SET.add("jioindiawest");
55-
NON_EU_REGION_GEO_SET.add("japaneast");
56-
NON_EU_REGION_GEO_SET.add("japanwest");
57-
NON_EU_REGION_GEO_SET.add("koreacentral");
58-
NON_EU_REGION_GEO_SET.add("koreasouth");
59-
NON_EU_REGION_GEO_SET.add("australiacentral");
60-
NON_EU_REGION_GEO_SET.add("australiacentral2");
61-
NON_EU_REGION_GEO_SET.add("australiaeast");
62-
NON_EU_REGION_GEO_SET.add("australiasoutheast");
63-
NON_EU_REGION_GEO_SET.add("canadacentral");
64-
NON_EU_REGION_GEO_SET.add("canadaeast");
65-
NON_EU_REGION_GEO_SET.add("qatarcentral");
66-
NON_EU_REGION_GEO_SET.add("uaecentral");
67-
NON_EU_REGION_GEO_SET.add("uaenorth");
68-
NON_EU_REGION_GEO_SET.add("southafricanorth");
69-
NON_EU_REGION_GEO_SET.add("brazilsouth");
70-
NON_EU_REGION_GEO_SET.add("brazilsoutheast");
71-
NON_EU_REGION_GEO_SET.add("centralus");
72-
NON_EU_REGION_GEO_SET.add("eastus");
73-
NON_EU_REGION_GEO_SET.add("eastus2");
74-
NON_EU_REGION_GEO_SET.add("northcentralus");
75-
NON_EU_REGION_GEO_SET.add("southcentralus");
76-
NON_EU_REGION_GEO_SET.add("westus");
77-
NON_EU_REGION_GEO_SET.add("westus2");
78-
NON_EU_REGION_GEO_SET.add("westus3");
79-
}
31+
private static final Set<String> EU_REGION_GEO_SET =
32+
new HashSet<>(
33+
asList(
34+
"westeurope",
35+
"northeurope",
36+
"francecentral",
37+
"francesouth",
38+
"germanywestcentral",
39+
"norwayeast",
40+
"norwaywest",
41+
"swedencentral",
42+
"switzerlandnorth",
43+
"switzerlandwest",
44+
"uksouth",
45+
"ukwest"));
46+
47+
private static final Set<String> NON_EU_REGION_GEO_SET =
48+
new HashSet<>(
49+
asList(
50+
"eastasia",
51+
"southeastasia",
52+
"chinaeast2",
53+
"chinaeast3",
54+
"chinanorth3",
55+
"centralindia",
56+
"southindia",
57+
"jioindiacentral",
58+
"jioindiawest",
59+
"japaneast",
60+
"japanwest",
61+
"koreacentral",
62+
"koreasouth",
63+
"australiacentral",
64+
"australiacentral2",
65+
"australiaeast",
66+
"australiasoutheast",
67+
"canadacentral",
68+
"canadaeast",
69+
"qatarcentral",
70+
"uaecentral",
71+
"uaenorth",
72+
"southafricanorth",
73+
"brazilsouth",
74+
"brazilsoutheast",
75+
"centralus",
76+
"eastus",
77+
"eastus2",
78+
"northcentralus",
79+
"southcentralus",
80+
"westus",
81+
"westus2",
82+
"westus3"));
8083

8184
private final String ingestionEndpoint;
8285
private final String instrumentationKey;

agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/AzureMonitorExportersEndToEndTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@
4747

4848
public class AzureMonitorExportersEndToEndTest extends MonitorExporterClientTestBase {
4949

50-
private static final String TRACE_CONNECTION_STRING_OVERRIDE =
50+
private static final String CONNECTION_STRING_ENV =
5151
"InstrumentationKey=00000000-0000-0000-0000-0FEEDDADBEEF;"
5252
+ "IngestionEndpoint=https://test.in.applicationinsights.azure.com/;"
5353
+ "LiveEndpoint=https://test.livediagnostics.monitor.azure.com/";
54-
private static final String INSTRUMENTATION_KEY = "00000000-0000-0000-0000-0FEEDDADBEEF";
54+
private static final String INSTRUMENTATION_KEY = "00000000-0000-0000-0000-000000000000";
5555

5656
@Test
5757
public void testBuildTraceExporter() throws Exception {
@@ -167,7 +167,7 @@ private static Configuration getConfiguration() {
167167
new TestConfigurationSource(),
168168
new TestConfigurationSource(),
169169
new TestConfigurationSource()
170-
.put("APPLICATIONINSIGHTS_CONNECTION_STRING", TRACE_CONNECTION_STRING_OVERRIDE))
170+
.put("APPLICATIONINSIGHTS_CONNECTION_STRING", CONNECTION_STRING_ENV))
171171
.build();
172172
}
173173

0 commit comments

Comments
 (0)