Skip to main content

Overview

setContextValue() stores a value in the trace context that can be retrieved by child spans using getContextValue(). Useful for passing data without explicit parameters.

Signature

Basic Usage

Request Context

User Session Context

Feature Flags

Configuration Propagation

Dynamic Context Updates

Complex Objects

Parameters

string
required
The key to store the value under
any
required
The value to store (can be any type: string, number, object, array, etc.)

Best Practices

  • Use context for cross-cutting concerns (request IDs, user info, feature flags)
  • Set context early in the workflow for child spans to access
  • Store configuration that multiple tasks need without explicit passing
  • Context values can be updated dynamically as the workflow progresses
  • Context is scoped to the current trace and its child spans
  • Use meaningful key names for clarity
  • Context is useful for avoiding parameter drilling through many function layers