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.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#project_id ⇒ Object
readonly
Returns the value of attribute project_id.
-
#scheme ⇒ Object
readonly
Returns the value of attribute scheme.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #app_addr ⇒ Object
-
#initialize(dsn) ⇒ DSN
constructor
A new instance of DSN.
- #otlp_addr ⇒ 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 30 31 32 33 34 35 36 |
# 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 @port = uri.port @project_id = uri.path.delete_prefix('/') @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' return if @host != 'uptrace.dev' %w[project_id token].each do |k| v = public_send(k) raise ArgumentError, %(DSN=#{dsn.inspect} does not have a #{k}) if v.nil? || v.empty? end 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 |
#port ⇒ Object (readonly)
Returns the value of attribute port.
6 7 8 |
# File 'lib/uptrace/dsn.rb', line 6 def port @port end |
#project_id ⇒ Object (readonly)
Returns the value of attribute project_id.
6 7 8 |
# File 'lib/uptrace/dsn.rb', line 6 def project_id @project_id 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
#app_addr ⇒ Object
42 43 44 45 46 |
# File 'lib/uptrace/dsn.rb', line 42 def app_addr return 'https://app.uptrace.dev' if @host == 'uptrace.dev' "#{@scheme}://#{@host}:#{@port}" end |
#otlp_addr ⇒ Object
48 49 50 51 52 |
# File 'lib/uptrace/dsn.rb', line 48 def otlp_addr return 'https://otlp.uptrace.dev' if @host == 'uptrace.dev' "#{@scheme}://#{@host}:#{@port}" end |
#to_s ⇒ Object
38 39 40 |
# File 'lib/uptrace/dsn.rb', line 38 def to_s @dsn end |