> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mellea.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# mellea.telemetry

> OpenTelemetry instrumentation for Mellea.

export const SidebarFix = () => <script dangerouslySetInnerHTML={{
  __html: `
        (function () {
          const INTERVAL_MS = 500;

          const upgradeSidebar = () => {
            const links = document.querySelectorAll('a[href^="#"]');

            links.forEach((link) => {
              if (link.dataset.badged === "true") return;

              const rawText = (link.textContent || "").trim();

              // ========== FUNC ==========
              if (rawText.startsWith("FUNC ")) {
                const label = rawText.replace(/^FUNC\\s+/, "").trim();

                while (link.firstChild) link.removeChild(link.firstChild);

                // 👉 Make the whole link a single flex row & prevent wrapping
                link.style.display = "flex";
                link.style.alignItems = "center";
                link.style.whiteSpace = "nowrap";
                link.style.columnGap = "0.5rem";

                const badge = document.createElement("span");
                badge.style.marginRight = "0.5rem";
                badge.style.display = "inline-flex";
                badge.style.alignItems = "center";
                badge.style.borderRadius = "9999px";
                badge.style.padding = "0rem 0.6rem";
                badge.style.fontSize = "0.5rem";
                badge.style.fontWeight = "700";
                badge.style.letterSpacing = "0.05em";
                badge.style.backgroundColor = "rgba(48, 100, 227, 0.20)";
                badge.style.color = "#1D4ED8";

                badge.textContent = "FUNC";

                link.appendChild(badge);
                link.appendChild(document.createTextNode(label));
                link.dataset.badged = "true";
                return;
              }

              // ========== CLASS ==========
              if (rawText.startsWith("CLASS ")) {
                const label = rawText.replace(/^CLASS\\s+/, "").trim();

                while (link.firstChild) link.removeChild(link.firstChild);

                // 👉 Same flex / nowrap treatment for class links
                link.style.display = "flex";
                link.style.alignItems = "center";
                link.style.whiteSpace = "nowrap";
                link.style.columnGap = "0.5rem";

                const badge = document.createElement("span");
                badge.style.marginRight = "0.5rem";
                badge.style.display = "inline-flex";
                badge.style.alignItems = "center";
                badge.style.borderRadius = "9999px";
                badge.style.padding = "0rem 0.6rem";
                badge.style.fontSize = "0.5rem";
                badge.style.fontWeight = "700";
                badge.style.letterSpacing = "0.05em";
                badge.style.backgroundColor = "rgba(74, 222, 128, 0.20)";
                badge.style.color = "#15803D";

                badge.textContent = "CLASS";

                link.appendChild(badge);
                link.appendChild(document.createTextNode(label));
                link.dataset.badged = "true";
                return;
              }
            });
          };

          upgradeSidebar();
          setInterval(upgradeSidebar, INTERVAL_MS);
        })();
      `
}} />;

<SidebarFix />

OpenTelemetry instrumentation for Mellea.

This package provides observability capabilities for Mellea through OpenTelemetry,
enabling tracing, metrics, and logging for both application-level operations and
backend LLM interactions.

Package Structure:

* tracing: Distributed tracing with two independent scopes:
  * Application traces (mellea.application): User-facing operations
  * Backend traces (mellea.backend): LLM backend interactions
* metrics: Metrics collection for counters, histograms, and up-down counters
* logging: Log export via OTLP
* backend\_instrumentation: Automatic instrumentation for backend operations

Configuration:
All telemetry features are opt-in via environment variables:

Tracing:

* MELLEA\_TRACE\_APPLICATION: Enable application tracing (default: false)
* MELLEA\_TRACE\_BACKEND: Enable backend tracing (default: false)
* OTEL\_EXPORTER\_OTLP\_ENDPOINT: OTLP endpoint for trace export
* OTEL\_SERVICE\_NAME: Service name for traces (default: mellea)

Metrics:

* MELLEA\_METRICS\_ENABLED: Enable metrics collection (default: false)
* MELLEA\_METRICS\_CONSOLE: Print metrics to console (default: false)
* MELLEA\_METRICS\_OTLP: Enable OTLP metrics exporter (default: false)
* MELLEA\_METRICS\_PROMETHEUS: Enable Prometheus metric reader (default: false)
* OTEL\_EXPORTER\_OTLP\_ENDPOINT: OTLP endpoint for metric export (optional)
* OTEL\_EXPORTER\_OTLP\_METRICS\_ENDPOINT: Metrics-specific OTLP endpoint (optional)
* OTEL\_METRIC\_EXPORT\_INTERVAL: Export interval in milliseconds (default: 60000)
* OTEL\_SERVICE\_NAME: Service name for metrics (default: mellea)
* MELLEA\_PRICING\_FILE: Path to a JSON file with custom model pricing overrides (optional)

Logging:

* MELLEA\_LOG\_OTLP: Enable OTLP log export (default: false)
* OTEL\_EXPORTER\_OTLP\_LOG\_ENDPOINT: Logs-specific endpoint (optional)
* OTEL\_EXPORTER\_OTLP\_ENDPOINT: General OTLP endpoint (fallback)
* OTEL\_SERVICE\_NAME: Service name for logs (default: mellea)

Dependencies:
OpenTelemetry packages are optional. If not installed, telemetry features
are gracefully disabled. Install with: pip install mellea\[telemetry]

Example:
from mellea.telemetry import trace\_application, create\_counter, get\_otlp\_log\_handler
import logging

# Trace application operations

@trace\_application("my\_operation")
def my\_function():
pass

# Collect metrics

counter = create\_counter("mellea.requests", unit="1")
counter.add(1, \{"backend": "ollama"})

# Export logs via OTLP

logger = logging.getLogger("my\_app")
handler = get\_otlp\_log\_handler()
if handler:
logger.addHandler(handler)
