Class: Datadog::Contrib::Sinatra::TracerCfg
- Inherits:
-
Object
- Object
- Datadog::Contrib::Sinatra::TracerCfg
- Defined in:
- lib/ddtrace/contrib/sinatra/tracer.rb
Overview
TracerCfg is used to manipulate the configuration of the Sinatra tracing extension.
Constant Summary collapse
- DEFAULT_CFG =
{ enabled: true, default_service: 'sinatra', tracer: Datadog.tracer, debug: false, trace_agent_hostname: Datadog::Writer::HOSTNAME, trace_agent_port: Datadog::Writer::PORT }.freeze()
Instance Attribute Summary collapse
-
#cfg ⇒ Object
Returns the value of attribute cfg.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #apply ⇒ Object
- #configure(args = {}) ⇒ Object
- #enabled? ⇒ Boolean
-
#initialize ⇒ TracerCfg
constructor
A new instance of TracerCfg.
Constructor Details
#initialize ⇒ TracerCfg
Returns a new instance of TracerCfg.
34 35 36 |
# File 'lib/ddtrace/contrib/sinatra/tracer.rb', line 34 def initialize @cfg = DEFAULT_CFG.dup() end |
Instance Attribute Details
#cfg ⇒ Object
Returns the value of attribute cfg.
32 33 34 |
# File 'lib/ddtrace/contrib/sinatra/tracer.rb', line 32 def cfg @cfg end |
Instance Method Details
#[](key) ⇒ Object
59 60 61 62 |
# File 'lib/ddtrace/contrib/sinatra/tracer.rb', line 59 def [](key) raise ArgumentError, "unknown setting '#{key}'" unless @cfg.key? key @cfg[key] end |
#[]=(key, value) ⇒ Object
64 65 66 67 |
# File 'lib/ddtrace/contrib/sinatra/tracer.rb', line 64 def []=(key, value) raise ArgumentError, "unknown setting '#{key}'" unless @cfg.key? key @cfg[key] = value end |
#apply ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ddtrace/contrib/sinatra/tracer.rb', line 46 def apply Datadog::Tracer.debug_logging = @cfg[:debug] tracer = @cfg[:tracer] tracer.enabled = @cfg[:enabled] tracer.configure(hostname: @cfg[:trace_agent_hostname], port: @cfg[:trace_agent_port]) tracer.set_service_info(@cfg[:default_service], 'sinatra', Datadog::Ext::AppTypes::WEB) end |
#configure(args = {}) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/ddtrace/contrib/sinatra/tracer.rb', line 38 def configure(args = {}) args.each do |name, value| self[name] = value end apply() end |
#enabled? ⇒ Boolean
69 70 71 |
# File 'lib/ddtrace/contrib/sinatra/tracer.rb', line 69 def enabled? @cfg[:enabled] && !@cfg[:tracer].nil? end |