Package Config

Package-specific observability configuration that respects parent settings.

This module provides configuration that: 1. Never overrides global OTEL configuration 2. Reads package-specific environment variables 3. Provides sensible defaults that work with any parent setup 4. Allows runtime enable/disable of features 5. Supports multiple verbosity levels

Classes

class arshai.observability.package_config.ObservabilityLevel(value)[source]

Bases: str, Enum

Package observability levels.

OFF = 'OFF'
ERROR = 'ERROR'
INFO = 'INFO'
DEBUG = 'DEBUG'
class arshai.observability.package_config.PackageObservabilityConfig(**data)[source]

Bases: IDTO

LLM-friendly observability configuration for Arshai package.

This configuration is designed to be a well-behaved OTEL citizen: - Never creates or configures OTEL providers/exporters - Respects parent application’s OTEL setup - Uses package-specific environment variables - Provides runtime control over telemetry features

enabled: bool
level: ObservabilityLevel
trace_llm_calls: bool
trace_agent_operations: bool
trace_workflow_execution: bool
collect_metrics: bool
span_kind: SpanKind
track_token_timing: bool
track_cost_metrics: bool
provider_configs: Dict[str, Dict[str, Any]]
log_prompts: bool
log_responses: bool
max_prompt_length: int
max_response_length: int
service_namespace: Optional[str]
package_name: str
package_version: str
otlp_endpoint: Optional[str]
custom_attributes: Dict[str, str]
classmethod from_environment()[source]

Create configuration from package-specific environment variables.

Uses ARSHAI_TELEMETRY_* environment variables to avoid conflicts with parent application’s OTEL configuration.

Return type:

PackageObservabilityConfig

Returns:

PackageObservabilityConfig instance

is_feature_enabled(feature)[source]

Check if a specific observability feature is enabled.

Parameters:

feature (str) – Feature name (e.g., ‘trace_llm_calls’, ‘collect_metrics’)

Return type:

bool

Returns:

True if feature is enabled based on global and feature-specific settings

is_provider_enabled(provider)[source]

Check if observability is enabled for a specific LLM provider.

Parameters:

provider (str) – Provider name (e.g., ‘openai’, ‘anthropic’, ‘google’)

Return type:

bool

Returns:

True if provider observability is enabled

get_provider_config(provider)[source]

Get observability configuration for a specific provider.

Parameters:

provider (str) – Provider name

Return type:

Dict[str, Any]

Returns:

Provider-specific configuration dictionary

should_log_content(content_type)[source]

Check if content logging is enabled for the given type.

Parameters:

content_type (str) – ‘prompts’ or ‘responses’

Return type:

bool

Returns:

True if content logging is enabled and safe

get_content_length_limit(content_type)[source]

Get the length limit for content logging.

Parameters:

content_type (str) – ‘prompts’ or ‘responses’

Return type:

int

Returns:

Maximum length to log

get_span_attributes()[source]

Get default span attributes for this package.

Return type:

Dict[str, str]

Returns:

Dictionary of default span attributes

configure_provider(provider, enabled=None, **kwargs)[source]

Create a new config with provider-specific settings.

Parameters:
  • provider (str) – Provider name

  • enabled (Optional[bool]) – Whether to enable observability for this provider

  • **kwargs – Additional provider-specific settings

Return type:

PackageObservabilityConfig

Returns:

New PackageObservabilityConfig instance

with_level(level)[source]

Create a new config with different observability level.

Parameters:

level (ObservabilityLevel) – New observability level

Return type:

PackageObservabilityConfig

Returns:

New PackageObservabilityConfig instance

disable_all()[source]

Create a new config with all observability disabled.

Return type:

PackageObservabilityConfig

Returns:

New PackageObservabilityConfig instance with everything disabled

model_config: ClassVar[ConfigDict] = {'allow_mutation': False, 'arbitrary_types_allowed': True, 'smart_union': True, 'validate_assignment': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class arshai.observability.package_config.SpanKind(value)[source]

Bases: str, Enum

Phoenix-compatible span kinds.

Based on Phoenix documentation: https://arize.com/docs/phoenix/tracing/how-to-tracing/setup-tracing/instrument-python

CHAIN = 'CHAIN'
LLM = 'LLM'
TOOL = 'TOOL'
RETRIEVER = 'RETRIEVER'
EMBEDDING = 'EMBEDDING'
AGENT = 'AGENT'
RERANKER = 'RERANKER'
GUARDRAIL = 'GUARDRAIL'
EVALUATOR = 'EVALUATOR'