Temporal interceptors and context propagation

Interceptors let you attach tracing, logging, auth headers and tenant context to every Temporal client call, workflow and activity without copying code into each one. This page covers what they do, how to design them safely and what to confirm before rollout.

On this page

Temporal interceptors and context propagation: when your team needs them

Interceptors are the mechanism Temporal provides for cross-cutting behavior on clients and workers, and context propagation is how values such as a request ID, trace context or tenant ID travel from a starting client through workflows and into activities. If your organization runs several workflows and workers that all need the same tracing, logging, auth header or tenant handling, copying that code into each workflow and activity is the error-prone path. One missed workflow leaves a gap in traces or a request without the tenant attribution your audit trail depends on. Your team needs this work when the same behavior must apply consistently across many workflow types, task queues and services, and when you want that behavior to stay out of business logic so workflow authors do not have to remember it.

Interceptors are typically unnecessary for a single workflow type owned by one team, or for behavior that only one activity needs. In those cases a plain helper function or an explicit parameter is easier to read and test. Before you design anything, confirm which interceptor hooks and propagation mechanisms your SDK and version expose, since the Go, Java, Python, TypeScript, .NET, Ruby and PHP SDKs differ in names and in how they handle workflow-side code. Check the current SDK documentation and your pinned version rather than assuming parity across languages. The Temporal self-hosted security documentation is the right place to confirm how authentication headers and claims reach the server, because interceptors on the client side are not a substitute for server-side authorization.

Plan the decision with three questions: which values must be carried, which components must read them, and who owns the code that sets them. Treat tenant and auth context as sensitive data, because anything propagated through headers or workflow inputs is recorded in event history, which is visible to anyone with read access to that history. Decide early whether those values need payload encryption through a custom codec, and whether logs and traces will redact them. Write down these choices before the first worker ships, because changing what is propagated later means reviewing every workflow and activity that reads it, and older executions will keep the values they were started with.

Where interceptors run: client, workflow, activity and worker

Client-side interceptors wrap the calls your application makes to Temporal, such as starting a workflow, sending a signal, running a query or waiting for a result. They run in your application process, outside the Temporal Service and outside deterministic workflow code, so they can perform I/O, read the local environment and call external identity or logging systems without restriction. This is where outbound request headers, caller identity and starting-context capture are usually added.

  • Start and signal calls: Inbound headers and metadata can be attached to workflow starts and signals so that downstream code receives the originating request or tenant.
  • Query and update calls: Client interceptors can observe the operation name and outcome, which suits request-level metrics and audit records.
  • Credential handling: Auth tokens are commonly injected here, but they must be refreshed and kept out of logs.
  • Failure visibility: Client-side wrappers see gRPC-level errors and retries that the workflow never receives.
  • Scope limit: A client interceptor cannot see work that happens inside a workflow once the call has been accepted.

Confirm the exact client interceptor interface, hook names and header APIs in the documentation for each SDK you use, because they differ by language.

Interceptor and propagation options compared

This table compares the places where cross-cutting behavior can live in a Temporal application: client, workflow and activity interceptors, context propagators and worker-level interceptors. Read each row for the fit, the main risk and the items to confirm with the SDK you use before choosing one.

