Module: Shipeasy::SDK
- Defined in:
- lib/shipeasy-sdk.rb,
lib/shipeasy/sdk/env.rb,
lib/shipeasy/sdk/see.rb,
lib/shipeasy/sdk/eval.rb,
lib/shipeasy/sdk/skill.rb,
lib/shipeasy/sdk/anon_id.rb,
lib/shipeasy/sdk/murmur3.rb,
lib/shipeasy/sdk/railtie.rb,
lib/shipeasy/sdk/version.rb,
lib/shipeasy/sdk/telemetry.rb,
lib/shipeasy/sdk/sticky_store.rb,
lib/shipeasy/sdk/internal_report.rb,
lib/shipeasy/sdk/rack_middleware.rb
Defined Under Namespace
Modules: AnonId, Env, Eval, InternalReport, Murmur3, See, Skill Classes: InMemoryStickyStore, RackMiddleware, Railtie, Telemetry
Constant Summary collapse
- VERSION =
"3.4.0"
Class Method Summary collapse
-
.add_extras(extras = nil, **kwargs) ⇒ Object
---- ambient per-request see() extras -------------------------------.
-
.clear_extras ⇒ Object
Drop the ambient extras buffer for the current request/context.
-
.control_flow_exception(err) ⇒ Object
Mark an exception as expected control flow (reports nothing).
- .default_client ⇒ Object
-
.new_client(api_key: Shipeasy.config.api_key, base_url: Shipeasy.config.base_url) ⇒ Object
Convenience constructor for a heavyweight Engine.
-
.see(problem) ⇒ Object
Report a caught exception via the default client.
-
.see_violation(name) ⇒ Object
Report a non-exception problem via the default client.
-
.set_default_client(client) ⇒ Object
Register the client backing the module-level see() funcs.
Class Method Details
.add_extras(extras = nil, **kwargs) ⇒ Object
---- ambient per-request see() extras -------------------------------
Attach context that merges into every see() report firing later in this request, from anywhere — no need to thread it into the rescue block:
Shipeasy::SDK.add_extras(order_id: order.id, tenant: tenant.slug)
# ...later, somewhere else in the same request...
rescue => e
Shipeasy::SDK.see(e).causes_the("checkout").to("use cached prices")
# ^ report carries order_id + tenant automatically
Fiber-local, so concurrent requests never bleed. The Rack middleware
clears the buffer per request (Rails auto-mounts it); outside Rack, call
clear_extras when a unit of work ends. Accepts a hash and/or keywords.
Works with no client configured (it only writes the buffer); never raises.
95 96 97 98 99 100 101 |
# File 'lib/shipeasy-sdk.rb', line 95 def self.add_extras(extras = nil, **kwargs) merged = {} merged.merge!(extras) if extras.is_a?(Hash) merged.merge!(kwargs) unless kwargs.empty? See::Context.add(merged) nil end |
.clear_extras ⇒ Object
Drop the ambient extras buffer for the current request/context.
104 105 106 107 |
# File 'lib/shipeasy-sdk.rb', line 104 def self.clear_extras See::Context.clear nil end |
.control_flow_exception(err) ⇒ Object
Mark an exception as expected control flow (reports nothing). Works without a client — it only stamps the exception object.
76 77 78 |
# File 'lib/shipeasy-sdk.rb', line 76 def self.control_flow_exception(err) See::ControlFlowChain.new(err) end |
.default_client ⇒ Object
49 50 51 |
# File 'lib/shipeasy-sdk.rb', line 49 def self.default_client @see_default_mutex.synchronize { @see_default_client } end |
.new_client(api_key: Shipeasy.config.api_key, base_url: Shipeasy.config.base_url) ⇒ Object
Convenience constructor for a heavyweight Engine. Reads api_key + base_url
from the gem-wide config when omitted. Most apps should prefer
Shipeasy.configure { … } + Shipeasy::Client.new(user) instead.
27 28 29 |
# File 'lib/shipeasy-sdk.rb', line 27 def self.new_client(api_key: Shipeasy.config.api_key, base_url: Shipeasy.config.base_url) Shipeasy::Engine.new(api_key: api_key, base_url: base_url) end |
.see(problem) ⇒ Object
Report a caught exception via the default client. Use client.see to target a specific client.
55 56 57 58 59 60 61 62 |
# File 'lib/shipeasy-sdk.rb', line 55 def self.see(problem) client = default_client if client.nil? Shipeasy::Logging.warn "[shipeasy] see() called before a client was created — error dropped" return See::NullChain.new end client.see(problem) end |
.see_violation(name) ⇒ Object
Report a non-exception problem via the default client.
65 66 67 68 69 70 71 72 |
# File 'lib/shipeasy-sdk.rb', line 65 def self.see_violation(name) client = default_client if client.nil? Shipeasy::Logging.warn "[shipeasy] see_violation() called before a client was created — error dropped" return See::NullChain.new end client.see_violation(name) end |
.set_default_client(client) ⇒ Object
Register the client backing the module-level see() funcs. Called automatically from Engine#initialize; also exposed for explicit use.
44 45 46 47 |
# File 'lib/shipeasy-sdk.rb', line 44 def self.set_default_client(client) @see_default_mutex.synchronize { @see_default_client = client } client end |