class AiIntegration extends Feature

Constants

private FEATURE_KEY

private FEATURE_KEY_INVOKE_AGENT

private FEATURE_KEY_CHAT

private FEATURE_KEY_EXECUTE_TOOL

private FEATURE_KEY_EMBEDDINGS

Methods

__construct(Container $container)

Create a new feature instance.

from  Feature
bool
isApplicable()

Determine whether AI tracing is enabled and the optional package is present.

void
register()

Register the feature in the environment.

from  Feature
void
onBoot()

Register only the enabled AI listener families.

void
onBootInactive()

Set up the feature in the environment in an inactive state (when no DSN was set).

from  Feature
void
boot()

Initialize the feature.

from  Feature
void
bootInactive()

Initialize the feature in an inactive state (when no DSN was set).

from  Feature
array
getUserConfig()

Retrieve the user configuration.

from  Feature
bool
shouldSendDefaultPii()

Determine if default PII should be sent.

from  Feature
bool
shouldCollectGenAiInputs()

Determine whether AI inputs may be collected.

from  Feature
bool
shouldCollectGenAiOutputs()

Determine whether AI outputs may be collected.

from  Feature
bool
isTracingFeatureEnabled(string $feature, bool $default = true)

Indicate if the given feature is enabled for tracing.

from  Feature
bool
isBreadcrumbFeatureEnabled(string $feature, bool $default = true)

Indicate if the given feature is enabled for breadcrumbs.

from  Feature
bool
canRecordSpans()

Determine if the active SDK client can record spans.

from  Feature
bool
canRecordBreadcrumbs()

Determine if the active SDK client can record breadcrumbs.

from  Feature
void
handlePromptingAgentForTracing(PromptingAgent $event)

Start an invocation under the current sampled span.

void
handleAgentPromptedForTracing(AgentPrompted $event)

Complete an invocation with response metadata.

void
handleAgentFailedForTracing(AgentFailed $event)

Close a failed invocation after failed-turn persistence.

void
handleAgentFailedOverForTracing(AgentFailedOver $event)

Close the failed attempt before another provider reuses the invocation ID.

void
handleAgentStreamAbandonedForTracing(AgentStreamAbandoned $event)

Close an invocation whose consumer stopped before completion.

void
handleStartingStepForTracing(StartingStep $event)

Capture resolved metadata and start the exact model step.

void
handleStepCompletedForTracing(StepCompleted $event)

Record the model response and finish its step span.

void
handleStepFailedForTracing(StepFailed $event)

Finish a failed model step, including failures during stream consumption.

void
handleInvokingToolForTracing(InvokingTool $event)

Start a tool span without resolving its schema again.

void
handleToolInvokedForTracing(ToolInvoked $event)

Record a tool result and restore its caller's span.

void
handleToolFailedForTracing(ToolFailed $event)

Close a tool span when execution throws or is canceled.

void
handleGeneratingEmbeddingsForTracing(GeneratingEmbeddings $event)

Start an embeddings span under the current sampled span.

void
handleEmbeddingsGeneratedForTracing(EmbeddingsGenerated $event)

Complete embeddings with the returned model and input-token count.

void
handleEmbeddingsFailedForTracing(EmbeddingsFailed $event)

Close a failed embeddings attempt by its exact invocation ID.

void
attachSpanToConversation(Span $span)

Method used so that other integrations that produce gen_ai spans can submit their spans here which will be populated with the conversation ID once it becomes available.

void
setCurrentConversationId(string|null $conversationId)

Set the conversation of the gen_ai spans started from now on in the current trace, replacing the current one.

Details

in Feature at line 35
__construct(Container $container)

Create a new feature instance.

Parameters

Container $container

at line 87
bool isApplicable()

Determine whether AI tracing is enabled and the optional package is present.

Return Value

bool

in Feature at line 48
void register()

Register the feature in the environment.

Return Value

void

at line 96
void onBoot()

Register only the enabled AI listener families.

Return Value

void

in Feature at line 64
void onBootInactive()

Set up the feature in the environment in an inactive state (when no DSN was set).

Return Value

void

in Feature at line 71
void boot()

Initialize the feature.

Return Value

void

in Feature at line 81
void bootInactive()

