Module: Atatus
- Defined in:
- lib/atatus.rb,
lib/atatus/grpc.rb,
lib/atatus/span.rb,
lib/atatus/util.rb,
lib/atatus/agent.rb,
lib/atatus/error.rb,
lib/atatus/grape.rb,
lib/atatus/rails.rb,
lib/atatus/spies.rb,
lib/atatus/config.rb,
lib/atatus/fields.rb,
lib/atatus/resque.rb,
lib/atatus/context.rb,
lib/atatus/graphql.rb,
lib/atatus/logging.rb,
lib/atatus/metrics.rb,
lib/atatus/railtie.rb,
lib/atatus/sinatra.rb,
lib/atatus/version.rb,
lib/atatus/metadata.rb,
lib/atatus/spies/s3.rb,
lib/atatus/error/log.rb,
lib/atatus/metricset.rb,
lib/atatus/spies/sns.rb,
lib/atatus/spies/sqs.rb,
lib/atatus/middleware.rb,
lib/atatus/spies/http.rb,
lib/atatus/spies/json.rb,
lib/atatus/spies/rake.rb,
lib/atatus/spies/tilt.rb,
lib/atatus/sql/tokens.rb,
lib/atatus/stacktrace.rb,
lib/atatus/subscriber.rb,
lib/atatus/metrics/set.rb,
lib/atatus/normalizers.rb,
lib/atatus/opentracing.rb,
lib/atatus/spies/mongo.rb,
lib/atatus/spies/redis.rb,
lib/atatus/transaction.rb,
lib/atatus/config/bytes.rb,
lib/atatus/context/user.rb,
lib/atatus/deprecations.rb,
lib/atatus/instrumenter.rb,
lib/atatus/span/context.rb,
lib/atatus/span_helpers.rb,
lib/atatus/spies/resque.rb,
lib/atatus/spies/sequel.rb,
lib/atatus/error_builder.rb,
lib/atatus/spies/faraday.rb,
lib/atatus/spies/sidekiq.rb,
lib/atatus/spies/sinatra.rb,
lib/atatus/sql/signature.rb,
lib/atatus/sql/tokenizer.rb,
lib/atatus/trace_context.rb,
lib/atatus/util/deep_dup.rb,
lib/atatus/util/throttle.rb,
lib/atatus/central_config.rb,
lib/atatus/collector/base.rb,
lib/atatus/collector/hist.rb,
lib/atatus/config/options.rb,
lib/atatus/internal_error.rb,
lib/atatus/metrics/metric.rb,
lib/atatus/metrics/vm_set.rb,
lib/atatus/spies/net_http.rb,
lib/atatus/spies/sneakers.rb,
lib/atatus/transport/base.rb,
lib/atatus/util/inflector.rb,
lib/atatus/util/lru_cache.rb,
lib/atatus/child_durations.rb,
lib/atatus/collector/layer.rb,
lib/atatus/config/duration.rb,
lib/atatus/context/company.rb,
lib/atatus/context/request.rb,
lib/atatus/context_builder.rb,
lib/atatus/error/exception.rb,
lib/atatus/metrics/jvm_set.rb,
lib/atatus/span/context/db.rb,
lib/atatus/spies/dynamo_db.rb,
lib/atatus/spies/shoryuken.rb,
lib/atatus/context/response.rb,
lib/atatus/naively_hashable.rb,
lib/atatus/stacktrace/frame.rb,
lib/atatus/transport/worker.rb,
lib/atatus/collector/builder.rb,
lib/atatus/span/context/http.rb,
lib/atatus/spies/delayed_job.rb,
lib/atatus/transport/filters.rb,
lib/atatus/transport/headers.rb,
lib/atatus/config/regexp_list.rb,
lib/atatus/config/round_float.rb,
lib/atatus/config/server_info.rb,
lib/atatus/span/context/links.rb,
lib/atatus/spies/sucker_punch.rb,
lib/atatus/stacktrace_builder.rb,
lib/atatus/collector/transport.rb,
lib/atatus/context/request/url.rb,
lib/atatus/metadata/cloud_info.rb,
lib/atatus/metrics/cpu_mem_set.rb,
lib/atatus/spies/elasticsearch.rb,
lib/atatus/config/log_level_map.rb,
lib/atatus/metadata/system_info.rb,
lib/atatus/span/context/message.rb,
lib/atatus/span/context/service.rb,
lib/atatus/transport/connection.rb,
lib/atatus/transport/user_agent.rb,
lib/atatus/metadata/process_info.rb,
lib/atatus/metadata/service_info.rb,
lib/atatus/metrics/breakdown_set.rb,
lib/atatus/spies/action_dispatch.rb,
lib/atatus/transport/serializers.rb,
lib/atatus/context/request/socket.rb,
lib/atatus/metrics/span_scoped_set.rb,
lib/atatus/metrics/transaction_set.rb,
lib/atatus/span/context/destination.rb,
lib/atatus/trace_context/tracestate.rb,
lib/atatus/util/precision_validator.rb,
lib/atatus/spies/azure_storage_table.rb,
lib/atatus/trace_context/traceparent.rb,
lib/atatus/transport/connection/http.rb,
lib/atatus/central_config/cache_control.rb,
lib/atatus/config/wildcard_pattern_list.rb,
lib/atatus/metadata/system_info/hw_info.rb,
lib/atatus/metadata/system_info/os_info.rb,
lib/atatus/normalizers/rails/action_view.rb,
lib/atatus/normalizers/grape/endpoint_run.rb,
lib/atatus/normalizers/rails/action_mailer.rb,
lib/atatus/normalizers/rails/active_record.rb,
lib/atatus/transport/connection/proxy_pipe.rb,
lib/atatus/transport/filters/hash_sanitizer.rb,
lib/atatus/transport/filters/secrets_filter.rb,
lib/atatus/metadata/system_info/container_info.rb,
lib/atatus/normalizers/rails/action_controller.rb,
lib/atatus/transport/serializers/span_serializer.rb,
lib/atatus/transport/serializers/error_serializer.rb,
lib/atatus/transport/serializers/context_serializer.rb,
lib/atatus/transport/serializers/metadata_serializer.rb,
lib/atatus/transport/serializers/metricset_serializer.rb,
lib/atatus/transport/serializers/transaction_serializer.rb
Overview
frozen_string_literal: true
Defined Under Namespace
Modules: ChildDurations, Collector, Deprecations, Fields, Grape, GraphQL, Logging, Metrics, NaivelyHashable, Normalizers, OpenTracing, Rails, Resque, Sinatra, SpanHelpers, Spies, Sql, Transport, Util Classes: Agent, BaseTransport, Builder, CentralConfig, Config, Context, ContextBuilder, Error, ErrorBuilder, ExistingTransactionError, GRPC, Instrumenter, InternalError, Metadata, Metricset, Middleware, Railtie, Span, Stacktrace, StacktraceBuilder, Subscriber, TraceContext, Transaction
Constant Summary collapse
- AGENT_NAME =
'Ruby'
- VERSION =
'2.0.3'
Class Method Summary collapse
-
.add_filter(key, callback = nil) {|Hash| ... } ⇒ Bool
Provide a filter to transform payloads before sending them off.
-
.agent ⇒ Agent
Currently running [Agent] if any.
-
.build_context(rack_env: nil, for_type: :transaction) ⇒ Context
Build a [Context] from a Rack ‘env`.
-
.current_span ⇒ Span
Returns the currently active span (if any).
-
.current_transaction ⇒ Transaction
Returns the currently active transaction (if any).
-
.end_span(span = nil) ⇒ Span
Ends the current span.
-
.end_transaction(result = nil) ⇒ Transaction
Ends the current transaction with ‘result`.
-
.log_ids {|String|nil, String|nil, String|nil| ... } ⇒ String
Get a formatted string containing transaction, span, and trace ids.
-
.report(exception, context: nil, handled: true) ⇒ String
Report and exception to APM.
-
.report_message(message, context: nil, **attrs) ⇒ String
Report a custom string error message to APM.
-
.restart(config = nil) ⇒ Object
Restarts the Atatus Agent using the same config or a new one, if it is provided.
-
.running? ⇒ Boolean
Whether there’s an [Agent] running.
-
.set_company(company) ⇒ Object
Provide a company to the current transaction.
-
.set_custom_context(custom) ⇒ Hash
Provide further context for the current transaction.
-
.set_custom_data(custom) ⇒ Hash
Provide further context for the current transaction.
-
.set_destination(address: nil, port: nil, service: nil, cloud: nil) ⇒ Object
Provide a filter to transform payloads before sending them off.
-
.set_label(key, value) ⇒ Object
Set a label value for the current transaction.
-
.set_response_body(response_body) ⇒ String
Provide the response body to the current transaction.
-
.set_user(user) ⇒ Object
Provide a user to the current transaction.
-
.start(config = {}) ⇒ Agent
Starts the Atatus Agent.
-
.start_span(name, type = nil, subtype: nil, action: nil, context: nil, include_stacktrace: true, trace_context: nil, parent: nil, sync: nil) ⇒ Span
rubocop:disable Metrics/ParameterLists Start a new span.
-
.start_transaction(name = nil, type = nil, context: nil, trace_context: nil) ⇒ Transaction
Start a new transaction.
-
.stop ⇒ Object
Stops the Atatus Agent.
-
.with_span(name, type = nil, subtype: nil, action: nil, context: nil, include_stacktrace: true, trace_context: nil, parent: nil, sync: nil) {|Span| ... } ⇒ Object
rubocop:disable Metrics/ParameterLists Wrap a block in a Span, ending it after the block.
-
.with_transaction(name = nil, type = nil, context: nil, trace_context: nil) {|Transaction| ... } ⇒ Object
Wrap a block in a Transaction, ending it after the block.
Class Method Details
.add_filter(key, callback = nil) {|Hash| ... } ⇒ Bool
Provide a filter to transform payloads before sending them off
428 429 430 431 432 433 434 |
# File 'lib/atatus.rb', line 428 def add_filter(key, callback = nil, &block) if callback.nil? && !block raise ArgumentError, '#add_filter needs either `callback\' or a block' end agent&.add_filter(key, block || callback) end |
.agent ⇒ Agent
Returns Currently running [Agent] if any.
85 86 87 |
# File 'lib/atatus.rb', line 85 def agent Agent.instance end |
.build_context(rack_env: nil, for_type: :transaction) ⇒ Context
Build a [Context] from a Rack ‘env`. The context may include information about the request, response, current user and more
319 320 321 322 323 324 |
# File 'lib/atatus.rb', line 319 def build_context( rack_env: nil, for_type: :transaction ) agent&.build_context(rack_env: rack_env, for_type: for_type) end |
.current_span ⇒ Span
Returns the currently active span (if any)
101 102 103 |
# File 'lib/atatus.rb', line 101 def current_span agent&.current_span end |
.current_transaction ⇒ Transaction
Returns the currently active transaction (if any)
94 95 96 |
# File 'lib/atatus.rb', line 94 def current_transaction agent&.current_transaction end |
.end_span(span = nil) ⇒ Span
Ends the current span
251 252 253 |
# File 'lib/atatus.rb', line 251 def end_span(span = nil) agent&.end_span(span) end |
.end_transaction(result = nil) ⇒ Transaction
Ends the current transaction with ‘result`
154 155 156 |
# File 'lib/atatus.rb', line 154 def end_transaction(result = nil) agent&.end_transaction(result) end |
.log_ids {|String|nil, String|nil, String|nil| ... } ⇒ String
Get a formatted string containing transaction, span, and trace ids. If a block is provided, the ids are yielded.
and trace ids. rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/atatus.rb', line 112 def log_ids trace_id = (current_transaction || current_span)&.trace_id if block_given? return yield(current_transaction&.id, current_span&.id, trace_id) end ids = [] ids << "transaction.id=#{current_transaction.id}" if current_transaction ids << "span.id=#{current_span.id}" if current_span ids << "trace.id=#{trace_id}" if trace_id ids.join(' ') end |
.report(exception, context: nil, handled: true) ⇒ String
Report and exception to APM
334 335 336 |
# File 'lib/atatus.rb', line 334 def report(exception, context: nil, handled: true) agent&.report(exception, context: context, handled: handled) end |
.report_message(message, context: nil, **attrs) ⇒ String
Report a custom string error message to APM
343 344 345 346 347 348 349 350 |
# File 'lib/atatus.rb', line 343 def (, context: nil, **attrs) agent&.( , context: context, backtrace: caller, **attrs ) end |
.restart(config = nil) ⇒ Object
Restarts the Atatus Agent using the same config or a new one, if it is provided. Starts the agent if it is not running. Stops and starts the agent if it is running.
73 74 75 76 77 |
# File 'lib/atatus.rb', line 73 def restart(config = nil) config ||= agent&.config stop if running? start(config) end |
.running? ⇒ Boolean
Returns Whether there’s an [Agent] running.
80 81 82 |
# File 'lib/atatus.rb', line 80 def running? Agent.running? end |
.set_company(company) ⇒ Object
Provide a company to the current transaction
400 401 402 |
# File 'lib/atatus.rb', line 400 def set_company(company) agent&.set_company(company) end |
.set_custom_context(custom) ⇒ Hash
Provide further context for the current transaction
384 385 386 |
# File 'lib/atatus.rb', line 384 def set_custom_context(custom) agent&.set_custom_context(custom) end |
.set_custom_data(custom) ⇒ Hash
Provide further context for the current transaction
376 377 378 |
# File 'lib/atatus.rb', line 376 def set_custom_data(custom) agent&.set_custom_context(custom) end |
.set_destination(address: nil, port: nil, service: nil, cloud: nil) ⇒ Object
Provide a filter to transform payloads before sending them off
418 419 420 |
# File 'lib/atatus.rb', line 418 def set_destination(address: nil, port: nil, service: nil, cloud: nil) agent&.set_destination(address: address, port: port, service: service, cloud: cloud) end |
.set_label(key, value) ⇒ Object
Set a label value for the current transaction
359 360 361 362 363 364 365 366 367 368 369 370 |
# File 'lib/atatus.rb', line 359 def set_label(key, value) case value when TrueClass, FalseClass, Numeric, NilClass, String agent&.set_label(key, value) else agent&.set_label(key, value.to_s) end end |
.set_response_body(response_body) ⇒ String
Provide the response body to the current transaction
408 409 410 |
# File 'lib/atatus.rb', line 408 def set_response_body(response_body) agent&.set_response_body(response_body.to_s) end |
.set_user(user) ⇒ Object
Provide a user to the current transaction
392 393 394 |
# File 'lib/atatus.rb', line 392 def set_user(user) agent&.set_user(user) end |
.start(config = {}) ⇒ Agent
Starts the Atatus Agent
60 61 62 |
# File 'lib/atatus.rb', line 60 def start(config = {}) Agent.start config end |
.start_span(name, type = nil, subtype: nil, action: nil, context: nil, include_stacktrace: true, trace_context: nil, parent: nil, sync: nil) ⇒ Span
rubocop:disable Metrics/ParameterLists Start a new span
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/atatus.rb', line 216 def start_span( name, type = nil, subtype: nil, action: nil, context: nil, include_stacktrace: true, trace_context: nil, parent: nil, sync: nil ) agent&.start_span( name, type, subtype: subtype, action: action, context: context, trace_context: trace_context, parent: parent, sync: sync ).tap do |span| break unless span && include_stacktrace break unless agent.config.span_frames_min_duration? span.original_backtrace ||= caller end end |
.start_transaction(name = nil, type = nil, context: nil, trace_context: nil) ⇒ Transaction
Start a new transaction
‘ExamplesController#index` `db.mysql2.query`
136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/atatus.rb', line 136 def start_transaction( name = nil, type = nil, context: nil, trace_context: nil ) agent&.start_transaction( name, type, context: context, trace_context: trace_context ) end |
.stop ⇒ Object
Stops the Atatus Agent
65 66 67 |
# File 'lib/atatus.rb', line 65 def stop Agent.stop end |
.with_span(name, type = nil, subtype: nil, action: nil, context: nil, include_stacktrace: true, trace_context: nil, parent: nil, sync: nil) {|Span| ... } ⇒ Object
rubocop:disable Metrics/ParameterLists Wrap a block in a Span, ending it after the block
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'lib/atatus.rb', line 271 def with_span( name, type = nil, subtype: nil, action: nil, context: nil, include_stacktrace: true, trace_context: nil, parent: nil, sync: nil ) unless block_given? raise ArgumentError, 'expected a block. Do you want `start_span\' instead?' end return yield nil unless agent begin span = start_span( name, type, subtype: subtype, action: action, context: context, include_stacktrace: include_stacktrace, trace_context: trace_context, parent: parent, sync: sync ) result = yield span span&.outcome ||= Span::Outcome::SUCCESS result rescue span&.outcome ||= Span::Outcome::FAILURE raise ensure end_span end end |
.with_transaction(name = nil, type = nil, context: nil, trace_context: nil) {|Transaction| ... } ⇒ Object
Wrap a block in a Transaction, ending it after the block
‘ExamplesController#index` `db.mysql2.query`
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/atatus.rb', line 169 def with_transaction( name = nil, type = nil, context: nil, trace_context: nil ) unless block_given? raise ArgumentError, 'expected a block. Do you want `start_transaction\' instead?' end return yield(nil) unless agent begin transaction = start_transaction( name, type, context: context, trace_context: trace_context ) result = yield transaction transaction&.outcome ||= Transaction::Outcome::SUCCESS result rescue transaction&.outcome ||= Transaction::Outcome::FAILURE raise ensure end_transaction end end |