diff --git a/client/client.go b/client/client.go index d77b2617..cd389466 100644 --- a/client/client.go +++ b/client/client.go @@ -107,6 +107,9 @@ func (c *Client) withMiddleware(wrapped http.RoundTripper) http.RoundTripper { if c.UserAgent != nil { req.Header.Set("User-Agent", *c.UserAgent) } + if c.TraceParent != nil { + req.Header.Set("Traceparent", *c.TraceParent) + } // log request and response c.logRequest(ctx, req) diff --git a/client/config.go b/client/config.go index e5668fdf..148e6f05 100644 --- a/client/config.go +++ b/client/config.go @@ -49,6 +49,9 @@ type Config struct { // optional managing id to tag Observe resources with ManagingObjectID *string `json:"managing_object_id"` + + // optional traceparent identifier to pass via header + TraceParent *string `json:"traceparent"` } func (c *Config) Hash() uint64 { diff --git a/observe/provider.go b/observe/provider.go index 92243426..b1726016 100644 --- a/observe/provider.go +++ b/observe/provider.go @@ -3,6 +3,7 @@ package observe import ( "context" "fmt" + "os" "sync" "time" @@ -247,6 +248,12 @@ func getConfigureContextFunc(userAgent func() string) schema.ConfigureContextFun config.ManagingObjectID = &managingId } + // trace identifier to attach to all HTTP requests in the traceparent header + // refer https://www.w3.org/TR/trace-context/#traceparent-header + if traceparent := os.Getenv("TRACEPARENT"); traceparent != "" { + config.TraceParent = &traceparent + } + // by omission, cache client useCache := true if v, ok := config.Flags[flagCacheClient]; ok {