-
Notifications
You must be signed in to change notification settings - Fork 294
/
main.go
53 lines (41 loc) · 1.03 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"context"
"fmt"
"os"
"time"
"github.com/newrelic/go-agent/v3/integrations/logcontext-v2/nrzerolog"
"github.com/newrelic/go-agent/v3/newrelic"
"github.com/rs/zerolog"
)
func main() {
baseLogger := zerolog.New(os.Stdout)
app, err := newrelic.NewApplication(
newrelic.ConfigFromEnvironment(),
newrelic.ConfigAppName("NRZerolog Example"),
newrelic.ConfigInfoLogger(os.Stdout),
newrelic.ConfigZerologPluginEnabled(true),
)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
app.WaitForConnection(5 * time.Second)
nrHook := nrzerolog.NewRelicHook{
App: app,
}
nrLogger := baseLogger.Hook(nrHook)
nrLogger.Info().Msg("Hello World")
// With transaction context
txn := app.StartTransaction("My Transaction")
ctx := newrelic.NewContext(context.Background(), txn)
nrTxnHook := nrzerolog.NewRelicHook{
App: app,
Context: ctx,
}
txnLogger := baseLogger.Hook(nrTxnHook)
txnLogger.Debug().Msg("This is a transaction log")
txn.End()
nrLogger.Info().Msg("Goodbye")
app.Shutdown(10 * time.Second)
}