-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require 'metrics/provider' | ||
|
||
class MyApplication | ||
def work | ||
# ... | ||
end | ||
|
||
Metrics::Provider(self) do | ||
WORK_METRIC = Metrics.metric('my_application.work.count', :counter, description: 'Work counter') | ||
|
||
def work | ||
WORK_METRIC.emit(1) | ||
super | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env sus | ||
|
||
ENV['METRICS_BACKEND'] ||= 'metrics/backend/test' | ||
|
||
require_relative 'app' | ||
|
||
describe MyApplication do | ||
it 'should emit metrics' do | ||
expect(MyApplication::WORK_METRIC).to receive(:emit).with(1) | ||
MyApplication.new.work | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
getting-started: | ||
order: 1 | ||
capture: | ||
order: 2 | ||
order: 2 | ||
testing: | ||
order: 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Testing | ||
|
||
This guide explains how to write assertions in your test suite to validate `metrics` are being emitted correctly. | ||
|
||
## Application Code | ||
|
||
In your application code, you should emit metrics, e.g. | ||
|
||
```ruby | ||
require 'metrics/provider' | ||
|
||
class MyApplication | ||
def work | ||
# ... | ||
end | ||
|
||
Metrics::Provider(self) do | ||
WORK_METRIC = Metrics.metric('my_application.work.count', :counter, description: 'Work counter') | ||
|
||
def work | ||
WORK_METRIC.emit(1) | ||
super | ||
end | ||
end | ||
end | ||
``` | ||
|
||
## Test Code | ||
|
||
In your test code, you should assert that the metrics are being emitted correctly, e.g. | ||
|
||
```ruby | ||
ENV['METRICS_BACKEND'] ||= 'metrics/backend/test' | ||
|
||
require_relative 'app' | ||
|
||
describe MyApplication do | ||
it 'should emit metrics' do | ||
expect(MyApplication::WORK_METRIC).to receive(:emit).with(1) | ||
MyApplication.new.work | ||
end | ||
end | ||
``` |