Skip to content

Commit

Permalink
fix: correct the context usage
Browse files Browse the repository at this point in the history
  • Loading branch information
1995parham committed Mar 3, 2024
1 parent 4662956 commit fa4dbfe
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 1 addition & 2 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,7 @@ func (c *Client) Disconnect() {
c.Client.Disconnect(DisconnectTimeout)
}

func (c *Client) Connect() error {
ctx := otel.GetTextMapPropagator().Extract(context.Background(), nil)
func (c *Client) Connect(ctx context.Context) error {
_, span := c.Tracer.Start(ctx, "client.on.connect")

defer span.End()
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func main(cfg config.Config, logger *zap.Logger, trace trace.Tracer) {

client := client.New(ctx, cfg.MQTT, logger.Named("mqtt"), trace, &c, true)

if err := client.Connect(); err != nil {
if err := client.Connect(ctx); err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, err.Error())

Expand All @@ -39,7 +39,7 @@ func main(cfg config.Config, logger *zap.Logger, trace trace.Tracer) {

client := client.New(ctx, cfg.MQTT, logger.Named("mqtt"), trace, &c, false)

if err := client.Connect(); err != nil {
if err := client.Connect(ctx); err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, err.Error())

Expand Down

0 comments on commit fa4dbfe

Please sign in to comment.