OptionBest fitMain riskConfirm with the SDK
Client-side interceptorsAttaching auth headers, API metadata and caller identity to every call a client startsCredentials or tokens copied into workflow input or memory if the interceptor is misusedWhich calls the interceptor covers (start, signal, query, update) and how headers reach the server
Workflow interceptorsLogging, metrics and tracing spans around workflow execution and its signals and queriesCalls to non-deterministic functions such as clocks or random values break replayWhich hooks run inside the deterministic sandbox and which must only use replay-safe APIs
Activity interceptorsTracing spans, error logging and timing around activity execution, where I/O is expectedLog lines or spans that record full payloads, exposing personal or regulated dataHow the activity context exposes attempt, task queue and heartbeat details, and the redaction options
Context propagatorsCarrying tenant ID, request ID or trace context from the starter through workflows into activitiesSensitive values written into event history, which is retained and visible to anyone with read accessWhich values the propagator serializes, how it restores them in workflows and activities, and whether it works across child workflows
Worker-level interceptorsGlobal behavior applied to every workflow and activity a worker runs, such as a shared audit or metrics layerA faulty interceptor affects all workflows on that worker, so one defect can stall a whole deploymentHow the worker registers interceptors, their ordering, and how to test them against replay histories
Header-based tenant routingChoosing a namespace, task queue or downstream tenant from a propagated valueA tenant value that is trusted without verification can route work to the wrong tenantWhether the value comes from an authenticated claim, and where the server authorization check applies
Payload encryption codecsProtecting sensitive propagated values that must still travel with workflow dataKeys held in the wrong place, or a codec server reachable without access controlWhether the codec applies to headers or only payloads, and how keys are rotated and reviewed

How context flows from client to workflow to activity

The diagram starts in the client application, where a client interceptor writes tenant and request values into Temporal headers before the call leaves the trust boundary. The Temporal frontend stores the request and schedules a workflow task, where a workflow interceptor reads those headers and restores the context for workflow code. When the workflow schedules an activity, an outbound workflow interceptor copies the context into the activity task, and an activity interceptor extracts it again. Check that every hop reads and writes the same header keys and that nothing sensitive is placed in headers unencrypted.

Headers move from the client through Temporal services into workflow and activity code.

How to set up interceptors and propagation in a Temporal application

This sequence moves tenant, request and trace context from the caller into workflows and activities without putting sensitive data into workflow history. Each step ends with a check that confirms the value arrives where it is needed.

  1. Define context keys and their owners

    Agree on a short list of context keys, such as tenant ID, request ID, trace parent and the calling user's subject, and name the team that owns each one. Write down the format, the source of truth (for example, the API gateway or the authenticated session) and which services may read or change each key. The step is done when every key has a named owner and a written format that both client and worker teams have reviewed. Confirm the list with the security team before code is written, because the keys determine what the interceptors will trust.

  2. Decide what must never enter workflow history

    Workflow inputs, activity results, signals and headers are recorded in workflow event history, and that history is retained and may be read by anyone with access to the namespace. Classify each context value as safe to store there, safe only in encrypted form, or never to be propagated, and treat bearer tokens, raw credentials and personal data as the last category unless your payload codec and access model say otherwise. The step is complete when the classification is documented and a reviewer has confirmed that no secret is on the propagation list. Check the Temporal self-hosted security documentation for payload encryption options before you decide what to encrypt.

  3. Implement client and worker interceptors

    Write a client interceptor that adds outbound headers when a workflow is started or signaled, and a worker interceptor that handles inbound headers for workflows and activities. Keep each interceptor focused on one concern, such as tracing, logging or tenant context, so they can be tested and replaced separately. The step is done when each interceptor compiles and its unit tests show that it writes or reads only the keys defined in step one. Use the SDK's documented interceptor types for your language, because the hook names and signatures differ between SDKs.

  4. Register interceptors on the client and worker

    Attach the client interceptor when the Temporal client is created, and attach the worker interceptors when the worker is configured, so that every workflow started by this code path and every activity run by this worker passes through them. Register the same set of keys on both sides, and avoid creating a second client in a code path that skips the interceptor. The step is done when a workflow started from the API carries the expected header and a worker started from the same configuration reports that the interceptor chain is loaded. Confirm the registration in a test environment before rolling it into shared service code.

  5. Add propagation and extraction on both sides

    Inject the context on the caller side, extract it in the workflow interceptor, and pass it into activities through the activity interceptor so that the workflow does not need to know about the header names. Use the SDK's context-passing mechanism for workflow code, and make sure that any value read in workflow code is deterministic and does not depend on wall-clock time or random sources. The step is complete when the extracted value is available to workflow code and to the activity without any explicit parameter being added to the business function signatures.

  6. Verify that context reaches activities

    Start a test workflow with a known tenant ID and request ID, run a worker with the interceptors enabled, and read the values from an activity's log output or trace span. Compare the value in the activity with the value sent by the caller, and confirm that the value appears in the trace or log fields that your observability stack indexes. Repeat the test with a missing or malformed header to confirm that the code fails closed or uses the documented default. The step is done when the expected value appears in the activity logs and the failure case behaves as designed.

  7. Check workflow history for leaked values

    Open the event history of the test workflow in the Temporal Web UI or through the command line, and search it for the values you marked as sensitive during the classification step. Confirm that the headers you expected are present, that no credential or personal data appears in plaintext, and that encrypted fields are shown as encrypted when your codec is in place. Record the result with the test run so that the same check can be repeated after each interceptor change. The step is done when the history review shows only the approved fields and a reviewer has signed off.

  8. Test changes to propagated context

    Before you change a context key, a header format or the interceptor order, run the workflow tests and replay tests against existing event histories so that in-flight workflows do not fail on the new code. Confirm the change with the owners recorded in step one, and keep a rollback path for the worker deployment. The step is complete when replay of recorded histories succeeds on the new worker build and the owners have approved the change. Work with the replay testing and versioning pages in this group before you deploy any change that affects workflow code.

