BaggageBuilder class

Per request baggage builder for OpenTelemetry context propagation.

This class provides a fluent API for setting baggage values that will be propagated in the OpenTelemetry context.

Example

const scope = new BaggageBuilder()
  .tenantId("tenant-123")
  .agentId("agent-456")
  .build();

scope.enter();
// Baggage is set in this context
// ... do work ...
scope.exit();
// Baggage is restored after exiting the context

Methods

agentAuid(string | null | undefined)

Set the agent AUID baggage value.

agentBlueprintId(string | null | undefined)

Set the agent blueprint ID baggage value.

agentDescription(string | null | undefined)

Set the agent description baggage value.

agentEmail(string | null | undefined)

Set the agent email baggage value.

agentId(string | null | undefined)

Set the agent ID baggage value.

agentName(string | null | undefined)

Set the agent name baggage value.

agentPlatformId(string | null | undefined)

Set the agent platform ID baggage value.

agentVersion(string | null | undefined)

Set the agent version baggage value.

build()

Apply the collected baggage to the current context.

callerAgentPlatformId(string | null | undefined)

Set the caller agent platform ID baggage value.

callerClientIp(string | null | undefined)

Set the caller client IP baggage value. Used to capture the originating client IP for the request so it can be propagated via OpenTelemetry baggage.

channelLink(string | null | undefined)

Set the channel link/URL.

channelName(string | null | undefined)

Set the channel name (e.g., Teams, Slack).

conversationId(string | null | undefined)

Set the conversation ID baggage value.

conversationItemLink(string | null | undefined)

Set the conversation item link baggage value.

invokeAgentServer(string | null | undefined, number)

Sets the invoke agent server address and port baggage values.

operationSource(string | null | undefined)

Set the operation source baggage value. Used for server spans to identify the service (e.g., ATG, ACF).

sessionDescription(string | null | undefined)

Set the session description baggage value.

sessionId(string)

Set the session ID baggage value.

setPairs(Record<string, any> | Iterable<[string, any], any, any> | null | undefined)

Set multiple baggage pairs from a dictionary or iterable.

setRequestContext(string | null, string | null)

Convenience method to begin a request baggage scope with common fields.

tenantId(string | null | undefined)

Set the tenant ID baggage value.

userEmail(string | null | undefined)

Set the user email baggage value.

userId(string | null | undefined)

Set the user ID baggage value.

userName(string | null | undefined)

Set the user name baggage value.

Method Details

agentAuid(string | null | undefined)

Set the agent AUID baggage value.

function agentAuid(value: string | null | undefined): BaggageBuilder

Parameters

value

string | null | undefined

The agent AUID

Returns

Self for method chaining

agentBlueprintId(string | null | undefined)

Set the agent blueprint ID baggage value.

function agentBlueprintId(value: string | null | undefined): BaggageBuilder

Parameters

value

string | null | undefined

The agent blueprint ID

Returns

Self for method chaining

agentDescription(string | null | undefined)

Set the agent description baggage value.

function agentDescription(value: string | null | undefined): BaggageBuilder

Parameters

value

string | null | undefined

The agent description

Returns

Self for method chaining

agentEmail(string | null | undefined)

Set the agent email baggage value.

function agentEmail(value: string | null | undefined): BaggageBuilder

Parameters

value

string | null | undefined

The agent email

Returns

Self for method chaining

agentId(string | null | undefined)

Set the agent ID baggage value.

function agentId(value: string | null | undefined): BaggageBuilder

Parameters

value

string | null | undefined

The agent ID

Returns

Self for method chaining

agentName(string | null | undefined)

Set the agent name baggage value.

function agentName(value: string | null | undefined): BaggageBuilder

Parameters

value

string | null | undefined

The agent name

Returns

Self for method chaining

agentPlatformId(string | null | undefined)

Set the agent platform ID baggage value.

function agentPlatformId(value: string | null | undefined): BaggageBuilder

Parameters

value

string | null | undefined

The agent platform ID

Returns

Self for method chaining

agentVersion(string | null | undefined)

Set the agent version baggage value.

function agentVersion(value: string | null | undefined): BaggageBuilder

Parameters

value

string | null | undefined

