Class: Tinymon::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/tinymon/client.rb

Constant Summary collapse

DEFAULT_ENDPOINT =
"https://console.tinymon.dev/api/ingest"

Instance Method Summary collapse

Constructor Details

#initialize(dsn:, endpoint: nil, environment: nil, release: nil, sample_rate: 1.0, before_send: nil, scrub_url_query: true, scrub_patterns: nil, send_default_pii: false) ⇒ Client

Returns a new instance of Client.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/tinymon/client.rb', line 12

def initialize(
  dsn:,
  endpoint: nil,
  environment: nil,
  release: nil,
  sample_rate: 1.0,
  before_send: nil,
  # Privacy controls — defaults are privacy-preserving.
  scrub_url_query: true,
  scrub_patterns: nil,
  send_default_pii: false
)
  @dsn = dsn
  @endpoint = endpoint || DEFAULT_ENDPOINT
  @environment = environment
  @release = release
  @sample_rate = sample_rate
  @before_send = before_send
  @scrub_url_query = scrub_url_query
  @scrub_patterns = scrub_patterns
  @send_default_pii = send_default_pii
  @transport = Transport.new(@endpoint, dsn)
end

Instance Method Details

#capture_exception(exception) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/tinymon/client.rb', line 36

def capture_exception(exception)
  return if rand > @sample_rate
  event = _prepare(exception)
  return if event.nil?
  @transport.enqueue(event)
rescue StandardError
  # SWALLOW. The SDK must never throw into the host app.
  nil
end

#capture_exception_with_context(exception, request: nil, user: nil, tags: nil) ⇒ Object

Per-event context capture. Use from Rack middleware; do NOT use Tinymon.set_user/set_tag for per-request data — they race under concurrency.



59
60
61
62
63
64
65
66
# File 'lib/tinymon/client.rb', line 59

def capture_exception_with_context(exception, request: nil, user: nil, tags: nil)
  return if rand > @sample_rate
  event = _prepare(exception, ctx: { request: request, user: user, tags: tags })
  return if event.nil?
  @transport.enqueue(event)
rescue StandardError
  nil
end

#capture_message(message, level: "info") ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/tinymon/client.rb', line 46

def capture_message(message, level: "info")
  event = _prepare(StandardError.new(message))
  return if event.nil?
  event["level"] = level
  event["exception"]["type"] = "Message"
  @transport.enqueue(event)
rescue StandardError
  nil
end