Class: ElasticAPM::Agent Private

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/elastic_apm/agent.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

rubocop:disable Metrics/ClassLength

Constant Summary collapse

LOCK =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Mutex.new

Constants included from Logging

Logging::LEVELS, Logging::PREFIX

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

#debug, #error, #fatal, #info, #warn

Constructor Details

#initialize(config) ⇒ Agent

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Agent.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/elastic_apm/agent.rb', line 50

def initialize(config)
  @config = config

  @stacktrace_builder = StacktraceBuilder.new(config)
  @context_builder = ContextBuilder.new(config)
  @error_builder = ErrorBuilder.new(self)

  @transport = Transport::Base.new(config)
  @instrumenter = Instrumenter.new(
    config,
    stacktrace_builder: stacktrace_builder
  ) { |event| enqueue event }
  @metrics = Metrics.new(config) { |event| enqueue event }
end

Instance Attribute Details

#configObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



65
66
67
# File 'lib/elastic_apm/agent.rb', line 65

def config
  @config
end

#context_builderObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



65
66
67
# File 'lib/elastic_apm/agent.rb', line 65

def context_builder
  @context_builder
end

#error_builderObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



65
66
67
# File 'lib/elastic_apm/agent.rb', line 65

def error_builder
  @error_builder
end

#instrumenterObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



65
66
67
# File 'lib/elastic_apm/agent.rb', line 65

def instrumenter
  @instrumenter
end

#metricsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



65
66
67
# File 'lib/elastic_apm/agent.rb', line 65

def metrics
  @metrics
end

#stacktrace_builderObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



65
66
67
# File 'lib/elastic_apm/agent.rb', line 65

def stacktrace_builder
  @stacktrace_builder
end

#transportObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



65
66
67
# File 'lib/elastic_apm/agent.rb', line 65

def transport
  @transport
end

Class Method Details

.instanceObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

life cycle



21
22
23
# File 'lib/elastic_apm/agent.rb', line 21

def self.instance # rubocop:disable Style/TrivialAccessors
  @instance
end

.running?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


46
47
48
# File 'lib/elastic_apm/agent.rb', line 46

def self.running?
  !!@instance
end

.start(config) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/elastic_apm/agent.rb', line 25

def self.start(config)
  return @instance if @instance

  config = Config.new(config) unless config.is_a?(Config)

  LOCK.synchronize do
    return @instance if @instance

    @instance = new(config).start
  end
end

.stopObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



37
38
39
40
41
42
43
44
# File 'lib/elastic_apm/agent.rb', line 37

def self.stop
  LOCK.synchronize do
    return unless @instance

    @instance.stop
    @instance = nil
  end
end

Instance Method Details

#add_filter(key, callback) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

filters



189
190
191
# File 'lib/elastic_apm/agent.rb', line 189

def add_filter(key, callback)
  transport.add_filter(key, callback)
end

#build_context(rack_env) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



162
163
164
# File 'lib/elastic_apm/agent.rb', line 162

def build_context(rack_env)
  @context_builder.build(rack_env)
end

#current_spanObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



108
109
110
# File 'lib/elastic_apm/agent.rb', line 108

def current_span
  instrumenter.current_span
end

#current_transactionObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

instrumentation



104
105
106
# File 'lib/elastic_apm/agent.rb', line 104

def current_transaction
  instrumenter.current_transaction
end

#end_spanObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



146
147
148
# File 'lib/elastic_apm/agent.rb', line 146

def end_span
  instrumenter.end_span
end

#end_transaction(result = nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



126
127
128
# File 'lib/elastic_apm/agent.rb', line 126

def end_transaction(result = nil)
  instrumenter.end_transaction(result)
end

#enqueue(obj) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

transport



98
99
100
# File 'lib/elastic_apm/agent.rb', line 98

def enqueue(obj)
  transport.submit obj
end

#report(exception, handled: true) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

errors



168
169
170
171
172
173
174
175
176
# File 'lib/elastic_apm/agent.rb', line 168

def report(exception, handled: true)
  return if config.filter_exception_types.include?(exception.class.to_s)

  error = @error_builder.build_exception(
    exception,
    handled: handled
  )
  enqueue error
end

#report_message(message, backtrace: nil, **attrs) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



178
179
180
181
182
183
184
185
# File 'lib/elastic_apm/agent.rb', line 178

def report_message(message, backtrace: nil, **attrs)
  error = @error_builder.build_log(
    message,
    backtrace: backtrace,
    **attrs
  )
  enqueue error
end

#set_custom_context(context) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



154
155
156
# File 'lib/elastic_apm/agent.rb', line 154

def set_custom_context(context)
  instrumenter.set_custom_context(context)
end

#set_tag(key, value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



150
151
152
# File 'lib/elastic_apm/agent.rb', line 150

def set_tag(key, value)
  instrumenter.set_tag(key, value)
end

#set_user(user) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



158
159
160
# File 'lib/elastic_apm/agent.rb', line 158

def set_user(user)
  instrumenter.set_user(user)
end

#startObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/elastic_apm/agent.rb', line 68

def start
  info '[%s] Starting agent, reporting to %s', VERSION, config.server_url

  transport.start
  instrumenter.start
  metrics.start

  config.enabled_spies.each do |lib|
    require "elastic_apm/spies/#{lib}"
  end

  self
end

#start_span(name = nil, type = nil, backtrace: nil, context: nil, trace_context: nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/elastic_apm/agent.rb', line 130

def start_span(
  name = nil,
  type = nil,
  backtrace: nil,
  context: nil,
  trace_context: nil
)
  instrumenter.start_span(
    name,
    type,
    backtrace: backtrace,
    context: context,
    trace_context: trace_context
  )
end

#start_transaction(name = nil, type = nil, context: nil, trace_context: nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/elastic_apm/agent.rb', line 112

def start_transaction(
  name = nil,
  type = nil,
  context: nil,
  trace_context: nil
)
  instrumenter.start_transaction(
    name,
    type,
    context: context,
    trace_context: trace_context
  )
end

#stopObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



82
83
84
85
86
87
88
89
90
# File 'lib/elastic_apm/agent.rb', line 82

def stop
  debug 'Stopping agent'

  instrumenter.stop
  transport.stop
  metrics.stop

  self
end