Skip to content

Commit

Permalink
feat: inject context in header
Browse files Browse the repository at this point in the history
  • Loading branch information
mgjules committed Apr 11, 2022
1 parent 8060c71 commit 040e79f
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"github.com/JulesMike/spoty/config"
"github.com/JulesMike/spoty/json"
"github.com/go-resty/resty/v2"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/propagation"
)

// Client is a simple wrapper around resty.Client.
Expand All @@ -20,6 +22,11 @@ func NewClient(cfg *config.Config) *Client {
client.EnableTrace()
client.SetDebug(true)
}
client.OnBeforeRequest(func(_ *resty.Client, r *resty.Request) error {
otel.GetTextMapPropagator().Inject(r.Context(), propagation.HeaderCarrier(r.Header))

return nil
})

return &Client{client}
}

0 comments on commit 040e79f

Please sign in to comment.