Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NH-90184: add doc for add_tracer api call #174

Merged
merged 11 commits into from
Jan 8, 2025
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,44 @@ The metrics submitted are aggregated by metric name and tag(s), then sent every
SolarWindsAPM::API.increment_metric('loop.iteration')
SolarWindsAPM::API.summary_metric('sleep.time', 5000)
```

#### Instrument on custom function

To instrument a custom function outside the default scope in [opentelemetry-ruby-contrib](https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/main/instrumentation), use the `add_tracer` function in solarwinds_apm.

For example, if you want to instrument class function `create_session` inside application controller

```ruby
class SessionsController < ApplicationController
include SolarWindsAPM::API::Tracer

def create
user = User.find_by(email: params[:session][:email].downcase)
create_session(user)
end

def create_session(user)
end
add_tracer :create_session
end
```

For example, if you want to instrument instance function `create_session` inside application controller

```ruby
class SessionsController < ApplicationController

def create
user = User.find_by(email: params[:session][:email].downcase)
SessionsController.create_session(user)
end

def self.create_session(user)
end

class << self
include SolarWindsAPM::API::Tracer
add_tracer :create_session
end
end
```
Loading