-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from foodora/newrelic_transaction_manually
NewRelic add method to start transaction manually and send error messages to newrelic
- Loading branch information
Showing
2 changed files
with
77 additions
and
7 deletions.
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
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,7 +1,46 @@ | ||
package ranger_metrics | ||
|
||
import "testing" | ||
import ( | ||
"errors" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/foodora/go-ranger/ranger_logger" | ||
) | ||
|
||
func TestInitNewRelic(t *testing.T) { | ||
//t.Error("@todo TestInitNewRelic") | ||
} | ||
|
||
func ExampleStartTransactionManually() { | ||
var logger ranger_logger.LoggerInterface | ||
|
||
newRelic := NewNewRelic("appName", "license", logger) | ||
|
||
// Start and end manually | ||
closeTxn := newRelic.StartTransaction(nil, nil) | ||
// your code here | ||
closeTxn() | ||
|
||
// Start and end with defer | ||
closeTxn = newRelic.StartTransaction(nil, nil) | ||
defer closeTxn() | ||
// your code here | ||
|
||
// Start and end with defer in the same line | ||
defer newRelic.StartTransaction(nil, nil)() | ||
// your code here | ||
} | ||
|
||
func ExampleNoticeError() { | ||
var logger ranger_logger.LoggerInterface | ||
|
||
newRelic := NewNewRelic("appName", "license", logger) | ||
|
||
// Ensure that your handler is called by NewRelic.Middleware | ||
handler := newRelic.Middleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
newRelic.NoticeError(w, errors.New("Application failed!")) | ||
})) | ||
|
||
http.Handle("/foo", handler) | ||
} |