Skip to content

Commit a837b9d

Browse files
committed
Merge remote-tracking branch 'nullcubed/patch-1' into fixup
2 parents 9adcacd + 4fef2df commit a837b9d

File tree

2 files changed

+89
-108
lines changed

2 files changed

+89
-108
lines changed

articles/azure-functions/TOC.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,7 @@
620620
displayName: monitoring
621621
- name: Work with OpenTelemetry
622622
href: opentelemetry-howto.md
623+
displayName: OTel
623624
- name: Authenticate
624625
items:
625626
- name: Configure auth providers

articles/azure-functions/opentelemetry-howto.md

Lines changed: 88 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,33 @@ This article shows you how to configure your function app to export log and trac
1818

1919
> [!TIP]
2020
> Because this article is targeted at your development language of choice, remember to choose the correct language at the top of the article.
21-
::: zone pivot="programming-language-java"
22-
> Currently, there's no client optimized OpenTelemetry support for Java apps.
23-
:::zone-end
2421
::: zone pivot="programming-language-csharp"
25-
> OpenTelemetry currently isn't supported for C# in-process apps.
22+
> OpenTelemetry currently isn't supported for [C# in-process apps](./functions-dotnet-class-library.md).
2623
:::zone-end
2724

2825
You can obtain these benefits by enabling OpenTelemetry in your function app:
2926

30-
+ Correlation across traces and logs being generated both at the host and in your application code.
31-
+ Consistent, standards-based generation of exportable telemetry data.
27+
+ Correlates data across traces and logs being generated both at the host and in your application code.
28+
+ Enables consistent, standards-based generation of exportable telemetry data.
3229
+ Integrates with other providers that can consume OpenTelemetry-compliant data.
3330

3431
OpenTelemetry is enabled at the function app level, both in host configuration (`host.json`) and in your code project. Functions also provides a client optimized experience for exporting OpenTelemetry data from your function code that's running in a language-specific worker process.
3532

36-
## 1. Enable OpenTelemetry in the Functions host
33+
## Enable OpenTelemetry in the Functions host
3734

3835
When you enable OpenTelemetry output in the function app's host.json file, your host exports OpenTelemetry output regardless of the language stack used by your app.
3936

40-
To enable OpenTelemetry output from the Functions host, update the [host.json file](./functions-host-json.md) in your code project to add a `"telemetryMode": "openTelemetry"` element to the root collection. With OpenTelemetry enabled, your host.json file might look like this:
37+
To enable OpenTelemetry output from the Functions host, update the [host.json file](./functions-host-json.md) in your code project to add a `"telemetryMode": "OpenTelemetry"` element to the root collection. With OpenTelemetry enabled, your host.json file might look like this:
4138

4239
```json
4340
{
4441
"version": "2.0",
45-
"telemetryMode": "openTelemetry"
42+
"telemetryMode": "OpenTelemetry",
43+
...
4644
}
4745
```
4846

49-
## 2. Configure application settings
47+
## Configure application settings
5048

5149
When OpenTelemetry is enabled in the host.json file, the endpoints to which data is sent is determined based on which OpenTelemetry-supported application settings are available in your app's environment variables.
5250

@@ -60,15 +58,22 @@ Create specific application settings in your function app based on the OpenTelem
6058

6159
**`OTEL_EXPORTER_OTLP_ENDPOINT`**: an OTLP exporter endpoint URL.
6260

63-
**`OTEL_EXPORTER_OTLP_HEADERS`**: (Optional) list of headers to apply to all outgoing data. This is used by many endpoints to pass an API key.
61+
**`OTEL_EXPORTER_OTLP_HEADERS`**: (Optional) list of headers to apply to all outgoing data. This setting is used by many endpoints to pass an API key.
6462

6563
If your endpoint requires you to set other environment variables, you need to also add them to your application settings. For more information, see the [OTLP Exporter Configuration documentation](https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/).
6664

6765
You should remove the `APPLICATIONINSIGHTS_CONNECTION_STRING` setting, unless you also want OpenTelemetry output from the host sent to Application Insights.
6866

6967
---
7068

71-
## 3. Enable OpenTelemetry in your app
69+
::: zone pivot="programming-language-java"
70+
You must also add `JAVA_APPLICATIONINSIGHTS_ENABLE_TELEMETRY=true` to your application settings. Setting this flag tells the Functions host to let the Java worker process stream OpenTelemetry logs directly, which prevents duplicate host-level entries.
71+
72+
> [!NOTE]
73+
> When both Application Insights and OTLP exporter settings are present, telemetry flows to both backends.
74+
::: zone-end
75+
76+
## Enable OpenTelemetry in your app
7277

7378
With the Functions host configured to use OpenTelemetry, you should also update your application code to output OpenTelemetry data. Enabling OpenTelemetry in both the host and your application code enables better correlation between traces and logs emitted both by the Functions host process and from your language worker process.
7479

