Class: Uptrace::DSN
- Inherits:
-
Object
- Object
- Uptrace::DSN
- Defined in:
- lib/uptrace/dsn.rb
Overview
Uptrace DSN
Instance Attribute Summary collapse
-
#dsn ⇒ Object
readonly
Returns the value of attribute dsn.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#http_port ⇒ Object
readonly
Returns the value of attribute http_port.
-
#scheme ⇒ Object
readonly
Returns the value of attribute scheme.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
-
#initialize(dsn) ⇒ DSN
constructor
A new instance of DSN.
- #otlp_http_endpoint ⇒ Object
- #site_url ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(dsn) ⇒ DSN
Returns a new instance of DSN.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/uptrace/dsn.rb', line 8 def initialize(dsn) raise ArgumentError, "DSN can't be empty" if dsn.empty? begin uri = URI.parse(dsn) rescue URI::InvalidURIError => e raise ArgumentError, %(can't parse DSN=#{dsn.inspect}: #{e}) end @dsn = dsn @scheme = uri.scheme @host = uri.host @http_port = uri.port @token = uri.user %w[scheme host].each do |k| v = public_send(k) raise ArgumentError, %(DSN=#{dsn.inspect} does not have a #{k}) if v.nil? || v.empty? end @host = 'uptrace.dev' if @host == 'api.uptrace.dev' end |
Instance Attribute Details
#dsn ⇒ Object (readonly)
Returns the value of attribute dsn.
6 7 8 |
# File 'lib/uptrace/dsn.rb', line 6 def dsn @dsn end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
6 7 8 |
# File 'lib/uptrace/dsn.rb', line 6 def host @host end |
#http_port ⇒ Object (readonly)
Returns the value of attribute http_port.
6 7 8 |
# File 'lib/uptrace/dsn.rb', line 6 def http_port @http_port end |
#scheme ⇒ Object (readonly)
Returns the value of attribute scheme.
6 7 8 |
# File 'lib/uptrace/dsn.rb', line 6 def scheme @scheme end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
6 7 8 |
# File 'lib/uptrace/dsn.rb', line 6 def token @token end |
Instance Method Details
#otlp_http_endpoint ⇒ Object
42 43 44 45 46 47 |
# File 'lib/uptrace/dsn.rb', line 42 def otlp_http_endpoint return 'https://otlp.uptrace.dev' if @host == 'uptrace.dev' return "#{@scheme}://#{@host}:#{@http_port}" if @http_port != 443 "#{@scheme}://#{@host}" end |
#site_url ⇒ Object
35 36 37 38 39 40 |
# File 'lib/uptrace/dsn.rb', line 35 def site_url return 'https://app.uptrace.dev' if @host == 'uptrace.dev' return "#{@scheme}://#{@host}:#{@http_port}" if @http_port != 443 "#{@scheme}://#{@host}" end |
#to_s ⇒ Object
31 32 33 |
# File 'lib/uptrace/dsn.rb', line 31 def to_s @dsn end |