Initialize the feature in an inactive state (when no DSN was set).

Return Value

void

in Feature at line 91
protected array getUserConfig()

Retrieve the user configuration.

Return Value

array

in Feature at line 99
protected bool shouldSendDefaultPii()

Determine if default PII should be sent.

Return Value

bool

in Feature at line 113
protected bool shouldCollectGenAiInputs()

Determine whether AI inputs may be collected.

Return Value

bool

in Feature at line 121
protected bool shouldCollectGenAiOutputs()

Determine whether AI outputs may be collected.

Return Value

bool

in Feature at line 146
protected bool isTracingFeatureEnabled(string $feature, bool $default = true)

Indicate if the given feature is enabled for tracing.

Parameters

string $feature
bool $default

Return Value

bool

in Feature at line 159
protected bool isBreadcrumbFeatureEnabled(string $feature, bool $default = true)

Indicate if the given feature is enabled for breadcrumbs.

Parameters

string $feature
bool $default

Return Value

bool

in Feature at line 182
protected bool canRecordSpans()

Determine if the active SDK client can record spans.

Return Value

bool

in Feature at line 196
protected bool canRecordBreadcrumbs()

Determine if the active SDK client can record breadcrumbs.

Return Value

bool

at line 156
void handlePromptingAgentForTracing(PromptingAgent $event)

Start an invocation under the current sampled span.

Parameters

PromptingAgent $event

Return Value

void

at line 229
void handleAgentPromptedForTracing(AgentPrompted $event)

Complete an invocation with response metadata.

Parameters

AgentPrompted $event

Return Value

void

at line 256
void handleAgentFailedForTracing(AgentFailed $event)

Close a failed invocation after failed-turn persistence.

Parameters

AgentFailed $event

Return Value

void

at line 264
void handleAgentFailedOverForTracing(AgentFailedOver $event)

Close the failed attempt before another provider reuses the invocation ID.

Parameters

AgentFailedOver $event

Return Value

void

at line 272
void handleAgentStreamAbandonedForTracing(AgentStreamAbandoned $event)

Close an invocation whose consumer stopped before completion.

Parameters

AgentStreamAbandoned $event

Return Value

void

at line 313
void handleStartingStepForTracing(StartingStep $event)

Capture resolved metadata and start the exact model step.

Parameters

StartingStep $event

Return Value

void

at line 385
void handleStepCompletedForTracing(StepCompleted $event)

Record the model response and finish its step span.

Parameters

StepCompleted $event

Return Value

void

at line 409
void handleStepFailedForTracing(StepFailed $event)

Finish a failed model step, including failures during stream consumption.

Parameters

StepFailed $event

Return Value

void

at line 421
void handleInvokingToolForTracing(InvokingTool $event)

Start a tool span without resolving its schema again.

Parameters

InvokingTool $event

Return Value

void

at line 473
void handleToolInvokedForTracing(ToolInvoked $event)

Record a tool result and restore its caller's span.

Parameters

ToolInvoked $event

Return Value

void

at line 496
void handleToolFailedForTracing(ToolFailed $event)

Close a tool span when execution throws or is canceled.

Parameters

ToolFailed $event

Return Value

void

at line 508
void handleGeneratingEmbeddingsForTracing(GeneratingEmbeddings $event)

Start an embeddings span under the current sampled span.

Parameters

GeneratingEmbeddings $event

Return Value

void

at line 548
void handleEmbeddingsGeneratedForTracing(EmbeddingsGenerated $event)

Complete embeddings with the returned model and input-token count.

Parameters

EmbeddingsGenerated $event

Return Value

void

at line 570
void handleEmbeddingsFailedForTracing(EmbeddingsFailed $event)

Close a failed embeddings attempt by its exact invocation ID.

Parameters

EmbeddingsFailed $event

Return Value

void

at line 583
void attachSpanToConversation(Span $span)

Method used so that other integrations that produce gen_ai spans can submit their spans here which will be populated with the conversation ID once it becomes available.

Parameters

Span $span

Return Value

void

at line 592
void setCurrentConversationId(string|null $conversationId)

Set the conversation of the gen_ai spans started from now on in the current trace, replacing the current one.

Passing null forgets the current conversation.

Parameters

string|null $conversationId

Return Value

void