tpt-rails 1.7.0 → 1.7.1

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: 831a524d39259635bc860e843b2d2670f6c9915cdae576077b23fbfefbf238ad
4
- data.tar.gz: 8ad8e1171dbf2b6c8d2bae9ffac26a570364df1634adef7b26987fb100555077
3
+ metadata.gz: a17270ceace03741bb34bcac74250dd4f1b60a478a7870dde68896624bb892ca
4
+ data.tar.gz: ee980279b3354726a5a5050560fad3e8c5ef9324409acbf011890a8300f66bd8
5
5
  SHA512:
6
- metadata.gz: 3a4b96042265fa07dc0d02263107d71946b346ca2913e89965ff0e11fb53a57f5b048df17700eb4d57f5df3af8bc34a4e7bd148b1cfe38d811db65b0eee067ca
7
- data.tar.gz: ae189a0490e15964749f69eaf85431be09d2a57a25bcca5f74af42335889b7a1c44b7ce4934ee47a404a7807b433ebd24f7ffaab1e7dd7a540b19a1ea34cac72
6
+ metadata.gz: aa83fa139ee86f016380076133d29d2d2406d4aea9da733dd4842bd617a8c16a0418618252c87f10f5e099161bbb249bbc64955fdea15e1d8901bb26c6e6f045
7
+ data.tar.gz: b3b46f7c49c6d7675a84fafa0088e03b0edea729e7d3b604b568c4f9e45108cd853f43fffc1cf32d51c7c17d5f30be224eed2ac7c83c20fb7a77908088c7e982
data/README.md CHANGED
@@ -16,7 +16,7 @@ rails generate tpt:rails:configuration
16
16
 
17
17
  ### Configuration
18
18
 
19
- Running `rails generate tpt_rails:configure` will generate `config/initializers/tpt_rails.rb`. You
19
+ Running `rails generate tpt:rails:configuration` will generate `config/initializers/tpt_rails.rb`. You
20
20
  can configure this gem and enable optional features in that file.
21
21
 
22
22
  See the documentation in [lib/tpt/rails.rb](lib/tpt/rails.rb).
@@ -17,10 +17,12 @@ Tpt::Rails.configure do |config|
17
17
  # Either by setting a statsd url (a nil url will create a dummy statsd object):
18
18
  # config.datadog_statsd_url = "statsd://localhost:1234"
19
19
  #
20
- # Or by setting a custom statsd instance:
21
- # config.statsd = Tpt::Rails::DatadogFactory.make(
22
- # statsd_url: datadog_statsd_url,
23
- # )
20
+ # Or by setting a custom statsd setup lambda (which should return a statsd object):
21
+ # config.datadog_statsd_setup = -> {
22
+ # Tpt::Rails::DatadogFactory.make(
23
+ # statsd_url: "statsd://localhost:3000",
24
+ # )
25
+ # }
24
26
  #
25
27
  # See documentation in tpt-rails for all the options available on the make method
26
28
 
@@ -3,6 +3,12 @@ require 'tpt/rails/internal/error_reporter'
3
3
  require 'tpt/rails/internal/health_checks'
4
4
 
5
5
  class Tpt::Rails::Config
6
+ class MustBeCallableError < StandardError
7
+ def initialize(msg)
8
+ super(msg)
9
+ end
10
+ end
11
+
6
12
  #
7
13
  # You can set the following configs in your `Tpt::Rails.configure do |config|` block:
8
14
  #
@@ -13,8 +19,6 @@ class Tpt::Rails::Config
13
19
  attr_accessor :app_name
14
20
  # A project-specific api key from Bugsnag
15
21
  attr_accessor :bugsnag_api_key
16
- # Allow setting a customized Statsd; supercedes setting urls
17
- attr_accessor :statsd
18
22
  # Set this in the form of: statsd://[host]:[port]
19
23
  attr_accessor :datadog_statsd_url
20
24
  # Set this in the form of: datadog://[host]:[port]
@@ -27,6 +31,10 @@ class Tpt::Rails::Config
27
31
  attr_accessor :rollbar_access_token
28
32
  # Allow enabling/disabling Rollbar. Defaults to false.
29
33
  attr_accessor :rollbar_enabled
34
+ # Allows running a custom lambda to setup datadog statsd in configuration
35
+ attr_accessor :datadog_statsd_setup
36
+ # Allows running a custom lambda to setup datadog tracing in configuration
37
+ attr_accessor :datadog_trace_setup
30
38
 