Security risks when propagating tenant and auth context

Interceptors make it easy to carry tokens, tenant IDs and user identity across every client call, workflow and activity. Each of the risks below comes from that convenience, and each has a specific control in Temporal's self-hosted security model that you should confirm in your own configuration.

Tokens written into payloads

An interceptor that copies an access token into workflow input or activity arguments stores that token in event history, and event history persists in the server database. Anyone with read access to the database or the Web UI can then recover it. Keep credentials out of payloads entirely, and where data must travel, use payload encryption through a custom codec and confirm that the codec server is restricted to trusted staff.

Self-hosted security docs

Tenant context trusted without checks

A workflow that reads a tenant ID from a header propagated by an interceptor will act on that value as if it were verified. Headers set by a client can be forged unless the frontend validates them first. Treat propagated tenant context as a hint, re-derive authorization from verified claims on the server side, and test that a tampered value is rejected before any activity runs.

Forwarded auth without namespace authorization

Passing an auth header from the caller through to Temporal does not by itself restrict what that caller can do. Access is decided by the ClaimMapper (which maps JWT or certificate claims to namespace roles) and the Authorizer plugin. Confirm that each namespace has an explicit role mapping for every identity that sends propagated headers, and that no identity has broader roles than its workload needs.

Secrets captured in logs

Logging interceptors often record full request metadata, headers and workflow inputs for tracing. Those logs can hold bearer tokens or personal data and then flow into a log platform with wider access than the workflow itself. Add redaction for authorization headers and known secret fields in the interceptor, and review sample log lines from staging before enabling verbose logging in production.

Default noopAuthorizer allows all calls

If no Authorizer is configured, self-hosted Temporal uses the default noopAuthorizer, which allows every API request with no authentication or access control. An interceptor that validates auth on the client does not protect the server API from direct callers. Before relying on any propagated context, confirm which Authorizer is configured on the frontend and that the frontend is not reachable from untrusted networks.

Frontend network exposure

Temporal's deployment guidance says services should run on hosts not reachable from the public internet, with network access limited to trusted internal networks. Interceptor-based auth is only one layer, so the frontend and Web UI should sit behind private networking, with mTLS between internode and frontend traffic. Verify this with a network scan from outside your trusted zone, not only from the design document.

Deployment docs

Why interceptor changes can break workflows already running

Workflow-side interceptors run as part of workflow code, so a change to them can alter how existing workflows replay. Temporal rebuilds workflow state by re-executing workflow code against the recorded event history. If an interceptor now makes a different decision, reads a different value, or adds or removes a step at a point where the history expects something else, the replayed workflow can fail with a non-determinism error or, worse, take a different path than it did when it first ran. Activity-side and client-side interceptors do not replay in the same way, so the risk sits mainly in the workflow-side hooks your team adds or edits. Treat any change to those hooks as a change to workflow code, not as a logging tweak.

