Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add traceparent header support #81

Merged
merged 2 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions observe/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package observe
import (
"context"
"fmt"
"os"
"sync"
"time"

Expand Down Expand Up @@ -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 {
Expand Down