-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
38 lines (32 loc) · 1.33 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
package main
import (
"context"
"fmt"
"github.com/newrelic/go-agent/v3/integrations/nrlambda"
"github.com/newrelic/go-agent/v3/newrelic"
// log "github.com/sirupsen/logrus"
)
func handler(ctx context.Context) (string, error) {
// At this point, we're handling an invocation. Cold start is over; this code runs for each invocation.
// We'd like to add a custom event, and a custom attribute. For that, we need the transaction.
// log.Fatal("This is a critical error message, lambda will exit after this")
if txn := newrelic.FromContext(ctx); nil != txn {
// This is an example of a custom event. `FROM MyGoEvent SELECT *` in New Relic will find this event.
txn.Application().RecordCustomMetric("someMetric", 24)
// This attribute gets added to the normal AwsLambdaInvocation event
txn.AddAttribute("customAttribute", "customAttributeValue")
}
// As normal, anything you write to stdout ends up in CloudWatch
fmt.Println("hello saket testing!!!!!")
return "Success!", nil
}
func main() {
// Here we are in cold start. Anything you do in main happens once.
// In main, we initialize the agent.
app, err := newrelic.NewApplication(nrlambda.ConfigOption())
if nil != err {
fmt.Println("error creating app (invalid config):", err)
}
// Then we start the lambda handler using `nrlambda` rather than `lambda`
nrlambda.Start(handler, app)
}