31
39
  # Add a health check to the endpoint provided at `/internal/health-check` by
32
40
  # Tpt::Rails::HealthChecksController.
@@ -60,8 +68,18 @@ class Tpt::Rails::Config
60
68
  Redis.current = Redis.new(url: redis_url, driver: :hiredis)
61
69
  end
62
70
 
63
- if statsd
64
- @statsd = statsd
71
+ if !datadog_statsd_setup.nil?
72
+ if datadog_statsd_setup.respond_to?(:call)
73
+ @statsd = datadog_statsd_setup.call
74
+ datadog_statsd_setup = nil
75
+
76
+ unless @statsd.class == Datadog::Statsd
77
+ raise "datadog_statsd_setup MUST return a #{Datadog::Statsd.to_s} object! Instead, returned a #{@statsd.class}"
78
+ end
79
+ else
80
+ msg = "datadog_statsd_setup must be nil or callable. You should provide a lambda that returns a statsd object, probably from calling Tpt::Rails::DatadogFactory.make"
81
+ raise(MustBeCallableError.new(msg))
82
+ end
65
83
  else
66
84
  @statsd = Tpt::Rails::DatadogFactory.make(
67
85
  statsd_url: datadog_statsd_url,
@@ -70,6 +88,14 @@ class Tpt::Rails::Config
70
88
 
71
89
  if datadog_disable_trace
72
90
  Tpt::Rails::DatadogFactory.disable_tracing
91
+ elsif !datadog_trace_setup.nil?
92
+ if datadog_trace_setup.respond_to?(:call)
93
+ datadog_trace_setup.call
94
+ datadog_trace_setup = nil
95
+ else
96
+ msg = "datadog_trace_setup must be nil or callable. You should provide a lambda which calls Tpt::Rails::DatadogFactory.configure_tracing"
97
+ raise(MustBeCallableError.new(msg))
98
+ end
73
99
  elsif datadog_trace_url
74
100
  Tpt::Rails::DatadogFactory.configure_tracing(trace_url: datadog_trace_url)
75
101
  end
@@ -6,6 +6,12 @@ require 'datadog/statsd'
6
6
  require 'ddtrace'
7
7
 
8
8
  class Tpt::Rails::DatadogFactory
9
+ class DatadogFactoryNotConfigured < StandardError
10
+ def initialize(msg)
11
+ super(msg)
12
+ end
13
+ end
14
+
9
15
  DEFAULT_STATSD_PORT = 8125
10
16
  DEFAULT_TRACE_PORT = 8126
11
17
 
@@ -23,6 +29,11 @@ class Tpt::Rails::DatadogFactory
23
29
  # @return {Datadog::Statsd}
24
30
  ###
25
31
  def make(statsd_url: nil, environment: nil, statsd_tags: nil)
32
+ if !Tpt::Rails::configured?
33
+ msg = "Tpt::Rails is not configured. Either run make after configuration, or set a lamda for config.datadog_statsd_setup which will defer setup."
34
+ raise(DatadogFactoryNotConfigured.new(msg))
35
+ end
36
+
26
37
  statsd_tags = Array.wrap(statsd_tags)
27
38
 
28
39
  # Fall back to a dummy client so callers don't have to worry about null checking the client
@@ -52,6 +63,11 @@ class Tpt::Rails::DatadogFactory
52
63
  # @param {&block}: Pass to set custom configuration for tracing as part of a .configure call.
53
64
  # Accepts one parameter that is the configuration object.
54
65
  def configure_tracing(trace_url: nil, environment:nil, trace_tags: nil, trace_debug: false)
66
+ if !Tpt::Rails::configured?
67
+ msg = "Tpt::Rails is not configured. Either run configure_tracing after configuration, or set a lamda for config.datadog_trace_setup which will defer setup."
68
+ raise(DatadogFactoryNotConfigured.new(msg))
69
+ end
70
+
55
71
  uri = URI.parse(trace_url)
56
72
  tags = { 'env' => to_env(environment) }
57
73
  tags["tpt_release_version"] = Tpt::Rails.release_version if Tpt::Rails.release_version
@@ -1,6 +1,6 @@
1
1
  module Tpt
2
2
  module Rails
3
3
  # Do not change this manually. Our tooling will do it automatically.
4
- VERSION = '1.7.0'
4
+ VERSION = '1.7.1'
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tpt-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - TpT
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-10 00:00:00.000000000 Z
11
+ date: 2022-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails