diff --git a/docs/develop/go/workers/index.mdx b/docs/develop/go/workers/index.mdx index 62121ded3f..7bf109130a 100644 --- a/docs/develop/go/workers/index.mdx +++ b/docs/develop/go/workers/index.mdx @@ -23,4 +23,5 @@ import * as Components from '@site/src/components'; - [Run a Worker](/develop/go/workers/run-worker-process) - [Sessions](/develop/go/workers/sessions) +- [Interceptors](/develop/go/workers/interceptors) - [Serverless Workers](/develop/go/workers/serverless-workers) diff --git a/docs/develop/go/workers/interceptors.mdx b/docs/develop/go/workers/interceptors.mdx new file mode 100644 index 0000000000..3eee1f26e0 --- /dev/null +++ b/docs/develop/go/workers/interceptors.mdx @@ -0,0 +1,34 @@ +--- +id: interceptors +title: Interceptors - Go SDK +sidebar_label: Interceptors +description: + Implement Interceptors in the Temporal Go SDK to manage inbound and outbound SDK calls, enhance tracing, and add + authorization to your Workflows and Activities. +toc_max_heading_level: 3 +tags: + - Interceptors + - Go SDK + - Temporal SDKs +--- + +Interceptors wrap inbound and outbound Temporal calls so you can apply shared behavior such as tracing, logging, or +authorization. See [Interceptors](/encyclopedia/interceptors) for the inbound vs outbound model. + +Register them on the Client (`client.Options.Interceptors`), the Worker (`worker.Options.Interceptors`), or both. Embed +`ClientInterceptorBase` / `WorkerInterceptorBase` and override only the methods you need. Full API: +[`go.temporal.io/sdk/interceptor`](https://pkg.go.dev/go.temporal.io/sdk/interceptor). + +:::warning Workflow interceptors and replay + +Workflow interceptor methods also run during [replay](/develop/go/best-practices/testing-suite#replay). Use replay-safe +APIs for logging, randomness, and time. + +::: + +## Related + +- [Observability - Tracing](/develop/go/platform/observability#tracing) +- [Context Propagation](/develop/go/best-practices/context-propagation) +- [Logging Interceptor sample](https://github.com/temporalio/samples-go/tree/main/logger-interceptor) +- [Plugins - Interceptors](/develop/plugins-guide#interceptors) diff --git a/docs/develop/java/best-practices/error-handling.mdx b/docs/develop/java/best-practices/error-handling.mdx index 19e95a7284..9dfc8fab97 100644 --- a/docs/develop/java/best-practices/error-handling.mdx +++ b/docs/develop/java/best-practices/error-handling.mdx @@ -262,7 +262,7 @@ Because the interceptor sees the original exception before the SDK's default con attach `details` and a non-retryable classification consistently, rather than depending on every Activity implementation to do it the same way. `WorkerInterceptor` and `ActivityInboundCallsInterceptor` are marked `@Experimental`. For the general interceptor model — inbound versus outbound, and the other call categories you can -intercept — see [Interceptors](/develop/plugins-guide#interceptors). +intercept — see [Interceptors](/develop/java/workers/interceptors). ## Fail a Workflow deliberately {/* #fail-a-workflow */} diff --git a/docs/develop/java/workers/index.mdx b/docs/develop/java/workers/index.mdx index 57b54e17b4..54bac1792c 100644 --- a/docs/develop/java/workers/index.mdx +++ b/docs/develop/java/workers/index.mdx @@ -22,3 +22,5 @@ import * as Components from '@site/src/components'; ## Workers - [Run Worker processes](/develop/java/workers/run-worker-process) +- [Interceptors](/develop/java/workers/interceptors) +- [Serverless Workers](/develop/java/workers/serverless-workers) diff --git a/docs/develop/java/workers/interceptors.mdx b/docs/develop/java/workers/interceptors.mdx new file mode 100644 index 0000000000..3b4b8feaca --- /dev/null +++ b/docs/develop/java/workers/interceptors.mdx @@ -0,0 +1,37 @@ +--- +id: interceptors +title: Interceptors - Java SDK +sidebar_label: Interceptors +description: + Implement Interceptors in the Temporal Java SDK to manage inbound and outbound SDK calls, enhance tracing, and add + authorization to your Workflows and Activities. +toc_max_heading_level: 3 +tags: + - Interceptors + - Java SDK + - Temporal SDKs +--- + +Interceptors wrap inbound and outbound Temporal calls so you can apply shared behavior such as tracing, logging, or +authorization. See [Interceptors](/encyclopedia/interceptors) for the inbound vs outbound model. + +Register them on the Client (`WorkflowClientOptions.setInterceptors`) or the Worker Factory +(`WorkerFactoryOptions.setWorkerInterceptors`). Extend `WorkflowClientInterceptorBase` / `WorkerInterceptorBase` and +override only the methods you need. Full API: +[`io.temporal.common.interceptors`](https://www.javadoc.io/doc/io.temporal/temporal-sdk/latest/io/temporal/common/interceptors/package-summary.html). + +Several interceptor APIs are marked `@Experimental`. + +:::warning Workflow interceptors and replay + +Workflow interceptor methods also run during [replay](/develop/java/best-practices/testing-suite#replay). Use replay-safe +APIs for logging, randomness, and time. + +::: + +## Related + +- [Observability - Tracing](/develop/java/platform/observability#tracing) +- [Error handling - Worker Interceptor](/develop/java/best-practices/error-handling#centralize-with-interceptor) +- [Spring Boot - Interceptors](/develop/java/integrations/spring-boot-integration#interceptors) +- [Plugins - Interceptors](/develop/plugins-guide#interceptors) diff --git a/docs/develop/plugins-guide.mdx b/docs/develop/plugins-guide.mdx index 1307143386..55d3f23d51 100644 --- a/docs/develop/plugins-guide.mdx +++ b/docs/develop/plugins-guide.mdx @@ -646,7 +646,7 @@ Note that you can use an existing Data Converter such as, in Python, `PydanticPa ### Interceptors -Interceptors are middleware that can run before and after various calls such as Activities, Workflows, and Signals. You can [learn more about interceptors](/develop/python/workers/interceptors) for the details of implementing them. They're used to: +Interceptors are middleware that can run before and after various calls such as Activities, Workflows, and Signals. You can [learn more about interceptors](/encyclopedia/interceptors) for the details of implementing them. They're used to: - Create side effects such as logging and tracing. - Modify arguments, such as adding headers for authorization or tracing propagation. diff --git a/docs/encyclopedia/interceptors.mdx b/docs/encyclopedia/interceptors.mdx index 958c3f545f..808d1858c5 100644 --- a/docs/encyclopedia/interceptors.mdx +++ b/docs/encyclopedia/interceptors.mdx @@ -26,6 +26,8 @@ Common use cases: Here are SDK-specific guides: +- [Go](/develop/go/workers/interceptors) +- [Java](/develop/java/workers/interceptors) - [Python](/develop/python/workers/interceptors) - [TypeScript](/develop/typescript/workers/interceptors) - [.NET](/develop/dotnet/workers/interceptors) diff --git a/sidebars.js b/sidebars.js index 8f319350bf..5c65410774 100644 --- a/sidebars.js +++ b/sidebars.js @@ -205,6 +205,7 @@ const developGoCategory = { items: [ 'develop/go/workers/run-worker-process', 'develop/go/workers/sessions', + 'develop/go/workers/interceptors', { type: 'category', label: 'Serverless Workers', @@ -356,6 +357,7 @@ const developJavaCategory = { }, items: [ 'develop/java/workers/run-worker-process', + 'develop/java/workers/interceptors', { type: 'category', label: 'Serverless Workers',