Module: Lapsoss::Breadcrumb
- Defined in:
- lib/lapsoss/breadcrumb.rb
Class Method Summary collapse
-
.build(message, type: :default, metadata: {}) ⇒ Object
Canonical breadcrumb builder used by SDK message: String, type: Symbol, metadata: Hash, timestamp: Time (UTC).
- .for_insight_hub(crumbs) ⇒ Object
-
.for_sentry(crumbs) ⇒ Object
Adapter conversions.
-
.normalize(crumb) ⇒ Object
Normalize an incoming breadcrumb-like hash to the canonical structure.
Class Method Details
.build(message, type: :default, metadata: {}) ⇒ Object
Canonical breadcrumb builder used by SDK message: String, type: Symbol, metadata: Hash, timestamp: Time (UTC)
9 10 11 12 13 14 15 16 |
# File 'lib/lapsoss/breadcrumb.rb', line 9 def build(, type: :default, metadata: {}) { message: .to_s, type: type.to_sym, metadata: || {}, timestamp: Time.now.utc } end |
.for_insight_hub(crumbs) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/lapsoss/breadcrumb.rb', line 47 def for_insight_hub(crumbs) crumbs.map do |c| c = normalize(c) { timestamp: c[:timestamp].utc.iso8601, name: c[:message], type: c[:type].to_s, metaData: c[:metadata] } end end |
.for_sentry(crumbs) ⇒ Object
Adapter conversions
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/lapsoss/breadcrumb.rb', line 35 def for_sentry(crumbs) crumbs.map do |c| c = normalize(c) { timestamp: c[:timestamp].utc.iso8601, message: c[:message], type: c[:type].to_s, data: c[:metadata] } end end |
.normalize(crumb) ⇒ Object
Normalize an incoming breadcrumb-like hash to the canonical structure
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/lapsoss/breadcrumb.rb', line 19 def normalize(crumb) msg = crumb[:message] || crumb["message"] type = crumb[:type] || crumb["type"] || :default = crumb[:metadata] || crumb["metadata"] || crumb[:data] || crumb["data"] || {} ts = crumb[:timestamp] || crumb["timestamp"] ts = ts.utc if ts.respond_to?(:utc) { message: msg.to_s, type: type.to_sym, metadata: .is_a?(Hash) ? : Hash(), timestamp: ts || Time.now.utc } end |