coolhand 0.1.4 โ 0.2.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 +4 -4
- data/.rubocop.yml +2 -1
- data/CHANGELOG.md +53 -0
- data/README.md +32 -33
- data/docs/anthropic.md +518 -0
- data/lib/coolhand/ruby/anthropic_interceptor.rb +300 -0
- data/lib/coolhand/ruby/api_service.rb +18 -3
- data/lib/coolhand/ruby/base_interceptor.rb +148 -0
- data/lib/coolhand/ruby/faraday_interceptor.rb +129 -0
- data/lib/coolhand/ruby/version.rb +1 -1
- data/lib/coolhand/ruby.rb +38 -7
- metadata +12 -7
- data/coolhand-ruby.gemspec +0 -42
- data/lib/coolhand/ruby/interceptor.rb +0 -118
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fc0fc356a6cf69d4a0c67a906000cab9590d9fc2a452efec8037a7f541efa561
|
|
4
|
+
data.tar.gz: ec6f7a136ae1d8e139bf638175b81a2dda063b9bf19d0199ab7f7135cf6d833d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 131465dcaf94ae8cc4b5dce47252fe92effc9693ba4de6e61247714c682a717934fa3144cf3228bf754fe89a53803051f32a895c3a42fd3c07990d4cf74286a5
|
|
7
|
+
data.tar.gz: 26e03d0f27b9acbeb36ff6a0e0ee11cca55b8142cd17d494972013534ba4d8b3753b29fb3565dedb8c0f8daf1e26d7af443353999f5956f5b1b7b8d7ea139585
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,59 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.2.0] - 2025-12-16
|
|
9
|
+
|
|
10
|
+
### โจ Major New Features
|
|
11
|
+
- **Official Anthropic Gem Support** - Added comprehensive monitoring support for the official `anthropic` gem (v1.8+) through direct Net::HTTP interception
|
|
12
|
+
- **Dual Gem Compatibility** - Support for both `anthropic` (official) and `ruby-anthropic` (community) gems with automatic detection and appropriate interceptor selection
|
|
13
|
+
- **Streaming Response Support** - Enhanced SSE (Server-Sent Events) parsing for Anthropic streaming responses with proper message accumulation and reconstruction
|
|
14
|
+
- **Graceful Gem Conflict Handling** - Automatic detection when both anthropic gems are installed, with graceful degradation to ruby-anthropic monitoring
|
|
15
|
+
|
|
16
|
+
### ๐๏ธ Architecture Improvements
|
|
17
|
+
- **AnthropicInterceptor Module** - New dedicated interceptor for official anthropic gem requests with streaming response support
|
|
18
|
+
- **BaseInterceptor Module** - Shared functionality across interceptors with unified API logging format and DRY principles
|
|
19
|
+
- **Modular Design** - Moved from single `interceptor.rb` to specialized interceptors (`faraday_interceptor.rb`, `anthropic_interceptor.rb`)
|
|
20
|
+
- **Enhanced Configuration** - Automatic gem detection in `configure` block with appropriate interceptor selection
|
|
21
|
+
|
|
22
|
+
### ๐ง API & Format Changes
|
|
23
|
+
- **Unified Logging Format** - Standardized API request/response logging with `raw_request` wrapper and collector data integration
|
|
24
|
+
- **Headers Field Update** - API logs now use `headers` instead of `request_headers` for consistency
|
|
25
|
+
- **Silent Mode Override** - Critical warnings (like gem conflicts) now always display regardless of silent mode settings
|
|
26
|
+
|
|
27
|
+
### ๐งช Testing & Quality
|
|
28
|
+
- **Comprehensive Test Coverage** - Added 16 new specs covering all interceptor scenarios including gem conflict handling
|
|
29
|
+
- **RuboCop Compliance** - Applied linting with proper line length, verified doubles, and RSpec best practices
|
|
30
|
+
- **Thread Safety** - Enhanced request correlation with thread-local storage for streaming requests
|
|
31
|
+
|
|
32
|
+
### ๐๏ธ Supported Environments
|
|
33
|
+
- **Development Environment** - Uses official `anthropic` gem for Net::HTTP-based requests
|
|
34
|
+
- **AR_Dev Environment** - Uses `ruby-anthropic` gem for Faraday-based requests
|
|
35
|
+
- **Automatic Detection** - Coolhand detects which gem is loaded and applies appropriate interception
|
|
36
|
+
|
|
37
|
+
### ๐ Breaking Changes
|
|
38
|
+
- **Removed** - `lib/coolhand/ruby/interceptor.rb` replaced by specialized interceptor modules
|
|
39
|
+
- **API Change** - Logging format now uses `headers` field instead of `request_headers`
|
|
40
|
+
|
|
41
|
+
### ๐ Migration Guide
|
|
42
|
+
For users upgrading from v0.1.x:
|
|
43
|
+
- No code changes required for basic usage
|
|
44
|
+
- If depending on old `interceptor.rb` directly, update imports to use `faraday_interceptor.rb` or `anthropic_interceptor.rb`
|
|
45
|
+
- API log consumers should expect `headers` field instead of `request_headers`
|
|
46
|
+
|
|
47
|
+
### ๐ Compatibility Matrix
|
|
48
|
+
| Gem | Version | Interceptor | Status |
|
|
49
|
+
|-----|---------|-------------|--------|
|
|
50
|
+
| `anthropic` | 1.8+ | AnthropicInterceptor | โ
Full Support |
|
|
51
|
+
| `ruby-anthropic` | 0.4+ | FaradayInterceptor | โ
Full Support |
|
|
52
|
+
| Both gems | Any | FaradayInterceptor | โ ๏ธ Graceful Degradation |
|
|
53
|
+
|
|
54
|
+
## [0.1.5] - 2024-12-09
|
|
55
|
+
|
|
56
|
+
### ๐ Critical Bug Fixes
|
|
57
|
+
- **Fixed SystemStackError with APM tools** - Resolved critical conflict with Datadog and other APM tools that caused applications to crash on startup with "stack level too deep" error
|
|
58
|
+
- **Replaced alias_method with prepend** - Changed monkey-patching approach from `alias_method` to `prepend` for better compatibility with other instrumentation libraries
|
|
59
|
+
- **Added duplicate interceptor prevention** - Ensures only one Coolhand interceptor is added to each Faraday connection
|
|
60
|
+
|
|
8
61
|
## [0.1.3] - 2024-10-23
|
|
9
62
|
|
|
10
63
|
### โจ New Features
|
data/README.md
CHANGED
|
@@ -10,7 +10,7 @@ gem 'coolhand'
|
|
|
10
10
|
|
|
11
11
|
## Getting Started
|
|
12
12
|
|
|
13
|
-
1. **Get API Key**: Visit [
|
|
13
|
+
1. **Get API Key**: Visit [coolhandlabs.com](https://coolhandlabs.com/) to create a free account
|
|
14
14
|
2. **Install**: `gem install coolhand`
|
|
15
15
|
3. **Initialize**: Add configuration to your Ruby application
|
|
16
16
|
4. **Configure**: Set your API key in the configuration block
|
|
@@ -186,29 +186,7 @@ puts response.dig("choices", 0, "message", "content")
|
|
|
186
186
|
# The request and response have been automatically logged to Coolhand!
|
|
187
187
|
```
|
|
188
188
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
```ruby
|
|
192
|
-
require 'anthropic'
|
|
193
|
-
require 'coolhand/ruby'
|
|
194
|
-
|
|
195
|
-
# Configure Coolhand
|
|
196
|
-
Coolhand.configure do |config|
|
|
197
|
-
config.api_key = 'your_api_key_here'
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
# Use Anthropic normally - requests are automatically logged
|
|
201
|
-
anthropic = Anthropic::Client.new(access_token: ENV['ANTHROPIC_API_KEY'])
|
|
202
|
-
|
|
203
|
-
response = anthropic.messages(
|
|
204
|
-
model: "claude-3-opus",
|
|
205
|
-
max_tokens: 1024,
|
|
206
|
-
messages: [{ role: "user", content: "Hello, Claude!" }]
|
|
207
|
-
)
|
|
208
|
-
|
|
209
|
-
puts response["content"]
|
|
210
|
-
# Automatically logged to Coolhand!
|
|
211
|
-
```
|
|
189
|
+
๐ **[Complete Anthropic Integration Guide โ](docs/anthropic.md)** - Supports both official and community gems with automatic detection
|
|
212
190
|
|
|
213
191
|
## Logging Inbound Webhooks
|
|
214
192
|
|
|
@@ -285,23 +263,43 @@ The filtering is automatic and applies to all monitored API calls and webhook lo
|
|
|
285
263
|
|
|
286
264
|
## Supported Libraries
|
|
287
265
|
|
|
288
|
-
The monitor works with
|
|
266
|
+
The monitor works with multiple transport layers and Ruby libraries:
|
|
289
267
|
|
|
268
|
+
**Faraday-based libraries:**
|
|
290
269
|
- OpenAI Ruby SDK
|
|
291
|
-
- Anthropic
|
|
270
|
+
- ruby-anthropic gem (community Anthropic gem)
|
|
292
271
|
- ruby-openai gem
|
|
293
272
|
- LangChain.rb
|
|
294
273
|
- Direct Faraday requests
|
|
295
274
|
- Any other Faraday-based HTTP client
|
|
296
275
|
|
|
276
|
+
**Native HTTP libraries:**
|
|
277
|
+
- Official Anthropic Ruby SDK (using Net::HTTP)
|
|
278
|
+
- Any library using Net::HTTP directly
|
|
279
|
+
|
|
280
|
+
**Auto-detection**: Coolhand automatically detects which transport layer your libraries use and applies the appropriate monitoring strategy.
|
|
281
|
+
|
|
297
282
|
## How It Works
|
|
298
283
|
|
|
299
|
-
|
|
284
|
+
Coolhand uses a dual-interceptor strategy to monitor different HTTP transport layers:
|
|
285
|
+
|
|
286
|
+
### Faraday Interceptor
|
|
287
|
+
- Patches Faraday connections using middleware injection
|
|
288
|
+
- Monitors: OpenAI SDK, ruby-anthropic, LangChain.rb, and other Faraday-based libraries
|
|
289
|
+
- Handles: Standard HTTP requests and Server-Sent Events (SSE) for streaming
|
|
290
|
+
|
|
291
|
+
### Anthropic Interceptor
|
|
292
|
+
- Patches the official Anthropic gem's internal HTTP transport (Net::HTTP)
|
|
293
|
+
- Monitors: Official Anthropic Ruby SDK requests
|
|
294
|
+
|
|
295
|
+
### Request Flow
|
|
296
|
+
When a request matches configured LLM endpoints:
|
|
300
297
|
|
|
301
|
-
1. The original request executes normally
|
|
302
|
-
2. Request and response data (body, headers, status) are captured
|
|
303
|
-
3.
|
|
304
|
-
4.
|
|
298
|
+
1. The original request executes normally with zero performance impact
|
|
299
|
+
2. Request and response data (body, headers, status) are captured by the appropriate interceptor
|
|
300
|
+
3. For streaming requests, the complete accumulated response is captured (not individual chunks)
|
|
301
|
+
4. Data is sent to the Coolhand API asynchronously in a background thread
|
|
302
|
+
5. Your application continues without interruption
|
|
305
303
|
|
|
306
304
|
For non-matching endpoints, requests pass through unchanged.
|
|
307
305
|
|
|
@@ -351,7 +349,7 @@ end
|
|
|
351
349
|
|
|
352
350
|
## API Key
|
|
353
351
|
|
|
354
|
-
๐ **Sign up for free** at [
|
|
352
|
+
๐ **Sign up for free** at [coolhandlabs.com](https://coolhandlabs.com/) to get your API key and start monitoring your LLM usage.
|
|
355
353
|
|
|
356
354
|
**What you get:**
|
|
357
355
|
- Complete LLM request and response logging
|
|
@@ -369,6 +367,7 @@ The monitor handles errors gracefully:
|
|
|
369
367
|
|
|
370
368
|
## Integration Guides
|
|
371
369
|
|
|
370
|
+
- **[Anthropic Integration](docs/anthropic.md)** - Complete guide for both official and community Anthropic gems, including streaming, dual gem handling, and troubleshooting
|
|
372
371
|
- **[ElevenLabs Integration](docs/elevenlabs.md)** - Complete guide for integrating ElevenLabs Conversational AI with webhook capture and feedback submission
|
|
373
372
|
|
|
374
373
|
## Security
|
|
@@ -380,7 +379,7 @@ The monitor handles errors gracefully:
|
|
|
380
379
|
## Other Languages
|
|
381
380
|
|
|
382
381
|
- **Node.js**: [coolhand-node package](https://github.com/coolhand-io/coolhand-node) - Coolhand monitoring for Node.js applications
|
|
383
|
-
- **API Docs**: [API Documentation](https://
|
|
382
|
+
- **API Docs**: [API Documentation](https://coolhandlabs.com/docs) - Direct API integration documentation
|
|
384
383
|
|
|
385
384
|
## Community
|
|
386
385
|
|