mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Tracing: Use common traceID context value for opentracing and opentelemetry (#46411)
* use common traceID context value for opentracing and opentelemetry * support sampled trace IDs as well * inject traceID into NormalResponse on errors * Finally the test passed * fix the test * fix linter * change the function parameter Co-authored-by: Ying WANG <ying.wang@grafana.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
@@ -73,7 +74,15 @@ func (r *NormalResponse) ErrMessage() string {
|
||||
|
||||
func (r *NormalResponse) WriteTo(ctx *models.ReqContext) {
|
||||
if r.err != nil {
|
||||
ctx.Logger.Error(r.errMessage, "error", r.err, "remote_addr", ctx.RemoteAddr())
|
||||
v := map[string]interface{}{}
|
||||
traceID := tracing.TraceIDFromContext(ctx.Req.Context(), false)
|
||||
if err := json.Unmarshal(r.body.Bytes(), &v); err == nil {
|
||||
v["traceID"] = traceID
|
||||
if b, err := json.Marshal(v); err == nil {
|
||||
r.body = bytes.NewBuffer(b)
|
||||
}
|
||||
}
|
||||
ctx.Logger.Error(r.errMessage, "error", r.err, "remote_addr", ctx.RemoteAddr(), "traceID", traceID)
|
||||
}
|
||||
|
||||
header := ctx.Resp.Header()
|
||||
|
||||
Reference in New Issue
Block a user