Class: Tpt::Rails::DatadogFactory
- Inherits:
-
Object
- Object
- Tpt::Rails::DatadogFactory
- Defined in:
- lib/tpt/rails/datadog_factory.rb
Defined Under Namespace
Classes: DatadogFactoryNotConfigured
Constant Summary collapse
- DEFAULT_STATSD_PORT =
8125
- DEFAULT_TRACE_PORT =
8126
Class Method Summary collapse
-
.configure_tracing(trace_url: nil, environment: nil, trace_tags: nil, trace_debug: false) ⇒ Object
@description: Configure tracing.
- .disable_tracing ⇒ Object
-
.make(statsd_url: nil, environment: nil, statsd_tags: nil) ⇒ Datadog::Statsd
@description: Instantiates a datadog statsd instance.
- .make_dummy ⇒ Object
Class Method Details
.configure_tracing(trace_url: nil, environment: nil, trace_tags: nil, trace_debug: false) ⇒ Object
@description: Configure tracing. Just passing trace_url: is enough for a basic config.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/tpt/rails/datadog_factory.rb', line 65 def configure_tracing(trace_url: nil, environment:nil, trace_tags: nil, trace_debug: false) if !Tpt::Rails::configured? 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." raise(DatadogFactoryNotConfigured.new(msg)) end uri = URI.parse(trace_url) = { 'env' => to_env(environment) } ["tpt_release_version"] = Tpt::Rails.release_version if Tpt::Rails.release_version ::Datadog.configure do |c| # This will activate auto-instrumentation for Rails c.use :rails, { analytics_enabled: true, service_name: Tpt::Rails.app_name, } c.tracer( enabled: true, debug: trace_debug, hostname: uri.host, port: uri.port || DEFAULT_TRACE_PORT, tags: , ) c.logger.level = ::Logger::WARN yield(c) if block_given? end ::Datadog::Pipeline.before_flush( ::Datadog::Pipeline::SpanFilter.new { |span| span.resource =~ /TptRails::HealthChecksController/ }, ) end |
.disable_tracing ⇒ Object
102 103 104 |
# File 'lib/tpt/rails/datadog_factory.rb', line 102 def disable_tracing ::Datadog.configure { |c| c.tracer(enabled: false) } end |
.make(statsd_url: nil, environment: nil, statsd_tags: nil) ⇒ Datadog::Statsd
@description: Instantiates a datadog statsd instance. Note: has side effects, as it configures tracing.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/tpt/rails/datadog_factory.rb', line 31 def make(statsd_url: nil, environment: nil, statsd_tags: nil) if !Tpt::Rails::configured? msg = "Tpt::Rails is not configured. Either run make after configuration, or set a lamda for config.datadog_statsd_setup which will defer setup." raise(DatadogFactoryNotConfigured.new(msg)) end = Array.wrap() # Fall back to a dummy client so callers don't have to worry about null checking the client url = statsd_url || 'statsd://localhost' uri = URI.parse(url) = .nil? ? [] : << "env:#{to_env(environment)}" unless .map { |t| t.split(':')[0] }.include?("env") << "tpt-rails_release_version:#{Tpt::Rails.release_version}" if Tpt::Rails.release_version ::Datadog::Statsd.new( uri.host, uri.port || DEFAULT_STATSD_PORT, namespace: Tpt::Rails.app_name, tags: , ) end |
.make_dummy ⇒ Object
55 56 57 |
# File 'lib/tpt/rails/datadog_factory.rb', line 55 def make_dummy make end |