lf-cli 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: fdeceb3ae604e49a50b2c4e102e0406996505257235b7b10433f8df99c526ec6
4
+ data.tar.gz: 831fa990a296665a8dcfd6935ec4678c02c8671eb961a9ed0e3f106b13a95a0f
5
+ SHA512:
6
+ metadata.gz: f7de2b11e739ed088c1a4681549273e8668450a951dfae52fe87bcb071d1f6def1dfbc35ec551bb056e71615e0eb5a7d636dd3ac0df9df918a008fd376bcabb7
7
+ data.tar.gz: a34a06e7543ada8bca0b2451525222b173fa93c5de66edcc8f1b6344725a0027c7708a56717cb17d7fd3d1821d8de9d847cc784aa948c057802407e5998eae6b
data/CHANGELOG.md ADDED
@@ -0,0 +1,43 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [1.0.0] - 2025-01-23
9
+
10
+ ### Added
11
+ - Initial release of lf-cli (renamed from langfuse-cli)
12
+ - Interactive configuration setup with browser integration
13
+ - Traces command with list and get operations
14
+ - Sessions command with list and show operations
15
+ - Observations command with list and get operations
16
+ - Scores command with list and get operations
17
+ - Metrics command with query operation and custom aggregations
18
+ - Support for multiple output formats (table, JSON, CSV, markdown)
19
+ - Multi-profile configuration support
20
+ - Automatic pagination for list operations
21
+ - Time range filtering with ISO 8601 and natural language support
22
+ - Sorbet Runtime type safety with T::Enum and T::Struct
23
+ - Comprehensive help messages with valid values and examples
24
+ - 55 passing unit tests with 100% success rate
25
+
26
+ ### Changed
27
+ - Renamed project from `langfuse-cli` to `lf-cli` for trademark compliance
28
+ - Renamed executable from `langfuse` to `lf`
29
+ - Updated description to clarify unofficial/community status
30
+
31
+ ### Security
32
+ - Configuration file created with 0600 permissions (owner read/write only)
33
+ - API keys masked in configuration display commands
34
+ - Connection validation before saving credentials
35
+
36
+ ## [Unreleased]
37
+
38
+ ### Planned
39
+ - Support for filtering by metadata
40
+ - Trace export with full observation trees
41
+ - Watch mode for real-time trace monitoring
42
+ - Creating/updating scores via CLI
43
+ - Integration with other observability tools
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Vicente Reig Rincรณn de Arellano
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,399 @@
1
+ # lf-cli
2
+
3
+ **An open-source CLI for Langfuseยฎ**
4
+
5
+ A powerful command-line interface for querying and analyzing Langfuse LLM observability data. Built with Ruby and designed for developers who prefer working in the terminal.
6
+
7
+ [![Gem Version](https://badge.fury.io/rb/lf-cli.svg)](https://badge.fury.io/rb/lf-cli)
8
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
9
+
10
+ ## Disclaimer
11
+
12
+ **This is an unofficial, community-maintained CLI tool for Langfuse.**
13
+
14
+ This project is not affiliated with, endorsed by, or sponsored by Langfuse GmbH. Langfuseยฎ is a registered trademark of Langfuse GmbH.
15
+
16
+ ## Features
17
+
18
+ - ๐Ÿ” **Query Traces** - List and filter traces by name, user, session, tags, or time range
19
+ - ๐Ÿ“Š **Analyze Sessions** - View complete session details with all associated traces
20
+ - ๐ŸŽฏ **Inspect Observations** - List LLM generations, spans, and events
21
+ - ๐Ÿ“ˆ **Query Metrics** - Run analytics queries with custom aggregations and dimensions
22
+ - โญ **View Scores** - Access quality scores and evaluation metrics
23
+ - ๐ŸŽจ **Multiple Output Formats** - Table, JSON, CSV, or Markdown
24
+ - ๐Ÿ” **Multi-Profile Support** - Manage credentials for dev, staging, and production
25
+ - ๐ŸŒ **Interactive Setup** - Browser-integrated credential configuration
26
+ - โšก **Type-Safe** - Built with Sorbet Runtime for reliability
27
+
28
+ ## Installation
29
+
30
+ ### Install from RubyGems
31
+
32
+ ```bash
33
+ gem install lf-cli
34
+ ```
35
+
36
+ ### Install from Source
37
+
38
+ ```bash
39
+ git clone https://github.com/vicentereig/lf-cli.git
40
+ cd lf-cli
41
+ bundle install
42
+ bundle exec rake install
43
+ ```
44
+
45
+ ### Requirements
46
+
47
+ - Ruby >= 2.7.0
48
+ - Langfuse account (cloud or self-hosted)
49
+
50
+ ## Quick Start
51
+
52
+ ### 1. Configure Credentials
53
+
54
+ Run the interactive setup wizard:
55
+
56
+ ```bash
57
+ lf config setup
58
+ ```
59
+
60
+ This will:
61
+ 1. Ask for your Langfuse project name
62
+ 2. Open your browser to the Langfuse settings page
63
+ 3. Prompt you to enter your API keys
64
+ 4. Test the connection
65
+ 5. Save credentials securely to `~/.langfuse/config.yml`
66
+
67
+ ### 2. Start Querying
68
+
69
+ ```bash
70
+ # List recent traces
71
+ lf traces list --from "1 hour ago" --limit 20
72
+
73
+ # Get specific trace details
74
+ lf traces get trace_abc123
75
+
76
+ # Query metrics
77
+ lf metrics query --view traces --measure count --aggregation count
78
+ ```
79
+
80
+ ## Usage
81
+
82
+ ### Configuration Commands
83
+
84
+ ```bash
85
+ # Interactive setup (recommended)
86
+ lf config setup
87
+
88
+ # Set credentials manually
89
+ lf config set production \
90
+ --public-key pk_... \
91
+ --secret-key sk_...
92
+
93
+ # Show current configuration (keys are masked)
94
+ lf config show
95
+
96
+ # List all profiles
97
+ lf config list
98
+ ```
99
+
100
+ ### Trace Commands
101
+
102
+ ```bash
103
+ # List all traces
104
+ lf traces list
105
+
106
+ # Filter traces by various criteria
107
+ lf traces list \
108
+ --name "chat_completion" \
109
+ --user-id user_123 \
110
+ --from "2024-01-01" \
111
+ --limit 50
112
+
113
+ # Get detailed trace information
114
+ lf traces get trace_abc123
115
+
116
+ # Export to CSV
117
+ lf traces list --format csv --output traces.csv
118
+ ```
119
+
120
+ ### Session Commands
121
+
122
+ ```bash
123
+ # List all sessions
124
+ lf sessions list
125
+
126
+ # Show specific session with details
127
+ lf sessions show session_xyz789
128
+ ```
129
+
130
+ ### Observation Commands
131
+
132
+ ```bash
133
+ # List all observations
134
+ lf observations list
135
+
136
+ # Filter by type
137
+ lf observations list --type generation
138
+
139
+ # Filter by trace
140
+ lf observations list --trace-id trace_abc123
141
+ ```
142
+
143
+ ### Score Commands
144
+
145
+ ```bash
146
+ # List all scores
147
+ lf scores list
148
+
149
+ # Filter by name
150
+ lf scores list --name quality
151
+
152
+ # Get specific score
153
+ lf scores get score_123
154
+ ```
155
+
156
+ ### Metrics Commands
157
+
158
+ ```bash
159
+ # Count total traces
160
+ lf metrics query \
161
+ --view traces \
162
+ --measure count \
163
+ --aggregation count
164
+
165
+ # Average latency by trace name
166
+ lf metrics query \
167
+ --view observations \
168
+ --measure latency \
169
+ --aggregation avg \
170
+ --dimensions name
171
+
172
+ # Token usage with time range
173
+ lf metrics query \
174
+ --view observations \
175
+ --measure tokens \
176
+ --aggregation sum \
177
+ --from "2024-01-01" \
178
+ --to "2024-12-31"
179
+
180
+ # P95 latency grouped by model
181
+ lf metrics query \
182
+ --view observations \
183
+ --measure latency \
184
+ --aggregation p95 \
185
+ --dimensions model
186
+ ```
187
+
188
+ ### Global Options
189
+
190
+ All commands support these global options:
191
+
192
+ ```bash
193
+ -f, --format [table|json|csv|markdown] # Output format (default: table)
194
+ -o, --output FILE # Save output to file
195
+ -l, --limit N # Limit number of results
196
+ -P, --profile PROFILE # Use specific profile
197
+ --from TIMESTAMP # Start of time range (ISO 8601 or relative)
198
+ --to TIMESTAMP # End of time range
199
+ -v, --verbose # Verbose output
200
+ ```
201
+
202
+ ### Time Range Examples
203
+
204
+ Supports both ISO 8601 and natural language:
205
+
206
+ ```bash
207
+ # ISO 8601
208
+ --from "2024-01-01T00:00:00Z" --to "2024-12-31T23:59:59Z"
209
+
210
+ # Natural language (requires 'chronic' gem)
211
+ --from "1 hour ago"
212
+ --from "yesterday"
213
+ --from "last monday"
214
+ ```
215
+
216
+ ## Output Formats
217
+
218
+ ### Table (Default)
219
+
220
+ ```bash
221
+ lf traces list --format table
222
+ ```
223
+
224
+ Outputs a formatted ASCII table - great for terminal viewing.
225
+
226
+ ### JSON
227
+
228
+ ```bash
229
+ lf traces list --format json
230
+ ```
231
+
232
+ Perfect for piping to `jq` or other tools:
233
+
234
+ ```bash
235
+ lf traces list --format json | jq '.[] | select(.name == "chat")'
236
+ ```
237
+
238
+ ### CSV
239
+
240
+ ```bash
241
+ lf traces list --format csv --output data.csv
242
+ ```
243
+
244
+ Import into spreadsheets or data analysis tools.
245
+
246
+ ### Markdown
247
+
248
+ ```bash
249
+ lf traces list --format markdown
250
+ ```
251
+
252
+ Great for documentation and reports.
253
+
254
+ ## Configuration
255
+
256
+ ### Configuration File
257
+
258
+ Credentials are stored in `~/.langfuse/config.yml`:
259
+
260
+ ```yaml
261
+ profiles:
262
+ default:
263
+ host: https://cloud.langfuse.com
264
+ public_key: pk_...
265
+ secret_key: sk_...
266
+ output_format: table
267
+ page_limit: 50
268
+
269
+ production:
270
+ host: https://cloud.langfuse.com
271
+ public_key: pk_prod_...
272
+ secret_key: sk_prod_...
273
+ ```
274
+
275
+ The file is created with `0600` permissions (owner read/write only) for security.
276
+
277
+ ### Environment Variables
278
+
279
+ You can also use environment variables:
280
+
281
+ ```bash
282
+ export LANGFUSE_PUBLIC_KEY="pk_..."
283
+ export LANGFUSE_SECRET_KEY="sk_..."
284
+ export LANGFUSE_HOST="https://cloud.langfuse.com"
285
+ export LANGFUSE_PROFILE="production"
286
+ ```
287
+
288
+ ### Priority Order
289
+
290
+ Configuration is loaded in this order (highest to lowest priority):
291
+
292
+ 1. Command-line flags (`--public-key`, `--secret-key`, etc.)
293
+ 2. Environment variables (`LANGFUSE_PUBLIC_KEY`, etc.)
294
+ 3. Config file (`~/.langfuse/config.yml`)
295
+ 4. Defaults
296
+
297
+ ## Development
298
+
299
+ ### Setup
300
+
301
+ ```bash
302
+ git clone https://github.com/vicentereig/lf-cli.git
303
+ cd lf-cli
304
+ bundle install
305
+ ```
306
+
307
+ ### Run Tests
308
+
309
+ ```bash
310
+ # Run all tests
311
+ bundle exec rspec
312
+
313
+ # Run with documentation format
314
+ bundle exec rspec --format documentation
315
+
316
+ # Run specific test file
317
+ bundle exec rspec spec/unit/commands/traces_spec.rb
318
+ ```
319
+
320
+ ### Run CLI Locally
321
+
322
+ ```bash
323
+ ./bin/lf help
324
+ ./bin/lf config setup
325
+ ```
326
+
327
+ ### Code Structure
328
+
329
+ ```
330
+ lib/langfuse/cli/
331
+ โ”œโ”€โ”€ client.rb # API client with Faraday
332
+ โ”œโ”€โ”€ config.rb # Configuration management
333
+ โ”œโ”€โ”€ types.rb # Sorbet type definitions
334
+ โ”œโ”€โ”€ formatters/ # Output formatters
335
+ โ”‚ โ”œโ”€โ”€ table_formatter.rb
336
+ โ”‚ โ”œโ”€โ”€ csv_formatter.rb
337
+ โ”‚ โ””โ”€โ”€ markdown_formatter.rb
338
+ โ””โ”€โ”€ commands/ # Command modules
339
+ โ”œโ”€โ”€ traces.rb
340
+ โ”œโ”€โ”€ sessions.rb
341
+ โ”œโ”€โ”€ observations.rb
342
+ โ”œโ”€โ”€ scores.rb
343
+ โ”œโ”€โ”€ metrics.rb
344
+ โ””โ”€โ”€ config.rb
345
+ ```
346
+
347
+ ## API Reference
348
+
349
+ This CLI uses the Langfuse Public API:
350
+
351
+ - **API Documentation**: https://api.reference.langfuse.com/
352
+ - **OpenAPI Spec**: https://cloud.langfuse.com/generated/api/openapi.yml
353
+
354
+ Valid enum values for `metrics query`:
355
+
356
+ - **View**: `traces`, `observations`, `scores-numeric`, `scores-categorical`
357
+ - **Measure**: `count`, `latency`, `value`, `tokens`, `cost`
358
+ - **Aggregation**: `count`, `sum`, `avg`, `p50`, `p95`, `p99`, `min`, `max`, `histogram`
359
+ - **Granularity**: `minute`, `hour`, `day`, `week`, `month`, `auto`
360
+
361
+ ## Contributing
362
+
363
+ Contributions are welcome! Please feel free to submit a Pull Request.
364
+
365
+ 1. Fork the repository
366
+ 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
367
+ 3. Write tests for your changes
368
+ 4. Commit your changes (`git commit -m 'Add amazing feature'`)
369
+ 5. Push to the branch (`git push origin feature/amazing-feature`)
370
+ 6. Open a Pull Request
371
+
372
+ ## License
373
+
374
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
375
+
376
+ ## Acknowledgments
377
+
378
+ - Built with [Thor](https://github.com/rails/thor) CLI framework
379
+ - Uses [Faraday](https://github.com/lostisland/faraday) for HTTP requests
380
+ - Type safety with [Sorbet Runtime](https://sorbet.org/)
381
+ - Inspired by the excellent [Langfuse](https://langfuse.com/) observability platform
382
+
383
+ ## Support
384
+
385
+ - ๐Ÿ› **Bug Reports**: [GitHub Issues](https://github.com/vicentereig/lf-cli/issues)
386
+ - ๐Ÿ’ฌ **Questions**: [GitHub Discussions](https://github.com/vicentereig/lf-cli/discussions)
387
+ - ๐Ÿ“ง **Email**: hey@vicente.services
388
+
389
+ ## Roadmap
390
+
391
+ - [ ] Add support for filtering by metadata
392
+ - [ ] Implement trace export with full observation trees
393
+ - [ ] Add watch mode for real-time trace monitoring
394
+ - [ ] Support for creating/updating scores via CLI
395
+ - [ ] Integration with other observability tools
396
+
397
+ ---
398
+
399
+ **Note**: This is a community project. For official Langfuse support and documentation, visit [langfuse.com](https://langfuse.com/).
data/bin/lf ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "langfuse_cli"
5
+
6
+ begin
7
+ Langfuse::CLI::Main.start(ARGV)
8
+ rescue Langfuse::CLI::Error => e
9
+ puts "Error: #{e.message}"
10
+ exit 1
11
+ rescue StandardError => e
12
+ puts "Unexpected error: #{e.message}"
13
+ puts e.backtrace if ENV['DEBUG']
14
+ exit 1
15
+ end