Six context managers from openinference.instrumentation that attach session IDs, user IDs, metadata, tags, and prompt templates to every span in scope.
OpenInference provides a set of context managers that attach attributes to every span created while they’re in scope. They are the easiest way to add cross-cutting context — session ID, user ID, metadata, tags, prompt templates — without modifying every span by hand.Context managers are the recommended way to handle attributes that apply to a group of spans. For attributes that only apply to one span, set them directly on that span instead.
How They Work
Each context manager attaches a value to the OpenTelemetry context. When a span is created while the manager is in scope, the OITracer returned by register() reads those context attributes and stamps them onto the span as it’s created.This is why register() matters: it returns an OITracer instead of a vanilla OTel tracer. If you bypass register() and use the raw OTel tracer, these context managers still set context values, but the tracer won’t pick them up automatically.
The Six Helpers
All six live in openinference.instrumentation:
Helper
Sets
Use case
using_session
session.id
Group traces into a multi-turn conversation.
using_user
user.id
Tag spans with the user the request belongs to.
using_metadata
metadata
Arbitrary JSON-stringified data.
using_tags
tag.tags
A list of tags for filtering and search.
using_prompt_template
llm.prompt_template.{template,version,variables}
Attach the prompt template, its version, and the variables used.
using_attributes
Any combination of the above
Set multiple in one block to avoid nesting.
using_session
Sets the session.id attribute on every span in scope. This is how Arize AX groups traces into a session.
from openinference.instrumentation import using_sessionwith using_session(session_id="user-42-conv-7"): response = client.chat.completions.create(...) # every span created in this block gets session.id = "user-42-conv-7"
from openinference.instrumentation import using_userwith using_user(user_id="user-42"): response = client.chat.completions.create(...)
using_metadata
Sets arbitrary JSON-stringified metadata. Useful for application-specific context (tenant, environment, request source) that doesn’t fit the other helpers.
Sets the tag.tags attribute — a list of strings used for filtering and search in the Arize AX UI.
from openinference.instrumentation import using_tagswith using_tags(["experiment-7", "high-priority"]): response = client.chat.completions.create(...)
using_prompt_template
Sets the three prompt-template attributes — llm.prompt_template.template, llm.prompt_template.version, llm.prompt_template.variables — at once.
from openinference.instrumentation import using_prompt_templatetemplate = "You are a helpful assistant. The user's name is {{name}}."with using_prompt_template( template=template, version="v3", variables={"name": "Alice"},): response = client.chat.completions.create(...)
Attaching the template (rather than only the final prompt) makes it possible to evaluate, compare, and re-run prompts directly from the Arize AX UI.
using_attributes
Sets several of the above in one block — useful when you’d otherwise nest three or four context managers.
Context managers attach attributes to the OTel context. The OITracer reads those attributes when it creates a span — that’s how auto-instrumented spans (and spans created with the OITracer) automatically inherit them.Manual spans created with a raw OTel tracer do not automatically pick up these context attributes. If you mix manual spans with context managers, use the helper from openinference.instrumentation:
from openinference.instrumentation import get_attributes_from_contextdef create_span_with_context(tracer, name, **kwargs): with tracer.start_as_current_span(name, **kwargs) as span: context_attributes = dict(get_attributes_from_context()) span.set_attributes(context_attributes) return span# Usagewith using_session(session_id="my-session-id"): with create_span_with_context(tracer, "my-manual-span") as span: # span now has session.id attached ...
The value applies to many spans (whole conversation, whole request).
The value applies to just this one span.
You’re using auto-instrumentation and can’t reach inside library code.
You’re creating the span by hand anyway.
You want to scope cross-cutting context cleanly with a with block.
The value is computed from per-span data.
Next step
You’ve covered every approach to setting attributes. Next, the mechanics that keep traces intact across process, thread, and service boundaries — context propagation:
Next: Context Propagation
Last modified on September 14, 2026
Was this page helpful?
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"Arize AX Docs","colors":{"primary":"#EA338A","light":"#FF3CA8","dark":"#FF3CA8"},"logo":{"light":"https://mintcdn.com/arize-ax/V-uvingrGLOCK4VD/logo/light.svg?fit=max\u0026auto=format\u0026n=V-uvingrGLOCK4VD\u0026q=85\u0026s=cc58ee9388d5b5253d39b65cc662908f","dark":"https://mintcdn.com/arize-ax/V-uvingrGLOCK4VD/logo/dark.svg?fit=max\u0026auto=format\u0026n=V-uvingrGLOCK4VD\u0026q=85\u0026s=b16a0266f5913934131301a1b60af51e","href":"https://arize.com"},"favicon":"https://mintcdn.com/arize-ax/1gcABHkqP5TIGbru/favicon.ico?fit=max\u0026auto=format\u0026n=1gcABHkqP5TIGbru\u0026q=85\u0026s=aef538e87b54a3c819583bc40acfc2f8","appearance":{"default":"dark"},"background":{"color":{"light":"#F8F8F6","dark":"#0E0C0B"}},"navbar":{"links":[],"primary":{"type":"button","label":"Get started","href":"https://app.arize.com/auth/join"}},"footer":{"socials":{"x":"https://x.com/arizeai","bluesky":"https://bsky.app/profile/arize.bsky.social","threads":"https://www.threads.com/@arize.ai","instagram":"https://www.instagram.com/arize_ai","linkedin":"https://www.linkedin.com/company/arizeai","youtube":"https://youtube.com/@arizeai","slack":"https://arize-ai.slack.com/ssb/redirect","website":"https://fosstodon.org/@arizeai"},"links":[{"header":"Support","items":[{"label":"Chat Us On Slack","href":"https://arize-ai.slack.com/ssb/redirect"},{"label":"support@arize.com","href":"mailto:support@arize.com"},{"label":"System Status","href":"https://status.arize.com"}]},{"header":"Get Started","items":[{"label":"Signup For Free","href":"https://arize.com/join"},{"label":"Book A Demo","href":"https://arize.com/request-a-demo"}]},{"header":"Resources","items":[{"label":"Blog","href":"https://arize.com/blog"}]}]},"seo":{"metatags":{"canonical":"https://arize.com/docs"},"indexing":"all"},"fonts":{"heading":{"family":"Geist","weight":600},"body":{"family":"Geist"}},"styling":{"codeblocks":{"theme":{"light":"github-light-default","dark":"github-dark-default"}},"latex":true},"integrations":{"gtm":{"tagId":"GTM-W96XM35"}},"contextual":{"options":["copy","view","chatgpt","claude"],"display":"header"},"interaction":{"drilldown":false},"metadata":{"timestamp":true},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"arize-ax","hasAudioNarration":false,"actualSubdomain":"arize-ax","customDomains":[],"gitSource":{"type":"github","owner":"arize-ai","repo":"docs","deployBranch":"main","contentDirectory":"","isPrivate":true,"mountPath":"","label":""},"feedback":{"thumbs":true,"contextualFeedback":{"allowEmail":true,"emailDisclaimer":"We will only use your email to follow up with you about this feedback."}},"entitlements":{"AI_CHAT":{"status":"ENABLED"},"REMOVE_BRANDING":{"status":"ENABLED"},"CONTEXTUAL_FEEDBACK":{"status":"ENABLED"},"CODE_SNIPPET_FEEDBACK":{"status":"ENABLED"},"WEB_MCP":{"status":"ENABLED"},"NARRATION":{"status":"ENABLED"}},"buildId":"6b090202a0b114e01df50fa9","clientVersion":"0.0.4340","searchFilterCounts":[{"language":"default","tag":"APIs, SDKs, Skills \u0026 MCP","count":377},{"language":"default","tag":"Get Started","count":256},{"language":"default","tag":"API reference","count":222},{"language":"default","tag":"REST","count":189},{"language":"default","tag":"Endpoints","count":186},{"language":"default","tag":"API clients","count":143},{"language":"default","tag":"Machine Learning","count":139},{"language":"default","tag":"ML observability","count":139},{"language":"default","tag":"Integrations","count":129},{"language":"default","tag":"Python SDK","count":67}]},"assistantConfig":{"enableAskAiButton":true,"enableStarterQuestions":true,"enableAskAiSearchBar":true,"deflection":{"enabled":true,"email":"support@arize.com"}},"basePath":"/docs","hasChatPermissions":true,"hasWebMcpPermissions":true,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-rbac-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"rbac-expansion","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"site-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-metadata","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-serve","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"live-agents","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"starter-pricing","enabled":true,"variant":{"name":"treatment","enabled":true,"payload":{"type":"string","value":"treatment"},"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"wildcard-email-auth","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"starterQuestions":[{"_id":"6944513fe59e82150b5700b3","deploymentId":"6894ef048eafbd2a7c20796e","questionText":"Need more help? Ask our team in #arize-ax-platform-support on community Slack.","status":"active","generatedBy":"manual","createdAt":"2025-12-18T19:08:47.802Z","updatedAt":"2025-12-18T19:15:01.436Z","__v":0}],"googleFontsInlined":true},"customCss":[{"filePath":"style.css","content":"/* cyrillic-ext */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 300;\n font-display: swap;\n src: url(/docs/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrodmgPn.woff2) format('woff2');\n unicode-range: U+0460-052F, U+1C80-1C8A, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;\n}\n/* cyrillic */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 300;\n font-display: swap;\n src: url(/docs/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrMdmgPn.woff2) format('woff2');\n unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;\n}\n/* symbols2 */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 300;\n font-display: swap;\n src: url(/docs/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFg08vz7ehw.woff2) format('woff2');\n unicode-range: U+2000-2001, U+2004-2008, U+200A, U+23B8-23BD, U+2500-259F;\n}\n/* vietnamese */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 300;\n font-display: swap;\n src: url(/docs/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrgdmgPn.woff2) format('woff2');\n unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;\n}\n/* latin-ext */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 300;\n font-display: swap;\n src: url(/docs/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrkdmgPn.woff2) format('woff2');\n unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;\n}\n/* latin */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 300;\n font-display: swap;\n src: url(/docs/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrcdmg.woff2) format('woff2');\n unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;\n}\n/* cyrillic-ext */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 400;\n font-display: swap;\n src: url(/docs/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrodmgPn.woff2) format('woff2');\n unicode-range: U+0460-052F, U+1C80-1C8A, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;\n}\n/* cyrillic */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 400;\n font-display: swap;\n src: url(/docs/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrMdmgPn.woff2) format('woff2');\n unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;\n}\n/* symbols2 */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 400;\n font-display: swap;\n src: url(/docs/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFg08vz7ehw.woff2) format('woff2');\n unicode-range: U+2000-2001, U+2004-2008, U+200A, U+23B8-23BD, U+2500-259F;\n}\n/* vietnamese */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 400;\n font-display: swap;\n src: url(/docs/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrgdmgPn.woff2) format('woff2');\n unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;\n}\n/* latin-ext */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 400;\n font-display: swap;\n src: url(/docs/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrkdmgPn.woff2) format('woff2');\n unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;\n}\n/* latin */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 400;\n font-display: swap;\n src: url(/docs/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrcdmg.woff2) format('woff2');\n unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;\n}\n/* cyrillic-ext */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 500;\n font-display: swap;\n src: url(/docs/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrodmgPn.woff2) format('woff2');\n unicode-range: U+0460-052F, U+1C80-1C8A, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;\n}\n/* cyrillic */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 500;\n font-display: swap;\n src: url(/docs/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrMdmgPn.woff2) format('woff2');\n unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;\n}\n/* symbols2 */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 500;\n font-display: swap;\n src: url(/docs/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFg08vz7ehw.woff2) format('woff2');\n unicode-range: U+2000-2001, U+2004-2008, U+200A, U+23B8-23BD, U+2500-259F;\n}\n/* vietnamese */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 500;\n font-display: swap;\n src: url(/docs/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrgdmgPn.woff2) format('woff2');\n unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;\n}\n/* latin-ext */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 500;\n font-display: swap;\n src: url(/docs/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrkdmgPn.woff2) format('woff2');\n unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;\n}\n/* latin */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 500;\n font-display: swap;\n src: url(/docs/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrcdmg.woff2) format('woff2');\n unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;\n}\n/* cyrillic-ext */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 600;\n font-display: swap;\n src: url(/docs/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrodmgPn.woff2) format('woff2');\n unicode-range: U+0460-052F, U+1C80-1C8A, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;\n}\n/* cyrillic */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 600;\n font-display: swap;\n src: url(/docs/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrMdmgPn.woff2) format('woff2');\n unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;\n}\n/* symbols2 */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 600;\n font-display: swap;\n src: url(/docs/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFg08vz7ehw.woff2) format('woff2');\n unicode-range: U+2000-2001, U+2004-2008, U+200A, U+23B8-23BD, U+2500-259F;\n}\n/* vietnamese */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 600;\n font-display: swap;\n src: url(/docs/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrgdmgPn.woff2) format('woff2');\n unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;\n}\n/* latin-ext */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 600;\n font-display: swap;\n src: url(/docs/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrkdmgPn.woff2) format('woff2');\n unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;\n}\n/* latin */\n@font-face {\n font-family: 'Geist Mono';\n font-style: normal;\n font-weight: 600;\n font-display: swap;\n src: url(/docs/_mintlify/assets/fonts/google/s/geistmono/v6/or3nQ6H-1_WfwkMZI_qYFrcdmg.woff2) format('woff2');\n unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;\n}\nhtml:root{--font-family-mono-custom: 'Geist Mono'}html:root{--gray-50: 248 248 246;--gray-100: 242 242 237;--gray-200: 230 230 223;--gray-300: 205 205 200;--gray-400: 179 179 191;--gray-500: 138 138 150;--gray-600: 91 91 105;--gray-700: 62 62 78;--gray-800: 46 46 61;--gray-900: 21 21 31;--gray-950: 10 10 18}html:root{--ax-radius-sm: 2px;--ax-radius-md: 6px;--ax-radius-lg: 8px;--ax-accent-bg: #FF74BF;--ax-panel: #CDBEF7;--ax-panel-2: #E3DBFC;--ax-panel-code: #FFFFFF;--ax-panel-border: rgba(19, 22, 64, 0.22);--ax-panel-icon: #4827C1;--ax-panel-t1: #121221;--ax-panel-t2: #2A2A38;--ax-panel-accent: #6E1046;--ax-panel-code-kw: #3F4110;--ax-panel-code-flag: #5A3200;--ax-panel-code-url: #004A70;--ax-panel-selection: #FFE9F4}html:not(.dark){--ax-bg: #FFFFFF;--ax-surface: #F8F8F4;--ax-code-bg: #F5F5ED;--ax-chip: #EDEDE2;--ax-line: rgba(19, 22, 64, 0.20);--ax-t1: #121221;--ax-t2: #2E2E3D;--ax-t3: #3E3E4E;--ax-accent: #7A0047;--ax-accent-line: rgba(255, 98, 182, 0.55);--ax-accent-soft: #FFE9F4;--ax-on-accent: #121221;--ax-note: #E8F3EC;--ax-note-line: rgba(30, 70, 50, 0.24);--ax-note-t: #1B4230;--ax-warn: #FBEEE0;--ax-warn-line: rgba(90, 50, 0, 0.24);--ax-warn-t: #54300A;--ax-blue: #E7F3FD;--ax-blue-line: rgba(0, 82, 125, 0.24);--ax-blue-t: #00527D;--ax-danger: #FFEBE9;--ax-danger-line: rgba(207, 34, 46, 0.28);--ax-danger-t: #A40E26}html.dark{--ax-bg: #0A0A12;--ax-surface: #15151F;--ax-code-bg: #05050B;--ax-chip: #221B3A;--ax-line: rgba(247, 247, 252, 0.16);--ax-t1: #F5F5FA;--ax-t2: #DCDCE6;--ax-t3: #B3B3C4;--ax-accent: #FF8AC8;--ax-accent-line: rgba(255, 138, 200, 0.45);--ax-accent-soft: #2A1425;--ax-on-accent: #0A0A12;--ax-note: #10241A;--ax-note-line: rgba(159, 224, 188, 0.30);--ax-note-t: #9FE0BC;--ax-warn: #2A1B0A;--ax-warn-line: rgba(255, 201, 138, 0.30);--ax-warn-t: #FFC98A;--ax-blue: #0A1A24;--ax-blue-line: rgba(57, 195, 255, 0.30);--ax-blue-t: #97D8FF;--ax-danger: #2A0F12;--ax-danger-line: rgba(255, 138, 148, 0.30);--ax-danger-t: #FFB3B8}#content{line-height:1.75}#page-title,#content h1{font-size:clamp(2rem, 1.4rem + 2.1vw, 2.875rem);line-height:1.12;letter-spacing:-0.02em;font-weight:600}#content h2,#content h3,#content h4{letter-spacing:-0.01em;font-weight:600}#content code,#content kbd,#content samp{font-feature-settings:'tnum' 1}#content a:not(.card){color:var(--ax-accent);text-decoration-thickness:1px;text-underline-offset:3px}:focus-visible{outline:2px solid var(--ax-accent-line);outline-offset:2px}html.dark :focus-visible{outline-color:var(--ax-accent-line)}::selection{background:var(--ax-accent-soft)}#navbar{background:var(--ax-bg);border-bottom:1px solid var(--ax-line)}#navbar div:has(>.nav-tabs){position:relative}#navbar div:has(>.nav-tabs)::before{content:'';position:absolute;top:0;left:50%;width:100vw;margin-left:-50vw;border-top:1px solid var(--ax-line);pointer-events:none}.nav-tabs-item[data-active]{box-shadow:inset 0 -2px 0 var(--ax-accent)}.ax-product-selector{position:relative;display:inline-flex;align-items:stretch;flex:0 0 auto}.ax-product-selector--desktop{margin-left:0.75rem;align-self:center}.page-context-dropdown__label{font-family:inherit;font-weight:400}.page-context-dropdown__chevron>span{display:inline-block;transition:transform 150ms ease}.page-context-dropdown__chevron svg{display:block;width:1rem;height:1rem}.page-context-dropdown__chevron[aria-expanded=\"true\"]>span{transform:rotate(180deg)}.page-context-dropdown__menu{position:absolute;z-index:60;top:calc(100% + 0.55rem);right:0;min-width:12.5rem;padding:0.4rem;background:var(--ax-bg);border:1px solid var(--ax-line);border-radius:var(--ax-radius-md);box-shadow:0 0.75rem 1.5rem rgb(10 10 18 / 0.18)}.ax-product-selector--desktop .page-context-dropdown__menu{right:auto;left:0}.page-context-dropdown__menu[hidden]{display:none}.page-context-dropdown__item{display:flex;align-items:center;justify-content:space-between;min-height:2.5rem;padding:0.55rem 0.65rem;color:var(--ax-t1);border-radius:var(--ax-radius-sm);font-size:0.9375rem;font-weight:400;text-decoration:none;transition:background-color 150ms ease, color 150ms ease}.page-context-dropdown__item:hover,.page-context-dropdown__item:focus-visible{color:var(--ax-accent);background:var(--ax-accent-soft)}.page-context-dropdown__item[data-selected=\"true\"]{color:var(--ax-accent);font-weight:500}.page-context-dropdown__item[data-selected=\"true\"]::after{content:'✓';margin-left:1.5rem;color:var(--ax-accent);font-size:0.875rem}@media (prefers-reduced-motion: reduce){.page-context-dropdown__chevron>span,.page-context-dropdown__item{transition:none}}@media (max-width: 767px){#navbar .ax-product-selector--desktop{display:none}#mobile-nav-content .ax-product-selector--mobile{margin:0.5rem 0 1rem}#mobile-nav-content .page-context-dropdown__label{flex:1 1 auto}#mobile-nav-content .page-context-dropdown__chevron{flex:0 0 auto}#mobile-nav-content .page-context-dropdown__menu{position:static;margin-top:0.4rem}}#topbar-cta-button{background:var(--ax-accent-bg);color:var(--ax-on-accent);border-radius:var(--ax-radius-md);border:none}#topbar-cta-button span,#topbar-cta-button svg{color:var(--ax-on-accent)!important}#search-bar-entry{background:var(--ax-surface);border:1px solid var(--ax-line);border-radius:var(--ax-radius-md)}#assistant-entry{background:var(--ax-surface);border:1px solid var(--ax-accent-line);border-radius:var(--ax-radius-md)}#assistant-entry svg{color:var(--ax-accent)}#page-context-menu,.page-context-dropdown{font-size:0.9375rem;align-items:stretch}#page-context-menu-button,.page-context-dropdown__label{display:inline-flex;align-items:center;padding:10px 14px;border-radius:var(--ax-radius-md) 0 0 var(--ax-radius-md);background:var(--ax-surface);border-color:var(--ax-line);color:var(--ax-t1);border:1px solid var(--ax-line);text-decoration:none}#page-context-menu-button>div{font-size:0.9375rem;gap:9px}#page-context-menu>button[aria-haspopup],.page-context-dropdown__chevron{height:auto;align-self:stretch;aspect-ratio:auto;padding:10px 11px;border-radius:0 var(--ax-radius-md) var(--ax-radius-md) 0;background:var(--ax-surface);border-color:var(--ax-line);color:var(--ax-t3);border:1px solid var(--ax-line);border-left:0;cursor:pointer}#sidebar-content li[data-active]>a{background:var(--ax-accent-soft);color:var(--ax-accent);border-radius:var(--ax-radius-md);font-weight:500}.sidebar-group-header{font-weight:600;color:var(--ax-t1)}body:has(.nav-tabs-item[data-active][href$=\"/ax/cookbooks\"]) #sidebar{display:none}#content-container:has(.ax-guides){max-width:none}.toc-item[data-active],.toc-item[data-active] a{color:var(--ax-accent);font-weight:400}.card.card{background:var(--ax-surface);border-color:var(--ax-line);border-radius:var(--ax-radius-lg);box-shadow:none}.frame.frame{background:var(--ax-surface);border:1px solid var(--ax-line);border-radius:var(--ax-radius-lg)}.accordion.accordion,.accordion-group.accordion-group{border-radius:var(--ax-radius-md);border-color:var(--ax-line)}.accordion.accordion{background:var(--ax-surface)}.code-block.code-block,.code-group.code-group{background:var(--ax-code-bg);border-color:var(--ax-line);border-radius:var(--ax-radius-md)}.code-block-background{background:var(--ax-code-bg)!important}html.dark .code-block-background{background:var(--ax-code-bg)!important}#content :not(pre)>code{background:var(--ax-chip);border-radius:var(--ax-radius-sm)}.code-block:has([data-floating-buttons]) [data-fade-overlay]{background-image:none}[data-floating-buttons] button{background:var(--ax-chip)}.callout .code-block.code-block,.callout .code-group.code-group,.callout .code-block-background,html.dark .callout .code-block-background{background:var(--ax-bg)!important}.callout{border-radius:var(--ax-radius-lg)}.callout[data-callout-type=\"callout\"],.callout[data-callout-type=\"info\"]{background:var(--ax-surface);border-color:var(--ax-line)}.callout[data-callout-type=\"callout\"] [data-component-part=\"callout-content\"],.callout[data-callout-type=\"info\"] [data-component-part=\"callout-content\"]{color:var(--ax-t2)!important}.callout[data-callout-type=\"tip\"],.callout[data-callout-type=\"check\"]{background:var(--ax-note);border-color:var(--ax-note-line)}.callout[data-callout-type=\"tip\"] [data-component-part=\"callout-content\"],.callout[data-callout-type=\"check\"] [data-component-part=\"callout-content\"]{color:var(--ax-note-t)!important}.callout[data-callout-type=\"warning\"]{background:var(--ax-warn);border-color:var(--ax-warn-line)}.callout[data-callout-type=\"warning\"] [data-component-part=\"callout-content\"]{color:var(--ax-warn-t)!important}.callout[data-callout-type=\"note\"]{background:var(--ax-blue);border-color:var(--ax-blue-line)}.callout[data-callout-type=\"note\"] [data-component-part=\"callout-content\"]{color:var(--ax-blue-t)!important}.callout[data-callout-type=\"danger\"]{background:var(--ax-danger);border-color:var(--ax-danger-line)}.callout[data-callout-type=\"danger\"] [data-component-part=\"callout-content\"]{color:var(--ax-danger-t)!important}[data-component-part=\"step-number\"]>div{background:var(--ax-accent-soft);border:1px solid var(--ax-accent-line);color:var(--ax-accent);font-weight:500}.update.update-container{flex-direction:column;gap:0.5rem;border-top:1px solid var(--ax-line)}.update.update-container:first-of-type{border-top:none}.update.update-container>div:first-child{width:100%;position:static}.update.update-container>div:last-child{width:100%;max-width:none}#content th{color:var(--ax-t1);font-weight:600;border-bottom:1px solid var(--ax-line)}#content td{border-bottom:1px solid var(--ax-line)}footer{border-top:1px solid var(--ax-line)}.ax-hero .callout{background:var(--ax-panel);border-color:var(--ax-panel-border);border-radius:var(--ax-radius-lg)}.ax-hero .callout [data-component-part=\"callout-content\"],.ax-hero .callout p,.ax-hero .callout li{color:var(--ax-panel-t2)!important}.ax-hero .callout h2,.ax-hero .callout h3,.ax-hero .callout strong{color:var(--ax-panel-t1)!important}.ax-hero .callout [data-component-part=\"callout-icon\"] svg{background:var(--ax-panel-icon)!important}.ax-hero .code-block,.ax-hero .code-group,.ax-hero .code-block-background{background:var(--ax-panel-code)!important;border-color:var(--ax-panel-border)}.ax-hero .code-block,.ax-hero .code-group{padding:0;overflow:hidden}html.dark .ax-hero .code-block,html.dark .ax-hero .code-group,html.dark .ax-hero .code-block-background,html.dark .ax-hero .shiki,html:not(.dark) .ax-hero .code-block,html:not(.dark) .ax-hero .code-group,html:not(.dark) .ax-hero .code-block-background{background:var(--ax-panel-code)!important}html.dark .ax-hero .shiki,html.dark .ax-hero .shiki span{color:var(--ax-panel-t1)!important}html.dark .ax-hero .shiki span[style*=\"#FFA657\"]{color:var(--ax-panel-code-kw)!important}html.dark .ax-hero .shiki span[style*=\"#79C0FF\"]{color:var(--ax-panel-code-flag)!important}html.dark .ax-hero .shiki span[style*=\"#A5D6FF\"]{color:var(--ax-panel-code-url)!important}.ax-hero .code-group>div:first-child,html.dark .ax-hero .code-group>div:first-child{background:var(--ax-panel-2)!important;border-bottom:1px solid var(--ax-panel-border)}.ax-hero .code-group [role=\"tab\"]{color:var(--ax-panel-t2)!important}.ax-hero .code-group [role=\"tab\"][aria-selected=\"true\"]{color:var(--ax-panel-accent)!important}.ax-hero .code-group [role=\"tab\"][aria-selected=\"true\"]>div:last-child{background:var(--ax-panel-accent)!important}.ax-hero .code-block svg,.ax-hero .code-group svg{color:var(--ax-panel-t2)}html.dark .ax-hero [data-fade-overlay]{background-image:linear-gradient(\n to right,\n rgb(255 255 255 / 0) 0,\n rgb(255 255 255 / 0.2) 10px,\n rgb(255 255 255 / 0.5) 25px,\n rgb(255 255 255 / 0.8) 35px,\n rgb(255 255 255) 45px\n )}.ax-hero .callout a{color:var(--ax-panel-accent)!important}.ax-hero::selection,.ax-hero ::selection{background:var(--ax-panel-selection)}.card-group .card img{max-height:197px!important}.card-group[class$=\"-2\"] .card img{height:160px!important}.card-group[class$=\"-3\"] .card img{height:150px!important}table{display:table!important}.step-title{font-size:1.5rem!important}.ax-guides{margin-top:0;color:var(--ax-t2)}.ax-guides-controls{display:flex;flex-direction:column;gap:0.75rem;margin-top:1.5rem;padding-bottom:0;border-bottom:1px solid var(--ax-line)}.ax-guides-group{display:flex;flex-direction:column;gap:0.5rem;align-items:flex-start}.ax-guides-group-name{font-size:0.8125rem;color:var(--ax-t3)}.ax-guides-chips{display:flex;flex-wrap:wrap;gap:0.375rem}.ax-guides-chip{display:inline-flex;gap:0.375rem;align-items:center;padding:0.1875rem 0.5rem;font-size:0.8125rem;line-height:1.25rem;color:var(--ax-t2);background:transparent;border:1px solid var(--ax-line);border-radius:var(--ax-radius-md);cursor:pointer}.ax-guides-chip:hover{border-color:var(--ax-accent-line)}.ax-guides-chip:focus-visible,.ax-guides-link:focus-visible,.ax-guides-title:focus-visible,.ax-guides-tag:focus-visible,.ax-guides-card:focus-visible{outline:2px solid var(--ax-accent);outline-offset:2px}.ax-guides-chip.is-active{color:var(--ax-t1);border-color:var(--ax-accent)}.ax-guides-chip-count{font-size:0.75rem;color:var(--ax-t3)}.ax-guides-toolbar{display:flex;gap:1.25rem}.ax-guides-filterbar{display:flex;gap:1rem;align-items:center;margin-bottom:0.25rem}.ax-guides-popover-wrap{position:relative;z-index:20}.ax-guides-filter-btn{display:inline-flex;gap:0.5rem;align-items:center;padding:0.25rem 0.75rem;font-size:0.875rem;color:var(--ax-t1);background:var(--ax-surface);border:1px solid var(--ax-line);border-radius:var(--ax-radius-md);cursor:pointer}.ax-guides-filter-btn:hover,.ax-guides-filter-btn[aria-expanded=\"true\"]{border-color:var(--ax-accent-line)}.ax-guides-filter-btn:focus-visible{outline:2px solid var(--ax-accent);outline-offset:2px}.ax-guides-popover{position:absolute;top:calc(100% + 0.5rem);right:0;z-index:10;display:flex;flex-direction:column;gap:0.875rem;width:min(44rem, 92vw);padding:1rem;background:var(--ax-surface);border:1px solid var(--ax-line);border-radius:var(--ax-radius-lg);box-shadow:0 8px 24px rgba(0, 0, 0, 0.18)}.ax-guides-link{padding:0;font-size:0.8125rem;color:var(--ax-accent);background:none;border:0;cursor:pointer}.ax-guides-link:hover{text-decoration:underline}.ax-guides-heading{margin:1.75rem 0 0.75rem;font-size:0.8125rem;font-weight:600;letter-spacing:0.04em;text-transform:uppercase;color:var(--ax-t3)}.ax-guides-head{display:grid;grid-template-columns:minmax(0, 1fr) minmax(0, 36rem) 7rem;gap:1rem;padding:0.75rem 0.5rem 0.75rem;font-size:0.8125rem;font-weight:600;color:var(--ax-t2);border-bottom:1px solid var(--ax-line)}.ax-guides-sort{justify-self:end;padding:0;font:inherit;color:inherit;background:none;border:0;cursor:pointer}.ax-guides-sort:hover{color:var(--ax-t1)}.ax-guides-sort:focus-visible{outline:2px solid var(--ax-accent);outline-offset:2px}.ax-guides-count{margin:1.25rem 0 0;font-size:0.8125rem;color:var(--ax-t3)}.ax-guides-dot{display:inline-block;width:0.375rem;height:0.375rem;margin-right:0.375rem;vertical-align:middle;border-radius:999px;background:var(--ax-guides-dot, currentColor)}.ax-guides-list{margin:0;padding:0;list-style:none}.ax-guides-row{position:relative;display:grid;grid-template-columns:minmax(0, 1fr) minmax(0, 36rem) 7rem;gap:1rem;align-items:start;padding:0.875rem 0.5rem;border-bottom:1px solid var(--ax-line)}.ax-guides-row:hover{background:var(--ax-surface)}.ax-guides-date{padding-top:0.125rem;font-size:0.8125rem;white-space:nowrap;text-align:right;color:var(--ax-t3)}.ax-guides-main{display:flex;flex-direction:column;gap:0.25rem}.ax-guides-title{font-size:0.9375rem;font-weight:600;line-height:1.35;color:var(--ax-t1)}.ax-guides-title::after{content:\"\";position:absolute;inset:0}.ax-guides-summary{font-size:0.875rem;line-height:1.5;color:var(--ax-t3)}.ax-guides-tags{display:flex;flex-wrap:nowrap;gap:0.25rem;justify-content:flex-start;min-width:0;overflow:hidden;white-space:nowrap}.ax-guides-tag{padding:0.1875rem 0.5rem;font-size:0.8125rem;line-height:1.25rem;color:var(--ax-t2);border:1px solid var(--ax-line);border-radius:var(--ax-radius-md)}button.ax-guides-tag{position:relative;z-index:1;margin:0;font-family:inherit;background:transparent;cursor:pointer}button.ax-guides-tag:hover{color:var(--ax-t1);border-color:var(--ax-accent-line)}button.ax-guides-tag.is-active{color:var(--ax-t1);border-color:var(--ax-accent)}.ax-guides-empty{padding:2rem 0;text-align:center}@media (max-width: 900px){.ax-guides-head{display:none}.ax-guides-row{grid-template-columns:minmax(0, 1fr);gap:0.375rem}.ax-guides-date{text-align:left}}@media (max-width: 600px){.ax-guides-group{flex-direction:column;gap:0.375rem}.ax-guides-group-name{flex-basis:auto}}#content .ax-guides a.ax-guides-title,#content .ax-guides a.ax-guides-title:hover{color:var(--ax-t1);text-decoration:none;border-color:transparent}.mdx-content:has(>.ax-guides:first-child){margin-top:1rem}.ax-guides-tabrow{display:flex;flex-wrap:wrap;justify-content:space-between;align-items:center;gap:1rem}.ax-guides-segmented{display:flex;flex-wrap:wrap;gap:1.5rem}.ax-guides-segment{display:inline-flex;gap:0.375rem;align-items:center;margin-bottom:-1px;padding:0.5rem 0;font-size:0.9375rem;color:var(--ax-t3);background:none;border:0;border-bottom:2px solid transparent;cursor:pointer}.ax-guides-segment:hover{color:var(--ax-t1)}.ax-guides-segment.is-active{color:var(--ax-t1);border-bottom-color:var(--ax-accent)}.ax-guides-segment:focus-visible{outline:2px solid var(--ax-accent);outline-offset:2px}"}]}
{"page":{"pagePath":"ax/concepts/otel-openinference/context-managers","slug":"/ax/concepts/otel-openinference/context-managers","pageMetadata":{"title":"OpenInference Context Managers","sidebarTitle":"Context managers","description":"Six context managers from openinference.instrumentation that attach session IDs, user IDs, metadata, tags, and prompt templates to every span in scope.","keywords":["using_session","using_user","using_metadata","using_tags","using_prompt_template","using_attributes","OpenInference","OITracer"],"href":"/ax/concepts/otel-openinference/context-managers"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"Six context managers from openinference.instrumentation that attach session IDs, user IDs, metadata, tags, and prompt templates to every span in scope.\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,em:`em`,hr:`hr`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,tbody:`tbody`,td:`td`,th:`th`,thead:`thead`,tr:`tr`,..._provideComponents(),...props.components},{Card,CodeBlock,Heading,Table}=_components;if(!Card)_missingMdxReference(`Card`,true);if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Table)_missingMdxReference(`Table`,true);return _jsxs(_Fragment,{children:[_jsxs(_components.p,{children:[`OpenInference provides a set of `,_jsx(_components.strong,{children:`context managers`}),` that attach attributes to every span created while they’re in scope. They are the easiest way to add cross-cutting context — session ID, user ID, metadata, tags, prompt templates — without modifying every span by hand.`]}),`\n`,_jsxs(_components.p,{children:[`Context managers are the recommended way to handle attributes that apply to a `,_jsx(_components.em,{children:`group`}),` of spans. For attributes that only apply to one span, set them directly on that span instead.`]}),`\n`,_jsx(Heading,{level:`2`,id:`how-they-work`,children:`How They Work`}),`\n`,_jsxs(_components.p,{children:[`Each context manager attaches a value to the OpenTelemetry context. When a span is created while the manager is in scope, the `,_jsx(_components.a,{href:`/ax/concepts/otel-openinference/arize-otel-helpers#what-register-does-under-the-hood`,children:_jsx(_components.code,{children:`OITracer`})}),` returned by `,_jsx(_components.code,{children:`register()`}),` reads those context attributes and stamps them onto the span as it’s created.`]}),`\n`,_jsxs(_components.p,{children:[`This is why `,_jsx(_components.code,{children:`register()`}),` matters: it returns an `,_jsx(_components.code,{children:`OITracer`}),` instead of a vanilla OTel tracer. If you bypass `,_jsx(_components.code,{children:`register()`}),` and use the raw OTel tracer, these context managers still set context values, but the tracer won’t pick them up automatically.`]}),`\n`,_jsx(Heading,{level:`2`,id:`the-six-helpers`,children:`The Six Helpers`}),`\n`,_jsxs(_components.p,{children:[`All six live in `,_jsx(_components.code,{children:`openinference.instrumentation`}),`:`]}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{style:{textAlign:`left`},children:`Helper`}),_jsx(_components.th,{style:{textAlign:`left`},children:`Sets`}),_jsx(_components.th,{style:{textAlign:`left`},children:`Use case`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{style:{textAlign:`left`},children:_jsx(_components.code,{children:`using_session`})}),_jsx(_components.td,{style:{textAlign:`left`},children:_jsx(_components.code,{children:`session.id`})}),_jsx(_components.td,{style:{textAlign:`left`},children:`Group traces into a multi-turn conversation.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{style:{textAlign:`left`},children:_jsx(_components.code,{children:`using_user`})}),_jsx(_components.td,{style:{textAlign:`left`},children:_jsx(_components.code,{children:`user.id`})}),_jsx(_components.td,{style:{textAlign:`left`},children:`Tag spans with the user the request belongs to.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{style:{textAlign:`left`},children:_jsx(_components.code,{children:`using_metadata`})}),_jsx(_components.td,{style:{textAlign:`left`},children:_jsx(_components.code,{children:`metadata`})}),_jsx(_components.td,{style:{textAlign:`left`},children:`Arbitrary JSON-stringified data.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{style:{textAlign:`left`},children:_jsx(_components.code,{children:`using_tags`})}),_jsx(_components.td,{style:{textAlign:`left`},children:_jsx(_components.code,{children:`tag.tags`})}),_jsx(_components.td,{style:{textAlign:`left`},children:`A list of tags for filtering and search.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{style:{textAlign:`left`},children:_jsx(_components.code,{children:`using_prompt_template`})}),_jsx(_components.td,{style:{textAlign:`left`},children:_jsx(_components.code,{children:`llm.prompt_template.{template,version,variables}`})}),_jsx(_components.td,{style:{textAlign:`left`},children:`Attach the prompt template, its version, and the variables used.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{style:{textAlign:`left`},children:_jsx(_components.code,{children:`using_attributes`})}),_jsx(_components.td,{style:{textAlign:`left`},children:`Any combination of the above`}),_jsx(_components.td,{style:{textAlign:`left`},children:`Set multiple in one block to avoid nesting.`})]})]})]}),`\n`,_jsx(Heading,{level:`2`,id:`using_session`,children:_jsx(_components.code,{children:`using_session`})}),`\n`,_jsxs(_components.p,{children:[`Sets the `,_jsx(_components.code,{children:`session.id`}),` attribute on every span in scope. This is how Arize AX groups traces into a session.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`5`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default github-dark-default`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0d1117`,color:`#1f2328`,\"--shiki-dark\":`#e6edf3`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`5`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` openinference.instrumentation `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` using_session`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`with`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` using_session(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#FFA657`},children:`session_id`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#A5D6FF`},children:`\"user-42-conv-7\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` response `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` client.chat.completions.create(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#79C0FF`},children:`...`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#8B949E`},children:` # every span created in this block gets session.id = \"user-42-conv-7\"`})}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`For practical session setup, see `,_jsx(_components.a,{href:`/ax/instrument/set-up-sessions`,children:`Set up sessions`}),`.`]}),`\n`,_jsx(Heading,{level:`2`,id:`using_user`,children:_jsx(_components.code,{children:`using_user`})}),`\n`,_jsxs(_components.p,{children:[`Sets the `,_jsx(_components.code,{children:`user.id`}),` attribute.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`4`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default github-dark-default`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0d1117`,color:`#1f2328`,\"--shiki-dark\":`#e6edf3`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`4`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` openinference.instrumentation `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` using_user`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`with`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` using_user(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#FFA657`},children:`user_id`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#A5D6FF`},children:`\"user-42\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` response `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` client.chat.completions.create(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#79C0FF`},children:`...`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`)`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`using_metadata`,children:_jsx(_components.code,{children:`using_metadata`})}),`\n`,_jsx(_components.p,{children:`Sets arbitrary JSON-stringified metadata. Useful for application-specific context (tenant, environment, request source) that doesn’t fit the other helpers.`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`4`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default github-dark-default`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0d1117`,color:`#1f2328`,\"--shiki-dark\":`#e6edf3`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`4`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` openinference.instrumentation `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` using_metadata`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`with`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` using_metadata({`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#A5D6FF`},children:`\"tenant\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#A5D6FF`},children:`\"acme\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#A5D6FF`},children:`\"feature_flag\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#A5D6FF`},children:`\"v2\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`}):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` response `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` client.chat.completions.create(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#79C0FF`},children:`...`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`)`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`using_tags`,children:_jsx(_components.code,{children:`using_tags`})}),`\n`,_jsxs(_components.p,{children:[`Sets the `,_jsx(_components.code,{children:`tag.tags`}),` attribute — a list of strings used for filtering and search in the Arize AX UI.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`4`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default github-dark-default`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0d1117`,color:`#1f2328`,\"--shiki-dark\":`#e6edf3`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`4`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` openinference.instrumentation `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` using_tags`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`with`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` using_tags([`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#A5D6FF`},children:`\"experiment-7\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#A5D6FF`},children:`\"high-priority\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`]):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` response `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` client.chat.completions.create(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#79C0FF`},children:`...`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`)`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`using_prompt_template`,children:_jsx(_components.code,{children:`using_prompt_template`})}),`\n`,_jsxs(_components.p,{children:[`Sets the three prompt-template attributes — `,_jsx(_components.code,{children:`llm.prompt_template.template`}),`, `,_jsx(_components.code,{children:`llm.prompt_template.version`}),`, `,_jsx(_components.code,{children:`llm.prompt_template.variables`}),` — at once.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`10`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default github-dark-default`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0d1117`,color:`#1f2328`,\"--shiki-dark\":`#e6edf3`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`10`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` openinference.instrumentation `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` using_prompt_template`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`template `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#A5D6FF`},children:` \"You are a helpful assistant. The user's name is `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`{{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#A5D6FF`},children:`name`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`}}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#A5D6FF`},children:`.\"`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`with`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` using_prompt_template(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#FFA657`},children:` template`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`template,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#FFA657`},children:` version`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#A5D6FF`},children:`\"v3\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#FFA657`},children:` variables`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#A5D6FF`},children:`\"name\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#A5D6FF`},children:`\"Alice\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`},`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`):`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` response `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` client.chat.completions.create(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#79C0FF`},children:`...`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`)`})]}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`Attaching the template (rather than only the final prompt) makes it possible to evaluate, compare, and re-run prompts directly from the Arize AX UI.`}),`\n`,_jsx(Heading,{level:`2`,id:`using_attributes`,children:_jsx(_components.code,{children:`using_attributes`})}),`\n`,_jsx(_components.p,{children:`Sets several of the above in one block — useful when you’d otherwise nest three or four context managers.`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`12`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default github-dark-default`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0d1117`,color:`#1f2328`,\"--shiki-dark\":`#e6edf3`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`12`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` openinference.instrumentation `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` using_attributes`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`with`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` using_attributes(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#FFA657`},children:` session_id`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#A5D6FF`},children:`\"user-42-conv-7\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#FFA657`},children:` user_id`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#A5D6FF`},children:`\"user-42\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#FFA657`},children:` metadata`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#A5D6FF`},children:`\"tenant\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#A5D6FF`},children:`\"acme\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`},`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#FFA657`},children:` tags`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#A5D6FF`},children:`\"experiment-7\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#FFA657`},children:` prompt_template`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`template,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#FFA657`},children:` prompt_template_version`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#A5D6FF`},children:`\"v3\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#FFA657`},children:` prompt_template_variables`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#A5D6FF`},children:`\"name\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#A5D6FF`},children:`\"Alice\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`},`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`):`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` response `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` client.chat.completions.create(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#79C0FF`},children:`...`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`)`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`For the canonical reference, see `,_jsx(_components.a,{href:`/ax/instrument/customize-your-traces`,children:`Customize your traces`}),`.`]}),`\n`,_jsx(Heading,{level:`2`,id:`manual-spans-and-context-inheritance`,children:`Manual Spans and Context Inheritance`}),`\n`,_jsxs(_components.p,{children:[`Context managers attach attributes to the OTel context. The `,_jsx(_components.code,{children:`OITracer`}),` reads those attributes when it creates a span — that’s how auto-instrumented spans (and spans created with the `,_jsx(_components.code,{children:`OITracer`}),`) automatically inherit them.`]}),`\n`,_jsxs(_components.p,{children:[`Manual spans created with a raw OTel tracer do `,_jsx(_components.strong,{children:`not`}),` automatically pick up these context attributes. If you mix manual spans with context managers, use the helper from `,_jsx(_components.code,{children:`openinference.instrumentation`}),`:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`13`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default github-dark-default`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0d1117`,color:`#1f2328`,\"--shiki-dark\":`#e6edf3`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`13`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` openinference.instrumentation `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` get_attributes_from_context`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#D2A8FF`},children:` create_span_with_context`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`(tracer, name, `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`**`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`kwargs):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:` with`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` tracer.start_as_current_span(name, `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`**`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`kwargs) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`as`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` span:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` context_attributes `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#79C0FF`},children:` dict`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`(get_attributes_from_context())`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` span.set_attributes(context_attributes)`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:` return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` span`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#8B949E`},children:`# Usage`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`with`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` using_session(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#FFA657`},children:`session_id`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#A5D6FF`},children:`\"my-session-id\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:` with`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` create_span_with_context(tracer, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#A5D6FF`},children:`\"my-manual-span\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#FF7B72`},children:`as`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#E6EDF3`},children:` span:`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#8B949E`},children:` # span now has session.id attached`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#79C0FF`},children:` ...`})}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`This pulls the current context attributes and applies them to the new span. For more on this pattern, see `,_jsx(_components.a,{href:`/ax/instrument/advanced-patterns#inheriting-context-attributes-in-manual-spans`,children:`Advanced Patterns: Inheriting Context Attributes in Manual Spans`}),`.`]}),`\n`,_jsx(Heading,{level:`2`,id:`when-context-managers-help-and-when-they-don’t`,children:`When Context Managers Help (and When They Don’t)`}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{style:{textAlign:`left`},children:`Use a context manager when…`}),_jsx(_components.th,{style:{textAlign:`left`},children:`Set the attribute on the span directly when…`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{style:{textAlign:`left`},children:`The value applies to many spans (whole conversation, whole request).`}),_jsx(_components.td,{style:{textAlign:`left`},children:`The value applies to just this one span.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{style:{textAlign:`left`},children:`You’re using auto-instrumentation and can’t reach inside library code.`}),_jsx(_components.td,{style:{textAlign:`left`},children:`You’re creating the span by hand anyway.`})]}),_jsxs(_components.tr,{children:[_jsxs(_components.td,{style:{textAlign:`left`},children:[`You want to scope cross-cutting context cleanly with a `,_jsx(_components.code,{children:`with`}),` block.`]}),_jsx(_components.td,{style:{textAlign:`left`},children:`The value is computed from per-span data.`})]})]})]}),`\n`,_jsx(_components.hr,{}),`\n`,_jsx(Heading,{level:`2`,id:`next-step`,children:`Next step`}),`\n`,_jsx(_components.p,{children:`You’ve covered every approach to setting attributes. Next, the mechanics that keep traces intact across process, thread, and service boundaries — context propagation:`}),`\n`,_jsx(Card,{title:`Next: Context Propagation`,icon:`arrow-right`,href:`/ax/concepts/otel-openinference/context-propagation`})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"codeStyling":{"theme":{"light":"github-light-default","dark":"github-dark-default"}},"config":{},"pageMetadata":{"title":"OpenInference Context Managers","sidebarTitle":"Context managers","description":"Six context managers from openinference.instrumentation that attach session IDs, user IDs, metadata, tags, and prompt templates to every span in scope.","keywords":["using_session","using_user","using_metadata","using_tags","using_prompt_template","using_attributes","OpenInference","OITracer"],"href":"/ax/concepts/otel-openinference/context-managers"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"How They Work","slug":"how-they-work","depth":2,"children":[]},{"title":"The Six Helpers","slug":"the-six-helpers","depth":2,"children":[]},{"title":"using_session","slug":"using_session","depth":2,"children":[]},{"title":"using_user","slug":"using_user","depth":2,"children":[]},{"title":"using_metadata","slug":"using_metadata","depth":2,"children":[]},{"title":"using_tags","slug":"using_tags","depth":2,"children":[]},{"title":"using_prompt_template","slug":"using_prompt_template","depth":2,"children":[]},{"title":"using_attributes","slug":"using_attributes","depth":2,"children":[]},{"title":"Manual Spans and Context Inheritance","slug":"manual-spans-and-context-inheritance","depth":2,"children":[]},{"title":"When Context Managers Help (and When They Don’t)","slug":"when-context-managers-help-and-when-they-don’t","depth":2,"children":[]},{"title":"Next step","slug":"next-step","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":["/docs/_mintlify/custom/arize-ax/6a30b7a67da02161/analytics.js","/docs/_mintlify/custom/arize-ax/67a4d27b62fababa/product-selector.js"],"subdomain":"arize-ax","siteName":"Arize AX Docs","title":"OpenInference Context Managers - Arize AX Docs","contextualStarterQuestions":[],"navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-11-11T22:06:19.982Z","gitLastModified":"2026-09-14T15:05:13.000Z","originalFileLocation":"ax/concepts/otel-openinference/context-managers.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"dark\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"Six context managers from openinference.instrumentation that attach session IDs, user IDs, metadata, tags, and prompt templates to every span in scope.\">\u003cmeta data-mint-head name=\"application-name\" content=\"Arize AX Docs\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/docs/mintlify-assets/_mintlify/favicons/arize-ax/vxzD83QsbAzzm43O/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/docs/mintlify-assets/_mintlify/favicons/arize-ax/vxzD83QsbAzzm43O/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/docs/mintlify-assets/_mintlify/favicons/arize-ax/vxzD83QsbAzzm43O/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/docs/mintlify-assets/_mintlify/favicons/arize-ax/vxzD83QsbAzzm43O/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/docs/mintlify-assets/_mintlify/favicons/arize-ax/vxzD83QsbAzzm43O/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/docs/mintlify-assets/_mintlify/favicons/arize-ax/vxzD83QsbAzzm43O/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/docs/mintlify-assets/_mintlify/favicons/arize-ax/vxzD83QsbAzzm43O/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/docs/mintlify-assets/_mintlify/favicons/arize-ax/vxzD83QsbAzzm43O/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/docs/mintlify-assets/_mintlify/favicons/arize-ax/vxzD83QsbAzzm43O/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"OpenInference Context Managers - Arize AX Docs\">\u003cmeta data-mint-head property=\"og:description\" content=\"Six context managers from openinference.instrumentation that attach session IDs, user IDs, metadata, tags, and prompt templates to every span in scope.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Arize AX Docs\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://arize.com/docs/ax/concepts/otel-openinference/context-managers\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://arize-ax.mintlify.site/docs/_mintlify/api/og/v2?division=OpenTelemetry+and+OpenInference\u0026amp;title=OpenInference+Context+Managers\u0026amp;description=Six+context+managers+from+openinference.instrumentation+that+attach+session+IDs%2C+user+IDs%2C+metadata%2C+tags%2C+and+prompt+templates+to+every+span+in+scope.\u0026amp;theme=972bd1d2c11db90cc08206e1\u0026amp;signature=d52f2962025512fe8a27dcfb6894be2ffb1eb14995ac77643d4bf050f9744cd0\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"OpenInference Context Managers - Arize AX Docs\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Six context managers from openinference.instrumentation that attach session IDs, user IDs, metadata, tags, and prompt templates to every span in scope.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://arize-ax.mintlify.site/docs/_mintlify/api/og/v2?division=OpenTelemetry+and+OpenInference\u0026amp;title=OpenInference+Context+Managers\u0026amp;description=Six+context+managers+from+openinference.instrumentation+that+attach+session+IDs%2C+user+IDs%2C+metadata%2C+tags%2C+and+prompt+templates+to+every+span+in+scope.\u0026amp;theme=972bd1d2c11db90cc08206e1\u0026amp;signature=d52f2962025512fe8a27dcfb6894be2ffb1eb14995ac77643d4bf050f9744cd0\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/docs/mintlify-assets/_mintlify/favicons/arize-ax/vxzD83QsbAzzm43O/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Arize AX Docs\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#EA338A\">\u003clink data-mint-head rel=\"canonical\" href=\"https://arize.com/docs/ax/concepts/otel-openinference/context-managers\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/docs/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/docs/ax/concepts/otel-openinference/context-managers.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://arize.com/#organization\",\"name\":\"Arize AX Docs\",\"url\":\"https://arize.com\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/arize-ax/V-uvingrGLOCK4VD/logo/light.svg?fit=max\u0026auto=format\u0026n=V-uvingrGLOCK4VD\u0026q=85\u0026s=cc58ee9388d5b5253d39b65cc662908f\"}},{\"@type\":\"WebSite\",\"@id\":\"https://arize.com/docs#website\",\"name\":\"Arize AX Docs\",\"url\":\"https://arize.com/docs\",\"publisher\":{\"@id\":\"https://arize.com/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://arize.com/docs/ax/concepts/otel-openinference/context-managers#webpage\",\"url\":\"https://arize.com/docs/ax/concepts/otel-openinference/context-managers\",\"name\":\"OpenInference Context Managers\",\"description\":\"Six context managers from openinference.instrumentation that attach session IDs, user IDs, metadata, tags, and prompt templates to every span in scope.\",\"dateModified\":\"2026-09-14T15:05:13.000Z\",\"isPartOf\":{\"@id\":\"https://arize.com/docs#website\"},\"breadcrumb\":{\"@id\":\"https://arize.com/docs/ax/concepts/otel-openinference/context-managers#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://arize.com/docs/ax/concepts/otel-openinference/context-managers#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"OpenTelemetry and OpenInference\",\"item\":\"https://arize.com/docs/ax/concepts/otel-openinference/overview\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"OpenInference Context Managers\",\"item\":\"https://arize.com/docs/ax/concepts/otel-openinference/context-managers\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://arize.com/docs/ax/concepts/otel-openinference/context-managers#article\",\"headline\":\"OpenInference Context Managers\",\"name\":\"OpenInference Context Managers\",\"description\":\"Six context managers from openinference.instrumentation that attach session IDs, user IDs, metadata, tags, and prompt templates to every span in scope.\",\"url\":\"https://arize.com/docs/ax/concepts/otel-openinference/context-managers\",\"mainEntityOfPage\":{\"@id\":\"https://arize.com/docs/ax/concepts/otel-openinference/context-managers#webpage\"},\"dateModified\":\"2026-09-14T15:05:13.000Z\",\"keywords\":\"using_session, using_user, using_metadata, using_tags, using_prompt_template, using_attributes, OpenInference, OITracer\",\"publisher\":{\"@id\":\"https://arize.com/#organization\"},\"isPartOf\":{\"@id\":\"https://arize.com/docs#website\"}}]}\u003c/script>","agentPointerHref":"/docs/ax/concepts/otel-openinference/context-managers.md","siteName":"Arize AX Docs","nav":{"global":null,"tabs":[{"tab":"Get Started","pages":[{"title":"Get Started","href":"/ax"}]},{"tab":"Guides","pages":[{"title":"Guides","href":"/ax/cookbooks"}]},{"tab":"Integrations","pages":[{"title":"Integrations","href":"/ax/integrations"}]},{"tab":"APIs, SDKs, Skills \u0026 MCP","pages":[{"title":"APIs, SDKs, Skills \u0026 MCP","href":"/api-reference/overview"}]},{"tab":"Courses","pages":[{"title":"Courses","href":"/ax/learn/courses/overview"}]},{"tab":"Concepts","groups":[{"group":"OpenTelemetry and OpenInference","pages":[{"title":"OpenTelemetry and OpenInference","sidebarTitle":"Overview","href":"/ax/concepts/otel-openinference/overview"},{"title":"Signals, Spans, Traces, and Sessions","sidebarTitle":"Signals, spans, traces, and sessions","href":"/ax/concepts/otel-openinference/signals"},{"title":"Resource","sidebarTitle":"Resource","href":"/ax/concepts/otel-openinference/resource"},{"title":"Exporter and OTLP","sidebarTitle":"Exporter and OTLP","href":"/ax/concepts/otel-openinference/exporter"},{"title":"Span Processor","sidebarTitle":"Span processor","href":"/ax/concepts/otel-openinference/span-processor"},{"title":"Tracer Provider and Tracer","sidebarTitle":"Tracer provider and tracer","href":"/ax/concepts/otel-openinference/tracer-provider"},{"title":"The arize.otel Helpers","sidebarTitle":"arize.otel helpers","href":"/ax/concepts/otel-openinference/arize-otel-helpers"},{"title":"OpenInference Semantic Conventions","sidebarTitle":"Semantic conventions","href":"/ax/concepts/otel-openinference/semantic-conventions"},{"title":"OpenInference Span Kinds","sidebarTitle":"Span kinds","href":"/ax/concepts/otel-openinference/span-kinds"},{"title":"Instrumentation Approaches","sidebarTitle":"Instrumentation approaches","description":"Three ways to emit spans — auto-instrumentation, manual instrumentation, and hybrid — with trade-offs, mechanics, and the custom span processor pattern.","href":"/ax/concepts/otel-openinference/instrumentation-approaches"},{"title":"OpenInference Context Managers","sidebarTitle":"Context managers","href":"/ax/concepts/otel-openinference/context-managers"},{"title":"Context Propagation","sidebarTitle":"Context propagation","description":"How OpenTelemetry carries trace context across async boundaries, threads, and microservices — when propagation is automatic, when it's manual, and which propagators to use.","href":"/ax/concepts/otel-openinference/context-propagation"},{"title":"Sampling","sidebarTitle":"Sampling","href":"/ax/concepts/otel-openinference/sampling"},{"title":"OpenTelemetry Collector","sidebarTitle":"OpenTelemetry Collector","href":"/ax/concepts/otel-openinference/otel-collector"}]},{"group":"Prompts","pages":[{"title":"Prompts in Arize AX","sidebarTitle":"Overview","href":"/ax/concepts/prompts/overview"},{"title":"The Prompt Object","sidebarTitle":"The Prompt Object","href":"/ax/concepts/prompts/prompt-object"},{"title":"Versioning and Tags","sidebarTitle":"Versioning and tags","href":"/ax/concepts/prompts/versioning-and-tags"},{"title":"The Prompt Hub","sidebarTitle":"The Prompt Hub","href":"/ax/concepts/prompts/prompt-hub"},{"title":"Loading Prompts in Your Application","sidebarTitle":"Loading in applications","href":"/ax/concepts/prompts/loading-in-applications"},{"title":"The Prompt Playground","sidebarTitle":"The Prompt Playground","href":"/ax/concepts/prompts/prompt-playground"},{"title":"Datasets for Prompt Iteration","sidebarTitle":"Datasets","href":"/ax/concepts/prompts/datasets-for-prompts"},{"title":"Experiments for Prompts","sidebarTitle":"Experiments","href":"/ax/concepts/prompts/experiments-for-prompts"},{"title":"Prompts in CI/CD","sidebarTitle":"Prompts in CI/CD","href":"/ax/concepts/prompts/prompts-in-ci-cd"},{"title":"Optimizing Prompts","sidebarTitle":"Optimizing prompts","href":"/ax/concepts/prompts/optimizing-prompts"}]},{"group":"Evaluators","pages":[{"title":"Evaluators in Arize AX","sidebarTitle":"Overview","href":"/ax/concepts/evaluators/overview"},{"title":"Evaluation Levels — Span, Trace, and Session","sidebarTitle":"Evaluation levels","href":"/ax/concepts/evaluators/evaluation-levels"},{"title":"Evaluator Types — Human, Code, and LLM-as-a-Judge","sidebarTitle":"Evaluator types","href":"/ax/concepts/evaluators/evaluator-types"},{"title":"Anatomy of an Evaluator","sidebarTitle":"Anatomy of an evaluator","href":"/ax/concepts/evaluators/anatomy-of-an-evaluator"},{"title":"Online vs Offline Evaluators","sidebarTitle":"Online vs offline","href":"/ax/concepts/evaluators/online-vs-offline"},{"title":"Online LLM-as-a-Judge","sidebarTitle":"Online LLM-as-a-judge","href":"/ax/concepts/evaluators/online-llm-as-judge"},{"title":"Online Code Evaluators","sidebarTitle":"Online code evaluators","href":"/ax/concepts/evaluators/online-code-evaluators"},{"title":"Filters, Scope, and Cadence","sidebarTitle":"Filters, scope, and cadence","href":"/ax/concepts/evaluators/filters-scope-and-cadence"},{"title":"Offline Evaluation","sidebarTitle":"Offline evaluation","href":"/ax/concepts/evaluators/offline-evaluation-with-phoenix"},{"title":"Evaluating Agents","sidebarTitle":"Evaluating agents","href":"/ax/concepts/evaluators/evaluating-agents"},{"title":"Evaluator Best Practices","sidebarTitle":"Best practices","href":"/ax/concepts/evaluators/evaluator-best-practices"},{"title":"Validating and Improving Evaluators","sidebarTitle":"Validating and improving","href":"/ax/concepts/evaluators/validating-and-improving-evaluators"}]},{"group":"adb","pages":[{"title":"adb in Arize AX","sidebarTitle":"Overview","href":"/ax/concepts/adb/overview"},{"title":"adb architecture","sidebarTitle":"Architecture","href":"/ax/concepts/adb/architecture"},{"title":"Real-time ingestion in adb","sidebarTitle":"Real-time ingestion","href":"/ax/concepts/adb/real-time-ingestion"},{"title":"adb performance \u0026 benchmarks","sidebarTitle":"Performance \u0026 benchmarks","href":"/ax/concepts/adb/performance"}]}]},{"tab":"Self-Hosting","pages":[{"title":"Self-Hosting","href":"/ax/selfhosting"}]},{"tab":"Changelog","pages":[{"title":"Changelog","href":"/ax/release-notes"}]}]},"basePath":"","title":"OpenInference Context Managers - Arize AX Docs","deploymentId":"dpl_3UWrZQodFHfxeNZNwJGtAN3LFPAW","buildId":"dpl_3UWrZQodFHfxeNZNwJGtAN3LFPAW","dynamics":[],"chunks":[]}