Add HTTP client update function to tracing library
Signed-off-by: Derek McGowan <derek@mcg.dev>
This commit is contained in:
parent
ad3b806a4f
commit
8203bb9977
@ -39,7 +39,6 @@ import (
|
|||||||
"github.com/containerd/log"
|
"github.com/containerd/log"
|
||||||
"github.com/opencontainers/go-digest"
|
"github.com/opencontainers/go-digest"
|
||||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -596,12 +595,9 @@ func (r *request) do(ctx context.Context) (*http.Response, error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
client.Transport = otelhttp.NewTransport(
|
|
||||||
client.Transport,
|
tracing.UpdateHTTPClient(client, tracing.Name("remotes.docker.resolver", "HTTPRequest"))
|
||||||
otelhttp.WithSpanNameFormatter(func(operation string, r *http.Request) string {
|
|
||||||
return tracing.Name("remotes.docker.resolver", "HTTPRequest")
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to do request: %w", err)
|
return nil, fmt.Errorf("failed to do request: %w", err)
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
||||||
"go.opentelemetry.io/otel"
|
"go.opentelemetry.io/otel"
|
||||||
"go.opentelemetry.io/otel/attribute"
|
"go.opentelemetry.io/otel/attribute"
|
||||||
"go.opentelemetry.io/otel/codes"
|
"go.opentelemetry.io/otel/codes"
|
||||||
@ -47,6 +48,16 @@ func WithHTTPRequest(_ *http.Request) SpanOpt {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateHTTPClient updates the http client with the necessary otel transport
|
||||||
|
func UpdateHTTPClient(client *http.Client, name string) {
|
||||||
|
client.Transport = otelhttp.NewTransport(
|
||||||
|
client.Transport,
|
||||||
|
otelhttp.WithSpanNameFormatter(func(operation string, r *http.Request) string {
|
||||||
|
return name
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// StartSpan starts child span in a context.
|
// StartSpan starts child span in a context.
|
||||||
func StartSpan(ctx context.Context, opName string, opts ...SpanOpt) (context.Context, *Span) {
|
func StartSpan(ctx context.Context, opName string, opts ...SpanOpt) (context.Context, *Span) {
|
||||||
config := StartConfig{}
|
config := StartConfig{}
|
||||||
|
Loading…
Reference in New Issue
Block a user