Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(core): Emit low-cardinality gen_ai inference span names when streaming#23573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| import { | ||
| _INTERNAL_shouldSkipAiProviderWrapping, | ||
| getClient, | ||
| hasSpanStreamingEnabled, | ||
| isObjectLike, | ||
| SPAN_STATUS_ERROR, | ||
| startSpan, | ||
| @@ -42,7 +44,8 @@ function instrumentRun( | ||
| const operationName = getOperationName(inputs); | ||
| const requestAttributes = extractRequestAttributes(model, inputs, operationName); | ||
| const modelName = typeof model === 'string' ? model : 'unknown'; | ||
| const modelName = typeof model === 'string' && model ? model : 'unknown'; | ||
| const client = getClient(); | ||
| const isStreamRequested = | ||
| !!inputs && typeof inputs === 'object' && (inputs as { stream?: unknown }).stream === true; | ||
| @@ -52,7 +55,11 @@ function instrumentRun( | ||
| (runOptions.returnRawResponse === true || runOptions.websocket === true); | ||
| const spanConfig = { | ||
| name: `${operationName} ${modelName}`, | ||
| // With span streaming, omit the `'unknown'` model sentinel so the name stays low-cardinality. | ||
| name: | ||
| modelName !== 'unknown' || !(client && hasSpanStreamingEnabled(client)) | ||
| ? `${operationName} ${modelName}` | ||
| : operationName, | ||
cursor[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| op: `gen_ai.${operationName}`, | ||
| attributes: requestAttributes, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -4,6 +4,8 @@ import type { IntegrationFn, Span, SpanAttributeValue } from '@sentry/core'; | ||
| import { | ||
| _INTERNAL_shouldSkipAiProviderWrapping, | ||
| defineIntegration, | ||
| getClient, | ||
| hasSpanStreamingEnabled, | ||
| SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, | ||
| startInactiveSpan, | ||
| } from '@sentry/core'; | ||
| @@ -99,9 +101,11 @@ function createGenAiSpan( | ||
| const attributes = extractRequestAttributes(args, operation); | ||
| const model = (attributes[GEN_AI_REQUEST_MODEL] as string) || 'unknown'; | ||
| attributes[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] = ORIGIN; | ||
| const client = getClient(); | ||
| const span = startInactiveSpan({ | ||
| name: `${operation} ${model}`, | ||
| // With span streaming, omit the `'unknown'` model sentinel so the name stays low-cardinality. | ||
| name: model !== 'unknown' || !(client && hasSpanStreamingEnabled(client)) ? `${operation} ${model}` : operation, | ||
RulaKhaled marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| op: getGenAiSpanOp(operation), | ||
| attributes: attributes as Record<string, SpanAttributeValue>, | ||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.