Class: Uptrace::Client

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

Overview

Uptrace client that configures OpenTelemetry SDK to use Uptrace exporter.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dsn: '') ⇒ Client

Returns a new instance of Client.

Parameters:

  • dsn (string) (defaults to: '')


11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/uptrace/client.rb', line 11

def initialize(dsn: '')
  dsn = ENV.fetch('UPTRACE_DSN', '') if dsn.empty?

  begin
    @dsn = DSN.new(dsn)
  rescue ArgumentError => e
    Uptrace.logger.error("Uptrace is disabled: #{e.message}")
    @disabled = true

    @dsn = DSN.new('https://[email protected]/PROJECT_ID')
  end
end

Instance Attribute Details

#dsnObject (readonly)

Returns the value of attribute dsn.



8
9
10
# File 'lib/uptrace/client.rb', line 8

def dsn
  @dsn
end

Instance Method Details

#disabled?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/uptrace/client.rb', line 24

def disabled?
  @disabled
end

#trace_url(span = nil) ⇒ String

Parameters:

  • span (optional OpenTelemetry::Trace::Span) (defaults to: nil)

Returns:

  • (String)


30
31
32
33
34
# File 'lib/uptrace/client.rb', line 30

def trace_url(span = nil)
  span = OpenTelemetry::Trace.current_span if span.nil?
  trace_id = span.context.hex_trace_id
  "#{@dsn.app_addr}/traces/#{trace_id}"
end