Skip to content

Commit

Permalink
add traceid into context details
Browse files Browse the repository at this point in the history
  • Loading branch information
bpathak-ons committed Feb 28, 2022
1 parent 9a9152c commit 1aa0e99
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions cmd/producer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ func scanEvent(scanner *bufio.Scanner) *models.ContentPublished {
fmt.Println("Please type the URI")
fmt.Printf("$ ")
scanner.Scan()
name := scanner.Text()
uri := scanner.Text()

return &models.ContentPublished{
URI: name,
URI: uri,
DataType: "Reviewed-uris",
TraceID: "054435ded",
}
}
6 changes: 4 additions & 2 deletions event/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"

kafka "github.com/ONSdigital/dp-kafka/v2"
dprequest "github.com/ONSdigital/dp-net/request"
"github.com/ONSdigital/dp-search-data-extractor/config"
"github.com/ONSdigital/dp-search-data-extractor/models"
"github.com/ONSdigital/dp-search-data-extractor/schema"
Expand Down Expand Up @@ -56,8 +55,11 @@ func processMessage(ctx context.Context, message kafka.Message, handler Handler,
return
}

//nolint: revive, staticcheck, gocritic
//TODO: This needs to be looked into log library for customised context details
ctx = context.WithValue(ctx, "request-id", event.TraceID)

log.Info(ctx, "event received", log.Data{"event": event})
ctx = dprequest.WithRequestId(ctx, event.TraceID)

// handle - commit on failure (implement error handling to not commit if message needs to be consumed again)
err = handler.Handle(ctx, &event, *cfg)
Expand Down

0 comments on commit 1aa0e99

Please sign in to comment.