Observability answers which metrics, traces, and logs expose StoryMatrix pipeline and service health.

πŸ“Š Prometheus metrics

The metrics module registers 19 objects under the storymatrix_ namespace: seven counters, six histograms, five gauges, and one Info metric (src/storymatrix/infrastructure/observability/metrics.py).

NameTypeLabelsMeaning
storymatrix_stories_generated_totalCounterstatusCompleted story-generation outcomes.
storymatrix_stage_failures_totalCounterstage, error_typePipeline stage failures by stage and exception type.
storymatrix_api_requests_totalCountermethod, endpoint, status_codeAPI request totals.
storymatrix_tts_requests_totalCounterprovider, statusTTS synthesis requests.
storymatrix_sfx_requests_totalCounterprovider, statusSFX generation requests.
storymatrix_music_requests_totalCounterprovider, statusMusic generation requests.
storymatrix_llm_requests_totalCounterprovider, model, statusLLM API requests.
storymatrix_stage_duration_secondsHistogramstagePipeline stage durations.
storymatrix_generation_time_secondsHistogramscenes, charactersEnd-to-end generation duration by request shape.
storymatrix_tts_duration_secondsHistogramproviderTTS synthesis duration.
storymatrix_audio_length_secondsHistogramtypeGenerated audio length by audio type.
storymatrix_llm_response_time_secondsHistogramprovider, modelLLM response latency.
storymatrix_file_size_bytesHistogramtypeGenerated file sizes by file type.
storymatrix_active_generationsGaugenoneActive story generations.
storymatrix_pipeline_queue_sizeGaugenoneStories waiting in the pipeline queue.
storymatrix_voice_cache_sizeGaugenoneVoices in the cache.
storymatrix_asset_library_sizeGaugetypeAssets in the library by type.
storymatrix_memory_usage_bytesGaugecomponentCurrent memory use by component.
storymatrix_infoInfoversion, python_version, environmentStoryMatrix version and runtime configuration information.

The Info object is declared as storymatrix and Prometheus exposes its storymatrix_info family (src/storymatrix/infrastructure/observability/metrics.py).

πŸ”­ OpenTelemetry tracing

init_tracing() creates a resource with a fixed service name supplied by each entry point (storymatrix-api for the API and storymatrix-web for the web UI), plus the deployment environment, then installs a global tracer provider (src/storymatrix/infrastructure/observability/tracing.py, src/storymatrix/interfaces/api/main.py, src/storymatrix/interfaces/web/main.py). In the API and web startup paths, console export is off by default because each passes the OTEL_CONSOLE_EXPORTER default false; the lower-level tracing helper itself defaults to console export on when called directly. OTLP spans use gRPC when enable_otlp is true and an endpoint is available.

The runtime handles these telemetry settings as follows:

VariableConsumerRole
OTEL_EXPORTER_OTLP_ENDPOINTRead by application code in the tracing moduleOTLP collector endpoint when OTLP export is enabled.
OTEL_SERVICE_NAMESDK-level convention; not set or read by StoryMatrix application codeThe OpenTelemetry convention for service identity, superseded here by each entry point’s fixed service name.
OTEL_RESOURCE_ATTRIBUTESSDK-level convention; not set or read by StoryMatrix application codeThe OpenTelemetry convention for additional resource attributes; StoryMatrix supplies its own fixed resource fields.
OTEL_CONSOLE_EXPORTERRead by application code in API and web startupEnables console export only when set to true; the effective startup default is false.
DEPLOYMENT_ENVIRONMENTRead by application code in API and web startupDeployment environment passed to tracing resource metadata; defaults to development.

trace_pipeline_stage(stage_name, story_id) decorates an async stage, creates a span, records stage.name and optional story.id, marks success, and records exception type and message before re-raising failures (src/storymatrix/infrastructure/observability/tracing.py).

πŸͺ΅ Loguru files

configure_logging(log_name="app") creates the configured log directory and installs console, main-file, and debug-file sinks (src/storymatrix/config/logging.py). The default files are app.log and app_debug.log under config.app.log_dir.

FileLevelRotationRetentionCompression
app.logConfigured application level10 MB7 dayszip
app_debug.logDEBUG25 MB3 dayszip

Both file sinks enqueue writes and enable backtraces and diagnostics (src/storymatrix/config/logging.py).

🌐 Metrics scrape endpoint

FastAPI serves Prometheus output at GET /metrics (src/storymatrix/interfaces/api/main.py). Scrape this endpoint from the API service and correlate request counters with stage histograms and logs.