Skip to content

Commit

Permalink
background logs
Browse files Browse the repository at this point in the history
  • Loading branch information
iamemilio committed Jun 28, 2022
1 parent d1385ff commit f137814
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions v3/examples/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,26 +246,14 @@ func browser(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "browser header page")
}

func logMessage(w http.ResponseWriter, r *http.Request) {
txn := newrelic.FromContext(r.Context())
app := txn.Application()

app.RecordLog(newrelic.LogData{
Message: "Log Message",
Severity: "info",
})

io.WriteString(w, "A log message was recorded")
}

func logTxnMessage(w http.ResponseWriter, r *http.Request) {
txn := newrelic.FromContext(r.Context())
txn.RecordLog(newrelic.LogData{
Message: "Log Message",
Severity: "info",
})

io.WriteString(w, "A log message was recorded as part of a transaction")
io.WriteString(w, "A log message was recorded")
}

func main() {
Expand Down Expand Up @@ -297,8 +285,7 @@ func main() {
http.HandleFunc(newrelic.WrapHandleFunc(app, "/browser", browser))
http.HandleFunc(newrelic.WrapHandleFunc(app, "/async", async))
http.HandleFunc(newrelic.WrapHandleFunc(app, "/message", message))
http.HandleFunc(newrelic.WrapHandleFunc(app, "/log", logMessage))
http.HandleFunc(newrelic.WrapHandleFunc(app, "/transaction_log", logTxnMessage))
http.HandleFunc(newrelic.WrapHandleFunc(app, "/log", logTxnMessage))

http.HandleFunc("/background", func(w http.ResponseWriter, req *http.Request) {
// Transactions started without an http.Request are classified as
Expand All @@ -310,5 +297,17 @@ func main() {
time.Sleep(150 * time.Millisecond)
})

http.HandleFunc("/background_log", func(w http.ResponseWriter, req *http.Request) {
// Logs that occur outside of a transaction are classified as
// background logs.

app.RecordLog(newrelic.LogData{
Message: "Background Log Message",
Severity: "info",
})

io.WriteString(w, "A background log message was recorded")
})

http.ListenAndServe(":8000", nil)
}

0 comments on commit f137814

Please sign in to comment.