azure-functions-java-opentelemetry:1.1.0 swallows function exceptions, causing Service Bus messages to be completed instead of retried

Aperta
#65 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
79/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
azure, java

Direzione di ricerca

Start by reading OpenTelemetryInvocationMiddleware.java and trace how invoke() handles telemetry setup failures versus exceptions from chain.doNext(context). Then inspect the middleware tests and add the suggested regression case with an iterator-backed chain, confirming the business exception reaches the caller. Done means downstream execution occurs once and its failure is not swallowed or replaced.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

area:java-functions

Summary
With com.microsoft.azure.functions:azure-functions-java-opentelemetry:1.1.0 enabled, a Java Azure Function triggered by a Service Bus topic subscription reports Succeeded even when the function throws an exception.
Consequently, the failed message is completed rather than retried and never reaches the subscription’s dead-letter queue.
Removing the dependency restores the expected behavior: failed invocations, retries, and eventual dead-lettering.
Environment
Java: 17
Azure Functions Java Gradle plugin: 1.17.0
Azure Functions extension bundle: [4.*, 5.0.0)
Spring Boot: 3.5.6
azure-functions-java-opentelemetry: 1.1.0
opentelemetry-api: 1.49.0
Trigger: Service Bus topic subscription
Observed during local execution on Windows using Azure Functions Core Tools
Application Insights Java agent enabled
Steps to reproduce
Configure a Java Azure Function with a Service Bus topic trigger.
Include azure-functions-java-opentelemetry:1.1.0 and configure the telemetry agent.
Make the function synchronously throw a RuntimeException during message processing.
Send a test message to the topic.
Observe the function execution result and subscription delivery behavior.
Remove the telemetry integration dependency, clean-build, repackage, restart, and repeat with a new test message.
Expected behavior
The exception should propagate to the Java worker:
The invocation should be reported as Failed.
The message should be redelivered according to Service Bus delivery semantics.
Repeated processing failures should eventually move it to the subscription DLQ after exceeding MaxDeliveryCount.
Telemetry instrumentation should not change the function’s success/failure outcome.
Actual behavior
With the dependency enabled, the application logs a processing failure and rethrows the exception, but the host reports:
Executed 'Functions.ForgetUser'
(Succeeded, Id=822181d0-a0e0-40ee-aa1e-f8cba1408ed5, Duration=917ms)
No subsequent delivery was observed for that message, and it did not appear in the DLQ.
After removing the telemetry dependencies and rebuilding, retries and eventual dead-lettering worked.
Suspected root cause
In OpenTelemetryInvocationMiddleware.invoke():
chain.doNext(context) executes the function.
An inner catch (Throwable) records the exception, marks the span as failed, and rethrows it.
The outer catch (Exception spanCreationException) also catches this business-processing exception.
Instead of propagating it, the outer catch calls chain.doNext(context) again.
The Java worker’s InvocationChain uses an iterator. Once the downstream middleware has been consumed, the second doNext() call returns without invoking anything or rethrowing the original exception.
The middleware therefore returns normally, causing the invocation to be reported as successful.
Source: OpenTelemetryInvocationMiddleware.java
Impact
This can cause failed business processing to be silently acknowledged. Service Bus retries and dead-letter handling are bypassed, potentially leaving work permanently unprocessed unless messages can be replayed independently.
Suggested fix
Separate telemetry initialization failure handling from downstream function execution:
Invoke the downstream chain exactly once.
Always propagate exceptions from downstream execution.
Ensure failures while recording exceptions or closing spans do not suppress or replace the original processing exception.
Add a regression test using an iterator-backed middleware chain that verifies a thrown business exception reaches the caller.
Request
Could the maintainers confirm this defect and advise whether a patch release or supported workaround is planned?

Lingua principale
Java
Stelle
4
Fork
22
Merge medio
1g 19h
PR unite (30g)
1

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Azure/azure-functions-java-additions

Tutte le issue di Azure/azure-functions-java-additions

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.