Skip to content
This repository was archived by the owner on Dec 20, 2025. It is now read-only.

Commit 6bbf9ba

Browse files
committed
fix: resolve telemetry handler warnings
- Add try-rescue blocks around telemetry.attach_many calls - Handle case where telemetry app not yet started gracefully - Add explicit telemetry dependency to mix.exs - Fixes 'Failed to lookup telemetry handlers' warnings
1 parent 8c1029a commit 6bbf9ba

File tree

7 files changed

+38
-19
lines changed

7 files changed

+38
-19
lines changed

lib/ex_llm/infrastructure/circuit_breaker/metrics.ex

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -490,12 +490,18 @@ defmodule ExLLM.Infrastructure.CircuitBreaker.Metrics do
490490
[:ex_llm, :circuit_breaker, :health_check, :completed]
491491
]
492492

493-
:telemetry.attach_many(
494-
"circuit_breaker_metrics_handler",
495-
events,
496-
&handle_telemetry_event/4,
497-
%{}
498-
)
493+
try do
494+
:telemetry.attach_many(
495+
"circuit_breaker_metrics_handler",
496+
events,
497+
&handle_telemetry_event/4,
498+
%{}
499+
)
500+
rescue
501+
ArgumentError ->
502+
# Telemetry application not started yet, ignore
503+
:ok
504+
end
499505
end
500506

501507
defp handle_telemetry_event(

lib/ex_llm/infrastructure/circuit_breaker/telemetry.ex

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,25 @@ defmodule ExLLM.Infrastructure.CircuitBreaker.Telemetry do
7070
def attach_default_handlers do
7171
init_metrics()
7272

73-
:telemetry.attach_many(
74-
"ex_llm_circuit_breaker_logger",
75-
@events,
76-
&handle_telemetry_event/4,
77-
%{handler_type: :logger}
78-
)
79-
80-
:telemetry.attach_many(
81-
"ex_llm_circuit_breaker_metrics",
82-
@events,
83-
&handle_telemetry_event/4,
84-
%{handler_type: :metrics}
85-
)
73+
try do
74+
:telemetry.attach_many(
75+
"ex_llm_circuit_breaker_logger",
76+
@events,
77+
&handle_telemetry_event/4,
78+
%{handler_type: :logger}
79+
)
80+
81+
:telemetry.attach_many(
82+
"ex_llm_circuit_breaker_metrics",
83+
@events,
84+
&handle_telemetry_event/4,
85+
%{handler_type: :metrics}
86+
)
87+
rescue
88+
ArgumentError ->
89+
# Telemetry application not started yet, ignore
90+
:ok
91+
end
8692

8793
:ok
8894
end

mix.exs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ defmodule ExLLM.MixProject do
106106

107107
# HTTP client with middleware support
108108
{:tesla, "~> 1.8"},
109+
110+
# Telemetry instrumentation
111+
{:telemetry, "~> 1.0"},
109112

110113
# WebSocket client for Live API
111114
{:gun, "~> 2.1"},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"request_metadata":{"headers":[],"captured_at":"2025-07-07T01:43:20.143706Z","endpoint":"/v1/chat/completions/test_capture","environment":"test","headers":[],"provider":"test_openai_capture","request_summary":{"model":"gpt-4","temperature":0.7,"max_tokens":100,"messages_count":1},"response_time_ms":523,"status_code":200},"cached_at":"2025-07-07T01:43:20.143821Z","test_context":null,"api_version":null,"response_data":{"choices":[{"finish_reason":"stop","index":0,"message":{"content":"Hello! How can I help you today?","role":"assistant"}}],"created":1234567890,"id":"chatcmpl-123","model":"gpt-4","object":"chat.completion","usage":{"completion_tokens":8,"prompt_tokens":10,"total_tokens":18}},"cache_version":"1.0"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"access_count":0,"cache_hits":0,"cache_key":"test_openai_capture/v1/chat/completions/test_capture/2025-07-07T01:43:20.143706Z","cleanup_before":null,"entries":[{"api_version":null,"content_hash":"6228e3cfc66d523fcf1b6bb51816377535823b90e6630210f8ca8f983d42b35b","cost":null,"filename":"2025-07-07T01-43-20.143774Z.json","response_time_ms":0,"size":721,"status":"success","timestamp":"2025-07-07T01:43:20.143774Z"}],"fallback_strategy":"latest_success","last_accessed":"2025-07-07T01:43:20.144592Z","last_cleanup":null,"test_context":null,"total_requests":1,"ttl":604800000}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"request_metadata":{"headers":[],"captured_at":"2025-07-07T01:43:20.392401Z","endpoint":"/v1/chat/completions/test_display","environment":"test","headers":[],"provider":"test_openai_display","request_summary":{"model":"gpt-4","temperature":null,"max_tokens":null,"messages_count":0},"response_time_ms":123},"cached_at":"2025-07-07T01:43:20.392636Z","test_context":null,"api_version":null,"response_data":{"choices":[{"finish_reason":"stop","message":{"content":"Test response"}}],"usage":{"completion_tokens":5,"prompt_tokens":10,"total_tokens":15}},"cache_version":"1.0"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"access_count":0,"cache_hits":0,"cache_key":"test_openai_display/v1/chat/completions/test_display/2025-07-07T01:43:20.392401Z","cleanup_before":null,"entries":[{"api_version":null,"content_hash":"bf70cd379c91f776eed85417d3bac011c6935f3d8d6ea5e2010812a31f24564a","cost":null,"filename":"2025-07-07T01-43-20.392524Z.json","response_time_ms":0,"size":573,"status":"success","timestamp":"2025-07-07T01:43:20.392524Z"}],"fallback_strategy":"latest_success","last_accessed":"2025-07-07T01:43:20.393399Z","last_cleanup":null,"test_context":null,"total_requests":1,"ttl":604800000}

0 commit comments

Comments
 (0)