Module: Logtide

Defined in:
lib/logtide.rb,
lib/logtide/dsn.rb,
lib/logtide/hub.rb,
lib/logtide/error.rb,
lib/logtide/event.rb,
lib/logtide/scope.rb,
lib/logtide/client.rb,
lib/logtide/metrics.rb,
lib/logtide/tracing.rb,
lib/logtide/version.rb,
lib/logtide/breadcrumb.rb,
lib/logtide/retry_policy.rb,
lib/logtide/tracing/span.rb,
lib/logtide/configuration.rb,
lib/logtide/logger_bridge.rb,
lib/logtide/rails/railtie.rb,
lib/logtide/transport/http.rb,
lib/logtide/transport/otlp.rb,
lib/logtide/circuit_breaker.rb,
lib/logtide/rack/middleware.rb,
lib/logtide/transport/buffer.rb,
lib/logtide/transport/batcher.rb,
lib/logtide/structured_exception.rb

Overview

LogTide SDK for Ruby. The module-level methods are the documented entry point (spec 004 section 1); they delegate to the current Hub.

Defined Under Namespace

Modules: Rack, Rails, StructuredException, Tracing, Transport Classes: Breadcrumb, BreadcrumbBuffer, CircuitBreaker, Client, Configuration, ConfigurationError, DSN, Error, Event, Hub, LoggerBridge, Metrics, RetryPolicy, Scope

Constant Summary collapse

VERSION =
"1.0.0"
SPEC_VERSION =

The spec version this SDK implements (see logtide-sdk-spec).

"1.0"

Class Method Summary collapse

Class Method Details

.add_breadcrumb(breadcrumb) ⇒ Object



105
106
107
# File 'lib/logtide.rb', line 105

def add_breadcrumb(breadcrumb)
  current_hub.add_breadcrumb(breadcrumb)
end

.capture_exception(exception, **opts) ⇒ Object Also known as: capture_error



92
93
94
# File 'lib/logtide.rb', line 92

def capture_exception(exception, **opts)
  current_hub.capture_exception(exception, **opts)
end

.capture_log(level, message, metadata = nil, **opts) ⇒ Object



60
61
62
# File 'lib/logtide.rb', line 60

def capture_log(level, message,  = nil, **opts)
  current_hub.capture_log(level, message, , **opts)
end

.close(timeout = nil) ⇒ Object



129
130
131
# File 'lib/logtide.rb', line 129

def close(timeout = nil)
  current_hub.close(timeout)
end

.configure_scopeObject



97
98
99
# File 'lib/logtide.rb', line 97

def configure_scope(&)
  current_hub.configure_scope(&)
end

.critical(message, metadata_or_exception = nil, **opts) ⇒ Object



84
85
86
87
88
89
90
# File 'lib/logtide.rb', line 84

def critical(message,  = nil, **opts)
  if .is_a?(Exception)
    return capture_exception(, message: message, level: "critical", **opts)
  end

  capture_log("critical", message, , **opts)
end

.current_hubObject



42
43
44
# File 'lib/logtide.rb', line 42

def current_hub
  Thread.current[:logtide_hub] || main_hub
end

.current_hub=(hub) ⇒ Object



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

def current_hub=(hub)
  Thread.current[:logtide_hub] = hub
end

.debug(message, metadata = nil, **opts) ⇒ Object



64
65
66
# File 'lib/logtide.rb', line 64

def debug(message,  = nil, **opts)
  capture_log("debug", message, , **opts)
end

.error(message, metadata_or_exception = nil, **opts) ⇒ Object



76
77
78
79
80
81
82
# File 'lib/logtide.rb', line 76

def error(message,  = nil, **opts)
  if .is_a?(Exception)
    return capture_exception(, message: message, level: "error", **opts)
  end

  capture_log("error", message, , **opts)
end

.flush(timeout = nil) ⇒ Object



125
126
127
# File 'lib/logtide.rb', line 125

def flush(timeout = nil)
  current_hub.flush(timeout)
end

.get_metricsObject



133
134
135
# File 'lib/logtide.rb', line 133

def get_metrics
  current_hub.client&.metrics
end

.info(message, metadata = nil, **opts) ⇒ Object



68
69
70
# File 'lib/logtide.rb', line 68

def info(message,  = nil, **opts)
  capture_log("info", message, , **opts)
end

.init(**options) ⇒ Object

Initialise the SDK and bind the global Hub. Returns the Hub.



31
32
33
34
35
36
# File 'lib/logtide.rb', line 31

def init(**options)
  hub = Hub.new(Client.new(Configuration.new(**options)))
  @main_hub = hub
  register_shutdown
  hub
end

.main_hubObject



38
39
40
# File 'lib/logtide.rb', line 38

def main_hub
  @main_hub ||= Hub.new(nil)
end

.reset!Object

Test/teardown seam: drop the bound hubs.



138
139
140
141
# File 'lib/logtide.rb', line 138

def reset!
  Thread.current[:logtide_hub] = nil
  @main_hub = nil
end

.set_tag(key, value) ⇒ Object



121
122
123
# File 'lib/logtide.rb', line 121

def set_tag(key, value)
  configure_scope { |scope| scope.set_tag(key, value) }
end

.set_user(user) ⇒ Object



117
118
119
# File 'lib/logtide.rb', line 117

def set_user(user)
  configure_scope { |scope| scope.set_user(user) }
end

.start_span(name) ⇒ Object



109
110
111
# File 'lib/logtide.rb', line 109

def start_span(name, ...)
  current_hub.start_span(name, ...)
end

.trace_propagation_headersObject



113
114
115
# File 'lib/logtide.rb', line 113

def trace_propagation_headers
  current_hub.trace_propagation_headers
end

.warn(message, metadata = nil, **opts) ⇒ Object



72
73
74
# File 'lib/logtide.rb', line 72

def warn(message,  = nil, **opts)
  capture_log("warn", message, , **opts)
end

.with_request_hubObject

Run a block with a per-request hub cloned from the main hub, then restore the previous hub. Used by framework middleware for request isolation.



52
53
54
55
56
57
58
# File 'lib/logtide.rb', line 52

def with_request_hub
  previous = Thread.current[:logtide_hub]
  self.current_hub = main_hub.clone
  yield current_hub
ensure
  Thread.current[:logtide_hub] = previous
end

.with_scopeObject



101
102
103
# File 'lib/logtide.rb', line 101

def with_scope(&)
  current_hub.with_scope(&)
end