Class: Tinymon::Client
- Inherits:
-
Object
- Object
- Tinymon::Client
- Defined in:
- lib/tinymon/client.rb
Constant Summary collapse
- DEFAULT_ENDPOINT =
"https://console.tinymon.dev/api/ingest"
Instance Method Summary collapse
- #capture_exception(exception) ⇒ Object
- #capture_message(message, level: "info") ⇒ Object
-
#initialize(dsn:, endpoint: nil, environment: nil, release: nil, sample_rate: 1.0, before_send: nil) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(dsn:, endpoint: nil, environment: nil, release: nil, sample_rate: 1.0, before_send: nil) ⇒ Client
Returns a new instance of Client.
11 12 13 14 15 16 17 18 19 |
# File 'lib/tinymon/client.rb', line 11 def initialize(dsn:, endpoint: nil, environment: nil, release: nil, sample_rate: 1.0, before_send: nil) @dsn = dsn @endpoint = endpoint || DEFAULT_ENDPOINT @environment = environment @release = release @sample_rate = sample_rate @before_send = before_send @transport = Transport.new(@endpoint, dsn) end |
Instance Method Details
#capture_exception(exception) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/tinymon/client.rb', line 21 def capture_exception(exception) return if rand > @sample_rate snap = SCOPE.snapshot event = EventBuilder.build( exception, release: @release, environment: @environment, user: snap[:user], tags: snap[:tags], breadcrumbs: snap[:breadcrumbs], ) if @before_send event = @before_send.call(event) return if event.nil? end @transport.enqueue(event) rescue StandardError # SWALLOW. The SDK must never throw into the host app. nil end |
#capture_message(message, level: "info") ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/tinymon/client.rb', line 42 def (, level: "info") synthetic = StandardError.new() snap = SCOPE.snapshot event = EventBuilder.build( synthetic, release: @release, environment: @environment, user: snap[:user], tags: snap[:tags], breadcrumbs: snap[:breadcrumbs], ) event["level"] = level event["exception"]["type"] = "Message" @transport.enqueue(event) rescue StandardError nil end |