Skip to content

feat(event-normalization): Update is_ai_span and infer_ai_operation_type to use gen_ai.operation.name#5433

Merged
constantinius merged 13 commits intomasterfrom
constantinius/feat/event-normalization/is_ai_span-use-gen_ai.operation.name
Dec 4, 2025
Merged

feat(event-normalization): Update is_ai_span and infer_ai_operation_type to use gen_ai.operation.name#5433
constantinius merged 13 commits intomasterfrom
constantinius/feat/event-normalization/is_ai_span-use-gen_ai.operation.name

Conversation

@constantinius
Copy link
Copy Markdown
Contributor

@constantinius constantinius commented Dec 2, 2025

The gen_ai.operation.name should be used in preference over span.op in order to determine whether a span is an AI span.

Closes https://linear.app/getsentry/issue/TET-1525/update-relay-logic-to-use-gen-aioperationname

@constantinius constantinius requested a review from a team as a code owner December 2, 2025 14:38
@linear
Copy link
Copy Markdown

linear bot commented Dec 2, 2025

@constantinius constantinius requested review from a team and vgrozdanic December 2, 2025 14:38
@constantinius constantinius marked this pull request as draft December 2, 2025 14:58
@constantinius constantinius marked this pull request as ready for review December 2, 2025 16:04
@constantinius constantinius marked this pull request as draft December 2, 2025 16:05
@constantinius
Copy link
Copy Markdown
Contributor Author

This should be merged and deployed after getsentry/sentry#104242 is deployed, otherwise we would get wrong ai_client values for gen_ai.operation.type attributes since we would go to the catch-all clause.

@constantinius constantinius changed the title feat(event-normalization): is_ai_span shall use gen_ai.operation.name feat(event-normalization): Update is_ai_span and infer_ai_operation_type to use gen_ai.operation.name Dec 3, 2025
@constantinius constantinius marked this pull request as ready for review December 3, 2025 15:33
@constantinius
Copy link
Copy Markdown
Contributor Author

Okay, the dependent commit in Sentry seems deployed now, this is good to go.

@constantinius constantinius requested review from a team and vgrozdanic and removed request for a team and vgrozdanic December 3, 2025 15:34
Comment on lines 252 to 262
@@ -258,15 +263,24 @@ fn infer_ai_operation_type(span: &mut Span, operation_type_map: &AiOperationType
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be simplified to:

    let op_type = data
        .gen_ai_operation_name
        .value()
        .or(span.op.value())
        .and_then(|op| operation_type_map.get_operation_type(op));

    if let Some(operation_type) = op_type {
        data.gen_ai_operation_type
            .set_value(Some(operation_type.to_owned()));
    }

Also this is potentially a bug, it overwrites an existing type. If any SDK were to set this, it will be deleted. Generally we take the approach in Relay not to mess with existing data and only add data.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The potential bug is unrelated, but as far as I know this was intentional. I'll discuss with @vgrozdanic.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was made by design, because this is not intended to be set by SDK.

We want to control this mapping, and not commit to doing this in SDKs because this is partially based on OTEL spec which is still in development phase and not yet stable

@constantinius constantinius requested a review from Dav1dde December 4, 2025 08:27
@constantinius constantinius added this pull request to the merge queue Dec 4, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 4, 2025
@constantinius constantinius added this pull request to the merge queue Dec 4, 2025
Merged via the queue into master with commit e73455a Dec 4, 2025
29 checks passed
@constantinius constantinius deleted the constantinius/feat/event-normalization/is_ai_span-use-gen_ai.operation.name branch December 4, 2025 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants