dspy 0.27.0 → 0.27.1

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: 5bb3b493e5411fd1f18028a3177c99149c2507f4d05a100746b2da734daa6a63
4
- data.tar.gz: 78d2325d7b28a1b393284ec765c0f9fa3048c60afd864e3fcec0a88aac96cdc7
3
+ metadata.gz: 7962564b749798c462b3202e16153aa9e508e8d7fb10d6618c76e740ecb171d1
4
+ data.tar.gz: d81fad4637c82967745d644c291f7436e26c0c1bf06785ff56028c71d4d5f26d
5
5
  SHA512:
6
- metadata.gz: c11ef22db12b776b0dacb648cc60312aedb398b13020991827b85eca169b319960e8c4f31cc8216c93a766f67ed779998ee22f932bc02cb4ba802ce58c0a4ff4
7
- data.tar.gz: 68847a5ef35187be690b82e0bd1b30d4da7988c2bf1da9fd3820e4ae2315c96900f798b4580b1dcd236fa4c4e45a4289c57301b36b1c24564fda020ee174107b
6
+ metadata.gz: 38ed78b62481f7267a9d1fa7157af436bdfd82d6a8281b00b9d8915fa74e7b0b5d896f8dfa9d6f4a91aa829973f7db94445d76b3cdb5e7c66800cd23f28f1fe9
7
+ data.tar.gz: 61f0ef47790c3c9aa6c6ecd1f7ee11268ac81b27ca75212af2c69b4f4b077fa07c9acb237c7d7b3f4174c85d7de415684ac9fef5c88e01d538671b93910fa889
data/lib/dspy/context.rb CHANGED
@@ -6,29 +6,31 @@ module DSPy
6
6
  class Context
7
7
  class << self
8
8
  def current
9
- # Check if we're in an async context (fiber created by async gem)
10
- if in_async_context?
11
- # Use Fiber storage for async contexts to enable inheritance
12
- # Inherit from Thread.current if Fiber storage is not set
13
- Fiber[:dspy_context] ||= Thread.current[:dspy_context] || {
14
- trace_id: SecureRandom.uuid,
15
- span_stack: []
16
- }
17
-
18
- # Return Fiber storage in async contexts
19
- Fiber[:dspy_context]
9
+ # Use a combination of Thread and Fiber storage for proper context management
10
+ # Thread storage ensures thread isolation
11
+ # Fiber storage ensures OpenTelemetry context propagation
12
+
13
+ # Create a unique key for this thread to ensure isolation
14
+ thread_key = :"dspy_context_#{Thread.current.object_id}"
15
+
16
+ # Check if this thread has its own context
17
+ if Thread.current[thread_key]
18
+ # Thread has context, ensure fiber has it too for OpenTelemetry
19
+ Fiber[:dspy_context] ||= Thread.current[thread_key]
20
20
  else
21
- # Use Thread.current for regular synchronous contexts
22
- Thread.current[:dspy_context] ||= {
21
+ # No context for this thread - create new one
22
+ context = {
23
23
  trace_id: SecureRandom.uuid,
24
24
  span_stack: []
25
25
  }
26
-
27
- # Also sync to Fiber storage so async contexts can inherit it
28
- Fiber[:dspy_context] = Thread.current[:dspy_context]
29
-
30
- Thread.current[:dspy_context]
26
+ # Set in both Thread and Fiber storage
27
+ Thread.current[thread_key] = context
28
+ Thread.current[:dspy_context] = context # Keep for backward compatibility
29
+ Fiber[:dspy_context] = context
31
30
  end
31
+
32
+ # Return the context (from Fiber storage for OpenTelemetry compatibility)
33
+ Fiber[:dspy_context]
32
34
  end
33
35
 
34
36
  def with_span(operation:, **attributes)
@@ -65,6 +67,7 @@ module DSPy
65
67
  # Record start time for explicit duration tracking
66
68
  otel_start_time = Time.now
67
69
 
70
+ # Always use in_span which properly manages context internally
68
71
  DSPy::Observability.tracer.in_span(
69
72
  operation,
70
73
  attributes: span_attributes,
@@ -102,6 +105,9 @@ module DSPy
102
105
  end
103
106
 
104
107
  def clear!
108
+ # Clear both the thread-specific key and the legacy key
109
+ thread_key = :"dspy_context_#{Thread.current.object_id}"
110
+ Thread.current[thread_key] = nil
105
111
  Thread.current[:dspy_context] = nil
106
112
  Fiber[:dspy_context] = nil
107
113
  end
data/lib/dspy/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DSPy
4
- VERSION = "0.27.0"
4
+ VERSION = "0.27.1"
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dspy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.27.0
4
+ version: 0.27.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vicente Reig Rincón de Arellano
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-09-13 00:00:00.000000000 Z
10
+ date: 2025-09-14 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: dry-configurable