Enable Custom Exception Provider with Durable Functions Java#294
Open
nytian wants to merge 2 commits into
Open
Enable Custom Exception Provider with Durable Functions Java#294nytian wants to merge 2 commits into
nytian wants to merge 2 commits into
Conversation
Contributor
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.
Comment on lines
+128
to
+132
| } catch (Throwable t) { | ||
| // Discovery failures must not break activity execution; the feature is opt-in. | ||
| LOGGER.warning("Failed to load ExceptionPropertiesProvider via ServiceLoader using " | ||
| + classLoader + ": " + t); | ||
| } |
Comment on lines
+173
to
+177
| } catch (Exception providerException) { | ||
| // Don't let a misbehaving provider mask the original failure. | ||
| LOGGER.warning("ExceptionPropertiesProvider threw while extracting properties: " + providerException); | ||
| return null; | ||
| } |
Comment on lines
+70
to
+78
| Throwable userException = unwrap(e); | ||
| Map<String, Object> properties = safeGetProperties(provider, userException); | ||
| if (properties == null || properties.isEmpty()) { | ||
| // No custom properties for this failure - preserve the original behavior. | ||
| throw e; | ||
| } | ||
|
|
||
| throw new StructuredActivityFailure(buildFailureDetailsJson(userException, provider)); | ||
| } |
Comment on lines
+266
to
+277
| Path root = Files.createTempDirectory("amw-spi-"); | ||
| root.toFile().deleteOnExit(); | ||
| Path servicesDir = root.resolve("META-INF").resolve("services"); | ||
| Files.createDirectories(servicesDir); | ||
| Path serviceFile = servicesDir.resolve(ExceptionPropertiesProvider.class.getName()); | ||
| Files.write(serviceFile, | ||
| (TestExceptionPropertiesProvider.class.getName() + System.lineSeparator()) | ||
| .getBytes(StandardCharsets.UTF_8)); | ||
| serviceFile.toFile().deleteOnExit(); | ||
| servicesDir.toFile().deleteOnExit(); | ||
| root.resolve("META-INF").toFile().deleteOnExit(); | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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