The practical rules are the familiar ones for workflow code. Interceptor logic running in the workflow must stay deterministic: it should not read wall-clock time, generate random values, or call the network directly. Where tenant or request context is needed, take it from the workflow input or headers that Temporal records in history, and use the SDK's deterministic time and random facilities. When you do need a behavior change for workflows already running, plan a versioning or patching approach so old histories keep their original path. Confirm the exact rules, including which APIs are safe in workflow context and how patching is expressed, in the SDK documentation for the language your team uses, since they differ between SDKs.

The check that catches these problems before production is replay testing. Collect real event histories from the namespace, run them against the candidate build in CI, and fail the pipeline on any non-determinism error. Include histories from long-running workflows that started before the interceptor change, because those are the ones most likely to break. Keep this check as a required gate for every interceptor change, and record which histories were tested. The Temporal GitHub releases page is a useful place to track SDK and server changes that can affect replay behavior during upgrades.

Limits to confirm before you rely on context propagation

Context propagation through interceptors touches payload size, SDK behavior, tracing and your observability backend at the same time. The items below are not established facts for your setup, so each one is a check to run against the Temporal documentation and your own test environment before tenant or request context is trusted in production.

Header and payload size limits

Propagated context travels in workflow and activity headers, so every tenant ID, trace identifier or auth claim adds bytes to each command and history event. Confirm the size limits that apply to headers and payloads in your Temporal server version and SDK, and whether they count against workflow history limits. Measure the header size your interceptors add under realistic load, then set a ceiling and alert before it is reached.

Deployment docs

Interceptor hook support by SDK version

Interceptor hooks for clients, workflows, activities and workers are not guaranteed to be identical across SDK releases and languages. Confirm which hooks your target SDK version exposes, especially for inbound and outbound calls around workflow start, signal, query and activity execution. Pin the SDK version in your build and rerun the interceptor test suite whenever it changes.

Context propagator interaction with SDK features

Context propagators run alongside other SDK features such as data converters, codecs and payload encryption, and their behavior with these can differ by language. Confirm the order in which propagators, codecs and converters apply to headers and payloads in your SDK. Test that encrypted payloads and propagated context still decode correctly after a worker restart and during replay.

Tracing spans across workflow and activity boundaries

Workflow code must stay deterministic, so spans created inside it need care to avoid side effects on replay. Confirm whether your SDK and tracing library keep a single trace across the client call, the workflow and each activity, and whether child workflows keep the parent link. Check the trace tree in your test environment for a workflow that retries, is reset or continues as new.

Observability backend acceptance of identifiers

Propagated workflow, run and trace identifiers only help if your logging, tracing and metrics backend accepts and indexes them. Confirm the attribute names, cardinality limits and retention rules your backend applies to these fields, since high-cardinality tenant or request values can increase cost or be dropped. Verify that a sample identifier can be searched end to end before relying on it for incident response.

Auth header handling at the frontend

Auth headers added by client interceptors are only as trustworthy as the frontend that validates them. Self-hosted Temporal without a configured Authorizer allows every API request, so propagated identity headers are not an access control on their own. Confirm how your deployment's ClaimMapper and Authorizer treat the identity your interceptors send, and test that a request without valid credentials is refused.

Security docs

Questions teams ask before building interceptors

How much effort do Temporal interceptors take to build?

Effort depends mainly on how many hooks you need, which SDK your services use, how many teams share the interceptors, and how much existing observability you must connect to. A single tracing interceptor in one SDK for one team is a small, bounded task. Adding logging, auth headers and tenant context across several services, each with its own SDK and deployment pipeline, multiplies the testing and review work. Ask a partner for a written scope that lists each interceptor, the client and worker paths it touches, the SDKs involved, and the tests that prove context reaches activities. Ask whether the quote covers one-time build work, ongoing maintenance as the SDK changes, or both.

Can our internal team build Temporal interceptors without outside help?

