posthog-rails 3.12.2 → 3.12.3
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/lib/posthog/rails/facade.rb +100 -0
- data/lib/posthog/rails/railtie.rb +5 -88
- data/lib/posthog/rails.rb +3 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 499457f4cdb3d65001ca2052dcce6231b7f56879333a5dd5c957376460a70992
|
|
4
|
+
data.tar.gz: e06c59907254de2d57373a167b20c21d5e54df9aca89b59bda2f138cd81e731b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6c51cd064c094fc7df538a348a3faf842a873597e527eadb65e341850649beb09e18159d191b32bce744077ed54afa6c791479c74045ed018007cb647b666a05
|
|
7
|
+
data.tar.gz: c61468861d957d4a5cc41276fdae05ce4f00d621af51320dbb05c8f9571df28aa1d89524600f25ce71e2bfe1b9864678b5340583888e7682a9da7b1cc514a847
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module PostHog
|
|
4
|
+
module Rails
|
|
5
|
+
# Install the Rails singleton-style PostHog facade at load time so Rails app
|
|
6
|
+
# initializers can call PostHog.init before Railtie initializers run.
|
|
7
|
+
#
|
|
8
|
+
# @api private
|
|
9
|
+
# @return [void]
|
|
10
|
+
def self.install_posthog_facade!
|
|
11
|
+
return if @posthog_facade_installed
|
|
12
|
+
|
|
13
|
+
PostHog.class_eval do
|
|
14
|
+
class << self
|
|
15
|
+
attr_accessor :client
|
|
16
|
+
|
|
17
|
+
# Initialize the singleton PostHog client used by Rails delegators.
|
|
18
|
+
#
|
|
19
|
+
# @param options [Hash] Core {PostHog::Client} options.
|
|
20
|
+
# @yieldparam config [PostHog::Rails::InitConfig] Block-based core SDK configuration.
|
|
21
|
+
# @return [PostHog::Client]
|
|
22
|
+
def init(options = {})
|
|
23
|
+
# If block given, yield to configuration
|
|
24
|
+
if block_given?
|
|
25
|
+
config = PostHog::Rails::InitConfig.new(options)
|
|
26
|
+
yield config
|
|
27
|
+
options = config.to_client_options
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Let the PostHog Logs pipeline reuse the same api_key/host without
|
|
31
|
+
# the core client exposing public readers.
|
|
32
|
+
PostHog::Rails::Logs::Setup.remember_client_options(options) if defined?(PostHog::Rails::Logs::Setup)
|
|
33
|
+
|
|
34
|
+
# Create the PostHog client. If a client already exists, shut it down
|
|
35
|
+
# after replacement so repeated init calls do not leave background
|
|
36
|
+
# resources from the previous instance running.
|
|
37
|
+
previous_client = @client
|
|
38
|
+
@client = PostHog::Client.new(options)
|
|
39
|
+
begin
|
|
40
|
+
previous_client&.shutdown
|
|
41
|
+
rescue StandardError => e
|
|
42
|
+
PostHog::Logging.logger.warn("Failed to shut down previous PostHog client: #{e.message}")
|
|
43
|
+
end
|
|
44
|
+
@client
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# @return [Boolean] Whether {PostHog.init} has created a client.
|
|
48
|
+
def initialized?
|
|
49
|
+
!@client.nil?
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Fallback for any client methods not explicitly defined.
|
|
53
|
+
#
|
|
54
|
+
# @api private
|
|
55
|
+
def method_missing(method_name, ...)
|
|
56
|
+
ensure_initialized!
|
|
57
|
+
|
|
58
|
+
if client.respond_to?(method_name)
|
|
59
|
+
client.public_send(method_name, ...)
|
|
60
|
+
else
|
|
61
|
+
super
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# @api private
|
|
66
|
+
def respond_to_missing?(method_name, include_private = false)
|
|
67
|
+
ensure_initialized!
|
|
68
|
+
client.respond_to?(method_name, include_private) || super
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
private
|
|
72
|
+
|
|
73
|
+
def ensure_initialized!
|
|
74
|
+
return if initialized?
|
|
75
|
+
|
|
76
|
+
@client = PostHog::Client.new(api_key: nil, silence_disabled_client_error: true)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
%i[
|
|
82
|
+
capture
|
|
83
|
+
capture_exception
|
|
84
|
+
identify
|
|
85
|
+
alias
|
|
86
|
+
group_identify
|
|
87
|
+
is_feature_enabled
|
|
88
|
+
get_feature_flag
|
|
89
|
+
get_all_flags
|
|
90
|
+
].each do |method_name|
|
|
91
|
+
PostHog.define_singleton_method(method_name) do |*args, **kwargs, &block|
|
|
92
|
+
ensure_initialized!
|
|
93
|
+
client.public_send(method_name, *args, **kwargs, &block)
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
@posthog_facade_installed = true
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
@@ -1,97 +1,14 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'posthog/rails/facade'
|
|
4
|
+
|
|
3
5
|
module PostHog
|
|
4
6
|
module Rails
|
|
5
7
|
class Railtie < ::Rails::Railtie
|
|
6
|
-
#
|
|
8
|
+
# Keep the historical Railtie initializer name, but install the facade at
|
|
9
|
+
# load time so application initializers can call PostHog.init.
|
|
7
10
|
initializer 'posthog.set_configs' do |_app|
|
|
8
|
-
PostHog.
|
|
9
|
-
class << self
|
|
10
|
-
attr_accessor :client
|
|
11
|
-
|
|
12
|
-
# Methods explicitly delegated to the client
|
|
13
|
-
DELEGATED_METHODS = %i[
|
|
14
|
-
capture
|
|
15
|
-
capture_exception
|
|
16
|
-
identify
|
|
17
|
-
alias
|
|
18
|
-
group_identify
|
|
19
|
-
is_feature_enabled
|
|
20
|
-
get_feature_flag
|
|
21
|
-
get_all_flags
|
|
22
|
-
].freeze
|
|
23
|
-
|
|
24
|
-
# Initialize the singleton PostHog client used by Rails delegators.
|
|
25
|
-
#
|
|
26
|
-
# @param options [Hash] Core {PostHog::Client} options.
|
|
27
|
-
# @yieldparam config [PostHog::Rails::InitConfig] Block-based core SDK configuration.
|
|
28
|
-
# @return [PostHog::Client]
|
|
29
|
-
def init(options = {})
|
|
30
|
-
# If block given, yield to configuration
|
|
31
|
-
if block_given?
|
|
32
|
-
config = PostHog::Rails::InitConfig.new(options)
|
|
33
|
-
yield config
|
|
34
|
-
options = config.to_client_options
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
# Let the PostHog Logs pipeline reuse the same api_key/host without
|
|
38
|
-
# the core client exposing public readers.
|
|
39
|
-
PostHog::Rails::Logs::Setup.remember_client_options(options) if defined?(PostHog::Rails::Logs::Setup)
|
|
40
|
-
|
|
41
|
-
# Create the PostHog client. If a client already exists, shut it down
|
|
42
|
-
# after replacement so repeated init calls do not leave background
|
|
43
|
-
# resources from the previous instance running.
|
|
44
|
-
previous_client = @client
|
|
45
|
-
@client = PostHog::Client.new(options)
|
|
46
|
-
begin
|
|
47
|
-
previous_client&.shutdown
|
|
48
|
-
rescue StandardError => e
|
|
49
|
-
PostHog::Logging.logger.warn("Failed to shut down previous PostHog client: #{e.message}")
|
|
50
|
-
end
|
|
51
|
-
@client
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
# Define delegated methods using metaprogramming
|
|
55
|
-
DELEGATED_METHODS.each do |method_name|
|
|
56
|
-
define_method(method_name) do |*args, **kwargs, &block|
|
|
57
|
-
ensure_initialized!
|
|
58
|
-
client.public_send(method_name, *args, **kwargs, &block)
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
# @return [Boolean] Whether {PostHog.init} has created a client.
|
|
63
|
-
def initialized?
|
|
64
|
-
!@client.nil?
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
# Fallback for any client methods not explicitly defined.
|
|
68
|
-
#
|
|
69
|
-
# @api private
|
|
70
|
-
def method_missing(method_name, ...)
|
|
71
|
-
ensure_initialized!
|
|
72
|
-
|
|
73
|
-
if client.respond_to?(method_name)
|
|
74
|
-
client.public_send(method_name, ...)
|
|
75
|
-
else
|
|
76
|
-
super
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
# @api private
|
|
81
|
-
def respond_to_missing?(method_name, include_private = false)
|
|
82
|
-
ensure_initialized!
|
|
83
|
-
client.respond_to?(method_name, include_private) || super
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
private
|
|
87
|
-
|
|
88
|
-
def ensure_initialized!
|
|
89
|
-
return if initialized?
|
|
90
|
-
|
|
91
|
-
@client = PostHog::Client.new(api_key: nil, silence_disabled_client_error: true)
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
end
|
|
11
|
+
PostHog::Rails.install_posthog_facade!
|
|
95
12
|
end
|
|
96
13
|
|
|
97
14
|
# Insert middleware for request context and exception capturing
|
data/lib/posthog/rails.rb
CHANGED
|
@@ -12,6 +12,7 @@ require 'posthog/rails/logs/severity'
|
|
|
12
12
|
require 'posthog/rails/logs/rate_limiter'
|
|
13
13
|
require 'posthog/rails/logs/appender'
|
|
14
14
|
require 'posthog/rails/logs/setup'
|
|
15
|
+
require 'posthog/rails/facade'
|
|
15
16
|
require 'posthog/rails/railtie'
|
|
16
17
|
|
|
17
18
|
module PostHog
|
|
@@ -63,3 +64,5 @@ module PostHog
|
|
|
63
64
|
end
|
|
64
65
|
end
|
|
65
66
|
end
|
|
67
|
+
|
|
68
|
+
PostHog::Rails.install_posthog_facade!
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: posthog-rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.12.
|
|
4
|
+
version: 3.12.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- PostHog
|
|
@@ -52,6 +52,7 @@ files:
|
|
|
52
52
|
- lib/posthog/rails/capture_exceptions.rb
|
|
53
53
|
- lib/posthog/rails/configuration.rb
|
|
54
54
|
- lib/posthog/rails/error_subscriber.rb
|
|
55
|
+
- lib/posthog/rails/facade.rb
|
|
55
56
|
- lib/posthog/rails/logs/appender.rb
|
|
56
57
|
- lib/posthog/rails/logs/rate_limiter.rb
|
|
57
58
|
- lib/posthog/rails/logs/setup.rb
|