Module: Dontbugme

Defined in:
lib/dontbugme.rb,
lib/dontbugme/cli.rb,
lib/dontbugme/span.rb,
lib/dontbugme/trace.rb,
lib/dontbugme/engine.rb,
lib/dontbugme/context.rb,
lib/dontbugme/railtie.rb,
lib/dontbugme/version.rb,
lib/dontbugme/recorder.rb,
lib/dontbugme/store/base.rb,
lib/dontbugme/cleanup_job.rb,
lib/dontbugme/correlation.rb,
lib/dontbugme/store/async.rb,
lib/dontbugme/store/memory.rb,
lib/dontbugme/store/sqlite.rb,
lib/dontbugme/configuration.rb,
lib/dontbugme/formatters/diff.rb,
lib/dontbugme/formatters/json.rb,
lib/dontbugme/middleware/rack.rb,
lib/dontbugme/source_location.rb,
lib/dontbugme/span_collection.rb,
lib/dontbugme/store/json_safe.rb,
lib/dontbugme/store/postgresql.rb,
lib/dontbugme/subscribers/base.rb,
lib/dontbugme/variable_tracker.rb,
lib/dontbugme/subscribers/cache.rb,
lib/dontbugme/subscribers/redis.rb,
lib/dontbugme/middleware/sidekiq.rb,
lib/dontbugme/formatters/timeline.rb,
lib/dontbugme/subscribers/net_http.rb,
app/helpers/dontbugme/traces_helper.rb,
lib/dontbugme/subscribers/active_job.rb,
lib/dontbugme/middleware/sidekiq_client.rb,
lib/dontbugme/subscribers/action_mailer.rb,
lib/dontbugme/subscribers/active_record.rb,
app/controllers/dontbugme/traces_controller.rb,
lib/generators/dontbugme/install/install_generator.rb

Defined Under Namespace

Modules: Correlation, Formatters, Generators, Middleware, Store, Subscribers, TracesHelper Classes: CLI, CleanupJob, Configuration, Context, Engine, Error, Railtie, Recorder, SourceLocation, Span, SpanCollection, Trace, TracesController, VariableTracker

Constant Summary collapse

VERSION =
'0.1.8'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configObject



11
12
13
# File 'lib/dontbugme.rb', line 11

def config
  @config ||= Configuration.new
end

.storeObject



19
20
21
# File 'lib/dontbugme.rb', line 19

def store
  @store ||= build_store
end

Class Method Details

.configure {|config| ... } ⇒ Object

Yields:



15
16
17
# File 'lib/dontbugme.rb', line 15

def configure
  yield config
end

.observe(name, input = nil, &block) ⇒ Object

Captures input and output of in-house calculations for value transformation inspection. Example: token = Dontbugme.observe('token increment', token) { token + 1 }



53
54
55
56
57
58
59
# File 'lib/dontbugme.rb', line 53

def observe(name, input = nil, &block)
  return yield unless Context.active?

  payload = {}
  payload[:input] = format_output_value(input) unless input.nil?
  span(name, payload: payload, capture_output: true, &block)
end

.snapshot(data) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/dontbugme.rb', line 61

def snapshot(data)
  return unless Context.active?

  payload = data.is_a?(Hash) ? data : { value: data }
  Recorder.add_span(
    category: :snapshot,
    operation: 'snapshot',
    detail: 'snapshot',
    payload: payload,
    duration_ms: 0,
    started_at: Time.now
  )
end

.span(name, payload: {}, capture_output: true, &block) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/dontbugme.rb', line 27

def span(name, payload: {}, capture_output: true, &block)
  return yield unless Context.active?

  start_mono = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
  start_wall = Time.now
  result = yield
  duration_ms = (Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond) - start_mono).round(2)

  span_payload = payload.dup
  if capture_output && config.capture_span_output
    span_payload[:output] = format_output_value(result)
  end

  Recorder.add_span(
    category: :custom,
    operation: 'span',
    detail: name.to_s,
    payload: span_payload,
    duration_ms: duration_ms,
    started_at: start_wall
  )
  result
end

.tag(**metadata) ⇒ Object



75
76
77
78
79
# File 'lib/dontbugme.rb', line 75

def tag(**)
  return unless Context.active?

  Context.current&.merge_tags!(**)
end

.trace(identifier, metadata: {}, &block) ⇒ Object



23
24
25
# File 'lib/dontbugme.rb', line 23

def trace(identifier, metadata: {}, &block)
  Recorder.record(kind: :custom, identifier: identifier, metadata: , return_trace: true, &block)
end