Often yes, if the team already owns the Temporal SDK code, understands workflow determinism, and has someone who has run the observability stack in production. The harder parts are rarely the interceptor class itself. They are deciding which context is safe to carry, making sure workflow code stays deterministic when headers change, and testing replay against live event histories. Teams that lack one of these skills usually get the most value from a short design review before writing code. Decide early which parts your engineers own and which need a partner, and write that split into the scope.

What does the work need from our teams?

The work needs three groups of people. Engineers who know the SDK your services use, for the client and worker interceptor code and the workflow tests. Operations staff who run your tracing, logging and metrics backends, so the propagated fields land where they are queried. Security reviewers who approve which headers and tenant identifiers cross service boundaries, and how auth tokens are kept out of workflow history. If your Temporal deployment is self-hosted, the platform team also needs to confirm that any context added to requests fits the frontend authorization model described in the Temporal self-hosted security documentation.

How long does a rollout of interceptors take?

Duration depends on scope: the number of services, SDKs and environments, whether interceptors are added to workers only or to clients too, and how many review cycles your security and platform teams need. A rollout that starts with one service in a non-production namespace is shorter than a company-wide change across several SDKs. No general duration applies, so ask a partner to give a phased timeline in writing, with separate milestones for design sign-off, build, testing against replayed histories, staging and production rollout.

How do we handle existing workflows when interceptors change?

Treat interceptor changes as code changes to workflow-facing behavior. Interceptors that only touch client or activity code are usually safer than changes that alter workflow-side context, because workflow code must replay deterministically against recorded event histories. Before deploying, collect real histories from your environment and run them through replay tests in CI. If a change would alter workflow decisions for running executions, use Temporal's versioning or patching approach for that change. Ask the partner to state in the scope which changes need versioning, how replay tests are run, and who signs off before production.

What should we ask for in a written scope for interceptors?

Ask for a list of every interceptor and hook in scope, the SDK and service each one covers, and the context fields that will propagate, with a statement of which fields are sensitive. Request the test plan, including replay tests on histories from your environment, and the observability outputs you will receive, such as traces and log fields. Confirm what happens to credentials, whether tokens or tenant identifiers stay out of workflow history, and who approves security review. Finally, ask what the engagement includes after handover, including documentation, knowledge transfer and any retainer for maintenance across SDK upgrades.

Does adding interceptors cost more if we already run tracing and logging?

Existing observability usually lowers the build effort but adds integration work. If you already run OpenTelemetry or another tracing stack, the interceptor can emit spans that follow the existing conventions, which is less design work. The added work is mapping Temporal workflow and activity identifiers into your existing trace and log fields, and checking that sensitive values are filtered before they reach shared log stores. Ask a partner to price the mapping and filtering separately so you can see what the observability integration adds to the base interceptor work.

How DeployOpen scopes and delivers interceptor work

DeployOpen treats interceptors and context propagation as a defined piece of platform work with a written scope, a build that is tested before rollout, and handover material your team can maintain. Engagements are fixed-scope, so the interceptor behavior, the context fields and the deliverables are agreed in writing before any code changes start.

How we scope

  • Inventory the tracing, logging, auth header and tenant context each client and worker must carry.
  • Agree which SDKs, services and task queues the interceptors will cover, in writing.
  • Confirm which request and tenant fields may enter workflow inputs and which must stay out of payloads.

How we build

  • Implement client and worker interceptors in the languages your teams use, with the same header names across them.
  • Test that context survives workflow starts, signals, child workflows and activity retries.
  • Check that propagated headers and logs do not expose credentials or personal data before rollout.

How we hand over

  • Deliver interceptor source, configuration and a reference of propagated context keys and their owners.
  • Document how to add a new context field without breaking workflows already running in production.
  • Walk your engineers through the test cases that prove context propagation and the steps to rerun them.

How we support

  • Ongoing support for interceptor changes, SDK upgrades and new services is available as a retainer.
  • Retainers can include periodic retesting of propagation after Temporal Server and SDK upgrades.
  • Ask for the support scope, response expectations and upgrade handling in the written quote.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.