Skip to main content

OpenTelemetry exporter for Kubit analytics.

Project description

kubit-otel

OpenTelemetry exporter for Kubit analytics.

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 exported to Kubit using standard OpenTelemetry GenAI semantic conventions. Each trace's root span is recorded as the trace; every span (including the root) is recorded as an observation under it. gen_ai.* attributes are mapped to first-class, queryable fields for model name, prompt/completion, token counts, and cost.

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")

Supported attributes

OpenTelemetry attribute Purpose
gen_ai.request.model / gen_ai.response.model Model name
gen_ai.prompt / gen_ai.content.prompt Input prompt
gen_ai.completion / gen_ai.content.completion Output completion
gen_ai.usage.input_tokens Input token count
gen_ai.usage.output_tokens Output token count
gen_ai.usage.cost Total cost (USD)
session.id Conversation session id
enduser.id End-user id

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, …).

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)

Python compatibility

Python 3.9+

License

Proprietary — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kubit_otel-0.5.0.tar.gz (40.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kubit_otel-0.5.0-py3-none-any.whl (38.2 kB view details)

Uploaded Python 3

File details

Details for the file kubit_otel-0.5.0.tar.gz.

File metadata

  • Download URL: kubit_otel-0.5.0.tar.gz
  • Upload date:
  • Size: 40.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for kubit_otel-0.5.0.tar.gz
Algorithm Hash digest
SHA256 2e83211e7470d04c07422754b0be75b77127b66bb3ed7766f560476fe42ee622
MD5 48a2fa60a6bb9537b2d284ce6edf42a8
BLAKE2b-256 99bb6689b4236a10078a262e6188bac5b8b79001d0712125ee94fd77d9e5df0e

See more details on using hashes here.

File details

Details for the file kubit_otel-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: kubit_otel-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 38.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for kubit_otel-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 77b8faf754716ecbf0d93432a76124f6fa1562ecf952c7e3c67deacf093e63ea
MD5 f35a913a11824a2364696e5b05487519
BLAKE2b-256 0114c0be4cd52e170abeb4416ca2170d611644591fbfef8a0f79c047eed5392e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page