Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

fix(request): Add x-request-id header to match spec #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
module github.com/newrelic/newrelic-telemetry-sdk-go

go 1.14

require github.com/google/uuid v1.1.1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general our goal as been to not introduce new dependencies - for example, to create GUIDs in the Go Agent, we have our own method. Could something like that be used here as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, this could be refactored to do that, not sure I follow why though. Re-implementing a solution seems much more problematic / support burden / error prone than adding a dependency.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reasoning as I understand it is both so the library remains small, and doesn't take long for users to download and doesn't increase the size of their app, and also so that we don't need to worry about dependency versioning - if, for example, the user already is using this UUID library, but a different version in their app - there could be issues.

Happy to talk more about this when we chat tomorrow as well!

2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
7 changes: 7 additions & 0 deletions telemetry/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"fmt"
"net/http"

"github.com/google/uuid"

"github.com/newrelic/newrelic-telemetry-sdk-go/internal"
)

Expand Down Expand Up @@ -54,6 +56,11 @@ func newRequestsInternal(batch requestsBuilder, apiKey string, url string, userA
if nil != err {
return nil, fmt.Errorf("error creating request: %v", err)
}

reqId, err := uuid.NewRandom()
if err == nil {
req.Header.Add("x-request-id", reqId.String())
}
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Api-Key", apiKey)
req.Header.Add("Content-Encoding", "gzip")
Expand Down