The agent version (e.g., '1.0.0', '2025-05-01')

Returns

Self for method chaining

build()

Apply the collected baggage to the current context.

function build(): BaggageScope

Returns

A context manager that restores the previous baggage on exit

callerAgentPlatformId(string | null | undefined)

Set the caller agent platform ID baggage value.

function callerAgentPlatformId(value: string | null | undefined): BaggageBuilder

Parameters

value

string | null | undefined

The caller agent platform identifier

Returns

Self for method chaining

callerClientIp(string | null | undefined)

Set the caller client IP baggage value. Used to capture the originating client IP for the request so it can be propagated via OpenTelemetry baggage.

function callerClientIp(value: string | null | undefined): BaggageBuilder

Parameters

value

string | null | undefined

The caller client IP address

Returns

Self for method chaining

Set the channel link/URL.

function channelLink(value: string | null | undefined): BaggageBuilder

Parameters

value

string | null | undefined

The channel link

Returns

Self for method chaining

channelName(string | null | undefined)

Set the channel name (e.g., Teams, Slack).

function channelName(value: string | null | undefined): BaggageBuilder

Parameters

value

string | null | undefined

The channel name

Returns

Self for method chaining

conversationId(string | null | undefined)

Set the conversation ID baggage value.

function conversationId(value: string | null | undefined): BaggageBuilder

Parameters

value

string | null | undefined

The conversation ID

Returns

Self for method chaining

Set the conversation item link baggage value.

function conversationItemLink(value: string | null | undefined): BaggageBuilder

Parameters

value

string | null | undefined

The conversation item link

Returns

Self for method chaining

invokeAgentServer(string | null | undefined, number)

Sets the invoke agent server address and port baggage values.

function invokeAgentServer(address: string | null | undefined, port?: number): BaggageBuilder

Parameters

address

string | null | undefined

The server address (hostname) of the target agent service.

port

number

Optional server port. Only recorded when different from 443.

Returns

The current builder instance for method chaining.

operationSource(string | null | undefined)

Set the operation source baggage value. Used for server spans to identify the service (e.g., ATG, ACF).

function operationSource(value: string | null | undefined): BaggageBuilder

Parameters

value

string | null | undefined

The operation source

Returns

Self for method chaining

sessionDescription(string | null | undefined)

Set the session description baggage value.

function sessionDescription(value: string | null | undefined): BaggageBuilder

Parameters

value

string | null | undefined

The session description

Returns

Self for method chaining

sessionId(string)

Set the session ID baggage value.

function sessionId(value: string): BaggageBuilder

Parameters

value

string

The session ID

Returns

Self for method chaining

setPairs(Record<string, any> | Iterable<[string, any], any, any> | null | undefined)

Set multiple baggage pairs from a dictionary or iterable.

function setPairs(pairs: Record<string, any> | Iterable<[string, any], any, any> | null | undefined): BaggageBuilder

Parameters

pairs

Record<string, any> | Iterable<[string, any], any, any> | null | undefined

Dictionary or iterable of key-value pairs

Returns

Self for method chaining

setRequestContext(string | null, string | null)

Convenience method to begin a request baggage scope with common fields.

static function setRequestContext(tenantId?: string | null, agentId?: string | null): BaggageScope

Parameters

tenantId

string | null

The tenant ID

agentId

string | null

The agent ID

Returns

A context manager that restores the previous baggage on exit

tenantId(string | null | undefined)

Set the tenant ID baggage value.

function tenantId(value: string | null | undefined): BaggageBuilder

Parameters

value

string | null | undefined

The tenant ID

Returns

Self for method chaining

userEmail(string | null | undefined)

Set the user email baggage value.

function userEmail(value: string | null | undefined): BaggageBuilder

Parameters

value

string | null | undefined

The user email

Returns

Self for method chaining

userId(string | null | undefined)

Set the user ID baggage value.

function userId(value: string | null | undefined): BaggageBuilder

Parameters

value

string | null | undefined

The user ID

Returns

Self for method chaining

userName(string | null | undefined)

Set the user name baggage value.

function userName(value: string | null | undefined): BaggageBuilder

Parameters

value

string | null | undefined

The user name

Returns

Self for method chaining