langfuse-ruby 0.1.5 → 0.1.7

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.
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: langfuse-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Sun
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2025-12-26 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: concurrent-ruby
@@ -45,39 +44,39 @@ dependencies:
45
44
  - !ruby/object:Gem::Version
46
45
  version: '3.0'
47
46
  - !ruby/object:Gem::Dependency
48
- name: faraday-net_http
47
+ name: faraday-multipart
49
48
  requirement: !ruby/object:Gem::Requirement
50
49
  requirements:
51
- - - ">="
50
+ - - "~>"
52
51
  - !ruby/object:Gem::Version
53
52
  version: '1.0'
54
- - - "<"
55
- - !ruby/object:Gem::Version
56
- version: '4.0'
57
53
  type: :runtime
58
54
  prerelease: false
59
55
  version_requirements: !ruby/object:Gem::Requirement
60
56
  requirements:
61
- - - ">="
57
+ - - "~>"
62
58
  - !ruby/object:Gem::Version
63
59
  version: '1.0'
64
- - - "<"
65
- - !ruby/object:Gem::Version
66
- version: '4.0'
67
60
  - !ruby/object:Gem::Dependency
68
- name: faraday-multipart
61
+ name: faraday-net_http
69
62
  requirement: !ruby/object:Gem::Requirement
70
63
  requirements:
71
- - - "~>"
64
+ - - ">="
72
65
  - !ruby/object:Gem::Version
73
66
  version: '1.0'
67
+ - - "<"
68
+ - !ruby/object:Gem::Version
69
+ version: '4.0'
74
70
  type: :runtime
75
71
  prerelease: false
76
72
  version_requirements: !ruby/object:Gem::Requirement
77
73
  requirements:
78
- - - "~>"
74
+ - - ">="
79
75
  - !ruby/object:Gem::Version
80
76
  version: '1.0'
77
+ - - "<"
78
+ - !ruby/object:Gem::Version
79
+ version: '4.0'
81
80
  - !ruby/object:Gem::Dependency
82
81
  name: json
83
82
  requirement: !ruby/object:Gem::Requirement
@@ -201,23 +200,25 @@ files:
201
200
  - ".github/workflows/ci.yml"
202
201
  - ".github/workflows/release.yml"
203
202
  - ".gitignore"
203
+ - ".rubocop.yml"
204
204
  - CHANGELOG.md
205
+ - CLAUDE.md
205
206
  - Gemfile
206
207
  - Gemfile.lock
207
208
  - LICENSE
209
+ - Makefile
208
210
  - README.md
209
211
  - Rakefile
210
212
  - docs/FINAL_SUMMARY.md
211
213
  - docs/PUBLISH_GUIDE.md
212
214
  - docs/README.md
213
215
  - docs/RELEASE_CHECKLIST.md
214
- - docs/TYPE_VALIDATION_TROUBLESHOOTING.md
215
- - docs/URL_ENCODING_FIX.md
216
216
  - examples/auto_flush_control.rb
217
217
  - examples/basic_tracing.rb
218
218
  - examples/connection_config_demo.rb
219
219
  - examples/event_usage.rb
220
220
  - examples/prompt_management.rb
221
+ - examples/simplified_usage.rb
221
222
  - examples/url_encoding_demo.rb
222
223
  - langfuse-ruby.gemspec
223
224
  - lib/langfuse.rb
@@ -226,15 +227,17 @@ files:
226
227
  - lib/langfuse/evaluation.rb
227
228
  - lib/langfuse/event.rb
228
229
  - lib/langfuse/generation.rb
230
+ - lib/langfuse/null_objects.rb
229
231
  - lib/langfuse/observation_types.rb
232
+ - lib/langfuse/otel_exporter.rb
230
233
  - lib/langfuse/prompt.rb
231
234
  - lib/langfuse/span.rb
232
235
  - lib/langfuse/trace.rb
233
236
  - lib/langfuse/utils.rb
234
237
  - lib/langfuse/version.rb
235
238
  - scripts/release.sh
239
+ - scripts/test_offline.rb
236
240
  - scripts/verify_release.rb
237
- - test_offline.rb
238
241
  homepage: https://langfuse.com
239
242
  licenses:
240
243
  - MIT
