Tracing: Use common traceID context value for opentracing and opentelemetry (#46411) (#47786)

* 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>
(cherry picked from commit 41012af997)

Co-authored-by: Serge Zaitsev <serge.zaitsev@grafana.com>
This commit is contained in:
Grot (@grafanabot)
2022-04-14 18:08:51 +02:00
committed by GitHub
co-authored by Serge Zaitsev
parent a0ff246fcb
commit c8327d04a8
16 changed files with 140 additions and 78 deletions
+4 -1
View File
@@ -4,6 +4,7 @@ import (
"strings"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/infra/tracing"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/web"
"github.com/prometheus/client_golang/prometheus"
@@ -51,9 +52,11 @@ func (ctx *ReqContext) IsApiRequest() bool {
func (ctx *ReqContext) JsonApiErr(status int, message string, err error) {
resp := make(map[string]interface{})
traceID := tracing.TraceIDFromContext(ctx.Req.Context(), false)
if err != nil {
ctx.Logger.Error(message, "error", err)
resp["traceID"] = traceID
ctx.Logger.Error(message, "error", err, "traceID", traceID)
if setting.Env != setting.Prod {
resp["error"] = err.Error()
}