Skip to content

fix(otel): ensure nested context object creates separate attribute#15655

Merged
aayush-kapoor merged 3 commits into
mainfrom
aayush/nested-context-telemetry
May 27, 2026
Merged

fix(otel): ensure nested context object creates separate attribute#15655
aayush-kapoor merged 3 commits into
mainfrom
aayush/nested-context-telemetry

Conversation

@aayush-kapoor
Copy link
Copy Markdown
Collaborator

Background

for a nested runtime context defined as

runtimeContext: {
  userId: 'user-123',
  metadata: {
    tenant: 'acme',
    plan: 'pro',
  },
}

the spans we produced looked like

{
  'ai.settings.context.userId': 'user-123',
  'ai.settings.context.metadata': { tenant: 'acme', plan: 'pro' },
}

but the second attribute, which is an object, is not a valid OpenTelemetry span attribute value, so real OTel exporters drop it. Which would result in traces like

{
  'ai.settings.context.userId': 'user-123',
}

Summary

After the change, nested context is flattened into valid primitive attributes:

{
  'ai.settings.context.userId': 'user-123',
  'ai.settings.context.metadata.tenant': 'acme',
  'ai.settings.context.metadata.plan': 'pro',
}

Manual Verification

na

Checklist

  • All commits are signed (PRs with unsigned commits cannot be merged)
  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

Copy link
Copy Markdown
Contributor

@vercel vercel Bot left a comment

Choose a reason for hiding this comment

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

Additional Suggestion:

Missing @opentelemetry/sdk-trace-base devDependency causes test file open-telemetry.test.ts to fail at import time with "Cannot find module" error.

Fix on Vercel

@aayush-kapoor
Copy link
Copy Markdown
Collaborator Author

aayush-kapoor commented May 27, 2026

Additional Suggestion:

Missing @opentelemetry/sdk-trace-base devDependency causes test file open-telemetry.test.ts to fail at import time with "Cannot find module" error.

Fix on Vercel

stale review

@aayush-kapoor aayush-kapoor merged commit 1e200eb into main May 27, 2026
49 checks passed
@aayush-kapoor aayush-kapoor deleted the aayush/nested-context-telemetry branch May 27, 2026 21:55
@github-actions
Copy link
Copy Markdown
Contributor

🚀 Published in:

Package Version
ai 7.0.0-canary.156 github npm
@ai-sdk/amazon-bedrock 5.0.0-canary.72 github npm
@ai-sdk/angular 3.0.0-canary.156 github npm
@ai-sdk/azure 4.0.0-canary.65 github npm
@ai-sdk/groq 4.0.0-canary.49 github npm
@ai-sdk/langchain 3.0.0-canary.156 github npm
@ai-sdk/llamaindex 3.0.0-canary.156 github npm
@ai-sdk/openai 4.0.0-canary.65 github npm
@ai-sdk/otel 1.0.0-canary.102 github npm
@ai-sdk/react 4.0.0-canary.158 github npm
@ai-sdk/rsc 3.0.0-canary.157 github npm
@ai-sdk/svelte 5.0.0-canary.156 github npm
@ai-sdk/vue 4.0.0-canary.156 github npm
@ai-sdk/workflow 1.0.0-canary.73 github npm

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.

2 participants