boxcars 0.8.1 → 0.8.2
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/Gemfile.lock +1 -1
- data/README.md +29 -12
- data/lib/boxcars/observability_backends/posthog_backend.rb +8 -19
- data/lib/boxcars/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 842e02d2d8d43ea2a989c5a0b5708022443cf532d7616ab4319a063705f808fa
|
4
|
+
data.tar.gz: 0c3349ae1dc50be9984bd440c520a74f2f972151338f1ff23aca5bc47d56837c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68c3560e8e67c59f711c6433ba5950b48e5ecc0d955b039280399c81baf26361bb659eae89660f2180064b8a2ec7cf799bf0950b42cb5bc8c28b224fa6eb6c53
|
7
|
+
data.tar.gz: 9f2538a7659b6ab4f236f23fbecb0a594f0ad0778e82b4fc634a2179e355fb40fb5f9ec54f6b9df6cda558a93ca5d2522c950ed8fe454d800cea1db16f5b72ba
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -351,17 +351,30 @@ Set up observability by configuring a backend:
|
|
351
351
|
```ruby
|
352
352
|
# Using PostHog backend
|
353
353
|
require 'boxcars/observability_backends/posthog_backend'
|
354
|
+
require 'posthog'
|
355
|
+
|
356
|
+
# Create a PostHog client with your desired configuration
|
357
|
+
posthog_client = PostHog::Client.new(
|
358
|
+
api_key: ENV['POSTHOG_API_KEY'] || 'your_posthog_api_key',
|
359
|
+
host: 'https://app.posthog.com', # or your self-hosted instance
|
360
|
+
on_error: proc { |status, body|
|
361
|
+
Rails.logger.warn "PostHog error: #{status} - #{body}"
|
362
|
+
}
|
363
|
+
)
|
354
364
|
|
355
365
|
Boxcars.configure do |config|
|
356
|
-
config.observability_backend = Boxcars::PosthogBackend.new(
|
357
|
-
api_key: ENV['POSTHOG_API_KEY'] || 'your_posthog_api_key',
|
358
|
-
host: 'https://app.posthog.com' # or your self-hosted instance
|
359
|
-
)
|
366
|
+
config.observability_backend = Boxcars::PosthogBackend.new(client: posthog_client)
|
360
367
|
end
|
361
368
|
|
362
369
|
# Using multiple backends
|
363
370
|
require 'boxcars/observability_backends/multi_backend'
|
364
|
-
|
371
|
+
|
372
|
+
# Create PostHog client
|
373
|
+
posthog_client = PostHog::Client.new(
|
374
|
+
api_key: ENV['POSTHOG_API_KEY'],
|
375
|
+
host: 'https://app.posthog.com'
|
376
|
+
)
|
377
|
+
backend1 = Boxcars::PosthogBackend.new(client: posthog_client)
|
365
378
|
backend2 = YourCustomBackend.new
|
366
379
|
|
367
380
|
Boxcars.configure do |config|
|
@@ -440,14 +453,18 @@ The PostHog backend requires the `posthog-ruby` gem:
|
|
440
453
|
gem 'posthog-ruby'
|
441
454
|
|
442
455
|
# Configure the backend
|
456
|
+
require 'posthog'
|
457
|
+
|
458
|
+
posthog_client = PostHog::Client.new(
|
459
|
+
api_key: ENV['POSTHOG_API_KEY'],
|
460
|
+
host: 'https://app.posthog.com',
|
461
|
+
on_error: proc { |status, body|
|
462
|
+
Rails.logger.warn "PostHog error: #{status} - #{body}"
|
463
|
+
}
|
464
|
+
)
|
465
|
+
|
443
466
|
Boxcars.configure do |config|
|
444
|
-
config.observability_backend = Boxcars::PosthogBackend.new(
|
445
|
-
api_key: ENV['POSTHOG_API_KEY'],
|
446
|
-
host: 'https://app.posthog.com',
|
447
|
-
on_error: proc { |status, body|
|
448
|
-
Rails.logger.warn "PostHog error: #{status} - #{body}"
|
449
|
-
}
|
450
|
-
)
|
467
|
+
config.observability_backend = Boxcars::PosthogBackend.new(client: posthog_client)
|
451
468
|
end
|
452
469
|
```
|
453
470
|
|
@@ -9,10 +9,13 @@ module Boxcars
|
|
9
9
|
#
|
10
10
|
# Example Usage:
|
11
11
|
# require 'boxcars/observability_backends/posthog_backend'
|
12
|
-
#
|
12
|
+
# require 'posthog'
|
13
|
+
#
|
14
|
+
# client = PostHog::Client.new(
|
13
15
|
# api_key: 'YOUR_POSTHOG_API_KEY',
|
14
16
|
# host: 'https://app.posthog.com' # or your self-hosted instance
|
15
17
|
# )
|
18
|
+
# Boxcars::Observability.backend = Boxcars::PosthogBackend.new(client: client)
|
16
19
|
#
|
17
20
|
# # To track user-specific events, ensure :user_id is present in properties
|
18
21
|
# Boxcars::Observability.track(
|
@@ -23,32 +26,18 @@ module Boxcars
|
|
23
26
|
include Boxcars::ObservabilityBackend
|
24
27
|
|
25
28
|
# Initializes the PosthogBackend.
|
26
|
-
#
|
29
|
+
# Accepts a pre-configured PostHog client instance.
|
27
30
|
#
|
28
|
-
# @param
|
29
|
-
# @param host [String] The PostHog API host. Defaults to 'https://app.posthog.com'.
|
30
|
-
# @param _personal_api_key [String, nil] Optional: A personal API key for server-side operations if needed.
|
31
|
-
# @param on_error [Proc, nil] Optional: A lambda/proc to call when an error occurs during event capture.
|
32
|
-
# It receives the error code and error body as arguments.
|
33
|
-
# Defaults to a proc that logs the error to stderr.
|
31
|
+
# @param client [PostHog::Client] A configured PostHog client instance.
|
34
32
|
# @raise [LoadError] if the 'posthog-ruby' gem is not available.
|
35
|
-
def initialize(
|
33
|
+
def initialize(client:)
|
36
34
|
begin
|
37
35
|
require 'posthog'
|
38
36
|
rescue LoadError
|
39
37
|
raise LoadError, "The 'posthog-ruby' gem is required to use PosthogBackend. Please add it to your Gemfile."
|
40
38
|
end
|
41
39
|
|
42
|
-
@
|
43
|
-
Boxcars.error("PostHog error: Status #{status}, Body: #{body}", :red)
|
44
|
-
end
|
45
|
-
|
46
|
-
# The posthog-ruby gem uses a simpler API
|
47
|
-
@posthog_client = PostHog::Client.new(
|
48
|
-
api_key:,
|
49
|
-
host:,
|
50
|
-
on_error: @on_error_proc
|
51
|
-
)
|
40
|
+
@posthog_client = client
|
52
41
|
end
|
53
42
|
|
54
43
|
# Tracks an event with PostHog.
|
data/lib/boxcars/version.rb
CHANGED