Skip to content

Commit 108a2a3

Browse files
authored
Merge pull request #1608 from cortexproject/ruler-notifier-span
Add a tracing span for ruler calling Alertmanager
2 parents 11fdb05 + e23a15c commit 108a2a3

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

pkg/ruler/ruler.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"time"
1111

1212
"github.com/go-kit/kit/log/level"
13-
opentracing "github.com/opentracing/opentracing-go"
13+
ot "github.com/opentracing/opentracing-go"
1414
"github.com/prometheus/client_golang/prometheus"
1515
"github.com/prometheus/client_golang/prometheus/promauto"
1616
"github.com/prometheus/prometheus/config"
@@ -280,13 +280,18 @@ func (r *Ruler) getOrCreateNotifier(userID string) (*notifier.Manager, error) {
280280
n = newRulerNotifier(&notifier.Options{
281281
QueueCapacity: r.cfg.NotificationQueueCapacity,
282282
Do: func(ctx context.Context, client *http.Client, req *http.Request) (*http.Response, error) {
283-
// Note: The passed-in context comes from the Prometheus rule group code
283+
// Note: The passed-in context comes from the Prometheus notifier
284284
// and does *not* contain the userID. So it needs to be added to the context
285285
// here before using the context to inject the userID into the HTTP request.
286286
ctx = user.InjectOrgID(ctx, userID)
287287
if err := user.InjectOrgIDIntoHTTPRequest(ctx, req); err != nil {
288288
return nil, err
289289
}
290+
// Jaeger complains the passed-in context has an invalid span ID, so start a new root span
291+
sp := ot.GlobalTracer().StartSpan("notify", ot.Tag{Key: "organization", Value: userID})
292+
defer sp.Finish()
293+
ctx = ot.ContextWithSpan(ctx, sp)
294+
ot.GlobalTracer().Inject(sp.Context(), ot.HTTPHeaders, ot.HTTPHeadersCarrier(req.Header))
290295
return ctxhttp.Do(ctx, client, req)
291296
},
292297
}, util.Logger)
@@ -313,7 +318,7 @@ func (r *Ruler) Evaluate(userID string, item *workItem) {
313318
level.Debug(logger).Log("msg", "evaluating rules...", "num_rules", len(item.group.Rules()))
314319
ctx, cancelTimeout := context.WithTimeout(ctx, r.cfg.GroupTimeout)
315320
instrument.CollectedRequest(ctx, "Evaluate", evalDuration, nil, func(ctx native_ctx.Context) error {
316-
if span := opentracing.SpanFromContext(ctx); span != nil {
321+
if span := ot.SpanFromContext(ctx); span != nil {
317322
span.SetTag("instance", userID)
318323
span.SetTag("groupName", item.groupName)
319324
}

0 commit comments

Comments
 (0)