File: spotlight_transport.rb

package info (click to toggle)
ruby-sentry-ruby 5.18.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 564 kB
  • sloc: ruby: 4,701; makefile: 8; sh: 4
file content (50 lines) | stat: -rw-r--r-- 1,149 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# frozen_string_literal: true

require "net/http"
require "zlib"

module Sentry
  # Designed to just report events to Spotlight in development.
  class SpotlightTransport < HTTPTransport
    DEFAULT_SIDECAR_URL = "http://localhost:8969/stream"
    MAX_FAILED_REQUESTS = 3

    def initialize(configuration)
      super
      @sidecar_url = configuration.spotlight.is_a?(String) ? configuration.spotlight : DEFAULT_SIDECAR_URL
      @failed = 0
      @logged = false

      log_debug("[Spotlight] initialized for url #{@sidecar_url}")
    end

    def endpoint
      "/stream"
    end

    def send_data(data)
      if @failed >= MAX_FAILED_REQUESTS
        unless @logged
          log_debug("[Spotlight] disabling because of too many request failures")
          @logged = true
        end

        return
      end

      super
    end

    def on_error
      @failed += 1
    end

    # Similar to HTTPTransport connection, but does not support Proxy and SSL
    def conn
      sidecar = URI(@sidecar_url)
      connection = ::Net::HTTP.new(sidecar.hostname, sidecar.port, nil)
      connection.use_ssl = false
      connection
    end
  end
end