Hooks

OpenTelemetry integration hooks for metrics export.

Classes

class arshai.observability.metrics.hooks.OpenTelemetryHooks[source]

Bases: object

Hooks for integrating with OpenTelemetry.

This class provides integration points for exporting metrics to OpenTelemetry-compatible backends.

Example

hooks = OpenTelemetryHooks()

# Configure exporter (requires opentelemetry packages) if hooks.is_available():

hooks.configure_metrics_exporter(

endpoint=”http://localhost:4317”, service_name=”arshai-service”

)

# Export metrics hooks.export_metrics(collector.get_stats())

__init__()[source]

Initialize OpenTelemetry hooks.

is_available()[source]

Check if OpenTelemetry is available.

Return type:

bool

Returns:

True if OpenTelemetry packages are installed

configure_metrics_exporter(endpoint='http://localhost:4317', service_name='arshai', insecure=True)[source]

Configure OpenTelemetry metrics exporter.

Parameters:
  • endpoint (str) – OTLP endpoint URL

  • service_name (str) – Service name for metrics

  • insecure (bool) – Whether to use insecure connection

Note

Requires opentelemetry packages to be installed

export_metrics(metrics_data)[source]

Export metrics to OpenTelemetry.

Parameters:

metrics_data (Dict[str, Any]) – Metrics data from collector

Note

This is a simplified example. In production, you would create proper OpenTelemetry instruments (counters, histograms, etc.)

create_span_processor()[source]

Create a span processor for tracing.

Returns:

Span processor or None if not available

Note

This is for future tracing support