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 further attributes to span in tracing package #353

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
8 changes: 8 additions & 0 deletions tracing/cogs/cogs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package cogs

// const values used in setting span attributes for COGS: Cost Of Goods Sold.
const (
CostOfGoodsKey = "cogs"
CostOfGoodsMethodKey = "cogs.method"
CostOfGoodsAccountID = "cogs.accountID"
)
5 changes: 5 additions & 0 deletions tracing/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"go.opencensus.io/trace"

"github.com/infobloxopen/atlas-app-toolkit/auth"
"github.com/infobloxopen/atlas-app-toolkit/tracing/cogs"
)

const (
Expand Down Expand Up @@ -137,6 +138,10 @@ type Handler struct {
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
span := trace.FromContext(r.Context())

// Add accountID to span attributes
accountID, _ := auth.GetAccountID(r.Context(), nil)
span.AddAttributes(trace.StringAttribute(cogs.CostOfGoodsAccountID, accountID))

withHeaders := h.options.spanWithHeaders != nil && h.options.spanWithHeaders(r)
withPayload := h.options.spanWithPayload != nil && h.options.spanWithPayload(r)

Expand Down
2 changes: 1 addition & 1 deletion tracing/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func TestHandler_ServeHTTP(t *testing.T) {
// Test that Span attributes were populated with Headers
reflectAttrMap := reflect.ValueOf(trace.FromContext(result.request.Context())).Elem().Field(3).Elem().Field(0)
reflectKeys := reflectAttrMap.MapKeys()
assert.Len(t, reflectKeys, 8)
assert.Len(t, reflectKeys, 9)

resultHeadersMap := make(map[string]string)
for _, k := range reflectKeys {
Expand Down