InferenceScope class

Provides OpenTelemetry tracing scope for generative AI inference operations.

Extends

Methods

recordFinishReasons(string[])

Records the finish reasons.

recordInputMessages(InputMessagesParam)

Records the input messages for telemetry tracking.

recordInputTokens(number)

Records the number of input tokens.

recordOutputMessages(OutputMessagesParam)

Records the output messages for telemetry tracking.

recordOutputTokens(number)

Records the number of output tokens.

start(Request, InferenceDetails, AgentDetails, UserDetails, SpanDetails)

Creates and starts a new scope for inference tracing.

Inherited Methods

dispose()

Legacy dispose method for compatibility.

getSpanContext()

Gets the span context for this scope.

recordAttributes(undefined | null | Iterable<[string, AttributeValue]> | Record<string, AttributeValue>)

Records multiple attribute key/value pairs.

recordCancellation(string)

Records a cancellation event on the span.

recordError(Error)

Records an error that occurred during the operation.

setEndTime(TimeInput)

Sets a custom end time for the scope. When set, dispose() will pass this value to span.end() instead of using wall-clock time.

withActiveSpanAsync<T>(() => Promise<T>)

Makes this span active for the duration of the async callback execution.

Method Details

recordFinishReasons(string[])

Records the finish reasons.

function recordFinishReasons(finishReasons: string[])

Parameters

finishReasons

string[]

recordInputMessages(InputMessagesParam)

Records the input messages for telemetry tracking.

function recordInputMessages(messages: InputMessagesParam)

Parameters

recordInputTokens(number)

Records the number of input tokens.

function recordInputTokens(inputTokens: number)

Parameters

inputTokens

number

recordOutputMessages(OutputMessagesParam)

Records the output messages for telemetry tracking.

function recordOutputMessages(messages: OutputMessagesParam)

Parameters

recordOutputTokens(number)

Records the number of output tokens.

function recordOutputTokens(outputTokens: number)

Parameters

outputTokens

number

start(Request, InferenceDetails, AgentDetails, UserDetails, SpanDetails)

Creates and starts a new scope for inference tracing.

static function start(request: Request, details: InferenceDetails, agentDetails: AgentDetails, userDetails?: UserDetails, spanDetails?: SpanDetails): InferenceScope

Parameters

request
A365Request

Request payload (channel, conversationId, content, sessionId).

details
InferenceDetails

The inference call details (model, provider, tokens, etc.).

agentDetails
AgentDetails

The agent performing the inference. tenantId is required.

userDetails
UserDetails

Optional human caller identity.

spanDetails
A365SpanDetails

Optional span configuration. spanKind is always CLIENT.

Returns

Inherited Method Details

dispose()

Legacy dispose method for compatibility.

function dispose()

Inherited From OpenTelemetryScope.dispose

getSpanContext()

Gets the span context for this scope.

function getSpanContext(): SpanContext

Returns

SpanContext

Inherited From OpenTelemetryScope.getSpanContext

recordAttributes(undefined | null | Iterable<[string, AttributeValue]> | Record<string, AttributeValue>)

Records multiple attribute key/value pairs.

function recordAttributes(attributes: undefined | null | Iterable<[string, AttributeValue]> | Record<string, AttributeValue>)

Parameters

attributes

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

Inherited From OpenTelemetryScope.recordAttributes

recordCancellation(string)

Records a cancellation event on the span.

function recordCancellation(reason?: string)

Parameters

reason

string

Inherited From OpenTelemetryScope.recordCancellation

recordError(Error)

Records an error that occurred during the operation.

function recordError(error: Error)

Parameters

error

Error

Inherited From OpenTelemetryScope.recordError

setEndTime(TimeInput)

Sets a custom end time for the scope. When set, dispose() will pass this value to span.end() instead of using wall-clock time.

function setEndTime(endTime: TimeInput)

Parameters

endTime

TimeInput

Inherited From OpenTelemetryScope.setEndTime

withActiveSpanAsync<T>(() => Promise<T>)

Makes this span active for the duration of the async callback execution.

function withActiveSpanAsync<T>(callback: () => Promise<T>): Promise<T>

Parameters

callback

() => Promise<T>

Returns

Promise<T>

Inherited From OpenTelemetryScope.withActiveSpanAsync