Python API
ctxflow_otel
Section titled “ctxflow_otel”| Name | What it does |
|---|---|
init(config=None) -> TracerProvider |
Installs the ctxflow tracer provider from OTEL_* and CTXFLOW_* (or config). Idempotent: a second call returns the same provider. Also enables MCP and the installed ingestion extras (not the LlamaIndex instrumentation). See Python SDK. |
attach(provider, config=None) |
Adds identity and the ctxflow exporter to a provider you own. Idempotent per provider. |
conversation(conversation_id, user_id=None, session_id=None, turn=None) |
Context manager (sync and async) that sets identity on every span inside. See Identity. |
source_hash(data: bytes | str) -> str | None |
Hash of an original document: plain sha256, 64 hex. |
content_hash(text: str) -> str | None |
Hash of a text after cleanup (Unicode NFC, whitespace runs as one space, trim). The same hash ctxflow uses to match a retrieved chunk to the chunk you indexed. |
Config |
Frozen settings: deterministic_ids. Config.from_env() reads the environment. |
IdentityProcessor |
Span processor that copies identity from baggage to span attributes. |
Submodules
Section titled “Submodules”| Name | What it does |
|---|---|
ctxflow_otel.mcp.instrument_mcp() |
Enables MCP context propagation and, on mcp 2.x servers, tool text ([mcp] extra). Called by init(). See MCP. |
ctxflow_otel.llamaindex.instrument_llamaindex() |
Starts the OpenInference LlamaIndex instrumentation with embedding text and vectors hidden ([llamaindex] extra). Called by ctxflow-instrument, not by init(). Returns False when LlamaIndex or the instrumentor is not installed or llama_index is disabled. |
ctxflow_otel.mcp.child_env(service_name=None) |
Environment for a stdio MCP server: forwards OTEL_* and CTXFLOW_*, short batch delay and timeout. |
ctxflow_otel.ingest.instrument_ingest(config=None) |
Enables the installed ingestion extras. Called by init(). |
ctxflow_otel.ingest.common.source_version(value) |
Context manager: the version of every document ingested inside. |
ctxflow_otel.ingest.common.chunk_text_hashes(texts) |
Text hashes of chunks, for ctxflow.chunks.text_hashes. |
ctxflow_otel.ingest.llamaindex.load_documents(root, **reader_kwargs) |
Loads files under root with source_id and source_hash set. |
ctxflow_otel.ingest.llamaindex.ctxflow_transformations(transformations) |
Level 1 of the LlamaIndex extra. |
ctxflow_otel.ingest.docling.source_metadata(path) |
C1 keys of a file, for chunks you make yourself. |
ctxflow_semconv
Section titled “ctxflow_semconv”Constants for every attribute key and span name of the registry, for example:
import ctxflow_semconv as sc
sc.AGENT_TURN_SPAN # "agent.turn"sc.RETRIEVAL_SPAN # "retrieval"sc.SOURCE_ID # "ctxflow.source_id"sc.SOURCE_VERSION # "ctxflow.source_version"sc.SOURCE_HASH # "ctxflow.source_hash"sc.TOOL_NAME # "tool.name"Also: content_kind(key) ("drop", "filter" or None: whether a key carries content in one of the dialect maps), is_content_key(key), attributes_schema() (the JSON Schema of ctxflow.* attributes) and conformance_vectors(name).