Learn how to attach user ids to traces in Langtrace. You can use the withAdditionalAttributes or inject_additional_attributes function to pass user ids. This can inturn be used within Langtrace for filtering and grouping traces.
You can attach user ids to traces in Langtrace by simply wrapping your code with the withAdditionalAttributes for typescript or inject_additional_attributes function for python. This will add the specified attributes to the trace spans. Make sure to pass the user id as a key-value pair to the function.The key should be user_id and the value should be the user id. User ids should be unique for each user.
import * as Langtrace from "@langtrase/typescript-sdk";import OpenAI from 'openai'Langtrace.init({ write_spans_to_console: true,})const openai = new OpenAI()export const run = async ()=>{ const response = await Langtrace.withAdditionalAttributes(async () => { return await openai.chat.completions.create({ model: 'gpt-4', messages: [ { role: 'system', content: 'Talk like a pirate' }, { role: 'user', content: 'Tell me a story in 3 sentences or less.' } ], stream: false }) }, { user_id: "user1234" }) // Add user id to the trace spans}run().then(() => console.log('done'))
from langtrace_python_sdk import inject_additional_attributesdef do_llm_stuff(name=""): response = client.chat.completions.create( model="gpt-4", messages=[{"role": "user", "content": "Say this is a test three times"}], stream=False, ) return responsedef main(): response = inject_additional_attributes(lambda: do_llm_stuff(name="llm"), {'user_id': 'userid1234'}) # if the function do not take arguments then this syntax will work response = inject_additional_attributes(do_llm_stuff, {'user_id': 'userid1234'})main()
from langtrace_python_sdk import langtrace, with_additional_attributesfrom openai import OpenAIlangtrace.init(write_spans_to_console=True)openai = new OpenAI()@with_additional_attributes({'user_id': 1234, 'request_id': 'random_id'})def run(): response = openai.chat.completions.create( model="gpt-4", messages=[ {"role": "system", "content": "Talk like a pirate"}, {"role": "user", "content": "Tell me a story in 3 sentences or less."}, ], stream=True, ) return responserun()
DO NOT USE this the Python decorator - with_additional_attributes. It will be
deprecated soon. Please use inject_additional_attributes function instead.
Now, you can filter and group traces based on the user id. This can be useful for debugging and monitoring purposes.
{"docsConfig":{"$schema":"https://mintlify.com/docs.json","theme":"mint","name":"Langtrace AI Docs","colors":{"primary":"#005FAF","light":"#07C983","dark":"#005FAF"},"favicon":"/favicon.svg","logo":{"light":"https://mintcdn.com/langtraceai-2/-UwpI0EgGcwfnnlh/logo/light.svg?fit=max\u0026auto=format\u0026n=-UwpI0EgGcwfnnlh\u0026q=85\u0026s=77c6fb15878e0a52eb6a033906f6b2d7","dark":"https://mintcdn.com/langtraceai-2/-UwpI0EgGcwfnnlh/logo/dark.svg?fit=max\u0026auto=format\u0026n=-UwpI0EgGcwfnnlh\u0026q=85\u0026s=a60dcf3a9343815b24001622e4758ce1"},"api":{"playground":{"display":"none"},"mdx":{"server":"https://app.langtrace.ai/api","auth":{"method":"key","name":"x-api-key"}}},"navbar":{"links":[{"label":"Support","href":"/contact/contact-us"}],"primary":{"type":"button","label":"Langtrace App","href":"https://langtrace.ai"}},"footer":{"socials":{"twitter":"https://twitter.com/langtrace_ai?utm_source=langtrace-docs\u0026utm_medium=footer\u0026utm_campaign=langtrace-docs","github":"https://github.com/Scale3-Labs/langtrace","discord":"https://discord.com/invite/EaSATwtr4t","youtube":"https://www.youtube.com/channel/UCmqi7fUaU4kslkXl2qZFjNw?utm_source=langtrace-docs\u0026utm_medium=footer\u0026utm_campaign=langtrace-docs"}},"integrations":{"ga4":{"measurementId":"G-CLZFYWTWJR"}},"navigation":{"global":{"anchors":[{"anchor":"GitHub","href":"https://github.com/Scale3-Labs/langtrace","icon":"github"}]},"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"langtraceai-2","hasAudioNarration":false,"actualSubdomain":"langtraceai-2","customDomains":["docs.langtrace.ai"],"gitSource":{"type":"github","owner":"scale3-labs","repo":"langtrace-docs","deployBranch":"main","contentDirectory":"","isPrivate":false,"mountPath":"","label":""},"chroma":{"liveDeploymentHistoryId":"6a21e68b4c43fec466d79d3e","collectionId":"8dfb5abd-1639-487f-ab00-fa42b75659e8","schemaVersion":"v2"},"entitlements":{},"buildId":"6a21e68b4c43fec466d79d3e:success","clientVersion":"0.0.3918","searchFilterCounts":[{"language":"default","tag":"Documentation","count":95},{"language":"default","tag":"Supported Integrations","count":52},{"language":"default","tag":"LLM Frameworks","count":15},{"language":"default","tag":"LLM \u0026 Tools","count":14},{"language":"default","tag":"Tracing","count":13},{"language":"default","tag":"Features","count":12},{"language":"default","tag":"Hosting","count":10},{"language":"default","tag":"Getting Started","count":8},{"language":"default","tag":"Observability Tools","count":8},{"language":"default","tag":"Vector Stores","count":7}]},"assistantConfig":{},"hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[{"name":"kill-isr","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":"editor-v7-file-tree","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":"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":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"pause-universal-search-reconcile","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":"per-site-search-delta","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":"editor-branches-v2-autocommit","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-branches-v2","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":"editor-private-page-search","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":"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":"teamspace","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":"editor-nav-generations","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":"vite-origin","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":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"byok-sep-25","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":"editor-agent-model-picker","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"client-snapshot-docs-config","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}],"isAtlas":false,"googleFontsInlined":false},"customCss":[],"page":{"pagePath":"tracing/attach_user_id","slug":"/tracing/attach_user_id","pageMetadata":{"title":"Attach User IDs to Traces","sidebarTitle":"Attach User Id","description":"Learn how to attach user ids to traces in Langtrace. You can use the `withAdditionalAttributes` or `inject_additional_attributes` function to pass user ids. This can inturn be used within Langtrace for filtering and grouping traces.","href":"/tracing/attach_user_id"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx, jsxs: _jsxs} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n code: \"code\",\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsxs(_components.p, {\n children: [\"Learn how to attach user ids to traces in Langtrace. You can use the \", _jsx(_components.code, {\n children: \"withAdditionalAttributes\"\n }), \" or \", _jsx(_components.code, {\n children: \"inject_additional_attributes\"\n }), \" function to pass user ids. This can inturn be used within Langtrace for filtering and grouping traces.\"]\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={code:`code`,p:`p`,pre:`pre`,span:`span`,..._provideComponents(),...props.components},{CodeBlock,CodeGroup,OptimizedImage,Warning}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!CodeGroup)_missingMdxReference(`CodeGroup`,true);if(!OptimizedImage)_missingMdxReference(`OptimizedImage`,true);if(!Warning)_missingMdxReference(`Warning`,true);return _jsxs(_Fragment,{children:[_jsxs(_components.p,{children:[`You can attach user ids to traces in Langtrace by simply wrapping your code with the `,_jsx(_components.code,{children:`withAdditionalAttributes`}),` for typescript or `,_jsx(_components.code,{children:`inject_additional_attributes`}),` function for python. This will add the specified attributes to the trace spans. Make sure to pass the user id as a key-value pair to the function.`]}),`\n`,_jsxs(_components.p,{children:[`The key should be `,_jsx(_components.code,{children:`user_id`}),` and the value should be the user id. User ids should be unique for each user.`]}),`\n`,_jsxs(CodeGroup,{children:[_jsx(CodeBlock,{filename:`Typescript SDK`,numberOfLines:`19`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`19`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` *`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` as`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` Langtrace`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` from`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"@langtrase/typescript-sdk\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` OpenAI`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` from`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'openai'`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`Langtrace`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`init`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` write_spans_to_console:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` true`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`})`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` openai`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` new`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` OpenAI`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`()`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`export`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` const`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` run`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` async`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ()`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`=>`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` response`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` Langtrace`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`withAdditionalAttributes`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`async`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` () `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`=>`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` openai`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`chat`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`completions`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`create`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` model:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'gpt-4'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` messages:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` [`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`role:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'system'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'Talk like a pirate'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` },`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`role:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'user'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'Tell me a story in 3 sentences or less.'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ],`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` stream:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` false`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` })`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }, { `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`user_id:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"user1234\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }) `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// Add user id to the trace spans`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`run`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`().`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`then`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(() `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`=>`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'done'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`))`})]}),`\n`]})})}),_jsx(CodeBlock,{filename:`Python SDK - Function Based`,numberOfLines:`18`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`18`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` langtrace_python_sdk `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` inject_additional_attributes`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` do_llm_stuff`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`name`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` response `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` client.chat.completions.create(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` model`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"gpt-4\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` messages`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`[{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"role\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"user\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"content\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Say this is a test three times\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` stream`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`False`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` )`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` response`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` main`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`():`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` response `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` inject_additional_attributes(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`lambda`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: do_llm_stuff(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`name`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"llm\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`), {`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'user_id'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'userid1234'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`})`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` # if the function do not take arguments then this syntax will work`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` response `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` inject_additional_attributes(do_llm_stuff, {`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'user_id'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'userid1234'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`})`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`main()`})}),`\n`]})})}),_jsx(CodeBlock,{filename:`Python SDK - Decorator Based`,numberOfLines:`19`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`19`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` langtrace_python_sdk `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` langtrace, with_additional_attributes`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` openai `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` OpenAI`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`langtrace.init(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`write_spans_to_console`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`openai `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` new OpenAI()`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`@with_additional_attributes`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'user_id'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`1234`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'request_id'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'random_id'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`})`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` run`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`():`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` response `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` openai.chat.completions.create(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` model`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"gpt-4\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` messages`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`[`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"role\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"system\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"content\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Talk like a pirate\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`},`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"role\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"user\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"content\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Tell me a story in 3 sentences or less.\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`},`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ],`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` stream`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` )`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` response`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`run()`})}),`\n`]})})})]}),`\n`,_jsxs(Warning,{children:[` `,_jsxs(_components.p,{children:[`DO NOT USE this the Python decorator - `,_jsx(_components.code,{children:`with_additional_attributes`}),`. It will be\ndeprecated soon. Please use `,_jsx(_components.code,{children:`inject_additional_attributes`}),` function instead.`]})]}),`\n`,_jsx(_components.p,{children:`Now, you can filter and group traces based on the user id. This can be useful for debugging and monitoring purposes.`}),`\n`,_jsx(OptimizedImage,{src:`https://mintcdn.com/langtraceai-2/m7BVnnhK3Cx2yRxS/images/pass_user_id.png?fit=max\u0026auto=format\u0026n=m7BVnnhK3Cx2yRxS\u0026q=85\u0026s=70196e91071ba3bc515115b5cb76bf1e`,alt:`userid`,\"data-og-width\":`3138`,width:`3138`,\"data-og-height\":`1896`,height:`1896`,\"data-path\":`images/pass_user_id.png`,\"data-optimize\":`true`,\"data-opv\":`3`,srcset:`https://mintcdn.com/langtraceai-2/m7BVnnhK3Cx2yRxS/images/pass_user_id.png?w=280\u0026fit=max\u0026auto=format\u0026n=m7BVnnhK3Cx2yRxS\u0026q=85\u0026s=c814c936bd310bdc274e38d2c5d65542 280w, https://mintcdn.com/langtraceai-2/m7BVnnhK3Cx2yRxS/images/pass_user_id.png?w=560\u0026fit=max\u0026auto=format\u0026n=m7BVnnhK3Cx2yRxS\u0026q=85\u0026s=0a2d434e4cbb8953ef028a1d67061d3f 560w, https://mintcdn.com/langtraceai-2/m7BVnnhK3Cx2yRxS/images/pass_user_id.png?w=840\u0026fit=max\u0026auto=format\u0026n=m7BVnnhK3Cx2yRxS\u0026q=85\u0026s=fd8fd84bec43b3e7882aaf0e2c7d9b35 840w, https://mintcdn.com/langtraceai-2/m7BVnnhK3Cx2yRxS/images/pass_user_id.png?w=1100\u0026fit=max\u0026auto=format\u0026n=m7BVnnhK3Cx2yRxS\u0026q=85\u0026s=cc5a30ba7a22e706d53dacf74cd3253b 1100w, https://mintcdn.com/langtraceai-2/m7BVnnhK3Cx2yRxS/images/pass_user_id.png?w=1650\u0026fit=max\u0026auto=format\u0026n=m7BVnnhK3Cx2yRxS\u0026q=85\u0026s=3172903fa1391e21c74b869be08d1dea 1650w, https://mintcdn.com/langtraceai-2/m7BVnnhK3Cx2yRxS/images/pass_user_id.png?w=2500\u0026fit=max\u0026auto=format\u0026n=m7BVnnhK3Cx2yRxS\u0026q=85\u0026s=28a23874acd4411fe789a352a131b149 2500w`})]})}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":{"config":{},"pageMetadata":{"title":"Attach User IDs to Traces","sidebarTitle":"Attach User Id","description":"Learn how to attach user ids to traces in Langtrace. You can use the `withAdditionalAttributes` or `inject_additional_attributes` function to pass user ids. This can inturn be used within Langtrace for filtering and grouping traces.","href":"/tracing/attach_user_id"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[],"codeExamples":{}},"jsLinks":[],"subdomain":"langtraceai-2","siteName":"Langtrace AI Docs","title":"Attach User IDs to Traces - Langtrace AI Docs","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-01-07T06:43:01.815Z","originalFileLocation":"tracing/attach_user_id.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=\"system\"}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=\"Learn how to attach user ids to traces in Langtrace. You can use the withAdditionalAttributes or inject_additional_attributes function to pass user ids. This can inturn be used within Langtrace for filtering and grouping traces.\">\u003cmeta data-mint-head name=\"application-name\" content=\"Langtrace AI Docs\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/langtraceai-2/gZzt63U8gw8c3MYo/_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=\"/mintlify-assets/_mintlify/favicons/langtraceai-2/gZzt63U8gw8c3MYo/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/langtraceai-2/gZzt63U8gw8c3MYo/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/langtraceai-2/gZzt63U8gw8c3MYo/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/langtraceai-2/gZzt63U8gw8c3MYo/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/langtraceai-2/gZzt63U8gw8c3MYo/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/langtraceai-2/gZzt63U8gw8c3MYo/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/langtraceai-2/gZzt63U8gw8c3MYo/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/langtraceai-2/gZzt63U8gw8c3MYo/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Attach User IDs to Traces - Langtrace AI Docs\">\u003cmeta data-mint-head property=\"og:description\" content=\"Learn how to attach user ids to traces in Langtrace. You can use the withAdditionalAttributes or inject_additional_attributes function to pass user ids. This can inturn be used within Langtrace for filtering and grouping traces.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Langtrace AI Docs\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.langtrace.ai/tracing/attach_user_id\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://langtraceai-2.mintlify.app/_mintlify/api/og/v2?division=Features\u0026amp;title=Attach+User+IDs+to+Traces\u0026amp;description=Learn+how+to+attach+user+ids+to+traces+in+Langtrace.+You+can+use+the+%60withAdditionalAttributes%60+or+%60inject_additional_attributes%60+function+to+pass+user+ids.+Thi\u0026amp;theme=6ab898ec3a9cdae09d5322a0\u0026amp;signature=d4043bf5828393251c61c72817fdb978f0253837a05963979cbb74c8d0b2cfe7\">\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=\"Attach User IDs to Traces - Langtrace AI Docs\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Learn how to attach user ids to traces in Langtrace. You can use the withAdditionalAttributes or inject_additional_attributes function to pass user ids. This can inturn be used within Langtrace for filtering and grouping traces.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://langtraceai-2.mintlify.app/_mintlify/api/og/v2?division=Features\u0026amp;title=Attach+User+IDs+to+Traces\u0026amp;description=Learn+how+to+attach+user+ids+to+traces+in+Langtrace.+You+can+use+the+%60withAdditionalAttributes%60+or+%60inject_additional_attributes%60+function+to+pass+user+ids.+Thi\u0026amp;theme=6ab898ec3a9cdae09d5322a0\u0026amp;signature=d4043bf5828393251c61c72817fdb978f0253837a05963979cbb74c8d0b2cfe7\">\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=\"/mintlify-assets/_mintlify/favicons/langtraceai-2/gZzt63U8gw8c3MYo/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Langtrace AI Docs\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#005FAF\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.langtrace.ai/tracing/attach_user_id\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/tracing/attach_user_id.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.langtrace.ai/#organization\",\"name\":\"Langtrace AI Docs\",\"url\":\"https://docs.langtrace.ai\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/langtraceai-2/-UwpI0EgGcwfnnlh/logo/light.svg?fit=max\u0026auto=format\u0026n=-UwpI0EgGcwfnnlh\u0026q=85\u0026s=77c6fb15878e0a52eb6a033906f6b2d7\"}},{\"@type\":\"WebSite\",\"@id\":\"https://docs.langtrace.ai#website\",\"name\":\"Langtrace AI Docs\",\"url\":\"https://docs.langtrace.ai\",\"publisher\":{\"@id\":\"https://docs.langtrace.ai/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.langtrace.ai/tracing/attach_user_id#webpage\",\"url\":\"https://docs.langtrace.ai/tracing/attach_user_id\",\"name\":\"Attach User IDs to Traces\",\"description\":\"Learn how to attach user ids to traces in Langtrace. You can use the withAdditionalAttributes or inject_additional_attributes function to pass user ids. This can inturn be used within Langtrace for filtering and grouping traces.\",\"dateModified\":\"2026-01-07T06:43:01.815Z\",\"isPartOf\":{\"@id\":\"https://docs.langtrace.ai#website\"},\"breadcrumb\":{\"@id\":\"https://docs.langtrace.ai/tracing/attach_user_id#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.langtrace.ai/tracing/attach_user_id#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Tracing\",\"item\":\"https://docs.langtrace.ai/tracing/overview\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Features\",\"item\":\"https://docs.langtrace.ai/tracing/send_traces\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Attach User IDs to Traces\",\"item\":\"https://docs.langtrace.ai/tracing/attach_user_id\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://docs.langtrace.ai/tracing/attach_user_id#article\",\"headline\":\"Attach User IDs to Traces\",\"name\":\"Attach User IDs to Traces\",\"description\":\"Learn how to attach user ids to traces in Langtrace. You can use the withAdditionalAttributes or inject_additional_attributes function to pass user ids. This can inturn be used within Langtrace for filtering and grouping traces.\",\"url\":\"https://docs.langtrace.ai/tracing/attach_user_id\",\"mainEntityOfPage\":{\"@id\":\"https://docs.langtrace.ai/tracing/attach_user_id#webpage\"},\"dateModified\":\"2026-01-07T06:43:01.815Z\",\"publisher\":{\"@id\":\"https://docs.langtrace.ai/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.langtrace.ai#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"Langtrace AI Docs\",\"creator\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","siteName":"Langtrace AI Docs","nav":{"global":{"anchors":[{"anchor":"GitHub","href":"https://github.com/Scale3-Labs/langtrace","icon":"github"}]},"anchors":[{"anchor":"Documentation","icon":"book-open","groups":[{"group":"Getting Started","pages":[{"title":"Introduction","href":"/introduction"},{"title":"Quickstart","href":"/quickstart"},{"title":"How to Guides","href":"/how-to-guides"},{"title":"Concepts","href":"/concepts"},{"group":"SDK","pages":[{"title":"Langtrace Python SDK","sidebarTitle":"Python SDK","href":"/sdk/python_sdk"},{"title":"Langtrace Typescript SDK","sidebarTitle":"Typescript SDK","href":"/sdk/typescript_sdk"},{"title":"Langtrace SDK Features","sidebarTitle":"Features","href":"/sdk/sdk_features"}]},{"title":"FAQs","href":"/faqs"}]},{"group":"Tracing","pages":[{"title":"Tracing Overview","href":"/tracing/overview"},{"group":"Features","pages":[{"title":"Sending Traces","sidebarTitle":"Sending Traces","href":"/tracing/send_traces"},{"title":"Grouping Operations","sidebarTitle":"Grouping Traces","href":"/tracing/group_traces"},{"title":"Pass User Feedback","sidebarTitle":"Passing User Feedback","description":"The Langtrace SDK gives you the ability to pass user feedback from your application as scores for measuring accuracy.","href":"/tracing/trace_user_feedback"},{"title":"Attach User IDs to Traces","sidebarTitle":"Attach User Id","href":"/tracing/attach_user_id"},{"title":"Attach Prompt IDs and Versions to Traces","sidebarTitle":"Attach Prompt Id / Version","description":"Learn how to attach prompt ids and prompt versions to traces in Langtrace. You can use the `withAdditionalAttributes` or `inject_additional_attributes` function to pass prompt ids / versions. This can inturn be used within Langtrace for filtering and grouping traces.","href":"/tracing/attach_prompt_id"},{"title":"Add Additional Attributes to Traces","sidebarTitle":"Additional Attributes","href":"/tracing/additional_attributes"},{"title":"Disable Tracing For Functions","sidebarTitle":"Disable Function Tracing","href":"/tracing/disable_function_tracing"},{"title":"Disable Tracing For Specific Vendors","href":"/tracing/disable_vendor_instrumentation"},{"title":"Disable Tracing For Prompts \u0026 Completions","href":"/tracing/disable_prompt_\u0026_completions_tracing"},{"title":"Set custom span names to traces","sidebarTitle":"Set Custom Span Name","href":"/tracing/custom_span_naming"},{"title":"Filtering Traces by Session ID","sidebarTitle":"Filtering Traces by Session ID","href":"/tracing/filter_by_session_id"},{"title":null,"href":"/tracing/openai/chat-completion"}]}]},{"group":"Prompting","pages":[{"title":"Manage Prompts","sidebarTitle":"Manage Prompts","href":"/features/manage_prompts"},{"title":"Manage Zod Schema for Tool Calling","sidebarTitle":"Tool Calling Schema","href":"/features/manage_zod_schema"},{"title":"Model Playground","sidebarTitle":"Model Playground","href":"/features/playground"}]},{"group":"Evaluations \u0026 Testing","pages":[{"title":"Evaluations","href":"/features/evaluations"},{"title":"Compare Evaluations","href":"/features/compare-evaluations"},{"title":"Annotations","href":"/features/annotations"}]},{"group":"Supported Integrations","pages":[{"title":"Overview","href":"/supported-integrations/overview"},{"group":"LLM \u0026 Tools","pages":[{"title":"Anthropic","href":"/supported-integrations/llm-tools/anthropic"},{"title":"Arch","href":"/supported-integrations/llm-tools/arch"},{"title":"Azure-OpenAI","href":"/supported-integrations/llm-tools/azure-openai"},{"title":"Cerebras","href":"/supported-integrations/llm-tools/cerebras"},{"title":"Cohere","href":"/supported-integrations/llm-tools/cohere"},{"title":"DeepSeek","href":"/supported-integrations/llm-tools/deepseek"},{"title":"Gemini","href":"/supported-integrations/llm-tools/gemini"},{"title":"Groq","href":"/supported-integrations/llm-tools/groq"},{"title":"Mistral AI","href":"/supported-integrations/llm-tools/mistral-ai"},{"title":"KubeAI","href":"/supported-integrations/llm-tools/kubeai"},{"title":"Ollama","href":"/supported-integrations/llm-tools/ollama"},{"title":"OpenAI","href":"/supported-integrations/llm-tools/openai"},{"title":"Perplexity","href":"/supported-integrations/llm-tools/perplexity"},{"title":"xAI","href":"/supported-integrations/llm-tools/xai"}]},{"group":"LLM Frameworks","pages":[{"title":"LlamaIndex","href":"/supported-integrations/llm-frameworks/llamaindex"},{"title":"Langchain","href":"/supported-integrations/llm-frameworks/langchain"},{"title":"CrewAI","href":"/supported-integrations/llm-frameworks/crewai"},{"title":"DSPy","href":"/supported-integrations/llm-frameworks/dspy"},{"title":"Mem0","href":"/supported-integrations/llm-frameworks/mem0"},{"title":"OpenAI Agents SDK","href":"/supported-integrations/llm-frameworks/openai-agents-sdk"},{"title":"SwarmZero","sidebarTitle":"SwarmZero","href":"/supported-integrations/llm-frameworks/swarmzero"},{"title":"Vercel AI SDK","sidebarTitle":"Vercel AI","href":"/supported-integrations/llm-frameworks/vercelaisdk"},{"title":"LiteLLM","href":"/supported-integrations/llm-frameworks/litellm"},{"title":"AWS Bedrock","href":"/supported-integrations/llm-frameworks/bedrock"},{"title":"Graphlit","href":"/supported-integrations/llm-frameworks/graphlit"},{"title":"Guardrails","href":"/supported-integrations/llm-frameworks/guardrails"},{"title":"Agno","href":"/supported-integrations/llm-frameworks/agno"},{"title":"Cleanlab","href":"/supported-integrations/llm-frameworks/cleanlab"},{"title":"Neo4j GraphRAG","href":"/supported-integrations/llm-frameworks/neo4j-graphrag"}]},{"group":"Observability Tools","pages":[{"title":"Dash0","href":"/supported-integrations/observability-tools/dash0"},{"title":"Elastic APM","href":"/supported-integrations/observability-tools/elastic"},{"title":"Grafana Cloud","href":"/supported-integrations/observability-tools/grafana"},{"title":"SigNoz","href":"/supported-integrations/observability-tools/signoz"},{"title":"New Relic","href":"/supported-integrations/observability-tools/newrelic"},{"title":"Datadog","href":"/supported-integrations/observability-tools/datadog"},{"title":"Honeycomb","href":"/supported-integrations/observability-tools/honeycomb"},{"title":"IBM Instana","href":"/supported-integrations/observability-tools/ibm-instana"}]},{"group":"Vector Stores","pages":[{"title":"ChromaDB","href":"/supported-integrations/vector-stores/chromadb"},{"title":"Pinecone","href":"/supported-integrations/vector-stores/pinecone"},{"title":"Qdrant","href":"/supported-integrations/vector-stores/qdrant"},{"title":"Weaviate","href":"/supported-integrations/vector-stores/weaviate"},{"title":"MongoDB Vector Search","href":"/supported-integrations/vector-stores/mongodb"},{"title":"Milvus Vector Database","href":"/supported-integrations/vector-stores/milvus"},{"title":"Neo4j","href":"/supported-integrations/vector-stores/neo4j"}]},{"group":"Web Frameworks","pages":[{"title":"FastAPI","href":"/supported-integrations/web-frameworks/fastapi"},{"title":"Flask","href":"/supported-integrations/web-frameworks/flask"},{"title":"Django","href":"/supported-integrations/web-frameworks/django"},{"title":"NextJS","href":"/supported-integrations/web-frameworks/nextjs"}]},{"group":"OTEL Exporters","pages":[{"title":"OTEL Configuration","sidebarTitle":"Configuration","href":"/supported-integrations/otel-support/otel-configuration"},{"title":"TypeScript SDK","href":"/supported-integrations/otel-support/ts-http-json"},{"title":"Python SDK","href":"/supported-integrations/otel-support/python-http-json"}]}]},{"group":"API Reference","pages":[{"group":"Project APIs","pages":[{"title":"POST Project","api":"POST /project","href":"/api-reference/project/POST-project"},{"title":"POST Project API Key","api":"POST /api-key","href":"/api-reference/project/POST-project-api-key"}]},{"group":"Prompt Registry APIs","pages":[{"title":"GET Prompt from Registry","api":"GET /promptset","href":"/api-reference/prompt-registry/GET-prompt-registry"}]},{"group":"Traces API","pages":[{"title":"POST Traces","api":"POST /traces","href":"/api-reference/traces/POST-traces"},{"title":"Send Trace","api":"POST /api/trace","href":"/api-reference/traces/POST-trace"}]}]},{"group":"Hosting","pages":[{"title":"Overview","href":"/hosting/overview"},{"title":"Authentication","href":"/hosting/auth"},{"title":"Langtrace Self-Hosting Configuration","sidebarTitle":"Configuration","href":"/hosting/using_local_setup"},{"title":null,"href":"/hosting/traces_retention"},{"title":"Recommended Configurations","href":"/hosting/recommended_configurations"},{"group":"Hosting Options","pages":[{"title":"Docker Setup","sidebarTitle":"Docker","href":"/hosting/hosting_options/docker-standalone"},{"title":"Docker Compose Setup","sidebarTitle":"Docker Compose","href":"/hosting/hosting_options/docker-compose"},{"title":"Langtrace on Kubernetes","sidebarTitle":"Kubernetes","href":"/hosting/hosting_options/kubernetes"},{"title":"Langtrace Setup on Azure","sidebarTitle":"Azure","href":"/hosting/hosting_options/azure"},{"title":"Langtrace on Railway","sidebarTitle":"Railway","href":"/hosting/hosting_options/railway"}]}]},{"group":"Contact Us","pages":[{"title":"Contact Us","sidebarTitle":"Contact Us","href":"/contact/contact-us"}]}]}]},"title":"Attach User IDs to Traces - Langtrace AI Docs","buildId":"dpl_22zLaHtK6fmmSqApXTTP5tC7UBZn","deploymentId":"dpl_22zLaHtK6fmmSqApXTTP5tC7UBZn","dynamics":["a74be98ba7"],"chunks":["zoom-image-lightbox-BxIiCHya.js","PlusIcon-Br4qdG7I.js","lightbox-handle-r17bVUz3.js"]}