feat(otel): add option for custom span attributes#14975
Merged
aayush-kapoor merged 6 commits intomainfrom May 8, 2026
Merged
Conversation
lgrammel
reviewed
May 5, 2026
| sdk.start(); | ||
| registerTelemetry( | ||
| new OpenTelemetry({ | ||
| enrichSpanAttributes: ({ spanType, operationId, runtimeContext }) => ({ |
Collaborator
There was a problem hiding this comment.
I am working on restricting how the runtimeContext is exposed to telemetry for security so this might conflict somewhat
lgrammel
reviewed
May 5, 2026
lgrammel
reviewed
May 5, 2026
lgrammel
reviewed
May 5, 2026
Comment on lines
+20
to
+26
| export type OpenTelemetrySpanType = | ||
| | 'operation' | ||
| | 'step' | ||
| | 'languageModel' | ||
| | 'tool' | ||
| | 'embedding' | ||
| | 'reranking'; |
Collaborator
There was a problem hiding this comment.
these mix language model and other span -- i am wondering if there are better names, e.g. hierarchical
Collaborator
Author
There was a problem hiding this comment.
that is a span type but
lgrammel
reviewed
May 5, 2026
lgrammel
approved these changes
May 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
#14727
@ai-sdk/otelcurrently does not expose a supported way to add attributes at span creation time. this is for external observability systems that sometimes need to add additional span attributes that are specific to their ingestion pipelineSummary
Added a new
enrichSpanAttributesoption to OpenTelemetry so callers can append custom attributes when spans are createdManual Verification
ran the example
examples/ai-functions/src/telemetry/otel/generate-text-custom-attributes.tsChecklist
pnpm changesetin the project root)Related Issues
fixes #14727