kubit-otel
OpenTelemetry exporter for Kubit analytics. A thin convenience wrapper around the stock OTLP/HTTP exporter, preconfigured to ship spans to the Kubit collector.
Install
pip install kubit-otel
Quick start
from kubit_otel import configure
from opentelemetry import trace
configure(api_key="rg.v1.xxx", service_name="my-app")
tracer = trace.get_tracer("my-app")
with tracer.start_as_current_span("chat.completion") as span:
span.set_attribute("gen_ai.request.model", "gpt-4o")
span.set_attribute("gen_ai.prompt", "Hello, world!")
span.set_attribute("gen_ai.completion", "Hi there!")
span.set_attribute("gen_ai.usage.input_tokens", 10)
span.set_attribute("gen_ai.usage.output_tokens", 5)
Spans are sent as standard OTLP/HTTP protobuf to the Kubit collector, which normalizes them across LLM frameworks (OTel GenAI semconv, OpenInference, Langfuse, Vercel AI, Braintrust, Logfire, OpenLLMetry/Traceloop, Mastra, OpenAI Agents, Pydantic AI) into the canonical Kubit schema and routes them to your workspace.
Configuration
| Option (kwarg) | Env var | Default |
|---|---|---|
api_key |
— | required |
endpoint |
KUBIT_OTEL_ENDPOINT |
https://otel.kubit.ai/v1/traces |
service_name |
— | default |
service_version |
— | unset |
resource_attributes |
— | {} |
KUBIT_OTEL_LOG_LEVEL (debug | info | warn | error) controls the SDK's internal logger.
The standard OTEL_EXPORTER_OTLP_TRACES_ENDPOINT / OTEL_EXPORTER_OTLP_ENDPOINT env vars are intentionally not consulted — they are process-wide and would silently redirect Kubit traces if another OTel-based SDK in the same process sets them. Use KUBIT_OTEL_ENDPOINT to override.
Works alongside other OTel-based SDKs
configure() detects whether a real TracerProvider is already installed as the global OTel provider. If so, it attaches KubitSpanProcessor to that provider and merges in your resource attributes — it does not replace the existing provider. You can call configure() before or after other OTel-based libraries (Langfuse, OpenLLMetry, an OTel distro, …) and every span will reach both sinks.
If you want explicit "attach only, never register" behavior, use attach():
from kubit_otel import attach
# Must be called after another library has installed a real provider.
attach(api_key="rg.v1.xxx")
Span filtering
By default, only LLM-relevant spans are forwarded to Kubit. A span is exported if it:
- was created by the Kubit SDK tracer (
kubit-sdk), - carries any
gen_ai.*semantic-convention attribute, or - comes from a known LLM instrumentation scope (OpenInference, Langfuse, Vercel AI SDK, Braintrust, Logfire, OpenLLMetry/Traceloop, Mastra, OpenAI Agents, …).
This keeps HTTP/DB/framework auto-instrumentation noise out of your Kubit workspace without extra configuration.
Extend the default filter
from kubit_otel import configure, is_default_export_span
configure(
api_key="rg.v1.xxx",
should_export_span=lambda span: (
is_default_export_span(span)
or (
span.instrumentation_scope is not None
and span.instrumentation_scope.name.startswith("my_framework")
)
),
)
Full override
configure(
api_key="rg.v1.xxx",
should_export_span=lambda span: span.name.startswith("llm."),
)
Export everything
configure(api_key="rg.v1.xxx", should_export_span=lambda _span: True)
Masking sensitive content
Pass a mask function to redact PII, secrets, or regulated data before spans leave your process. Masking is opt-in, synchronous, and runs after the filter but before the batch queue — un-masked spans never sit in memory waiting to flush. If the function raises or returns None, the SDK ships a tombstone in place of the span: trace structure and timing are preserved, but all payload-bearing fields (attributes, events) are wiped, status is forced to ERROR, and a kubit.sdk.mask_error attribute names the cause. The full exception (with traceback) is logged at error level so you can fix the offending mask code.
Author your mask defensively. It runs on every span your app emits — top-level LLM calls, child tool-call spans, retries, framework-internal spans (LangGraph, Mastra, Vercel AI SDK, …). If your mask only knows the shape of your top-level calls, child spans that copy slices of your prompt may slip through unmasked. Either handle every span shape, or scope your logic to an allow-list (e.g. by
span.nameorspan.instrumentation_scope.name).
Helpers live in kubit_otel.mask:
from kubit_otel import configure
from kubit_otel.mask import set_attr, mask_events
import re
CARD_RE = re.compile(r"\b(?:\d[ -]*?){13,19}\b")
def mask(span):
# 1. Scrub credit-card numbers out of the prompt attribute (OTel GenAI v1).
prompt = (span.attributes or {}).get("gen_ai.prompt")
if isinstance(prompt, str):
set_attr(span, "gen_ai.prompt", CARD_RE.sub("[REDACTED CC]", prompt))
# 2. Drop user-message events entirely (OTel GenAI v2 puts prompts here).
mask_events(span, lambda e: None if e.name == "gen_ai.user.message" else e)
return span
configure(api_key="rg.v1.xxx", mask=mask)
set_attr / delete_attr work on both spans and events. mask_events(span, fn) keeps events for which fn returns the event, drops events for which it returns None. To drop the entire span, use should_export_span — mask is a transform, not a filter.
Bare
KubitExporterconsumers do not inherit masking. Masking lives inKubitSpanProcessorso dropped spans never enter the batch queue. Wrap the exporter in your ownSpanProcessorand apply the helpers there.
Python compatibility
Python 3.9+
License
Proprietary — see LICENSE.
Metadata
Release files for kubit-otel 0.7.3
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 |
|---|---|---|---|---|
| kubit_otel-0.7.3.tar.gz | 28.6 kB | Without provenance | Details for kubit_otel-0.7.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| kubit_otel-0.7.3-py3-none-any.whl | Python 3 | none | any | Details for kubit_otel-0.7.3-py3-none-any.whl |
Total release size: 48.1 kB
Release files / kubit_otel-0.7.3.tar.gz
| Download URL | kubit_otel-0.7.3.tar.gz |
|---|---|
| Size | 28.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5a306901139f2f769c5b0176c74674b45afba8a3461f639ae94dfd86fb664f9c
|
|
BLAKE2b-256 checksum How to use checksums |
3fba31f5b806e143712c1762309fb42959f2bb86bc9139ffdfc458ae0ac8c2fb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.15
|
Release files / kubit_otel-0.7.3-py3-none-any.whl
| Download URL | kubit_otel-0.7.3-py3-none-any.whl |
|---|---|
| Size | 19.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a4a81bba255b026a6168f260f635cf1d9605c84acc2006b85b4bc9e9c65dbe06
|
|
BLAKE2b-256 checksum How to use checksums |
b05efbc40ef20aab1db8028b9b2003d79925c62949a2404d1370dc8e7a61bd8a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.15
|
Security for kubit-otel 0.7.3
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.