Skip to main content

OpenTelemetry instrumentation for LLM applications with Dakora observability

Project description

Dakora Instrumentation

OTLP backend for LLM observability

PyPI version Python 3.11+ License

Dakora accepts OpenTelemetry traces via OTLP/HTTP. This package provides:

  1. Generic helper - Thin wrapper to configure OTEL exporters pointing to Dakora
  2. Framework integrations - Batteries-included support for Microsoft Agent Framework (MAF)
    • LangChain, CrewAI, and more coming soon

Features

OTLP Backend - Point your existing OTEL setup at Dakora
Multi-Export - Send traces to Dakora + Jaeger/Grafana/Azure Monitor
BYO OpenTelemetry - Use your own OTEL versions, no dependency conflicts
Framework Integrations - Batteries-included MAF support
Template Linkage - Track Dakora prompts used in executions
Budget Enforcement - Pre-execution checks with caching (MAF integration)


Architecture

Your App → OTEL SDK → Instrumentation → OTLP Exporter → Dakora API
                                                    ↓
                                            /api/v1/traces
                                         (with X-API-Key header)

Quick Start

1. With OpenTelemetry Collector (Recommended)

Already running a collector? Just add Dakora as an exporter:

# otel-collector-config.yaml
exporters:
  otlphttp/dakora:
    endpoint: ${DAKORA_BASE_URL}/api/v1/traces
    headers:
      X-API-Key: ${DAKORA_API_KEY}

service:
  pipelines:
    traces:
      exporters: [otlphttp/dakora, jaeger, ...] # Multi-export!

2. Direct Integration (Python)

Step 1: Install OpenTelemetry + Instrumentations

# Core OTEL
pip install opentelemetry-sdk opentelemetry-exporter-otlp-proto-http

# Provider instrumentations (choose what you need)
pip install opentelemetry-instrumentation-openai
pip install opentelemetry-instrumentation-anthropic

# Dakora helper (optional convenience)
pip install dakora-instrumentation

Step 2: Instrument Your Providers

# Do this once at application startup
from opentelemetry.instrumentation.openai import OpenAIInstrumentor
from opentelemetry.instrumentation.anthropic import AnthropicInstrumentor

OpenAIInstrumentor().instrument()
AnthropicInstrumentor().instrument()

Step 3: Configure Dakora Exporter

from dakora import Dakora
from dakora_instrumentation import setup_instrumentation

dakora = Dakora(api_key="dk_proj_...")
setup_instrumentation(dakora, service_name="my-app")

# That's it! All instrumented SDKs now export to Dakora

2. With Microsoft Agent Framework (Batteries Included)

pip install 'dakora-instrumentation[maf]'
from dakora import Dakora
from dakora_instrumentation.frameworks.maf import DakoraIntegration
from agent_framework.azure import AzureOpenAIChatClient

# Initialize Dakora
dakora = Dakora(api_key="dk_proj_...")

# One-line OTEL setup
middleware = DakoraIntegration.setup(dakora)

# Use with any MAF client
azure_client = AzureOpenAIChatClient(
    endpoint=...,
    deployment_name=...,
    api_key=...,
    middleware=[middleware],
)

agent = azure_client.create_agent(
    id="chat-v1",
    name="ChatBot",
    instructions="You are helpful.",
)

response = await agent.run("Hello!")

Package Structure

dakora_instrumentation/
├── frameworks/maf/          # Microsoft Agent Framework integration
├── generic.py               # Generic OTEL setup helper
└── _internal/               # Internal utilities (private)

Public API:

from dakora_instrumentation import setup_instrumentation
from dakora_instrumentation.frameworks.maf import DakoraIntegration

Examples

See examples/ directory for progressive examples:

  • 01_quickstart/ - Start here: basic setup and template usage
  • 02_providers/ - BYO OTEL patterns (OpenAI, Anthropic, multi-provider)
  • 03_maf_agents/ - MAF agent patterns (simple, tools, templates)
  • 04_maf_multi_agent/ - Multi-agent orchestration (sequential, parallel, workflows)
  • 05_advanced/ - Production patterns (dual export, budget checking, custom attributes)

FAQ

Q: Do I need to install dakora-instrumentation?

No! If you already have OTEL configured, point your exporter at Dakora's OTLP endpoint: ${DAKORA_BASE_URL}/api/v1/traces with X-API-Key header. This package provides convenience helpers.

Q: How do I install provider instrumentations?

Install them directly from the opentelemetry-instrumentation packages:

pip install opentelemetry-instrumentation-openai
pip install opentelemetry-instrumentation-anthropic

Q: When should I use which integration?

  • Generic setup_instrumentation() - For direct SDK calls (OpenAI, Anthropic, etc.)
  • MAF Integration - For Microsoft Agent Framework agents (batteries included)

Q: Do I need to instrument providers manually?

Yes, OpenTelemetry instrumentation is global:

OpenAIInstrumentor().instrument()  # Do once at startup

Q: Can I send traces to multiple backends?

Yes! Use additional_exporters parameter:

from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter

jaeger_exporter = OTLPSpanExporter(endpoint="http://localhost:4317")
setup_instrumentation(dakora, additional_span_exporters=[jaeger_exporter])

Q: Does this work with LangChain/CrewAI?

Not yet, but support is coming! Use generic setup_instrumentation() for now.


Links


License

Apache License 2.0

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

dakora_instrumentation-0.2.0.tar.gz (59.9 kB view details)

Uploaded Source

Built Distribution

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

dakora_instrumentation-0.2.0-py3-none-any.whl (31.8 kB view details)

Uploaded Python 3

File details

Details for the file dakora_instrumentation-0.2.0.tar.gz.

File metadata

File hashes

Hashes for dakora_instrumentation-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4c5893f90caf52c92733d5d7f3ea46f90ead88e5941a0e646c4a7eb96818a9a2
MD5 08402fceccc569f869d5814491b8fb51
BLAKE2b-256 8a20bdd7ddbf55ba8ca11f6b35dbeb768beacf530376ebd90343684783ab09e8

See more details on using hashes here.

File details

Details for the file dakora_instrumentation-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for dakora_instrumentation-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 89915dab9c513212ddb2c2635704e33ad0cbff06b0d5360e48ca04e42fb897a7
MD5 f1870a52ab359ad218ec75c60c8673d7
BLAKE2b-256 d12bef5a4f604da64c6747ff13bd7620302a8427441e639b3c85cb39beebdc9a

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