@@ -128,107 +133,70 @@ The way that you instrument your application to use OpenTelemetry depends on you
128133
To export to both OpenTelemetry endpoints, call both `UseAzureMonitor` and `UseOtlpExporter`.
129134
::: zone-end
130135
::: zone pivot="programming-language-java"
136+
1. Add the required libraries to your app. The way you add libraries depends on whether you deploy using Maven or Kotlin and if you want to also send data to Application Insights.
137+
138+
### [Maven](#tab/maven/app-insights)
139+
140+
```xml
141+
<dependency>
142+
<groupId>com.microsoft.azure.functions</groupId>
143+
<artifactId>azure-functions-java-opentelemetry</artifactId>
144+
<version>1.0.0</version>
145+
</dependency>
146+
<dependency>
147+
<groupId>com.azure</groupId>
148+
<artifactId>azure-monitor-opentelemetry-autoconfigure</artifactId>
149+
<version>1.2.0</version>
150+
</dependency>
151+
```
131152
132-
### Step 1 – Add the required libraries
133-
134-
**Core bridge** (always) – enables OpenTelemetry inside the Java worker
135-
136-
**Maven**
137-
```xml
138-
<dependency>
139-
<groupId>com.microsoft.azure.functions</groupId>
140-
<artifactId>azure-functions-java-opentelemetry</artifactId>
141-
<version>1.0.0</version>
142-
</dependency>
143-
```
144-
145-
**Gradle (Kotlin DSL)**
146-
```kotlin
147-
implementation("com.microsoft.azure.functions:azure-functions-java-opentelemetry:1.0.0")
148-
```
149-
150-
**Application Insights exporter** (optional) – add only if you plan to send data to AI
151-
152-
**Maven**
153-
```xml
154-
<dependency>
155-
<groupId>com.azure</groupId>
156-
<artifactId>azure-monitor-opentelemetry-autoconfigure</artifactId>
157-
<version>1.2.0</version>
158-
</dependency>
159-
```
160-
161-
**Gradle (Kotlin DSL)**
162-
```kotlin
163-
implementation("com.azure:azure-monitor-opentelemetry-autoconfigure:1.2.0")
164-
```
165-
166-
> The bridge looks for `AzureMonitorAutoConfigure` by reflection; if this dependency isn’t present, it simply skips the AI exporter.
167-
168-
---
169-
170-
### Step 2 – Add application settings
171-
172-
Set this flag **in every Java Functions app that uses the bridge**, even if you export only to OTLP:
173-
174-
```text
175-
JAVA_APPLICATIONINSIGHTS_ENABLE_TELEMETRY=true
176-
```
177-
178-
This capability tells the Functions host to let the Java worker stream OpenTelemetry logs directly, preventing duplicate host-level entries.
179-
180-
Additional settings:
181-
182-
* **Application Insights**
183-
`APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=...;IngestionEndpoint=https://...`
184-
185-
* **OTLP export**
186-
`OTEL_EXPORTER_OTLP_ENDPOINT=https://otlp.example.com:4318`
187-
`OTEL_EXPORTER_OTLP_HEADERS=api-key=abcd1234` (optional)
188-
189-
If both AI *and* OTLP variables are present, telemetry flows to **both** back-ends.
190-
191-
---
192-
193-
### Step 3 – (Optional) create custom spans
194-
195-
```java
196-
import com.microsoft.azure.functions.opentelemetry.FunctionsOpenTelemetry;
197-
import io.opentelemetry.api.trace.Span;
198-
import io.opentelemetry.api.trace.SpanKind;
199-
import io.opentelemetry.context.Scope;
153+
### [Kotlin](#tab/kotlin/app-insights)
200154
201-
Span span = FunctionsOpenTelemetry.startSpan(
202-
"com.contoso.PaymentFunction", // tracer name
203-
"validateCharge", // span name
204-
null, // parent = current context
205-
SpanKind.INTERNAL);
155+
```kotlin
156+
implementation("com.microsoft.azure.functions:azure-functions-java-opentelemetry:1.0.0")
157+
implementation("com.azure:azure-monitor-opentelemetry-autoconfigure:1.2.0")
158+
```
206159
207-
try (Scope ignored = span.makeCurrent()) {
208-
// business logic here
209-
} finally {
210-
span.end();
211-
}
212-
```
160+
### [Maven](#tab/maven/otlp-export)
213161
214-
Custom spans inherit all resource attributes and exporters configured by the bridge.
162+
```xml
163+
<dependency>
164+
<groupId>com.microsoft.azure.functions</groupId>
165+
<artifactId>azure-functions-java-opentelemetry</artifactId>
166+
<version>1.0.0</version>
167+
</dependency>
168+
```
215169
216-
---
170+
### [Kotlin](#tab/maven/otlp-export)
217171
218-
### Step 4 – Local development and testing tips
172+
```kotlin
173+
implementation("com.microsoft.azure.functions:azure-functions-java-opentelemetry:1.0.0")
174+
```
219175
220-
* Outside Azure, the resource detector defaults `service.name` to `java-function-app`.
221-
* **Java Virtual Machine (JVM)** flags to silence telemetry during unit tests:
176+
---
222177
223-
```text
224-
-Dotel.traces.exporter=none
225-
-Dotel.metrics.exporter=none
226-
-Dotel.logs.exporter=none
227-
```
228-
* You don’t need to register anything manually—the Java worker **autodiscovers** `OpenTelemetryInvocationMiddleware`.
178+
2. You can optionally add this code to create custom spans:
229179
230-
::: zone-end
180+
```java
181+
import com.microsoft.azure.functions.opentelemetry.FunctionsOpenTelemetry;
182+
import io.opentelemetry.api.trace.Span;
183+
import io.opentelemetry.api.trace.SpanKind;
184+
import io.opentelemetry.context.Scope;
185+
186+
Span span = FunctionsOpenTelemetry.startSpan(
187+
"com.contoso.PaymentFunction", // tracer name
188+
"validateCharge", // span name
189+
null, // parent = current context
190+
SpanKind.INTERNAL);
191+
192+
try (Scope ignored = span.makeCurrent()) {
193+
// business logic here
194+
} finally {
195+
span.end();
196+
}
197+
```
231198
199+
::: zone-end
232200
::: zone pivot="programming-language-javascript,programming-language-typescript"
233201
1. Install these npm packages in your project:
234202
@@ -328,7 +296,7 @@ These instructions only apply for an OTLP exporter:
328296
```
329297
---
330298
331-
1. Make sure the below library is in your `requirements.txt` file, whether from uncommenting or adding yourself:
299+
1. Make sure these libraries are in your `requirements.txt` file, whether from uncommenting or adding yourself:
332300
333301
### [Application Insights](#tab/app-insights)
334302
@@ -349,7 +317,7 @@ These instructions only apply for an OTLP exporter:
349317
350318
### [Application Insights](#tab/app-insights)
351319
352-
If you followed the above steps by setting the `PYTHON_APPLICATIONINSIGHTS_ENABLE_TELEMETRY`, you don't need to add any additional code and skip the below.
320+
If you followed the above steps by setting the `PYTHON_APPLICATIONINSIGHTS_ENABLE_TELEMETRY`, you don't need to add any other code and skip the below.
353321
354322
If you would like to enable Application Insights collection manually without automatic instrumentation, add the following code:
355323
@@ -390,22 +358,34 @@ These instructions only apply for an OTLP exporter:
390358
391359
---
392360
393-
1. Refer to [Azure monitor Distro usage]https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/monitor/azure-monitor-opentelemetry#usage) documentation for how to configure the SDK.
361+
1. Refer to [Azure monitor Distro usage](https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/monitor/azure-monitor-opentelemetry#usage) documentation for how to configure the SDK.
394362
395363
::: zone-end
396364
## Considerations for OpenTelemetry
397365
398366
When you export your data using OpenTelemetry, keep these current considerations in mind.
399367
400-
+ At this time, only HTTP, Service Bus and Event Hub triggers are supported with OpenTelemetry outputs.
368+
+ At this time, only HTTP, Service Bus and Event Hubs triggers are supported with OpenTelemetry outputs.
401369
402370
+ When the host is configured to use OpenTelemetry, the Azure portal doesn't support log streaming or recent function invocation traces.
371+
::: zone pivot="programming-language-java"
372+
+ Custom spans automatically include all resource attributes and use the exporters configured in your app.
373+
374+
+ When your app runs outside Azure, including during local development, the resource detector sets the `service.name` attribute to `java-function-app` by default.
403375
376+
+ Use these Java Virtual Machine (JVM) flags to silence telemetry when running locally during unit tests:
377+
378+
+ `-Dotel.traces.exporter=none`
379+
+ `-Dotel.metrics.exporter=none`
380+
+ `-Dotel.logs.exporter=none`
381+
382+
* You aren't required to manually register middleware; the Java worker autodiscovers `OpenTelemetryInvocationMiddleware`.
383+
::: zone-end
404384
+ [Azure Functions diagnostics](functions-diagnostics.md) in the Azure portal is a useful resource for detecting and diagnosing potential monitoring-related issues.
405385
406386
To access diagnostics in your app:
407387
408-
1. In the [Azure portal](https://portal.azure.com) navigate to your function app resource.
388+
1. In the [Azure portal](https://portal.azure.com), navigate to your function app resource.
409389
410390
1. In the left pane, select **Diagnose and solve problems** and search for the *Function App missing telemetry Application Insights or OpenTelemetry* workflow.
411391

0 commit comments

Comments
 (0)