@@ -245,7 +248,7 @@ metadata:
245
248
  changelog_uri: https://github.com/ai-firstly/langfuse-ruby/blob/main/CHANGELOG.md
246
249
  documentation_uri: https://rubydoc.info/gems/langfuse-ruby
247
250
  bug_tracker_uri: https://github.com/ai-firstly/langfuse-ruby/issues
248
- post_install_message:
251
+ rubygems_mfa_required: 'true'
249
252
  rdoc_options: []
250
253
  require_paths:
251
254
  - lib
@@ -260,8 +263,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
260
263
  - !ruby/object:Gem::Version
261
264
  version: '0'
262
265
  requirements: []
263
- rubygems_version: 3.5.11
264
- signing_key:
266
+ rubygems_version: 3.6.9
265
267
  specification_version: 4
266
268
  summary: Ruby SDK for Langfuse - Open source LLM engineering platform
267
269
  test_files: []
@@ -1,202 +0,0 @@
1
- # 类型验证错误故障排除指南
2
-
3
- ## 问题描述
4
-
5
- 当您遇到以下错误时:
6
-
7
- ```json
8
- {
9
- "id": "xxx",
10
- "status": 400,
11
- "message": "Invalid request data",
12
- "error": [
13
- {
14
- "code": "invalid_union",
15
- "errors": [],
16
- "note": "No matching discriminator",
17
- "path": ["type"],
18
- "message": "Invalid input"
19
- }
20
- ]
21
- }
22
- ```
23
-
24
- 这表示 Langfuse 服务器端的 API 验证发现事件的 `type` 字段不符合预期的格式。
25
-
26
- ## 根本原因
27
-
28
- 1. **事件类型无效**: 发送的事件类型不在服务器端支持的列表中
29
- 2. **事件数据结构错误**: 事件的数据结构不符合对应类型的要求
30
- 3. **数据序列化问题**: 事件数据在序列化过程中出现问题
31
-
32
- ## 常见修复案例
33
-
34
- ### 1. 事件类型无效
35
-
36
- ```ruby
37
- client.trace(name: "my-trace", user_id: "user-123", input: { query: "Hello" })
38
- ```
39
-
40
- ## 解决方案
41
-
42
- ### 1. 启用调试模式
43
-
44
- ```ruby
45
- client = Langfuse.new(
46
- public_key: "your-key",
47
- secret_key: "your-secret",
48
- debug: true # 启用调试模式
49
- )
50
- ```
51
-
52
- 调试模式会显示:
53
- - 发送的事件类型
54
- - 事件数据结构
55
- - 详细的错误信息
56
-
57
- ### 2. 检查支持的事件类型
58
-
59
- 当前支持的事件类型:
60
- - `trace-create`
61
- - `generation-create`
62
- - `generation-update`
63
- - `span-create`
64
- - `span-update`
65
- - `event-create`
66
- - `score-create`
67
-
68
- ### 3. 验证事件数据
69
-
70
- 确保事件数据包含必要的字段:
71
-
72
- #### Trace 事件
73
- ```ruby
74
- {
75
- id: "uuid",
76
- name: "trace-name",
77
- user_id: "user-id",
78
- input: { ... },
79
- metadata: { ... },
80
- tags: [...],
81
- timestamp: "2025-01-01T00:00:00.000Z"
82
- }
83
- ```
84
-
85
- #### Generation 事件
86
- ```ruby
87
- {
88
- id: "uuid",
89
- trace_id: "trace-uuid",
90
- name: "generation-name",
91
- model: "gpt-3.5-turbo",
92
- input: [...],
93
- output: { ... },
94
- usage: { ... },
95
- metadata: { ... }
96
- }
97
- ```
98
-
99
- #### Span 事件
100
- ```ruby
101
- {
102
- id: "uuid",
103
- trace_id: "trace-uuid",
104
- name: "span-name",
105
- start_time: "2025-01-01T00:00:00.000Z",
106
- end_time: "2025-01-01T00:00:01.000Z",
107
- input: { ... },
108
- output: { ... },
109
- metadata: { ... }
110
- }
111
- ```
112
-
113
- #### Event 事件
114
- ```ruby
115
-
116
- ```ruby
117
-
118
- ```
119
-
120
- #### Score 事件
121
- ```ruby
122
-
123
- ```
124
-
125
- ### 4. 检查网络和认证
126
-
127
- 确保:
128
- - API 密钥正确
129
- - 网络连接正常
130
- - 服务器端点可访问
131
-
132
- ### 5. 使用错误处理
133
-
134
- ```ruby
135
- begin
136
- client.flush
137
- rescue Langfuse::ValidationError => e
138
- if e.message.include?('Event type validation failed')
139
- puts "类型验证错误: #{e.message}"
140
- # 检查事件数据格式
141
- else
142
- puts "其他验证错误: #{e.message}"
143
- end
144
- rescue Langfuse::APIError => e
145
- puts "API 错误: #{e.message}"
146
- end
147
- ```
148
-
149
- ## 预防措施
150
-
151
- 1. **使用官方 SDK 方法**: 避免直接构造事件数据
152
- 2. **数据验证**: 在发送前验证数据完整性
153
- 3. **错误监控**: 实施适当的错误处理和监控
154
- 4. **测试环境**: 在测试环境中验证集成
155
- 5. **保持更新**: 定期更新 SDK 到最新版本
156
-
157
- ## 示例代码
158
-
159
- ```ruby
160
- # 正确的使用方式
161
- client = Langfuse.new(
162
- public_key: "pk-lf-xxx",
163
- secret_key: "sk-lf-xxx",
164
- debug: true
165
- )
166
-
167
- # 创建 trace
168
- trace = client.trace(
169
- name: "my-trace",
170
- user_id: "user-123",
171
- input: { query: "Hello" }
172
- )
173
-
174
- # 创建 generation
175
- generation = trace.generation(
176
- name: "my-generation",
177
- model: "gpt-3.5-turbo",
178
- input: [{ role: "user", content: "Hello" }],
179
- output: { content: "Hi there!" }
180
- )
181
-
182
- # 安全地刷新事件
183
- begin
184
- client.flush
185
- puts "事件发送成功"
186
- rescue => e
187
- puts "发送失败: #{e.message}"
188
- end
189
- ```
190
-
191
- ## 联系支持
192
-
193
- 如果问题持续存在,请提供:
194
- 1. 完整的错误消息
195
- 2. 调试模式的输出
196
- 3. 相关的代码片段
197
- 4. SDK 版本信息
198
-
199
- ## 更新日志
200
-
201
- - v0.1.1: 改进了错误消息的可读性
202
- - v0.1.0: 初始版本
@@ -1,164 +0,0 @@
1
- # URL Encoding Fix for Prompt Names
2
-
3
- ## Issue Summary
4
-
5
- **Issue ID**: AIF-2
6
- **Title**: Prompt names with `/` are not URL-encoded
7
- **Status**: Fixed
8
-
9
- ## Problem Description
10
-
11
- Prompt names containing special characters (particularly `/`) were not being URL-encoded before being interpolated into the API path when using `get_prompt`. This caused the server to misinterpret the prompt name as a nested path structure, resulting in 404 errors.
12
-
13
- ### Example
14
-
15
- ```ruby
16
- # Before fix
17
- client.get_prompt("EXEMPLE/my-prompt")
18
-
19
- # Generated URL (broken):
20
- # /api/public/v2/prompts/EXEMPLE/my-prompt
21
- # Server interprets this as: /api/public/v2/prompts/EXEMPLE/<nested-path>/my-prompt
22
- # Result: 404 Not Found
23
- ```
24
-
25
- ### Expected Behavior
26
-
27
- ```ruby
28
- # After fix
29
- client.get_prompt("EXEMPLE/my-prompt")
30
-
31
- # Generated URL (correct):
32
- # /api/public/v2/prompts/EXEMPLE%2Fmy-prompt
33
- # Server correctly interprets this as a single prompt name
34
- # Result: Prompt found successfully
35
- ```
36
-
37
- ## Solution
38
-
39
- ### Changes Made
40
-
41
- 1. **Added URL encoding utility** (`lib/langfuse/utils.rb`):
42
- - Added `Utils.url_encode` method using Ruby's `ERB::Util.url_encode`
43
- - Provides consistent URL encoding across the SDK
44
-
45
- 2. **Updated `get_prompt` method** (`lib/langfuse/client.rb`):
46
- - Automatically URL-encodes prompt names before constructing API paths
47
- - No breaking changes - existing code continues to work
48
-
49
- 3. **Added comprehensive tests** (`spec/langfuse/client_spec.rb`):
50
- - Tests for forward slashes in prompt names
51
- - Tests for spaces in prompt names
52
- - Tests for multiple special characters
53
- - Tests for simple names (no encoding needed)
54
-
55
- 4. **Updated documentation**:
56
- - Added note in README about automatic URL encoding
57
- - Added example demonstrating the feature
58
- - Updated CHANGELOG with fix details
59
-
60
- ### Code Changes
61
-
62
- #### lib/langfuse/utils.rb
63
- ```ruby
64
- def url_encode(string)
65
- ERB::Util.url_encode(string.to_s)
66
- end
67
- ```
68
-
69
- #### lib/langfuse/client.rb
70
- ```ruby
71
- def get_prompt(name, version: nil, label: nil, cache_ttl_seconds: 60)
72
- # ... existing code ...
73
-
74
- encoded_name = Utils.url_encode(name)
75
- path = "/api/public/v2/prompts/#{encoded_name}"
76
-
77
- # ... rest of method ...
78
- end
79
- ```
80
-
81
- ## Testing
82
-
83
- ### Test Coverage
84
-
85
- All test cases pass successfully:
86
-
87
- ```bash
88
- $ bundle exec rspec spec/langfuse/client_spec.rb -e "get_prompt"
89
-
90
- Langfuse::Client
91
- #get_prompt
92
- URL-encodes prompt names with special characters ✓
93
- URL-encodes prompt names with spaces ✓
94
- URL-encodes prompt names with multiple special characters ✓
95
- handles simple prompt names without special characters ✓
96
-
97
- 4 examples, 0 failures
98
- ```
99
-
100
- ### Test Cases
101
-
102
- 1. **Forward slash**: `EXEMPLE/my-prompt` → `EXEMPLE%2Fmy-prompt`
103
- 2. **Spaces**: `my prompt` → `my%20prompt`
104
- 3. **Multiple special chars**: `test/prompt name?query` → `test%2Fprompt%20name%3Fquery`
105
- 4. **Simple names**: `simple-prompt` → `simple-prompt` (no encoding needed)
106
-
107
- ## Usage
108
-
109
- ### Before Fix (Workaround)
110
-
111
- Users had to manually encode prompt names:
112
-
113
- ```ruby
114
- encoded_name = ERB::Util.url_encode("EXEMPLE/my-prompt")
115
- client.get_prompt(encoded_name)
116
- ```
117
-
118
- ### After Fix (Automatic)
119
-
120
- Users can now use prompt names directly:
121
-
122
- ```ruby
123
- # Works automatically!
124
- client.get_prompt("EXEMPLE/my-prompt")
125
- client.get_prompt("my prompt name")
126
- client.get_prompt("test/prompt?query")
127
- ```
128
-
129
- ## Backward Compatibility
130
-
131
- This fix is **100% backward compatible**:
132
-
133
- - Existing code continues to work without changes
134
- - Simple prompt names (without special characters) work exactly as before
135
- - If users were manually encoding names, double-encoding is prevented by the URL encoding algorithm
136
-
137
- ## Special Characters Supported
138
-
139
- The following special characters are now properly encoded:
140
-
141
- - `/` (forward slash) → `%2F`
142
- - ` ` (space) → `%20`
143
- - `?` (question mark) → `%3F`
144
- - `#` (hash) → `%23`
145
- - `@` (at sign) → `%40`
146
- - `&` (ampersand) → `%26`
147
- - `=` (equals) → `%3D`
148
- - `+` (plus) → `%2B`
149
- - And all other URL-unsafe characters
150
-
151
- ## Related Files
152
-
153
- - `lib/langfuse/utils.rb` - URL encoding utility
154
- - `lib/langfuse/client.rb` - Updated `get_prompt` method
155
- - `spec/langfuse/client_spec.rb` - Test coverage
156
- - `examples/url_encoding_demo.rb` - Usage examples
157
- - `CHANGELOG.md` - Change documentation
158
- - `README.md` - Updated documentation
159
-
160
- ## References
161
-
162
- - Linear Issue: AIF-2
163
- - Ruby ERB::Util documentation: https://ruby-doc.org/stdlib-3.0.0/libdoc/erb/rdoc/ERB/Util.html
164
- - URL encoding standard: RFC 3986