Enable Custom Exception Provider with Durable Functions Java#294
Enable Custom Exception Provider with Durable Functions Java#294nytian wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds Azure Functions activity middleware that enables opt-in structured exception properties (via ExceptionPropertiesProvider) to be surfaced as a TaskFailureDetails-shaped JSON payload when an activity fails, aligning behavior with Durable Task failure details handling.
Changes:
- Introduces
ActivityMiddlewareto reshape activity failures intoTaskFailureDetailsJSON when a provider returns custom properties, with SPI-based provider discovery across class loaders. - Registers the new middleware via
META-INF/servicesand adds unit tests (including cross-class-loader SPI discovery regression coverage). - Updates protobuf source tracking and fixes a minor syntax typo in the proto file.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/durabletask-protobuf/protos/orchestrator_service.proto | Fixes a proto syntax typo (extra semicolon) in a deprecated field. |
| internal/durabletask-protobuf/PROTO_SOURCE_COMMIT_HASH | Updates the recorded upstream protobuf source commit hash. |
| azurefunctions/src/main/java/com/microsoft/durabletask/azurefunctions/internal/middleware/ActivityMiddleware.java | Adds new activity middleware to reshape failures into TaskFailureDetails JSON and discover providers via SPI. |
| azurefunctions/src/main/resources/META-INF/services/com.microsoft.azure.functions.internal.spi.middleware.Middleware | Registers ActivityMiddleware for Azure Functions SPI middleware discovery. |
| azurefunctions/src/test/java/com/microsoft/durabletask/azurefunctions/internal/middleware/ActivityMiddlewareTest.java | Adds unit coverage for reshaping behavior and SPI discovery across class loaders. |
| azurefunctions/src/test/java/com/microsoft/durabletask/azurefunctions/internal/middleware/TestExceptionPropertiesProvider.java | Adds a test-only provider for verifying SPI discovery behavior. |
| azurefunctions/build.gradle | Adds azure-functions-java-spi as a test dependency so middleware tests compile. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public class ActivityMiddleware implements Middleware { | ||
|
|
||
| private static final String ACTIVITY_TRIGGER = "DurableActivityTrigger"; | ||
| private static final int MAX_INNER_FAILURE_DEPTH = 10; |
There was a problem hiding this comment.
Does this match the depth configured in the other SDKs?
There was a problem hiding this comment.
I remember .NET has a similar configuration,but the max depth value may be different. And for dotnet, it applies more broadly to all TaskFailedException scenarios, not just activity functions. Since this change only affects activity functions, I think a limit of 10 should be sufficient. It just helps ensure we don't end up recursing indefinitely.
|
|
||
| Throwable userException = unwrap(e); | ||
| Map<String, Object> properties = safeGetProperties(provider, userException); | ||
| if (properties == null || properties.isEmpty()) { |
There was a problem hiding this comment.
Should we also check inner exceptions for custom properties when the outer exception has none?
There was a problem hiding this comment.
yeah Imissed that. We do support inner failures for at dotnet and js, let me update this part..
Today when a Java activity fails, only the exception type and message reach the Durable extension. The TaskFailureDetails from the worker cannot carry user context like error codes or correlation IDs, so that data is dropped at the worker to host boundary. Users have no supported way to surface it in their error handling.
This PR adds an
ActivityMiddlewarethat fixes this. When an activity throws, it runs a registered ExceptionPropertiesProvider and serializes the exception into structured TaskFailureDetails JSON, including error type, message, stack trace, nested causes, and custom properties. It runs worker side while the live Exception still exists, which is the only place this data is available before serialization.Nested causes are emitted as innerFailure, bounded by MAX_INNER_FAILURE_DEPTH (10). Provider discovery uses cross class loader SPI lookup so it works from worker threads. When no provider is registered, the original exception is rethrown unchanged, so the change is additive. Also registers the middleware via SPI and adds the
propertiesfield to TaskFailureDetails. Adds ActivityMiddlewareTest, and the e2e test at durable extension repo accordingy