Module: Pyroscope

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

Defined Under Namespace

Modules: Rust, Utils Classes: Config

Constant Summary collapse

VERSION =
'0.3.2'.freeze

Class Method Summary collapse

Class Method Details

._add_tags(thread_id, tags) ⇒ Object

add tags



86
87
88
89
90
# File 'lib/pyroscope.rb', line 86

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

._remove_tags(thread_id, tags) ⇒ Object

remove tags



93
94
95
96
97
# File 'lib/pyroscope.rb', line 93

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

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

Yields:

  • (@config)


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

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 || 100,
    @config.detect_subprocesses || false,
    @config.on_cpu || false,
    @config.report_pid || false,
    @config.report_thread_id || false,
    tags_to_string(@config.tags || {})
  )
end

.dropObject



99
100
101
# File 'lib/pyroscope.rb', line 99

def drop
  Rust.drop_agent
end

.remove_tags(*tags) ⇒ Object



71
72
73
# File 'lib/pyroscope.rb', line 71

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

.tag(tags) ⇒ Object



67
68
69
# File 'lib/pyroscope.rb', line 67

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

.tag_wrapper(tags) ⇒ Object



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

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



76
77
78
# File 'lib/pyroscope.rb', line 76

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

.thread_idObject

get thread id



81
82
83
# File 'lib/pyroscope.rb', line 81

def thread_id
  return Utils.thread_id
end