Class: Datadog::Contrib::Sinatra::TracerCfg

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeTracerCfg

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

#cfgObject

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

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


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

#applyObject



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

Returns:

  • (Boolean)


69
70
71
# File 'lib/ddtrace/contrib/sinatra/tracer.rb', line 69

def enabled?
  @cfg[:enabled] && !@cfg[:tracer].nil?
end