added request tracing
This commit is contained in:
parent
dae45986f6
commit
d7ad6c44bd
3 changed files with 92 additions and 11 deletions
|
|
@ -12,8 +12,35 @@ import (
|
||||||
|
|
||||||
var version string
|
var version string
|
||||||
|
|
||||||
func get(c *http.Client, url string) (body string, err error) {
|
var tracer = []string{
|
||||||
resp, err := c.Get(url)
|
"x-request-id",
|
||||||
|
"x-b3-traceid",
|
||||||
|
"x-b3-spanid",
|
||||||
|
"x-b3-parentspanid",
|
||||||
|
"x-b3-sampled",
|
||||||
|
"x-b3-flags",
|
||||||
|
"x-ot-span-context",
|
||||||
|
}
|
||||||
|
|
||||||
|
func trace(rd, rs *http.Request) {
|
||||||
|
if rd == nil || rs == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, t := range tracer {
|
||||||
|
v := rs.Header.Get(t)
|
||||||
|
if v != "" {
|
||||||
|
rd.Header.Set(t, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func get(c *http.Client, req *http.Request, url string) (body string, err error) {
|
||||||
|
r, err := http.NewRequest("GET", url, nil)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
trace(r, req)
|
||||||
|
resp, err := c.Do(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -39,11 +66,11 @@ func main() {
|
||||||
Timeout: 5 * time.Second,
|
Timeout: 5 * time.Second,
|
||||||
}).DialContext,
|
}).DialContext,
|
||||||
}}
|
}}
|
||||||
health, err := get(c, "http://testapp-db:8080/healthz")
|
health, err := get(c, r, "http://testapp-db:8080/healthz")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
health = err.Error()
|
health = err.Error()
|
||||||
}
|
}
|
||||||
ext, err := get(c, "http://httpbin.org/robots.txt")
|
ext, err := get(c, nil, "http://httpbin.org/robots.txt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ext = err.Error()
|
ext = err.Error()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,35 @@ import (
|
||||||
|
|
||||||
var version string
|
var version string
|
||||||
|
|
||||||
func get(c *http.Client, url string) (body string, err error) {
|
var tracer = []string{
|
||||||
resp, err := c.Get(url)
|
"x-request-id",
|
||||||
|
"x-b3-traceid",
|
||||||
|
"x-b3-spanid",
|
||||||
|
"x-b3-parentspanid",
|
||||||
|
"x-b3-sampled",
|
||||||
|
"x-b3-flags",
|
||||||
|
"x-ot-span-context",
|
||||||
|
}
|
||||||
|
|
||||||
|
func trace(rd, rs *http.Request) {
|
||||||
|
if rd == nil || rs == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, t := range tracer {
|
||||||
|
v := rs.Header.Get(t)
|
||||||
|
if v != "" {
|
||||||
|
rd.Header.Set(t, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func get(c *http.Client, req *http.Request, url string) (body string, err error) {
|
||||||
|
r, err := http.NewRequest("GET", url, nil)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
trace(r, req)
|
||||||
|
resp, err := c.Do(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -39,7 +66,7 @@ func main() {
|
||||||
Timeout: 5 * time.Second,
|
Timeout: 5 * time.Second,
|
||||||
}).DialContext,
|
}).DialContext,
|
||||||
}}
|
}}
|
||||||
body, err := get(c, "http://testapp-api:8080/healthz")
|
body, err := get(c, r, "http://testapp-api:8080/healthz")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
body = err.Error()
|
body = err.Error()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,35 @@ import (
|
||||||
|
|
||||||
var version string
|
var version string
|
||||||
|
|
||||||
func get(c *http.Client, url string) (body string, err error) {
|
var tracer = []string{
|
||||||
resp, err := c.Get(url)
|
"x-request-id",
|
||||||
|
"x-b3-traceid",
|
||||||
|
"x-b3-spanid",
|
||||||
|
"x-b3-parentspanid",
|
||||||
|
"x-b3-sampled",
|
||||||
|
"x-b3-flags",
|
||||||
|
"x-ot-span-context",
|
||||||
|
}
|
||||||
|
|
||||||
|
func trace(rd, rs *http.Request) {
|
||||||
|
if rd == nil || rs == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, t := range tracer {
|
||||||
|
v := rs.Header.Get(t)
|
||||||
|
if v != "" {
|
||||||
|
rd.Header.Set(t, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func get(c *http.Client, req *http.Request, url string) (body string, err error) {
|
||||||
|
r, err := http.NewRequest("GET", url, nil)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
trace(r, req)
|
||||||
|
resp, err := c.Do(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -49,12 +76,12 @@ func main() {
|
||||||
}).DialContext,
|
}).DialContext,
|
||||||
}}
|
}}
|
||||||
dbUrl := "http://testapp-db:8080"
|
dbUrl := "http://testapp-db:8080"
|
||||||
dbBody, err := get(c, dbUrl)
|
dbBody, err := get(c, r, dbUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
dbBody = err.Error()
|
dbBody = err.Error()
|
||||||
}
|
}
|
||||||
apiUrl := "http://testapp-api:8080"
|
apiUrl := "http://testapp-api:8080"
|
||||||
apiBody, err := get(c, apiUrl)
|
apiBody, err := get(c, r, apiUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
apiBody = err.Error()
|
apiBody = err.Error()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue