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:
co-authored by
Ying WANG
parent
ab4c7f14aa
commit
41012af997
@@ -19,10 +19,10 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
"github.com/grafana/grafana/pkg/services/contexthandler"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
cw "github.com/weaveworks/common/tracing"
|
||||
)
|
||||
|
||||
func Logger(cfg *setting.Cfg) web.Handler {
|
||||
@@ -58,8 +58,8 @@ func Logger(cfg *setting.Cfg) web.Handler {
|
||||
"referer", req.Referer(),
|
||||
}
|
||||
|
||||
traceID, exist := cw.ExtractTraceID(ctx.Req.Context())
|
||||
if exist {
|
||||
traceID := tracing.TraceIDFromContext(ctx.Req.Context(), false)
|
||||
if traceID != "" {
|
||||
logParams = append(logParams, "traceID", traceID)
|
||||
}
|
||||
|
||||
|
||||
@@ -7,10 +7,10 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/metrics"
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
cw "github.com/weaveworks/common/tracing"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -80,7 +80,7 @@ func RequestMetrics(features featuremgmt.FeatureToggles) web.Handler {
|
||||
// since they dont make much sense. We should remove them later.
|
||||
histogram := httpRequestDurationHistogram.
|
||||
WithLabelValues(handler, code, req.Method)
|
||||
if traceID, ok := cw.ExtractSampledTraceID(c.Req.Context()); ok {
|
||||
if traceID := tracing.TraceIDFromContext(c.Req.Context(), true); traceID != "" {
|
||||
// Need to type-convert the Observer to an
|
||||
// ExemplarObserver. This will always work for a
|
||||
// HistogramVec.
|
||||
|
||||
Reference in New Issue
Block a user