Module: Pyroscope

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

Defined Under Namespace

Modules: Rust Classes: Config, Engine

Constant Summary collapse

VERSION =

x-release-please-version

'1.0.8'.freeze

Class Method Summary collapse

Class Method Details

._add_tags(tags) ⇒ Object



140
141
142
143
144
# File 'lib/pyroscope.rb', line 140

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

._remove_tags(tags) ⇒ Object



146
147
148
149
150
# File 'lib/pyroscope.rb', line 146

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

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

Yields:

  • (@config)


72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/pyroscope.rb', line 72

def configure
  @config = Config.new

  # Pass config to the block
  yield @config

  # Determine Logging level (kinda like an enum).
  case @config.log_level
  when 'trace'
    @log_level = 10
  when 'debug'
    @log_level = 20
  when 'info'
    @log_level = 30
  when 'warn'
    @log_level = 40
  when 'error'
    @log_level = 50
  else
    @log_level = 50
  end

  Rust.initialize_logging(@log_level)

  Rust.initialize_agent(
    # these are defaults in case user-provided values are nil:
    @config.app_name || @config.application_name || "",
    @config.server_address || "",
    @config.basic_auth_username || "",
    @config.basic_auth_password || "",
    @config.sample_rate || 100,
    @config.oncpu || false,
    @config.report_pid || false,
    @config.report_thread_id || false,
    tags_to_string(@config.tags || {}),
    @config.tenant_id || "",
    http_headers_to_json(@config.http_headers || {})
  )
end

.current_configObject



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

def current_config
  @config
end

.initialize_rails_hooksObject



112
113
114
115
116
117
118
119
120
121
# File 'lib/pyroscope.rb', line 112

def initialize_rails_hooks
  block = lambda do |ctrl, action|
    Pyroscope.tag_wrapper({
      "action" => "#{ctrl.controller_name}/#{ctrl.action_name}"
    }, &action)
  end

  ActionController::API.__send__(:around_action, block) if defined? ActionController::API
  ActionController::Base.__send__(:around_action, block) if defined? ActionController::Base
end

.remove_tags(*tags) ⇒ Object



136
137
138
# File 'lib/pyroscope.rb', line 136

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

.shutdownObject



156
157
158
# File 'lib/pyroscope.rb', line 156

def shutdown
  stop
end

.stopObject



152
153
154
# File 'lib/pyroscope.rb', line 152

def stop
  Rust.drop_agent
end

.tag(tags) ⇒ Object



132
133
134
# File 'lib/pyroscope.rb', line 132

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

.tag_wrapper(tags) ⇒ Object



123
124
125
126
127
128
129
130
# File 'lib/pyroscope.rb', line 123

def tag_wrapper(tags)
  _add_tags(tags)
  begin
    yield
  ensure
    _remove_tags(tags)
  end
end