-
Notifications
You must be signed in to change notification settings - Fork 295
/
main.go
68 lines (57 loc) · 1.84 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"context"
"fmt"
"log"
"os"
"time"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/newrelic/go-agent/v3/integrations/nrawssdk-v2"
"github.com/newrelic/go-agent/v3/newrelic"
)
func main() {
// Create a New Relic application. This will look for your license key in an
// environment variable called NEW_RELIC_LICENSE_KEY. This example turns on
// Distributed Tracing, but that's not required.
app, err := newrelic.NewApplication(
newrelic.ConfigFromEnvironment(),
newrelic.ConfigAppName("Example App"),
newrelic.ConfigInfoLogger(os.Stdout),
newrelic.ConfigDistributedTracerEnabled(true),
)
if nil != err {
fmt.Println(err)
os.Exit(1)
}
// For demo purposes only. Don't use the app.WaitForConnection call in
// production unless this is a very short-lived process and the caller
// doesn't block or exit if there's an error.
app.WaitForConnection(5 * time.Second)
// Start recording a New Relic transaction
txn := app.StartTransaction("My sample transaction")
ctx := context.Background()
awsConfig, err := config.LoadDefaultConfig(ctx, func(awsConfig *config.LoadOptions) error {
// Instrument all new AWS clients with New Relic
nrawssdk.AppendMiddlewares(&awsConfig.APIOptions, nil)
return nil
})
if err != nil {
log.Fatal(err)
}
s3Client := s3.NewFromConfig(awsConfig)
output, err := s3Client.ListBuckets(ctx, nil)
if err != nil {
log.Fatal(err)
}
for _, object := range output.Buckets {
log.Printf("Bucket name is %s\n", aws.ToString(object.Name))
}
// End the New Relic transaction
txn.End()
// Force all the harvests and shutdown. Like the app.WaitForConnection call
// above, this is for the purposes of this demo only and can be safely
// removed for longer-running processes.
app.Shutdown(10 * time.Second)
}