Class: Dontbugme::Recorder
- Inherits:
-
Object
- Object
- Dontbugme::Recorder
- Defined in:
- lib/dontbugme/recorder.rb
Class Method Summary collapse
- .add_span(category:, operation:, detail:, payload: {}, duration_ms: 0, started_at: nil) ⇒ Object
- .record(kind:, identifier:, metadata: {}, return_trace: false, &block) ⇒ Object
Class Method Details
.add_span(category:, operation:, detail:, payload: {}, duration_ms: 0, started_at: nil) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/dontbugme/recorder.rb', line 31 def add_span(category:, operation:, detail:, payload: {}, duration_ms: 0, started_at: nil) trace = Context.current return unless trace # started_at can be a Time (from ActiveSupport::Notifications) or we compute from monotonic started_offset = if started_at ((started_at - trace.started_at_time) * 1000).round(2) else (Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond) - trace.started_at_monotonic - duration_ms).round(2) end source = SourceLocation.capture span = Span.new( category: category, operation: operation, detail: detail, payload: payload, started_at: started_offset, duration_ms: duration_ms, source: source ) trace.add_span(span) end |
.record(kind:, identifier:, metadata: {}, return_trace: false, &block) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/dontbugme/recorder.rb', line 6 def record(kind:, identifier:, metadata: {}, return_trace: false, &block) return yield unless Dontbugme.config.recording? return yield unless should_sample? = .dup [:correlation_id] ||= Correlation.current || Correlation.generate Correlation.current = [:correlation_id] trace = Trace.new(kind: kind, identifier: identifier, metadata: ) Context.current = trace VariableTracker.clear_state! if defined?(VariableTracker) result = yield trace.finish! persist(trace) return_trace ? trace : result rescue StandardError => e trace&.finish!(error: e) persist(trace) if trace && Dontbugme.config.record_on_error raise ensure Context.clear! Correlation.clear! unless kind == :request end |