Jaeger: Create child span for remote read (#7187)

* Jaeger: Create child span for remote read
* Jaeger: use middleware to trace client http request

Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
This commit is contained in:
Julien Pivotto 2020-05-02 22:41:55 +02:00 committed by GitHub
parent 18d45e564b
commit 7ecd2d1c24
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -27,12 +27,12 @@ import (
"github.com/gogo/protobuf/proto" "github.com/gogo/protobuf/proto"
"github.com/golang/snappy" "github.com/golang/snappy"
"github.com/opentracing/opentracing-go" "github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/ext"
"github.com/pkg/errors" "github.com/pkg/errors"
config_util "github.com/prometheus/common/config" config_util "github.com/prometheus/common/config"
"github.com/prometheus/common/model" "github.com/prometheus/common/model"
"github.com/prometheus/common/version" "github.com/prometheus/common/version"
"github.com/opentracing-contrib/go-stdlib/nethttp"
"github.com/prometheus/prometheus/prompb" "github.com/prometheus/prometheus/prompb"
) )
@ -62,6 +62,11 @@ func NewClient(remoteName string, conf *ClientConfig) (*Client, error) {
return nil, err return nil, err
} }
t := httpClient.Transport
httpClient.Transport = &nethttp.Transport{
RoundTripper: t,
}
return &Client{ return &Client{
remoteName: remoteName, remoteName: remoteName,
url: conf.URL, url: conf.URL,
@ -151,21 +156,23 @@ func (c *Client) Read(ctx context.Context, query *prompb.Query) (*prompb.QueryRe
httpReq.Header.Set("User-Agent", userAgent) httpReq.Header.Set("User-Agent", userAgent)
httpReq.Header.Set("X-Prometheus-Remote-Read-Version", "0.1.0") httpReq.Header.Set("X-Prometheus-Remote-Read-Version", "0.1.0")
if span := opentracing.SpanFromContext(ctx); span != nil {
ext.SpanKindRPCClient.Set(span)
ext.HTTPUrl.Set(span, httpReq.URL.String())
ext.HTTPMethod.Set(span, httpReq.Method)
_ = span.Tracer().Inject(
span.Context(),
opentracing.HTTPHeaders,
opentracing.HTTPHeadersCarrier(httpReq.Header),
)
}
ctx, cancel := context.WithTimeout(ctx, c.timeout) ctx, cancel := context.WithTimeout(ctx, c.timeout)
defer cancel() defer cancel()
httpResp, err := c.client.Do(httpReq.WithContext(ctx)) httpReq = httpReq.WithContext(ctx)
if parentSpan := opentracing.SpanFromContext(ctx); parentSpan != nil {
var ht *nethttp.Tracer
httpReq, ht = nethttp.TraceRequest(
parentSpan.Tracer(),
httpReq,
nethttp.OperationName("Remote Read"),
nethttp.ClientTrace(false),
)
defer ht.Finish()
}
httpResp, err := c.client.Do(httpReq)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "error sending request") return nil, errors.Wrap(err, "error sending request")
} }