Module: Pyroscope

Defined in:
lib/pyroscope.rb,
lib/pyroscope/version.rb

Defined Under Namespace

Classes: Config

Constant Summary collapse

VERSION =
'0.3.0'.freeze

Class Method Summary collapse

Class Method Details

._add_tags(thread_id, tags) ⇒ Object

add tags



84
85
86
87
88
# File 'lib/pyroscope.rb', line 84

def _add_tags(thread_id, tags)
  tags.each do |tag_name, tag_value|
    Rust.add_tag(thread_id, tag_name.to_s, tag_value.to_s)
  end
end

._remove_tags(thread_id, tags) ⇒ Object

remove tags



91
92
93
94
95
# File 'lib/pyroscope.rb', line 91

def _remove_tags(thread_id, tags)
  tags.each do |tag_name, tag_value|
    Rust.remove_tag(thread_id, tag_name.to_s, tag_value.to_s)
  end
end

.configure {|@config| ... } ⇒ Object

Yields:

  • (@config)


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/pyroscope.rb', line 36

def configure
  @config = Config.new

  # Pass config to the block
  yield @config

  Rust.initialize_agent(
    @config.app_name || @config.application_name,
    @config.server_address,
    @config.auth_token,
    @config.sample_rate,
    @config.detect_subprocesses,
    @config.on_cpu,
    @config.report_pid,
    @config.report_thread_id,
    tags_to_string(@config.tags)
  )
end

.dropObject



97
98
99
# File 'lib/pyroscope.rb', line 97

def drop
  Rust.drop_agent
end

.remove_tags(*tags) ⇒ Object



69
70
71
# File 'lib/pyroscope.rb', line 69

def remove_tags(*tags)
  warn("deprecated. Use `Pyroscope.tag_wrapper` instead.")
end

.tag(tags) ⇒ Object



65
66
67
# File 'lib/pyroscope.rb', line 65

def tag(tags)
  warn("deprecated. Use `Pyroscope.tag_wrapper` instead.")
end

.tag_wrapper(tags) ⇒ Object



55
56
57
58
59
60
61
62
63
# File 'lib/pyroscope.rb', line 55

def tag_wrapper(tags)
  tid = thread_id
  _add_tags(tid, tags)
  begin
    yield
  ensure
    _remove_tags(tid, tags)
  end
end

.tags_to_string(tags) ⇒ Object

convert tags object to string



74
75
76
# File 'lib/pyroscope.rb', line 74

def tags_to_string(tags)
  tags.map { |k, v| "#{k}=#{v}" }.join(',')
end

.thread_idObject

get thread id



79
80
81
# File 'lib/pyroscope.rb', line 79

def thread_id
  return Utils.thread_id
end