llm_logs 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 87a8d5b11b7782e2dbda613ce9ef2c0717f2984574953d1070e7df443366d9d4
4
- data.tar.gz: b18d3628a4658e2288744f680df716850a99bac16afaf4de07af199513034d46
3
+ metadata.gz: c9f1ecb908532e887783dec76409b9d1064e414c2560864b984dde135757e507
4
+ data.tar.gz: e2a6567f55ef52cb4defaed521506502640c2a57e1df33709c8a598910ef767c
5
5
  SHA512:
6
- metadata.gz: c5ddca4dfee273333daf57dbd8b7e96959183547fece1e3c08b1de9e4f556bc8bdf1c2001ecd0110eab703580a559d4a75f4d8472fe6df06ef7a2b5bb757ec59
7
- data.tar.gz: 1a740b579f7d7c84950edd7b3a70a33a843f8bf8e32a4e5eef902de80110b3a161eef1e2e65ec556b353c9ab7d7ed77c07f84c883d0b62a1e30c168866ca9919
6
+ metadata.gz: 60677029d50f6bb17c6a3e580643bbe2615a8886b2f9e5c40678e737175e41d6ab56d39990abccf7ce8a17354e4d101d7724273e987f70c0b65fdb48c1037317
7
+ data.tar.gz: 46fdf2fb90bfaf0ea4b85044c2f12baf38decb36d5d7f96e540d99cc4afecdf7a8b6a43322c3f45320111ecdc990aaf21a899d14623a7443aafff327a82e4dd5
@@ -15,8 +15,8 @@ module LlmLogs
15
15
  duration_ms: (Time.current - started_at) * 1000
16
16
  )
17
17
 
18
- # Restore parent span as current
19
- Thread.current[:llm_logs_span] = parent_span
18
+ # Restore parent span as current (Fiber[] so child fibers inherit it)
19
+ LlmLogs::Tracer.current_span = parent_span
20
20
  end
21
21
 
22
22
  def record_response(message)
@@ -1,11 +1,20 @@
1
1
  module LlmLogs
2
2
  module Tracer
3
+ # Trace/span context is kept in Fiber-local storage (Fiber[]), which child
4
+ # fibers inherit on creation. This matters for fiber-based schedulers such as
5
+ # socketry/async: work driven inside a child fiber still sees the active
6
+ # trace. The legacy Thread.current[:key] store is *not* inherited by child
7
+ # fibers, which caused spans to auto-create orphan traces instead of nesting.
3
8
  def self.current_trace
4
- Thread.current[:llm_logs_trace]
9
+ Fiber[:llm_logs_trace]
5
10
  end
6
11
 
7
12
  def self.current_span
8
- Thread.current[:llm_logs_span]
13
+ Fiber[:llm_logs_span]
14
+ end
15
+
16
+ def self.current_span=(span)
17
+ Fiber[:llm_logs_span] = span
9
18
  end
10
19
 
11
20
  def self.start_trace(name, metadata: {})
@@ -16,10 +25,10 @@ module LlmLogs
16
25
  started_at: Time.current
17
26
  )
18
27
 
19
- previous_trace = Thread.current[:llm_logs_trace]
20
- previous_span = Thread.current[:llm_logs_span]
21
- Thread.current[:llm_logs_trace] = trace
22
- Thread.current[:llm_logs_span] = nil
28
+ previous_trace = Fiber[:llm_logs_trace]
29
+ previous_span = Fiber[:llm_logs_span]
30
+ Fiber[:llm_logs_trace] = trace
31
+ Fiber[:llm_logs_span] = nil
23
32
 
24
33
  begin
25
34
  yield trace
@@ -28,8 +37,8 @@ module LlmLogs
28
37
  raise
29
38
  ensure
30
39
  trace.complete! if trace.status == "running"
31
- Thread.current[:llm_logs_trace] = previous_trace
32
- Thread.current[:llm_logs_span] = previous_span
40
+ Fiber[:llm_logs_trace] = previous_trace
41
+ Fiber[:llm_logs_span] = previous_span
33
42
  end
34
43
  end
35
44
 
@@ -50,7 +59,7 @@ module LlmLogs
50
59
  started_at: Time.current
51
60
  )
52
61
 
53
- Thread.current[:llm_logs_span] = span
62
+ Fiber[:llm_logs_span] = span
54
63
  span
55
64
  end
56
65
 
@@ -60,7 +69,7 @@ module LlmLogs
60
69
  status: "running",
61
70
  started_at: Time.current
62
71
  )
63
- Thread.current[:llm_logs_trace] = trace
72
+ Fiber[:llm_logs_trace] = trace
64
73
  trace
65
74
  end
66
75
  end
@@ -1,3 +1,3 @@
1
1
  module LlmLogs
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: llm_logs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton