Skip to main content

One-line LangChain observability for Netra Runtime: traces into your Usage tab.

Project description

netra-observe

One-line LangChain observability for Netra Runtime: your agents, chains, tools, and LLM calls land as traces in the dashboard's Usage tab, with cost and token numbers taken from the gateway's billing ledger — never from client-side estimates.

Install

pip install netra-observe

Quickstart

from netra_observe import instrument

instrument(api_key="sk_live_...", project="support-agent")

Call it once at startup, before building your chains. Everything LangChain runs after that — agents, chains, tools, retrievers, LLM calls — is traced automatically (via OpenInference's LangChain instrumentation) and exported to Netra over OTLP.

Point your LLM at the Netra gateway as usual:

from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="qwen3.6-35b",
    base_url="https://api.netraruntime.com/v1",
    api_key="sk_live_...",  # same Netra key
)

See examples/langchain_agent.py for a runnable tool-calling agent.

Configuration

instrument() argument Env fallback Default
api_key NETRA_API_KEY — (required)
project NETRA_PROJECT None
environment NETRA_ENVIRONMENT None
endpoint NETRA_OTEL_ENDPOINT https://api.netraruntime.com/v1/otel
tracer_provider netra-observe creates one

instrument() returns a handle: handle.flush() forces an export, handle.shutdown() (or using the handle as a context manager) flushes and detaches everything. Pass your own tracer_provider to attach Netra's exporter setup to an existing OpenTelemetry deployment instead of letting the SDK own one.

How cost attribution works

The SDK propagates W3C trace context (traceparent) on HTTP requests to the Netra gateway — propagation only, it never starts spans of its own. The gateway records the trace/span id on its billing ledger row, so the LLM span in your trace is joined server-side to the exact request the gateway metered. Tokens and cost shown in the Usage tab come from that ledger; client-reported numbers are never billed.

Failure isolation

netra-observe must never break your app: export failures are logged and dropped (spans are batched and sent in the background), header injection degrades to "no header" on any error, and shutdown() caps its final flush at 5 seconds.

Known limitations (0.1.x)

  • Worker threads: the LLM-run context that drives exact span attribution is a ContextVar; threads you spawn yourself (e.g. ThreadPoolExecutor) don't inherit it, so bare llm.invoke() calls made inside such threads fall back to trace-level (not span-exact) attribution. LangChain's own batch()/async paths propagate context correctly.
  • Existing OpenInference instrumentation (e.g. Phoenix): if LangChainInstrumentor is already active, instrument() adds trace propagation but leaves span export with your existing setup; pass tracer_provider= to route spans through Netra as well. shutdown() never tears down instrumentation it didn't create.
  • Redirects: traceparent is injected before the request is sent; if the gateway host redirects off-host, the header follows the redirect.

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

netra_observe-0.1.1.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

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

netra_observe-0.1.1-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file netra_observe-0.1.1.tar.gz.

File metadata

  • Download URL: netra_observe-0.1.1.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for netra_observe-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f4e8bde504666f9f6cafbc08c9f9d1f2ba61eebb59b5f80a451784d95aa25808
MD5 e230f535c82a2606d485f5cf42a7a0f5
BLAKE2b-256 b1ac2162761f1a02f4ac0ce0b17c040e2950055fa620cdb5cb31a03e3ea0e543

See more details on using hashes here.

Provenance

The following attestation bundles were made for netra_observe-0.1.1.tar.gz:

Publisher: publish.yml on NetraRuntime/netra-observe

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file netra_observe-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: netra_observe-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for netra_observe-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f0c18567660e23016083bc9c6d98ff5f36d67a0aa37f2f7ea628639d39f044e9
MD5 158f0b211bfeb00cda1e0657546c29aa
BLAKE2b-256 fe57f6df59e36da4eac1b103efc37753f6ab32cc3f2a4c486d4bf5fc256bae32

See more details on using hashes here.

Provenance

The following attestation bundles were made for netra_observe-0.1.1-py3-none-any.whl:

Publisher: publish.yml on NetraRuntime/netra-observe

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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