How to use OpenLLMetry with ThreadPoolExecutor and other thread-based libraries.
Since many LLM operations tend to be I/O bound, it is often useful to use threads to perform multiple operations at once.
Usually, you’ll use the ThreadPoolExecutor class from the concurrent.futures module in the Python standard library, like this:
indexes = [pinecone.Index(f"index{i}") for i in range(3)]executor = ThreadPoolExecutor(max_workers=3)for i in range(3): executor.submit(indexes[i].query, [1.0, 2.0, 3.0], top_k=10)
Unfortunately, this won’t work as you expect and may cause you to see “broken” traces or missing spans.
The reason relies in how OpenTelemetry (which is what we use under the hood in OpenLLMetry, hence the name)
uses Python’s context to propagate the trace.
You’ll need to explictly propagate the context to the threads:
indexes = [pinecone.Index(f"index{i}") for i in range(3)]executor = ThreadPoolExecutor(max_workers=3)for i in range(3): ctx = contextvars.copy_context() executor.submit( ctx.run, functools.partial(index.query, [1.0, 2.0, 3.0], top_k=10), )
{"docsConfig":{"$schema":"https://mintlify.com/docs.json","theme":"mint","name":"traceloop","colors":{"primary":"#EAB308","light":"#EAB308","dark":"#EAB308"},"favicon":"https://mintcdn.com/enrolla/-xQ9K52hAYrcQGvz/favicon.png?fit=max\u0026auto=format\u0026n=-xQ9K52hAYrcQGvz\u0026q=85\u0026s=6066426161fe311654d19ebca89ee7c0","logo":{"light":"https://mintcdn.com/enrolla/GspX1ocwd1gETLy0/logo/traceloop-light.png?fit=max\u0026auto=format\u0026n=GspX1ocwd1gETLy0\u0026q=85\u0026s=e245f77b5b8af11ef9aa4a0ce2ee97a6","dark":"https://mintcdn.com/enrolla/GspX1ocwd1gETLy0/logo/traceloop-dark.png?fit=max\u0026auto=format\u0026n=GspX1ocwd1gETLy0\u0026q=85\u0026s=d34d3b622526506a2a4512b32d4ebb9b"},"api":{"openapi":"openapi.json","mdx":{"server":"https://app.traceloop.com/api","auth":{"method":"bearer","name":null}}},"appearance":{"default":"dark","strict":null},"background":{"decoration":null,"color":{"light":null,"dark":"#09090B"}},"navbar":{"links":[{"label":"Community","href":"https://traceloop.com/slack"},{"label":"Support","href":"https://support.traceloop.com"}],"primary":{"type":"button","label":"Start now","href":"https://app.traceloop.com/"}},"footer":{"socials":{"github":"https://github.com/traceloop","twitter":"https://twitter.com/traceloopdev"}},"integrations":{"gtm":{"tagId":"GTM-NDQVZMH"}},"styling":{"latex":false},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"enrolla","hasAudioNarration":false,"actualSubdomain":"enrolla","customDomains":["www.traceloop.com"],"gitSource":{"type":"github","owner":"traceloop","repo":"docs","deployBranch":"main","contentDirectory":"","isPrivate":false,"mountPath":"","label":""},"chroma":{"liveDeploymentHistoryId":"6a50ddc4a3ca9e4edbc90a63","collectionId":"adc0afa5-95ac-4624-90b0-9d9b79bb22a1","schemaVersion":"v3"},"feedback":{"thumbs":true,"edits":true},"entitlements":{"AI_CHAT":{"status":"ENABLED"},"WEB_MCP":{"status":"ENABLED"},"NARRATION":{"status":"ENABLED"}},"buildId":"6a50ddc4a3ca9e4edbc90a63:success","clientVersion":"0.0.4044","searchFilterCounts":[{"language":"default","tag":"Dashboard API","count":55},{"language":"default","tag":"OpenLLMetry","count":55},{"language":"default","tag":"Evaluators","count":43},{"language":"default","tag":"Integrations","count":34},{"language":"default","tag":"Documentation","count":30},{"language":"default","tag":"Tracing","count":14},{"language":"default","tag":"Quick Start","count":9},{"language":"default","tag":"Auto-monitor-setups","count":6},{"language":"default","tag":"Playgrounds","count":4},{"language":"default","tag":"Self-host","count":4}]},"assistantConfig":{},"basePath":"/docs","hasChatPermissions":true,"hasWebMcpPermissions":true,"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":"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":"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":"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":"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":"vite-origin","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-updated-9-15","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-sso-scim","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":"workos-signup","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":"workos-enabled","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":"sso-setup-deadline-banner","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"googleFontsInlined":false},"customCss":[{"filePath":"style.css","content":"#topbar-cta-button span,#topbar-cta-button svg{color:#09090b!important}#topbar-cta-button span.absolute{border-radius:8px!important}.nav-logo{width:140px!important}"}],"page":{"pagePath":"openllmetry/tracing/python-threads","slug":"/openllmetry/tracing/python-threads","pageMetadata":{"title":"Usage with Threads (Python)","description":"How to use OpenLLMetry with `ThreadPoolExecutor` and other thread-based libraries.","href":"/openllmetry/tracing/python-threads"},"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: [\"How to use OpenLLMetry with \", _jsx(_components.code, {\n children: \"ThreadPoolExecutor\"\n }), \" and other thread-based libraries.\"]\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`,p:`p`,pre:`pre`,span:`span`,..._provideComponents(),...props.components},{CodeBlock}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);return _jsxs(_Fragment,{children:[_jsxs(_components.p,{children:[`Since many LLM operations tend to be I/O bound, it is often useful to use threads to perform multiple operations at once.\nUsually, you’ll use the `,_jsx(_components.code,{children:`ThreadPoolExecutor`}),` class from the `,_jsx(_components.code,{children:`concurrent.futures`}),` module in the Python standard library, like this:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`4`,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:`4`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`indexes `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` [pinecone.Index(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"index`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`i`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` i `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` range`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`3`}),_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:`executor `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ThreadPoolExecutor(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`max_workers`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`3`}),_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:`for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` i `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` range`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`3`}),_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:` executor.submit(indexes[i].query, [`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`1.0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`2.0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`3.0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`], `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`top_k`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`10`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`Unfortunately, this won’t work as you expect and may cause you to see “broken” traces or missing spans.\nThe reason relies in how OpenTelemetry (which is what we use under the hood in OpenLLMetry, hence the name)\nuses `,_jsx(_components.a,{href:`https://docs.python.org/3/library/contextvars.html`,children:`Python’s context`}),` to propagate the trace.\nYou’ll need to explictly propagate the context to the threads:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`8`,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:`8`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`indexes `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` [pinecone.Index(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"index`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`i`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` i `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` range`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`3`}),_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:`executor `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ThreadPoolExecutor(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`max_workers`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`3`}),_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:`for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` i `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` range`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`3`}),_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:` ctx `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` contextvars.copy_context()`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` executor.submit(`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ctx.run,`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` functools.partial(index.query, [`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`1.0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`2.0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`3.0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`], `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`top_k`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`10`}),_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`]})})}),`\n`,_jsxs(_components.p,{children:[`Also check out the `,_jsx(_components.a,{href:`https://github.com/traceloop/openllmetry/blob/main/packages/sample-app/sample_app/thread_pool_example.py`,children:`full example`}),`.`]})]})}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":"Usage with Threads (Python)","description":"How to use OpenLLMetry with `ThreadPoolExecutor` and other thread-based libraries.","href":"/openllmetry/tracing/python-threads"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[],"codeExamples":{}},"jsLinks":["/docs/_mintlify/custom/enrolla/99d79fc3a15df79c/vibekit.js","/docs/_mintlify/custom/enrolla/a052f9c2fb91f2bb/scripts/filter-openapi.js","/docs/_mintlify/custom/enrolla/f023a04dbd14c606/scripts/update-mint-navigation.js"],"subdomain":"enrolla","siteName":"traceloop","title":"Usage with Threads (Python) - traceloop","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-01-25T08:51:17.459Z","originalFileLocation":"openllmetry/tracing/python-threads.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=\"How to use OpenLLMetry with ThreadPoolExecutor and other thread-based libraries.\">\u003cmeta data-mint-head name=\"application-name\" content=\"traceloop\">\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/enrolla/c4jFPLhIQoqlp6LG/_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/enrolla/c4jFPLhIQoqlp6LG/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/docs/mintlify-assets/_mintlify/favicons/enrolla/c4jFPLhIQoqlp6LG/_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/enrolla/c4jFPLhIQoqlp6LG/_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/enrolla/c4jFPLhIQoqlp6LG/_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/enrolla/c4jFPLhIQoqlp6LG/_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/enrolla/c4jFPLhIQoqlp6LG/_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/enrolla/c4jFPLhIQoqlp6LG/_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/enrolla/c4jFPLhIQoqlp6LG/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Usage with Threads (Python) - traceloop\">\u003cmeta data-mint-head property=\"og:description\" content=\"How to use OpenLLMetry with ThreadPoolExecutor and other thread-based libraries.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"traceloop\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://www.traceloop.com/docs/openllmetry/tracing/python-threads\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://enrolla.mintlify.app/_mintlify/api/og/v2?division=Tracing\u0026amp;title=Usage+with+Threads+%28Python%29\u0026amp;description=How+to+use+OpenLLMetry+with+%60ThreadPoolExecutor%60+and+other+thread-based+libraries.\u0026amp;theme=ff62921debafe09ea1aaaffe\u0026amp;signature=ebe4d57879b1787d5d287b630eb464b7ee9a607bdbb32f0e8eb3ee23564caabb\">\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=\"Usage with Threads (Python) - traceloop\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"How to use OpenLLMetry with ThreadPoolExecutor and other thread-based libraries.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://enrolla.mintlify.app/_mintlify/api/og/v2?division=Tracing\u0026amp;title=Usage+with+Threads+%28Python%29\u0026amp;description=How+to+use+OpenLLMetry+with+%60ThreadPoolExecutor%60+and+other+thread-based+libraries.\u0026amp;theme=ff62921debafe09ea1aaaffe\u0026amp;signature=ebe4d57879b1787d5d287b630eb464b7ee9a607bdbb32f0e8eb3ee23564caabb\">\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/enrolla/c4jFPLhIQoqlp6LG/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"traceloop\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#EAB308\">\u003clink data-mint-head rel=\"canonical\" href=\"https://www.traceloop.com/docs/openllmetry/tracing/python-threads\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/docs/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/docs/openllmetry/tracing/python-threads.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://www.traceloop.com/#organization\",\"name\":\"traceloop\",\"url\":\"https://www.traceloop.com\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/enrolla/GspX1ocwd1gETLy0/logo/traceloop-light.png?fit=max\u0026auto=format\u0026n=GspX1ocwd1gETLy0\u0026q=85\u0026s=e245f77b5b8af11ef9aa4a0ce2ee97a6\"}},{\"@type\":\"WebSite\",\"@id\":\"https://www.traceloop.com/docs#website\",\"name\":\"traceloop\",\"url\":\"https://www.traceloop.com/docs\",\"publisher\":{\"@id\":\"https://www.traceloop.com/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://www.traceloop.com/docs/openllmetry/tracing/python-threads#webpage\",\"url\":\"https://www.traceloop.com/docs/openllmetry/tracing/python-threads\",\"name\":\"Usage with Threads (Python)\",\"description\":\"How to use OpenLLMetry with ThreadPoolExecutor and other thread-based libraries.\",\"dateModified\":\"2026-01-25T08:51:17.459Z\",\"isPartOf\":{\"@id\":\"https://www.traceloop.com/docs#website\"},\"breadcrumb\":{\"@id\":\"https://www.traceloop.com/docs/openllmetry/tracing/python-threads#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://www.traceloop.com/docs/openllmetry/tracing/python-threads#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Tracing\",\"item\":\"https://www.traceloop.com/docs/openllmetry/tracing/supported\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Usage with Threads (Python)\",\"item\":\"https://www.traceloop.com/docs/openllmetry/tracing/python-threads\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://www.traceloop.com/docs/openllmetry/tracing/python-threads#article\",\"headline\":\"Usage with Threads (Python)\",\"name\":\"Usage with Threads (Python)\",\"description\":\"How to use OpenLLMetry with ThreadPoolExecutor and other thread-based libraries.\",\"url\":\"https://www.traceloop.com/docs/openllmetry/tracing/python-threads\",\"mainEntityOfPage\":{\"@id\":\"https://www.traceloop.com/docs/openllmetry/tracing/python-threads#webpage\"},\"dateModified\":\"2026-01-25T08:51:17.459Z\",\"publisher\":{\"@id\":\"https://www.traceloop.com/#organization\"},\"isPartOf\":{\"@id\":\"https://www.traceloop.com/docs#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"traceloop\",\"creator\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","siteName":"traceloop","nav":{"global":null,"anchors":[{"anchor":"Documentation","icon":"book-open","pages":[{"title":"Documentation","href":"/introduction"}]},{"anchor":"OpenLLMetry","icon":"telescope","groups":[{"group":"Introduction","pages":[{"title":"What is OpenLLMetry?","href":"/openllmetry/introduction"}]},{"group":"Quick Start","pages":[{"title":"Python","href":"/openllmetry/getting-started-python"},{"title":"Node.js","href":"/openllmetry/getting-started-ts"},{"title":"Next.js","href":"/openllmetry/getting-started-nextjs"},{"title":"Go","href":"/openllmetry/getting-started-go"},{"title":"Ruby","href":"/openllmetry/getting-started-ruby"},{"title":"SDK Initialization Options","href":"/openllmetry/configuration"},{"title":"Troubleshooting","href":"/openllmetry/troubleshooting"}]},{"group":"Tracing","pages":[{"title":"What's Supported?","href":"/openllmetry/tracing/supported"},{"title":"Multi-Modality Support","href":"/openllmetry/tracing/multi-modality"},{"title":"Workflow Annotations","href":"/openllmetry/tracing/annotations"},{"title":"Sessions","href":"/openllmetry/tracing/sessions"},{"title":"Versioning","href":"/openllmetry/tracing/versions"},{"title":"Associating Entities with Traces","href":"/openllmetry/tracing/association"},{"title":"Tracking User Feedback","href":"/openllmetry/tracing/user-feedback"},{"title":"Manually reporting calls to LLMs and Vector DBs","href":"/openllmetry/tracing/manual-reporting"},{"title":"Issues with Auto-instrumentation (Typescript / Javascript)","description":"How to overcome issues with automatic instrumentations on Next.js and some Webpack environments.","href":"/openllmetry/tracing/js-force-instrumentations"},{"title":"Usage with Threads (Python)","href":"/openllmetry/tracing/python-threads"},{"title":"Without OpenLLMetry SDK","description":null,"href":"/openllmetry/tracing/without-sdk"}]},{"group":"Integrations","pages":[{"title":"Overview","href":"/openllmetry/integrations/introduction"},{"title":"LLM Observability with Traceloop","sidebarTitle":"Traceloop","href":"/openllmetry/integrations/traceloop"},{"title":"LLM Observability with Axiom and OpenLLMetry","sidebarTitle":"Axiom","href":"/openllmetry/integrations/axiom"},{"title":"Azure Application Insights","href":"/openllmetry/integrations/azure"},{"title":"LLM Observability with Braintrust and OpenLLMetry","sidebarTitle":"Braintrust","href":"/openllmetry/integrations/braintrust"},{"title":"LLM Observability with BMC and OpenLLMetry","sidebarTitle":"BMC Helix","href":"/openllmetry/integrations/bmc"},{"title":"LLM Observability with Dash0 and OpenLLMetry","sidebarTitle":"Dash0","href":"/openllmetry/integrations/dash0"},{"title":"LLM Observability with Datadog and OpenLLMetry","sidebarTitle":"Datadog","href":"/openllmetry/integrations/datadog"},{"title":"LLM Observability with Dynatrace and OpenLLMetry","sidebarTitle":"Dynatrace","href":"/openllmetry/integrations/dynatrace"},{"title":"LLM Observability with Elasticsearch APM Service","sidebarTitle":"Elasticsearch APM","href":"/openllmetry/integrations/elasticsearch-apm"},{"title":"LLM Observability with Google Cloud and OpenLLMetry","sidebarTitle":"Google Cloud","href":"/openllmetry/integrations/gcp"},{"title":"LLM Observability with Grafana and OpenLLMetry","sidebarTitle":"Grafana","href":"/openllmetry/integrations/grafana"},{"title":"LLM Observability with groundcover and OpenLLMetry","sidebarTitle":"groundcover","href":"/openllmetry/integrations/groundcover"},{"title":"LLM Observability with Highlight and OpenLLMetry","sidebarTitle":"Highlight","href":"/openllmetry/integrations/highlight"},{"title":"LLM Observability with Honeycomb and OpenLLMetry","sidebarTitle":"Honeycomb","href":"/openllmetry/integrations/honeycomb"},{"title":"LLM Observability with HyperDX and OpenLLMetry","sidebarTitle":"HyperDX","href":"/openllmetry/integrations/hyperdx"},{"title":"LLM Observability with Instana and OpenLLMetry","sidebarTitle":"Instana","href":"/openllmetry/integrations/instana"},{"title":"LLM Observability with KloudMate and OpenLLMetry","sidebarTitle":"KloudMate","href":"/openllmetry/integrations/kloudmate"},{"title":"LLM observability with Laminar and OpenLLMetry","sidebarTitle":"Laminar","href":"/openllmetry/integrations/laminar"},{"title":"Enhance LLM Observability with Langfuse and OpenLLMetry","sidebarTitle":"Langfuse","href":"/openllmetry/integrations/langfuse"},{"title":"LLM Observability with LangSmith and OpenLLMetry","sidebarTitle":"LangSmith","href":"/openllmetry/integrations/langsmith"},{"title":"LLM Observability with Middleware and OpenLLMetry","sidebarTitle":"Middleware","href":"/openllmetry/integrations/middleware"},{"title":"LLM observability with New Relic and OpenLLMetry","sidebarTitle":"New Relic","href":"/openllmetry/integrations/newrelic"},{"title":"LLM observability with OpenTelemetry Collector","sidebarTitle":"OpenTelemetry Collector","href":"/openllmetry/integrations/otel-collector"},{"title":"LLM Observability with Oracle Cloud Infrastructure Application Performance Monitoring(APM) service","sidebarTitle":"OCI Application Performance Monitoring","href":"/openllmetry/integrations/oraclecloud"},{"title":"LLM Observability with Scorecard and OpenLLMetry","sidebarTitle":"Scorecard","href":"/openllmetry/integrations/scorecard"},{"title":"LLM Observability with Service Now Cloud Observability and OpenLLMetry","sidebarTitle":"Service Now Cloud Observability","href":"/openllmetry/integrations/service-now"},{"title":"LLM Observability with SigNoz and OpenLLMetry","sidebarTitle":"SigNoz","href":"/openllmetry/integrations/signoz"},{"title":"LLM Observability with Sentry and OpenLLMetry","sidebarTitle":"Sentry","href":"/openllmetry/integrations/sentry"},{"title":"LLM Observability with Splunk and OpenLLMetry","sidebarTitle":"Splunk","href":"/openllmetry/integrations/splunk"},{"title":"LLM Observability with Tencent APM and OpenLLMetry","sidebarTitle":"Tencent Cloud","href":"/openllmetry/integrations/tencent"}]},{"group":"Privacy","pages":[{"title":"Prompts, Completions and Embeddings","href":"/openllmetry/privacy/traces"},{"title":"Telemetry","href":"/openllmetry/privacy/telemetry"}]},{"group":"Contribute","pages":[{"title":"Overview","href":"/openllmetry/contributing/overview"},{"title":"Local Development","href":"/openllmetry/contributing/developing"},{"title":"GenAI Semantic Conventions","href":"/openllmetry/contributing/semantic-conventions"}]}]},{"anchor":"Hub","icon":"arrows-to-dot","pages":[{"title":"Hub","href":"/hub/getting-started"}]},{"anchor":"Dashboard API","icon":"webhook","pages":[{"title":"Dashboard API","href":"/api-reference/introduction"}]},{"anchor":"Community","href":"https://traceloop.com/slack","icon":"slack"},{"anchor":"GitHub","href":"https://github.com/traceloop","icon":"github"}]},"basePath":"","title":"Usage with Threads (Python) - traceloop","buildId":"dpl_6cCEiK8XNNvaLBBkWzcBhdE9QfLC","deploymentId":"dpl_6cCEiK8XNNvaLBBkWzcBhdE9QfLC","dynamics":[],"chunks":[]}