TraceLink Python SDK
English | 简体中文
The Python SDK builds protocol-compatible spans, keeps async context with
contextvars, writes optional local files, exports events to the shared
TraceLink Receiver, and integrates incoming FastAPI/Starlette requests.
It does not ship a Python Receiver, Dashboard, or CLI. Start those from the npm
package with npx tracelink dashboard.
Install
pip install tracelink
pip install "tracelink[fastapi]"
Optional Coding-Assistant Skill
The PyPI package provides the Python SDK but does not install the repository's coding-assistant Skill. Install that separately with the Skills CLI:
npx skills add qinquan-ai/tracelink --skill tracelink
The CLI detects supported AI agents and either selects or prompts for the
installation target. Installation is project-local by default; pass --global
to make the skill available across projects.
The Skill helps a coding assistant add TraceLink instrumentation and analyze existing debug data. It does not provide AI-agent runtime integration or agent-specific tracing semantics.
Trace And Export
from tracelink import tracer
exporter = tracer.configure(
enabled=True,
http_endpoint="http://127.0.0.1:5174/__debug_log",
scope_sync_endpoint="http://127.0.0.1:5174/__debug_log/scopes",
file_enabled=False,
)
async def load_order():
tracer.db("orders.py:load", "load order", scope="checkout")
await tracer.span(
"BE-ENTRY",
"routes.py:checkout",
"checkout",
load_order,
scope="checkout",
)
exporter.flush(timeout=5.0)
Without enabled=True, startup follows TRACELINK_ENABLED, then the DEBUG or
DEV environment variables. TRACELINK_SCOPES initializes the local Scope
policy (* or a comma-separated list).
Custom Exporter
from tracelink import HttpExporter, tracer
off = tracer.add_exporter(HttpExporter())
off()
HttpExporter uses a bounded background queue and standard-library HTTP. Its
network failures never escape into application code. FileExporter writes
.tracelink/trace.ndjson and .tracelink/trace.log locally. It is enabled by
default; set file_enabled=False when a Receiver in the same project owns those
files, otherwise the SDK and Receiver can write duplicate rows.
FastAPI
from fastapi import FastAPI
from tracelink import TraceMiddleware
app = FastAPI()
app.add_middleware(TraceMiddleware)
The Extension extracts x-trace-id, x-parent-span-id, and x-debug-scopes,
installs request-local context, and restores the previous values after the
request. The caller's active span becomes the backend entry's parent. Middleware
does not create application spans; instrument route or service boundaries
explicitly.
Outgoing HTTP
from tracelink import create_trace_headers
requests.get(url, headers=create_trace_headers())
The helper is explicit and client-agnostic; TraceLink does not patch Requests, HTTPX, or aiohttp globally.
Context Guarantees
ContextVar preserves nested calls, await, and concurrent asyncio tasks.
Fresh OS threads do not automatically inherit context; copy or pass it
explicitly when creating a thread.
Development
From the repository root:
npm run verify:python
This runs pytest, Ruff, strict mypy, builds an isolated wheel, installs it into a temporary directory, and imports the installed artifact.
Metadata
Release files for tracelink 0.6.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tracelink-0.6.6.tar.gz | 33.3 kB | Without provenance | Details for tracelink-0.6.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tracelink-0.6.6-py3-none-any.whl | Python 3 | none | any | Details for tracelink-0.6.6-py3-none-any.whl |
Total release size: 61.4 kB
Release files / tracelink-0.6.6.tar.gz
| Download URL | tracelink-0.6.6.tar.gz |
|---|---|
| Size | 33.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
056f51ab19e3b7c0f80b02ed44b473e936287d45ec47c3dde649a3fb8b135692
|
|
BLAKE2b-256 checksum How to use checksums |
d304a8bc8aae77f0b18577e8213b387803bbb4bee96bb33ff9e87cfe6d8851f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.0
|
Release files / tracelink-0.6.6-py3-none-any.whl
| Download URL | tracelink-0.6.6-py3-none-any.whl |
|---|---|
| Size | 28.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b8824636ba4d97efa4c046a46cc66ee60d4470b9441c16dff6a86766563c1233
|
|
BLAKE2b-256 checksum How to use checksums |
625ade8a28459651f769b278ea0f84f71ce34e0f3c7d066efe2a8d259e3be7e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.0
|
Security for tracelink 0.6.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.