@@ -128,8 +128,106 @@ The way that you instrument your application to use OpenTelemetry depends on you
128
128
To export to both OpenTelemetry endpoints, call both `UseAzureMonitor` and `UseOtlpExporter`.
129
129
::: zone-end
130
130
::: zone pivot="programming-language-java"
131
- Java worker optimizations aren't yet available for OpenTelemetry, so there's nothing to configure in your Java code.
132
- ::: zone-end
131
+
132
+ ### 1 Add the required libraries
133
+
134
+ 1. **Core bridge (always)** – enables OpenTelemetry inside the Java worker
135
+
136
+ **Maven**
137
+
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
+ ```
145
+
146
+ ** Gradle (Kotlin DSL)**
147
+
148
+ ``` kotlin
149
+ implementation(" com.microsoft.azure.functions:azure-functions-java-opentelemetry:1.0.0" )
150
+ ```
151
+
152
+ 2 . ** Application Insights exporter (optional)** – only if you want to send data to AI
153
+
154
+ ** Maven**
155
+
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
+ ```
163
+
164
+ ** Gradle (Kotlin DSL)**
165
+
166
+ ``` kotlin
167
+ implementation(" com.azure:azure-monitor-opentelemetry-autoconfigure:1.2.0" )
168
+ ```
169
+
170
+ > The bridge locates ` AzureMonitorAutoConfigure ` by reflection; if this dependency is absent, it just skips the AI exporter.
171
+
172
+ ---
173
+
174
+ ### 2 Add application settings
175
+
176
+ ``` text
177
+ JAVA_APPLICATIONINSIGHTS_ENABLE_TELEMETRY=true
178
+ ```
179
+
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.**
181
+
182
+ Other settings:
183
+
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 ` |
189
+
190
+ If both AI * and* OTLP variables are present, telemetry is sent to ** both** back-ends.
191
+
192
+ ---
193
+
194
+ ### 3 (Optional) create custom spans
195
+
196
+ ``` java
197
+ import com.microsoft.azure.functions.opentelemetry.FunctionsOpenTelemetry ;
198
+ import io.opentelemetry.api.trace.Span ;
199
+ import io.opentelemetry.api.trace.SpanKind ;
200
+ import io.opentelemetry.context.Scope ;
201
+
202
+ Span span = FunctionsOpenTelemetry . startSpan(
203
+ " com.contoso.PaymentFunction" , // tracer
204
+ " validateCharge" , // span
205
+ null , // parent = current context
206
+ SpanKind . INTERNAL );
207
+
208
+ try (Scope ignored = span. makeCurrent()) {
209
+ // your business logic here
210
+ } finally {
211
+ span. end();
212
+ }
213
+ ```
214
+
215
+ Custom spans inherit the same resource attributes and exporters configured by the bridge.
216
+
217
+ ---
218
+
219
+ ### 4 Local development & testing tips
220
+
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:
223
+
224
+ ``` text
225
+ -Dotel.traces.exporter=none
226
+ -Dotel.metrics.exporter=none
227
+ -Dotel.logs.exporter=none
228
+ ```
229
+ * No manual registration is required—` OpenTelemetryInvocationMiddleware ` is auto-discovered by the Java worker.
230
+ ::: zone-end
133
231
::: zone pivot="programming-language-javascript,programming-language-typescript"
134
232
1 . Install these npm packages in your project:
135
233
0 commit comments