Skip to content

Commit

Permalink
Add further attributes to span in tracing package
Browse files Browse the repository at this point in the history
  • Loading branch information
hramazani committed Dec 8, 2022
1 parent 2a142f3 commit b8bbe44
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
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

0 comments on commit b8bbe44

Please sign in to comment.