forked from newrelic/go-agent
/
main.go
42 lines (34 loc) · 916 Bytes
/
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
package main
import (
"context"
"database/sql"
"fmt"
"os"
"time"
_ "github.com/newrelic/go-agent/v3/integrations/nrmssql"
"github.com/newrelic/go-agent/v3/newrelic"
)
func main() {
// Set up a local ms sql docker
db, err := sql.Open("nrmssql", "server=localhost;user id=sa;database=master;app name=MyAppName")
if nil != err {
panic(err)
}
app, err := newrelic.NewApplication(
newrelic.ConfigAppName("MSSQL App"),
newrelic.ConfigLicense(os.Getenv("NEW_RELIC_LICENSE_KEY")),
newrelic.ConfigDebugLogger(os.Stdout),
)
if nil != err {
panic(err)
}
app.WaitForConnection(5 * time.Second)
txn := app.StartTransaction("mssqlQuery")
ctx := newrelic.NewContext(context.Background(), txn)
row := db.QueryRowContext(ctx, "SELECT count(*) from tables")
var count int
row.Scan(&count)
txn.End()
app.Shutdown(5 * time.Second)
fmt.Println("number of tables in information_schema", count)
}