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
-
.add_breadcrumb(breadcrumb) ⇒ Object
-
.capture_exception(exception, **opts) ⇒ Object
(also: capture_error)
-
.capture_log(level, message, metadata = nil, **opts) ⇒ Object
-
.close(timeout = nil) ⇒ Object
-
.configure_scope ⇒ Object
-
.critical(message, metadata_or_exception = nil, **opts) ⇒ Object
-
.current_hub ⇒ Object
-
.current_hub=(hub) ⇒ Object
-
.debug(message, metadata = nil, **opts) ⇒ Object
-
.error(message, metadata_or_exception = nil, **opts) ⇒ Object
-
.flush(timeout = nil) ⇒ Object
-
.get_metrics ⇒ Object
-
.info(message, metadata = nil, **opts) ⇒ Object
-
.init(**options) ⇒ Object
Initialise the SDK and bind the global Hub.
-
.main_hub ⇒ Object
-
.reset! ⇒ Object
Test/teardown seam: drop the bound hubs.
-
.set_tag(key, value) ⇒ Object
-
.set_user(user) ⇒ Object
-
.start_span(name) ⇒ Object
-
.trace_propagation_headers ⇒ Object
-
.warn(message, metadata = nil, **opts) ⇒ Object
-
.with_request_hub ⇒ Object
Run a block with a per-request hub cloned from the main hub, then restore the previous hub.
-
.with_scope ⇒ Object
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, metadata = nil, **opts)
current_hub.capture_log(level, message, metadata, **opts)
end
|
.close(timeout = nil) ⇒ Object
129
130
131
|
# File 'lib/logtide.rb', line 129
def close(timeout = nil)
current_hub.close(timeout)
end
|
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, metadata_or_exception = nil, **opts)
if metadata_or_exception.is_a?(Exception)
return capture_exception(metadata_or_exception, message: message, level: "critical", **opts)
end
capture_log("critical", message, metadata_or_exception, **opts)
end
|
.current_hub ⇒ Object
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, metadata = nil, **opts)
capture_log("debug", message, metadata, **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, metadata_or_exception = nil, **opts)
if metadata_or_exception.is_a?(Exception)
return capture_exception(metadata_or_exception, message: message, level: "error", **opts)
end
capture_log("error", message, metadata_or_exception, **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_metrics ⇒ Object
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, metadata = nil, **opts)
capture_log("info", message, metadata, **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_hub ⇒ Object
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
|
113
114
115
|
# File 'lib/logtide.rb', line 113
def
current_hub.
end
|
.warn(message, metadata = nil, **opts) ⇒ Object
72
73
74
|
# File 'lib/logtide.rb', line 72
def warn(message, metadata = nil, **opts)
capture_log("warn", message, metadata, **opts)
end
|
.with_request_hub ⇒ Object
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_scope ⇒ Object
101
102
103
|
# File 'lib/logtide.rb', line 101
def with_scope(&)
current_hub.with_scope(&)
end
|