Skip to content

Commit 5aae57c

Browse files
committed
fixes
1 parent 8747516 commit 5aae57c

File tree

1 file changed

+63
-46
lines changed

1 file changed

+63
-46
lines changed

articles/azure-functions/opentelemetry-howto.md

Lines changed: 63 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -129,69 +129,84 @@ The way that you instrument your application to use OpenTelemetry depends on you
129129
::: zone-end
130130
::: zone pivot="programming-language-java"
131131
132-
### 1 Add the required libraries
132+
### Step 1 – Add the required libraries
133133
134-
1. **Core bridge (always)** – enables OpenTelemetry inside the Java worker
134+
**Core bridge** (always) – enables OpenTelemetry inside the Java worker
135135
136-
**Maven**
136+
<details open>
137+
<summary>Maven</summary>
137138
138-
```xml
139-
<dependency>
140-
<groupId>com.microsoft.azure.functions</groupId>
141-
<artifactId>azure-functions-java-opentelemetry</artifactId>
142-
<version>1.0.0</version>
143-
</dependency>
144-
```
139+
```xml
140+
<dependency>
141+
<groupId>com.microsoft.azure.functions</groupId>
142+
<artifactId>azure-functions-java-opentelemetry</artifactId>
143+
<version>1.0.0</version>
144+
</dependency>
145+
```
146+
147+
</details>
148+
149+
<details>
150+
<summary>Gradle (Kotlin DSL)</summary>
151+
152+
```kotlin
153+
implementation("com.microsoft.azure.functions:azure-functions-java-opentelemetry:1.0.0")
154+
```
155+
156+
</details>
145157

146-
**Gradle (Kotlin DSL)**
158+
**Application Insights exporter** (optional) – add only if you plan to send data to AI
147159

148-
```kotlin
149-
implementation("com.microsoft.azure.functions:azure-functions-java-opentelemetry:1.0.0")
150-
```
160+
<details>
161+
<summary>Maven</summary>
151162

152-
2. **Application Insights exporter (optional)** – only if you want to send data to AI
163+
```xml
164+
<dependency>
165+
<groupId>com.azure</groupId>
166+
<artifactId>azure-monitor-opentelemetry-autoconfigure</artifactId>
167+
<version>1.2.0</version>
168+
</dependency>
169+
```
153170

154-
**Maven**
171+
</details>
155172

156-
```xml
157-
<dependency>
158-
<groupId>com.azure</groupId>
159-
<artifactId>azure-monitor-opentelemetry-autoconfigure</artifactId>
160-
<version>1.2.0</version>
161-
</dependency>
162-
```
173+
<details>
174+
<summary>Gradle (Kotlin DSL)</summary>
163175

164-
**Gradle (Kotlin DSL)**
176+
```kotlin
177+
implementation("com.azure:azure-monitor-opentelemetry-autoconfigure:1.2.0")
178+
```
165179

166-
```kotlin
167-
implementation("com.azure:azure-monitor-opentelemetry-autoconfigure:1.2.0")
168-
```
180+
</details>
169181

170-
> The bridge locates `AzureMonitorAutoConfigure` by reflection; if this dependency is absent, it just skips the AI exporter.
182+
> The bridge looks for `AzureMonitorAutoConfigure` by reflection; if this dependency isn’t present, it simply skips the AI exporter.
171183
172184
---
173185

174-
### 2 Add application settings
186+
### Step 2 – Add application settings
187+
188+
Set this flag **in every Java Functions app that uses the bridge**, even if you export only to OTLP:
175189

176190
```text
177191
JAVA_APPLICATIONINSIGHTS_ENABLE_TELEMETRY=true
178192
```
179193

180-
Setting this flag **enables a worker capability that tells the Functions host to stop forwarding its own logs and let the Java worker stream OpenTelemetry records instead, preventing duplicate log entries.**
194+
This capability tells the Functions host to let the Java worker stream OpenTelemetry logs directly, preventing duplicate host-level entries.
181195

182-
Other settings:
196+
Additional settings:
183197

184-
| Purpose | Name | Example |
185-
| ------------------------------- | --------------------------------------- | -------------------------------------------------- |
186-
| Application Insights connection | `APPLICATIONINSIGHTS_CONNECTION_STRING` | `InstrumentationKey=…;IngestionEndpoint=https://…` |
187-
| OTLP export | `OTEL_EXPORTER_OTLP_ENDPOINT` | `https://otlp.example.com:4318` |
188-
| | `OTEL_EXPORTER_OTLP_HEADERS` (optional) | `api-key=abcd1234` |
198+
* **Application Insights**
199+
`APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=...;IngestionEndpoint=https://...`
189200

190-
If both AI *and* OTLP variables are present, telemetry is sent to **both** back-ends.
201+
* **OTLP export**
202+
`OTEL_EXPORTER_OTLP_ENDPOINT=https://otlp.example.com:4318`
203+
`OTEL_EXPORTER_OTLP_HEADERS=api-key=abcd1234` (optional)
204+
205+
If both AI *and* OTLP variables are present, telemetry flows to **both** back-ends.
191206

192207
---
193208

194-
### 3 (Optional) create custom spans
209+
### Step 3 – (Optional) create custom spans
195210

196211
```java
197212
import com.microsoft.azure.functions.opentelemetry.FunctionsOpenTelemetry;
@@ -200,34 +215,36 @@ import io.opentelemetry.api.trace.SpanKind;
200215
import io.opentelemetry.context.Scope;
201216

202217
Span span = FunctionsOpenTelemetry.startSpan(
203-
"com.contoso.PaymentFunction", // tracer
204-
"validateCharge", // span
218+
"com.contoso.PaymentFunction", // tracer name
219+
"validateCharge", // span name
205220
null, // parent = current context
206221
SpanKind.INTERNAL);
207222

208223
try (Scope ignored = span.makeCurrent()) {
209-
// your business logic here
224+
// business logic here
210225
} finally {
211226
span.end();
212227
}
213228
```
214229

215-
Custom spans inherit the same resource attributes and exporters configured by the bridge.
230+
Custom spans inherit all resource attributes and exporters configured by the bridge.
216231

217232
---
218233

219-
### 4 Local development & testing tips
234+
### Step 4 – Local development and testing tips
220235

221-
* When not running in Azure, the resource detector defaults `service.name` to `java-function-app`.
222-
* Silence telemetry during unit tests with JVM flags:
236+
* Outside Azure, the resource detector defaults `service.name` to `java-function-app`.
237+
* **Java Virtual Machine (JVM)** flags to silence telemetry during unit tests:
223238

224239
```text
225240
-Dotel.traces.exporter=none
226241
-Dotel.metrics.exporter=none
227242
-Dotel.logs.exporter=none
228243
```
229-
* No manual registration is required—`OpenTelemetryInvocationMiddleware` is auto-discovered by the Java worker.
244+
* You don’t need to register anything manually—the Java worker **autodiscovers** `OpenTelemetryInvocationMiddleware`.
245+
230246
::: zone-end
247+
231248
::: zone pivot="programming-language-javascript,programming-language-typescript"
232249
1. Install these npm packages in your project:
233250

0 commit comments

Comments
 (0)