ensure otel tracing is passed through all event handlers and clients

This commit is contained in:
Mike Mason
2023-07-21 16:12:24 +00:00
parent 4ac8929644
commit c27e50ea0b
9 changed files with 46 additions and 9 deletions

View File

@@ -10,6 +10,7 @@ import (
"strings"
"time"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"go.uber.org/zap"
"go.equinixmetal.net/infra9-metal-bridge/internal/metal/providers"
@@ -27,7 +28,8 @@ const (
// DefaultHTTPClient is the default http client used if no client is provided.
var DefaultHTTPClient = &http.Client{
Timeout: defaultHTTPTimeout,
Timeout: defaultHTTPTimeout,
Transport: otelhttp.NewTransport(http.DefaultTransport),
}
var _ providers.Provider = &Client{}

View File

@@ -1,6 +1,8 @@
package emapi
import (
"net/http"
"go.uber.org/zap"
)
@@ -15,3 +17,12 @@ func WithLogger(logger *zap.SugaredLogger) Option {
return nil
}
}
// WithHTTPClient sets the http client to be used by the client.
func WithHTTPClient(httpClient *http.Client) Option {
return func(c *Client) error {
c.httpClient = httpClient
return nil
}
}

View File

@@ -5,6 +5,7 @@ import (
"net/url"
"time"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"go.uber.org/zap"
"go.equinixmetal.net/infra9-metal-bridge/internal/metal/providers"
@@ -16,7 +17,8 @@ const (
// DefaultHTTPClient is the default http client used if no client is provided.
var DefaultHTTPClient = &http.Client{
Timeout: defaultHTTPTimeout,
Timeout: defaultHTTPTimeout,
Transport: otelhttp.NewTransport(http.DefaultTransport),
}
var _ providers.Provider = &Client{}

View File

@@ -1,6 +1,7 @@
package emgql
import (
"net/http"
"net/url"
"go.uber.org/zap"
@@ -32,6 +33,15 @@ func WithBaseURL(baseURL string) Option {
}
}
// WithHTTPClient sets the http client to be used by the client.
func WithHTTPClient(httpClient *http.Client) Option {
return func(c *Client) error {
c.httpClient = httpClient
return nil
}
}
// WithConfig applies all configurations defined in the config.
func WithConfig(config Config) Option {
return func(c *Client) error {

View File

@@ -13,6 +13,7 @@ import (
"github.com/labstack/echo/v4"
"go.infratographer.com/x/gidx"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"go.uber.org/zap"
)
@@ -32,7 +33,8 @@ const (
// DefaultHTTPClient is the default HTTP client for the Permissions Client.
var DefaultHTTPClient = &http.Client{
Timeout: defaultHTTPClientTimeout,
Timeout: defaultHTTPClientTimeout,
Transport: otelhttp.NewTransport(http.DefaultTransport),
}
// Client defines the Permissions API client interface.

View File

@@ -142,7 +142,9 @@ func (s *Subscriber) processEvent(msg *changeEvent) error {
"event.type", msg.EventType,
)
ctx, span := tracer.Start(context.Background(), "pubsub.receive", trace.WithAttributes(attribute.String("pubsub.subject", msg.SubjectID.String())))
ctx := events.TraceContextFromChangeMessage(context.Background(), msg.ChangeMessage)
ctx, span := tracer.Start(ctx, "pubsub.receive", trace.WithAttributes(attribute.String("pubsub.subject", msg.SubjectID.String())))
defer span.End()