-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathmain.go
62 lines (46 loc) · 975 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// (c) Copyright IBM Corp. 2023
package main
import (
"io"
"net/http"
_ "github.com/go-sql-driver/mysql"
instana "github.com/instana/go-sensor"
)
var s instana.TracerLogger
func init() {
s = instana.InitCollector(&instana.Options{
Service: "MySQL app",
})
}
func agentReady() chan bool {
ch := make(chan bool)
go func() {
for {
if instana.Ready() {
ch <- true
}
}
}()
return ch
}
func handler(w http.ResponseWriter, req *http.Request) {
db, err := instana.SQLInstrumentAndOpen(s, "mysql", "go:gopw@tcp(localhost:3306)/godb")
if err != nil {
panic(err)
}
r, err := db.QueryContext(req.Context(), "SELECT 'Current date is' || CURDATE();")
if err != nil {
panic(err)
}
var buf, res string
for r.Next() {
r.Scan(&buf)
res += " " + buf
}
io.WriteString(w, res+" - hello\n")
}
func main() {
<-agentReady()
http.HandleFunc("/mysql", instana.TracingHandlerFunc(s, "/mysql", handler))
http.ListenAndServe(":9090", nil)
}