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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e76c5930ad4510169e7b27bca16789e5e8b72f1627f8e05546fe6450a649416a
4
- data.tar.gz: 7a3a1f3e8eb58674481f57e814b68d797135f5ea41856629bbbae9f17743e429
3
+ metadata.gz: 842e02d2d8d43ea2a989c5a0b5708022443cf532d7616ab4319a063705f808fa
4
+ data.tar.gz: 0c3349ae1dc50be9984bd440c520a74f2f972151338f1ff23aca5bc47d56837c
5
5
  SHA512:
6
- metadata.gz: 0b660877e4644a88e4a024512be55b2eeb5ea5cae8fb72a66f117a7ebfca2eefce6f2cfc10587afd9083b03b40e38c0fb30ca56ffbd4ce6723c09f2bf886acdf
7
- data.tar.gz: f17d7b1cc975749780feecf2dfca65056332e98bb6b2a3ef40cbe0663820ed66ee51f88776910590b8c27a8ec4fcfe586c188ee7126c99127e4dd410d4e7f8fb
6
+ metadata.gz: 68c3560e8e67c59f711c6433ba5950b48e5ecc0d955b039280399c81baf26361bb659eae89660f2180064b8a2ec7cf799bf0950b42cb5bc8c28b224fa6eb6c53
7
+ data.tar.gz: 9f2538a7659b6ab4f236f23fbecb0a594f0ad0778e82b4fc634a2179e355fb40fb5f9ec54f6b9df6cda558a93ca5d2522c950ed8fe454d800cea1db16f5b72ba
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- boxcars (0.8.1)
4
+ boxcars (0.8.2)
5
5
  faraday-retry (~> 2.0)
6
6
  google_search_results (~> 2.2)
7
7
  gpt4all (~> 0.0.5)
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
- backend1 = Boxcars::PosthogBackend.new(api_key: ENV['POSTHOG_API_KEY'])
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
- # Boxcars::Observability.backend = Boxcars::PosthogBackend.new(
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
- # Configures the PostHog client with the provided API key and host.
29
+ # Accepts a pre-configured PostHog client instance.
27
30
  #
28
- # @param api_key [String] Your PostHog project API key.
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(api_key:, host: 'https://app.posthog.com', _personal_api_key: nil, on_error: nil)
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
- @on_error_proc = on_error || proc do |status, body|
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.
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Boxcars
4
4
  # The current version of the gem.
5
- VERSION = "0.8.1"
5
+ VERSION = "0.8.2"
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boxcars
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francis Sullivan