tracekit 0.1.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 +7 -0
- data/CHANGELOG.md +138 -0
- data/LICENSE +21 -0
- data/README.md +509 -0
- data/lib/tracekit/config.rb +61 -0
- data/lib/tracekit/endpoint_resolver.rb +69 -0
- data/lib/tracekit/local_ui/detector.rb +30 -0
- data/lib/tracekit/local_ui_detector.rb +33 -0
- data/lib/tracekit/metrics/counter.rb +33 -0
- data/lib/tracekit/metrics/exporter.rb +100 -0
- data/lib/tracekit/metrics/gauge.rb +42 -0
- data/lib/tracekit/metrics/histogram.rb +21 -0
- data/lib/tracekit/metrics/metric_data_point.rb +18 -0
- data/lib/tracekit/metrics/registry.rb +69 -0
- data/lib/tracekit/middleware.rb +136 -0
- data/lib/tracekit/railtie.rb +36 -0
- data/lib/tracekit/sdk.rb +271 -0
- data/lib/tracekit/security/detector.rb +87 -0
- data/lib/tracekit/security/patterns.rb +22 -0
- data/lib/tracekit/snapshots/client.rb +202 -0
- data/lib/tracekit/snapshots/models.rb +26 -0
- data/lib/tracekit/version.rb +5 -0
- data/lib/tracekit.rb +89 -0
- metadata +195 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: '058e090e61dfe2cb69c18c210dcf53e593f2a5f055e43f178e7a5d58f52f28e6'
|
|
4
|
+
data.tar.gz: 680249888fb2ae4a22a2e53549c45e6630fe35c9de9d85d8a8011a8fcc5feac2
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 1b1ab7651b55e88f4f53dd82c9634fea099937c4b66e2c0707474942ae6505b07ba1ff2a0be1b4707e776cfba85840b1c3de86810aa57e39925e0a801fa946d9
|
|
7
|
+
data.tar.gz: 2fcdbc362f4176c6907d9dc4c0089f79548d738e739248657b0c8274fe57ca020199b7d39a047bae5a6846ca842a0a8c6f549f1001cec6dfbd9d729b534a21a6
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
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
|
+
## [0.1.0] - 2024-02-04
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Initial release of TraceKit Ruby SDK
|
|
13
|
+
- OpenTelemetry-based distributed tracing with W3C TraceContext propagation
|
|
14
|
+
- Metrics API with Counter, Gauge, and Histogram support
|
|
15
|
+
- Automatic metrics buffering (100 metrics or 10 seconds)
|
|
16
|
+
- OTLP/HTTP export for traces and metrics
|
|
17
|
+
- Code monitoring with snapshot capture and auto-registration
|
|
18
|
+
- Security scanning for PII and credentials with automatic redaction
|
|
19
|
+
- Local UI auto-detection for development workflows
|
|
20
|
+
- Rails integration via Railtie with automatic configuration
|
|
21
|
+
- Rack middleware for request instrumentation
|
|
22
|
+
- Thread-safe metrics collection using concurrent-ruby
|
|
23
|
+
- Comprehensive test suite with RSpec
|
|
24
|
+
- Cross-service test application (ruby-test) on port 5002
|
|
25
|
+
- Builder pattern configuration with fluent API
|
|
26
|
+
- Endpoint resolution logic matching SDK specification
|
|
27
|
+
- Graceful shutdown with resource cleanup
|
|
28
|
+
- Ruby 2.7+ support
|
|
29
|
+
|
|
30
|
+
### Features
|
|
31
|
+
|
|
32
|
+
#### Configuration
|
|
33
|
+
- Environment variable-based configuration for Rails
|
|
34
|
+
- Manual configuration for vanilla Ruby applications
|
|
35
|
+
- Configurable sampling rate (0.0 - 1.0)
|
|
36
|
+
- Configurable code monitoring poll interval
|
|
37
|
+
- SSL/TLS support with configurable endpoint
|
|
38
|
+
|
|
39
|
+
#### Distributed Tracing
|
|
40
|
+
- Automatic HTTP request/response tracing
|
|
41
|
+
- W3C TraceContext header propagation
|
|
42
|
+
- OpenTelemetry auto-instrumentation for common libraries
|
|
43
|
+
- Trace correlation with code monitoring snapshots
|
|
44
|
+
|
|
45
|
+
#### Metrics
|
|
46
|
+
- Counter: Monotonic increasing values
|
|
47
|
+
- Gauge: Point-in-time values with inc/dec/set operations
|
|
48
|
+
- Histogram: Value distribution recording
|
|
49
|
+
- Tag support for dimensional metrics
|
|
50
|
+
- Automatic buffering and batch export
|
|
51
|
+
- Thread-safe concurrent collection
|
|
52
|
+
|
|
53
|
+
#### Code Monitoring
|
|
54
|
+
- Non-breaking snapshot capture
|
|
55
|
+
- Automatic file/line/function context extraction
|
|
56
|
+
- Variable state capture with security scanning
|
|
57
|
+
- Breakpoint auto-registration
|
|
58
|
+
- Polling-based activation check (30-second interval)
|
|
59
|
+
- Trace correlation (trace_id, span_id)
|
|
60
|
+
- Zero performance impact when breakpoints inactive
|
|
61
|
+
|
|
62
|
+
#### Security
|
|
63
|
+
- PII detection: email, SSN, credit card, phone numbers
|
|
64
|
+
- Credential detection: API keys, AWS keys, Stripe keys, JWT, private keys, passwords
|
|
65
|
+
- Automatic redaction with security flags
|
|
66
|
+
- Variable-level scanning
|
|
67
|
+
|
|
68
|
+
#### Rails Integration
|
|
69
|
+
- Automatic Railtie configuration
|
|
70
|
+
- ENV-based configuration loading
|
|
71
|
+
- Automatic middleware insertion
|
|
72
|
+
- Graceful shutdown on Rails exit
|
|
73
|
+
- Zero-configuration setup
|
|
74
|
+
|
|
75
|
+
#### Rack Integration
|
|
76
|
+
- Request/response instrumentation
|
|
77
|
+
- Automatic metric tracking:
|
|
78
|
+
- `http.server.requests` (counter)
|
|
79
|
+
- `http.server.active_requests` (gauge)
|
|
80
|
+
- `http.server.request.duration` (histogram)
|
|
81
|
+
- Client IP extraction from headers
|
|
82
|
+
- OpenTelemetry span enrichment
|
|
83
|
+
|
|
84
|
+
### Dependencies
|
|
85
|
+
|
|
86
|
+
- opentelemetry-sdk ~> 1.2
|
|
87
|
+
- opentelemetry-exporter-otlp ~> 0.26
|
|
88
|
+
- opentelemetry-instrumentation-all ~> 0.50
|
|
89
|
+
- concurrent-ruby ~> 1.2
|
|
90
|
+
|
|
91
|
+
### Test Application
|
|
92
|
+
|
|
93
|
+
- Rails 7 API-only application
|
|
94
|
+
- Standard test endpoints for cross-service communication
|
|
95
|
+
- HTTParty for HTTP client testing
|
|
96
|
+
- Port 5002 (as per SDK specification)
|
|
97
|
+
- Environment variable configuration
|
|
98
|
+
- Example usage of all SDK features
|
|
99
|
+
|
|
100
|
+
### Documentation
|
|
101
|
+
|
|
102
|
+
- Comprehensive README with quick start guide
|
|
103
|
+
- API documentation with code examples
|
|
104
|
+
- Configuration reference
|
|
105
|
+
- Test application setup guide
|
|
106
|
+
- MIT License
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## Release Notes
|
|
111
|
+
|
|
112
|
+
### v0.1.0 - Initial Release
|
|
113
|
+
|
|
114
|
+
This is the first production-ready release of the TraceKit Ruby SDK. It provides complete feature parity with other TraceKit SDKs, including distributed tracing, metrics, and code monitoring.
|
|
115
|
+
|
|
116
|
+
**Key Highlights**:
|
|
117
|
+
|
|
118
|
+
1. **Rails-First Design**: Automatic configuration via Railtie makes Rails integration zero-configuration
|
|
119
|
+
2. **OpenTelemetry Native**: Built on industry-standard OpenTelemetry for maximum compatibility
|
|
120
|
+
3. **Thread-Safe**: Uses concurrent-ruby for safe metric collection in multi-threaded applications
|
|
121
|
+
4. **Security Built-In**: Automatic PII and credential detection prevents accidental data exposure
|
|
122
|
+
5. **Production-Ready**: Comprehensive error handling, graceful shutdown, and resource cleanup
|
|
123
|
+
|
|
124
|
+
**Tested With**:
|
|
125
|
+
- Ruby 2.7, 3.0, 3.1, 3.2, 3.3
|
|
126
|
+
- Rails 6.0, 6.1, 7.0, 7.1
|
|
127
|
+
- Sinatra 3.0+
|
|
128
|
+
- Rack 2.2+
|
|
129
|
+
|
|
130
|
+
**Breaking Changes**: None (initial release)
|
|
131
|
+
|
|
132
|
+
**Migration Guide**: Not applicable (initial release)
|
|
133
|
+
|
|
134
|
+
**Known Issues**: None
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
[0.1.0]: https://github.com/Tracekit-Dev/ruby-sdk/releases/tag/v0.1.0
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 TraceKit
|
|
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,509 @@
|
|
|
1
|
+
# TraceKit Ruby SDK
|
|
2
|
+
|
|
3
|
+
[](https://rubygems.org/gems/tracekit)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://www.ruby-lang.org/)
|
|
6
|
+
|
|
7
|
+
Official Ruby SDK for TraceKit APM - OpenTelemetry-based distributed tracing, metrics collection, and application performance monitoring for Ruby applications.
|
|
8
|
+
|
|
9
|
+
## Status
|
|
10
|
+
|
|
11
|
+
The SDK is production-ready with full support for distributed tracing, metrics, and code monitoring.
|
|
12
|
+
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
TraceKit Ruby SDK provides production-ready distributed tracing, metrics, and code monitoring capabilities for Ruby and Rails applications. Built on OpenTelemetry standards, it offers seamless integration with Rails through automatic Railtie configuration, comprehensive security scanning, and a lightweight metrics API for tracking application performance.
|
|
16
|
+
|
|
17
|
+
## Features
|
|
18
|
+
|
|
19
|
+
- **OpenTelemetry-Native**: Built on OpenTelemetry for maximum compatibility
|
|
20
|
+
- **Distributed Tracing**: Full support for distributed trace propagation across microservices
|
|
21
|
+
- **Auto-Instrumentation**: Automatic tracing for Rails, Rack, PostgreSQL, MySQL, Redis, Sidekiq, and HTTP clients
|
|
22
|
+
- **Explicit Span Kinds**: Server spans explicitly marked with `kind: Server` for proper trace classification
|
|
23
|
+
- **Metrics API**: Counter, Gauge, and Histogram metrics with automatic OTLP export
|
|
24
|
+
- **Code Monitoring**: Live production debugging with non-breaking snapshots
|
|
25
|
+
- **Security Scanning**: Automatic detection of sensitive data (PII, credentials)
|
|
26
|
+
- **Local UI Auto-Detection**: Automatically sends traces to local TraceKit UI
|
|
27
|
+
- **Rails Auto-Configuration**: Zero-configuration setup via Railtie
|
|
28
|
+
- **Rack Middleware**: Automatic request instrumentation for any Rack application
|
|
29
|
+
- **Thread-Safe Metrics**: Concurrent metric collection with automatic buffering
|
|
30
|
+
- **Production-Ready**: Comprehensive error handling and graceful shutdown
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
Add this line to your application's Gemfile:
|
|
35
|
+
|
|
36
|
+
```ruby
|
|
37
|
+
gem 'tracekit'
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
And then execute:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
bundle install
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Or install it yourself as:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
gem install tracekit
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Quick Start
|
|
53
|
+
|
|
54
|
+
### Rails Applications
|
|
55
|
+
|
|
56
|
+
The SDK automatically configures itself in Rails applications using environment variables:
|
|
57
|
+
|
|
58
|
+
**1. Create `.env` file:**
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
TRACEKIT_API_KEY=ctxio_abc123...
|
|
62
|
+
TRACEKIT_ENDPOINT=app.tracekit.dev
|
|
63
|
+
TRACEKIT_SERVICE_NAME=my-rails-app
|
|
64
|
+
TRACEKIT_ENVIRONMENT=production
|
|
65
|
+
TRACEKIT_CODE_MONITORING=true
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
**2. That's it!** The Railtie automatically:
|
|
69
|
+
- Loads configuration from ENV variables
|
|
70
|
+
- Initializes OpenTelemetry with OTLP exporters
|
|
71
|
+
- Adds Rack middleware for request instrumentation
|
|
72
|
+
- Sets up graceful shutdown
|
|
73
|
+
|
|
74
|
+
**3. Use the SDK in your controllers:**
|
|
75
|
+
|
|
76
|
+
```ruby
|
|
77
|
+
class CheckoutController < ApplicationController
|
|
78
|
+
def create
|
|
79
|
+
sdk = Tracekit.sdk
|
|
80
|
+
|
|
81
|
+
# Capture snapshot with context
|
|
82
|
+
sdk.capture_snapshot("checkout-start", {
|
|
83
|
+
userId: params[:user_id],
|
|
84
|
+
amount: params[:amount]
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
# Track metrics
|
|
88
|
+
sdk.counter("checkout.requests").add(1)
|
|
89
|
+
sdk.gauge("checkout.active").set(active_checkouts)
|
|
90
|
+
|
|
91
|
+
# Your business logic here...
|
|
92
|
+
|
|
93
|
+
sdk.capture_snapshot("checkout-complete", {
|
|
94
|
+
userId: params[:user_id],
|
|
95
|
+
paymentId: payment.id,
|
|
96
|
+
status: "success"
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
render json: { status: "success" }
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Vanilla Ruby Applications
|
|
105
|
+
|
|
106
|
+
For non-Rails applications, manually configure the SDK:
|
|
107
|
+
|
|
108
|
+
```ruby
|
|
109
|
+
require 'tracekit'
|
|
110
|
+
|
|
111
|
+
# Configure the SDK
|
|
112
|
+
Tracekit.configure do |config|
|
|
113
|
+
config.api_key = ENV['TRACEKIT_API_KEY']
|
|
114
|
+
config.service_name = 'my-service'
|
|
115
|
+
config.endpoint = 'app.tracekit.dev'
|
|
116
|
+
config.environment = 'production'
|
|
117
|
+
config.enable_code_monitoring = true
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
# Use the SDK
|
|
121
|
+
sdk = Tracekit.sdk
|
|
122
|
+
|
|
123
|
+
# Capture snapshots
|
|
124
|
+
sdk.capture_snapshot("process-start", {
|
|
125
|
+
jobId: job.id,
|
|
126
|
+
status: "processing"
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
# Track metrics
|
|
130
|
+
counter = sdk.counter("jobs.processed", { type: "background" })
|
|
131
|
+
counter.add(1)
|
|
132
|
+
|
|
133
|
+
# At application shutdown
|
|
134
|
+
Tracekit.shutdown
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Rack Middleware (Sinatra, Grape, etc.)
|
|
138
|
+
|
|
139
|
+
For Rack-based frameworks:
|
|
140
|
+
|
|
141
|
+
```ruby
|
|
142
|
+
require 'tracekit'
|
|
143
|
+
|
|
144
|
+
Tracekit.configure do |config|
|
|
145
|
+
config.api_key = ENV['TRACEKIT_API_KEY']
|
|
146
|
+
config.service_name = 'my-sinatra-app'
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
# Add middleware
|
|
150
|
+
use Tracekit::Middleware
|
|
151
|
+
|
|
152
|
+
# Your application code...
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Configuration Options
|
|
156
|
+
|
|
157
|
+
```ruby
|
|
158
|
+
Tracekit.configure do |config|
|
|
159
|
+
config.api_key = "ctxio_abc123..." # Required: Your TraceKit API key
|
|
160
|
+
config.service_name = "my-service" # Required: Service identifier
|
|
161
|
+
config.endpoint = "app.tracekit.dev" # Optional: TraceKit endpoint
|
|
162
|
+
config.use_ssl = true # Optional: Use HTTPS (default: true)
|
|
163
|
+
config.environment = "production" # Optional: Environment name
|
|
164
|
+
config.service_version = "1.0.0" # Optional: Service version
|
|
165
|
+
config.enable_code_monitoring = true # Optional: Enable snapshots
|
|
166
|
+
config.code_monitoring_poll_interval = 30 # Optional: Polling interval (seconds)
|
|
167
|
+
config.local_ui_port = 4000 # Optional: Local UI port
|
|
168
|
+
config.sampling_rate = 1.0 # Optional: Trace sampling (0.0-1.0)
|
|
169
|
+
end
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Environment Variables (Rails Auto-Configuration)
|
|
173
|
+
|
|
174
|
+
| Variable | Description | Default |
|
|
175
|
+
|----------|-------------|---------|
|
|
176
|
+
| `TRACEKIT_API_KEY` | Your TraceKit API key (required) | - |
|
|
177
|
+
| `TRACEKIT_SERVICE_NAME` | Service identifier | - |
|
|
178
|
+
| `TRACEKIT_ENDPOINT` | TraceKit endpoint | `app.tracekit.dev` |
|
|
179
|
+
| `TRACEKIT_ENVIRONMENT` | Environment name | `development` |
|
|
180
|
+
| `TRACEKIT_CODE_MONITORING` | Enable code monitoring | `true` |
|
|
181
|
+
| `TRACEKIT_SAMPLING_RATE` | Trace sampling rate | `1.0` |
|
|
182
|
+
|
|
183
|
+
## Metrics API
|
|
184
|
+
|
|
185
|
+
### Counter (Monotonic)
|
|
186
|
+
|
|
187
|
+
```ruby
|
|
188
|
+
sdk = Tracekit.sdk
|
|
189
|
+
|
|
190
|
+
# Create counter with tags
|
|
191
|
+
counter = sdk.counter("http.requests.total", {
|
|
192
|
+
service: "api",
|
|
193
|
+
endpoint: "/users"
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
# Increment
|
|
197
|
+
counter.add(1)
|
|
198
|
+
counter.add(5) # Add specific value
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### Gauge (Point-in-Time Values)
|
|
202
|
+
|
|
203
|
+
```ruby
|
|
204
|
+
# Create gauge
|
|
205
|
+
gauge = sdk.gauge("memory.usage.bytes")
|
|
206
|
+
|
|
207
|
+
# Set value
|
|
208
|
+
gauge.set(1024 * 1024 * 512) # 512 MB
|
|
209
|
+
|
|
210
|
+
# Increment/decrement
|
|
211
|
+
gauge.inc # +1
|
|
212
|
+
gauge.inc(10) # +10
|
|
213
|
+
gauge.dec # -1
|
|
214
|
+
gauge.dec(5) # -5
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### Histogram (Distributions)
|
|
218
|
+
|
|
219
|
+
```ruby
|
|
220
|
+
# Create histogram with tags
|
|
221
|
+
histogram = sdk.histogram("http.request.duration", {
|
|
222
|
+
unit: "ms"
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
# Record values
|
|
226
|
+
histogram.record(123.45)
|
|
227
|
+
histogram.record(67.89)
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### Automatic Buffering
|
|
231
|
+
|
|
232
|
+
Metrics are automatically:
|
|
233
|
+
- Buffered in memory (up to 100 metrics or 10 seconds)
|
|
234
|
+
- Exported in OTLP JSON format
|
|
235
|
+
- Batched for efficiency
|
|
236
|
+
- Thread-safe for concurrent access
|
|
237
|
+
|
|
238
|
+
## Code Monitoring
|
|
239
|
+
|
|
240
|
+
TraceKit enables non-breaking snapshots of your application's runtime state:
|
|
241
|
+
|
|
242
|
+
```ruby
|
|
243
|
+
sdk = Tracekit.sdk
|
|
244
|
+
|
|
245
|
+
# Capture snapshot with variable state
|
|
246
|
+
sdk.capture_snapshot("checkout-start", {
|
|
247
|
+
userId: 123,
|
|
248
|
+
amount: 99.99,
|
|
249
|
+
cart_items: ["item1", "item2"],
|
|
250
|
+
status: "processing"
|
|
251
|
+
})
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### Features
|
|
255
|
+
|
|
256
|
+
- **Automatic Context Capture**: File path, line number, function name extracted automatically
|
|
257
|
+
- **Security Scanning**: PII and credentials automatically detected and redacted
|
|
258
|
+
- **Trace Correlation**: Snapshots linked to active trace_id and span_id
|
|
259
|
+
- **Auto-Registration**: Breakpoints automatically registered on first capture
|
|
260
|
+
- **Zero Performance Impact**: When breakpoints are inactive, snapshots are skipped
|
|
261
|
+
|
|
262
|
+
### Security Detection
|
|
263
|
+
|
|
264
|
+
The SDK automatically detects and redacts:
|
|
265
|
+
|
|
266
|
+
**PII (Personally Identifiable Information)**:
|
|
267
|
+
- Email addresses
|
|
268
|
+
- Social Security Numbers (SSN)
|
|
269
|
+
- Credit card numbers
|
|
270
|
+
- Phone numbers
|
|
271
|
+
|
|
272
|
+
**Credentials**:
|
|
273
|
+
- API keys
|
|
274
|
+
- AWS access keys
|
|
275
|
+
- Stripe keys
|
|
276
|
+
- JWT tokens
|
|
277
|
+
- Private keys
|
|
278
|
+
- Passwords
|
|
279
|
+
|
|
280
|
+
Example:
|
|
281
|
+
```ruby
|
|
282
|
+
sdk.capture_snapshot("user-login", {
|
|
283
|
+
email: "user@example.com", # Redacted: [REDACTED]
|
|
284
|
+
password: "secret123", # Redacted: [REDACTED]
|
|
285
|
+
api_key: "sk_live_abc123..." # Redacted: [REDACTED]
|
|
286
|
+
})
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
## Distributed Tracing
|
|
290
|
+
|
|
291
|
+
The SDK automatically:
|
|
292
|
+
- Propagates W3C TraceContext headers (`traceparent`, `tracestate`)
|
|
293
|
+
- Creates spans for incoming HTTP requests (via middleware)
|
|
294
|
+
- Extracts trace context from upstream services
|
|
295
|
+
- Exports traces to TraceKit using OTLP/HTTP
|
|
296
|
+
|
|
297
|
+
### Auto-Instrumentation
|
|
298
|
+
|
|
299
|
+
The TraceKit Ruby SDK automatically instruments the following components when available:
|
|
300
|
+
|
|
301
|
+
**Web Frameworks:**
|
|
302
|
+
- **Rails** - Controller actions, request routing, and lifecycle events
|
|
303
|
+
- **Rack** - HTTP requests/responses with explicit `Server` span kind
|
|
304
|
+
- **ActionPack** - Controller and request/response processing
|
|
305
|
+
- **ActionView** - Template and view rendering
|
|
306
|
+
|
|
307
|
+
**HTTP Clients:**
|
|
308
|
+
- **Net::HTTP** - Standard library HTTP client with automatic trace propagation
|
|
309
|
+
- **HTTP gem** - HTTP gem client library
|
|
310
|
+
|
|
311
|
+
**Databases:**
|
|
312
|
+
- **ActiveRecord** - ORM layer operations (creates `Internal` spans)
|
|
313
|
+
- **PostgreSQL (PG)** - SQL queries with statement, system, and operation attributes (creates `Client` spans)
|
|
314
|
+
- **MySQL2** - MySQL database operations
|
|
315
|
+
|
|
316
|
+
**Background Jobs & Cache:**
|
|
317
|
+
- **Redis** - Cache operations and data access
|
|
318
|
+
- **Sidekiq** - Background job processing and queues
|
|
319
|
+
|
|
320
|
+
**Important:** The SDK's Rack middleware explicitly creates server spans with `kind: Server` for all incoming HTTP requests, ensuring consistent span classification across all Ruby frameworks (Rails, Sinatra, Grape, etc.).
|
|
321
|
+
|
|
322
|
+
### HTTP Client Instrumentation
|
|
323
|
+
|
|
324
|
+
OpenTelemetry automatically instruments HTTP clients:
|
|
325
|
+
|
|
326
|
+
```ruby
|
|
327
|
+
require 'net/http'
|
|
328
|
+
|
|
329
|
+
# Automatically traced - propagates trace context
|
|
330
|
+
uri = URI('http://localhost:8080/api/data')
|
|
331
|
+
response = Net::HTTP.get_response(uri)
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
### Span Hierarchy Example
|
|
335
|
+
|
|
336
|
+
A typical Rails request produces the following span hierarchy:
|
|
337
|
+
|
|
338
|
+
```
|
|
339
|
+
GET /users (kind: Server) - Root span from Tracekit::Middleware
|
|
340
|
+
├─ ApplicationController#users (kind: Internal) - Rails controller action
|
|
341
|
+
├─ User.all (kind: Internal) - ActiveRecord query
|
|
342
|
+
│ └─ SELECT * FROM users (kind: Client) - PostgreSQL query span
|
|
343
|
+
├─ User.where (kind: Internal) - ActiveRecord query
|
|
344
|
+
│ └─ SELECT * FROM users WHERE... (kind: Client) - PostgreSQL query span
|
|
345
|
+
└─ users/index rendering (kind: Internal) - ActionView template rendering
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
**Span Kinds:**
|
|
349
|
+
- `Server` - Incoming HTTP requests (set explicitly by TraceKit middleware)
|
|
350
|
+
- `Client` - Outgoing HTTP requests and database queries
|
|
351
|
+
- `Internal` - Application-level operations (ORM, rendering, etc.)
|
|
352
|
+
|
|
353
|
+
## Project Structure
|
|
354
|
+
|
|
355
|
+
```
|
|
356
|
+
ruby-sdk/
|
|
357
|
+
├── lib/
|
|
358
|
+
│ ├── tracekit/
|
|
359
|
+
│ │ ├── config.rb # Configuration with builder pattern
|
|
360
|
+
│ │ ├── endpoint_resolver.rb # URL resolution logic
|
|
361
|
+
│ │ ├── sdk.rb # Main SDK class
|
|
362
|
+
│ │ ├── railtie.rb # Rails auto-configuration
|
|
363
|
+
│ │ ├── middleware.rb # Rack middleware
|
|
364
|
+
│ │ ├── metrics/ # Metrics implementation
|
|
365
|
+
│ │ ├── security/ # Security scanning
|
|
366
|
+
│ │ └── snapshots/ # Code monitoring
|
|
367
|
+
│ └── tracekit.rb # Entry point
|
|
368
|
+
├── spec/ # RSpec tests
|
|
369
|
+
├── ruby-test/ # Cross-service test app
|
|
370
|
+
├── README.md
|
|
371
|
+
└── tracekit.gemspec
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
## Development Setup
|
|
375
|
+
|
|
376
|
+
### Prerequisites
|
|
377
|
+
|
|
378
|
+
- Ruby 2.7 or higher
|
|
379
|
+
- Bundler
|
|
380
|
+
- Git
|
|
381
|
+
- TraceKit API key
|
|
382
|
+
|
|
383
|
+
### Building from Source
|
|
384
|
+
|
|
385
|
+
```bash
|
|
386
|
+
# Clone the repository
|
|
387
|
+
git clone git@github.com:Tracekit-Dev/ruby-sdk.git
|
|
388
|
+
cd ruby-sdk
|
|
389
|
+
|
|
390
|
+
# Install dependencies
|
|
391
|
+
bundle install
|
|
392
|
+
|
|
393
|
+
# Run tests
|
|
394
|
+
bundle exec rspec
|
|
395
|
+
|
|
396
|
+
# Run test application
|
|
397
|
+
cd ruby-test
|
|
398
|
+
bundle install
|
|
399
|
+
cp .env.example .env
|
|
400
|
+
# Edit .env with your API key
|
|
401
|
+
bundle exec rails server -p 5002
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
### Running Tests
|
|
405
|
+
|
|
406
|
+
```bash
|
|
407
|
+
# Run all tests
|
|
408
|
+
bundle exec rspec
|
|
409
|
+
|
|
410
|
+
# Run specific test file
|
|
411
|
+
bundle exec rspec spec/tracekit/endpoint_resolver_spec.rb
|
|
412
|
+
|
|
413
|
+
# Run with coverage
|
|
414
|
+
COVERAGE=true bundle exec rspec
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
## Test Application
|
|
418
|
+
|
|
419
|
+
The `ruby-test/` directory contains a Rails API application for testing cross-service communication:
|
|
420
|
+
|
|
421
|
+
```bash
|
|
422
|
+
cd ruby-test
|
|
423
|
+
bundle exec rails server -p 5002
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
**Endpoints**:
|
|
427
|
+
- `GET /` - Service information
|
|
428
|
+
- `GET /health` - Health check
|
|
429
|
+
- `GET /test` - Code monitoring test
|
|
430
|
+
- `GET /error-test` - Exception test
|
|
431
|
+
- `GET /checkout` - Checkout simulation
|
|
432
|
+
- `GET /api/call-go` - Call Go test service
|
|
433
|
+
- `GET /api/call-node` - Call Node test service
|
|
434
|
+
- `GET /api/call-all` - Call all test services
|
|
435
|
+
|
|
436
|
+
See [ruby-test/README.md](ruby-test/README.md) for details.
|
|
437
|
+
|
|
438
|
+
## Requirements
|
|
439
|
+
|
|
440
|
+
- **Ruby**: 2.7 or later (tested up to 3.3)
|
|
441
|
+
- **Rails**: 6.0+ (for Rails integration)
|
|
442
|
+
- **Dependencies**:
|
|
443
|
+
- opentelemetry-sdk (~> 1.2)
|
|
444
|
+
- opentelemetry-exporter-otlp (~> 0.26)
|
|
445
|
+
- opentelemetry-instrumentation-all (~> 0.50)
|
|
446
|
+
- concurrent-ruby (~> 1.2)
|
|
447
|
+
- httparty (~> 0.21) (test app only)
|
|
448
|
+
|
|
449
|
+
## Documentation
|
|
450
|
+
|
|
451
|
+
- [CHANGELOG](CHANGELOG.md) - Version history and release notes
|
|
452
|
+
- [TraceKit Documentation](https://app.tracekit.dev/docs)
|
|
453
|
+
- [Test Application README](ruby-test/README.md)
|
|
454
|
+
|
|
455
|
+
## Troubleshooting
|
|
456
|
+
|
|
457
|
+
### Rails not auto-configuring
|
|
458
|
+
|
|
459
|
+
Ensure your `.env` file is loaded:
|
|
460
|
+
|
|
461
|
+
```ruby
|
|
462
|
+
# config/application.rb
|
|
463
|
+
require 'dotenv/load' if defined?(Dotenv)
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
### Metrics not appearing
|
|
467
|
+
|
|
468
|
+
Check that:
|
|
469
|
+
1. API key is valid
|
|
470
|
+
2. Endpoint is reachable
|
|
471
|
+
3. Metrics are being flushed (wait 10 seconds or accumulate 100 metrics)
|
|
472
|
+
|
|
473
|
+
### Snapshots not capturing
|
|
474
|
+
|
|
475
|
+
Verify:
|
|
476
|
+
1. `TRACEKIT_CODE_MONITORING=true`
|
|
477
|
+
2. API key has snapshot permissions
|
|
478
|
+
3. Breakpoints are registered (check logs)
|
|
479
|
+
|
|
480
|
+
## Support
|
|
481
|
+
|
|
482
|
+
- **Documentation**: https://docs.tracekit.dev
|
|
483
|
+
- **Issues**: https://github.com/Tracekit-Dev/ruby-sdk/issues
|
|
484
|
+
- **Email**: support@tracekit.dev
|
|
485
|
+
|
|
486
|
+
## Contributing
|
|
487
|
+
|
|
488
|
+
We welcome contributions! To contribute:
|
|
489
|
+
|
|
490
|
+
1. Fork the repository
|
|
491
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
492
|
+
3. Write tests for your changes
|
|
493
|
+
4. Ensure all tests pass (`bundle exec rspec`)
|
|
494
|
+
5. Commit your changes (`git commit -m 'Add amazing feature'`)
|
|
495
|
+
6. Push to the branch (`git push origin feature/amazing-feature`)
|
|
496
|
+
7. Open a Pull Request
|
|
497
|
+
|
|
498
|
+
## License
|
|
499
|
+
|
|
500
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
501
|
+
|
|
502
|
+
## Acknowledgments
|
|
503
|
+
|
|
504
|
+
Built on [OpenTelemetry](https://opentelemetry.io/) - the industry standard for observability.
|
|
505
|
+
|
|
506
|
+
---
|
|
507
|
+
|
|
508
|
+
**Repository**: git@github.com:Tracekit-Dev/ruby-sdk.git
|
|
509
|
+
**Version**: v0.1.0
|