Skip to content

Commit

Permalink
feat(otelx): add workspace attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
zepatrik committed Oct 12, 2023
1 parent 4126131 commit 3e7f194
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 5 additions & 4 deletions otelx/semconv/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ func TestAttributesFromContext(t *testing.T) {
ctx := context.Background()
assert.Len(t, AttributesFromContext(ctx), 0)

nid := uuid.Must(uuid.NewV4())
ctx = ContextWithAttributes(ctx, AttrNID(nid))
assert.Len(t, AttributesFromContext(ctx), 1)
nid, wsID := uuid.Must(uuid.NewV4()), uuid.Must(uuid.NewV4())
ctx = ContextWithAttributes(ctx, AttrNID(nid), AttrWorkspace(wsID))
assert.Len(t, AttributesFromContext(ctx), 2)

uid1, uid2 := uuid.Must(uuid.NewV4()), uuid.Must(uuid.NewV4())
location := httpx.GeoLocation{
Expand All @@ -30,9 +30,10 @@ func TestAttributesFromContext(t *testing.T) {
}
ctx = ContextWithAttributes(ctx, append(AttrGeoLocation(location), AttrIdentityID(uid1), AttrClientIP("127.0.0.1"), AttrIdentityID(uid2))...)
attrs := AttributesFromContext(ctx)
assert.Len(t, attrs, 6, "should deduplicate")
assert.Len(t, attrs, 7, "should deduplicate")
assert.Equal(t, []attribute.KeyValue{
attribute.String(AttributeKeyNID.String(), nid.String()),
attribute.String(AttributeKeyWorkspace.String(), wsID.String()),
attribute.String(AttributeKeyGeoLocationCity.String(), "Berlin"),
attribute.String(AttributeKeyGeoLocationCountry.String(), "Germany"),
attribute.String(AttributeKeyGeoLocationRegion.String(), "BE"),
Expand Down
5 changes: 5 additions & 0 deletions otelx/semconv/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const (
AttributeKeyGeoLocationCity AttributeKey = "GeoLocationCity"
AttributeKeyGeoLocationRegion AttributeKey = "GeoLocationRegion"
AttributeKeyGeoLocationCountry AttributeKey = "GeoLocationCountry"
AttributeKeyWorkspace AttributeKey = "WorkspaceID"
)

func AttrIdentityID(val uuid.UUID) otelattr.KeyValue {
Expand All @@ -40,6 +41,10 @@ func AttrNID(val uuid.UUID) otelattr.KeyValue {
return otelattr.String(AttributeKeyNID.String(), val.String())
}

func AttrWorkspace(val uuid.UUID) otelattr.KeyValue {
return otelattr.String(AttributeKeyWorkspace.String(), val.String())
}

func AttrClientIP(val string) otelattr.KeyValue {
return otelattr.String(AttributeKeyClientIP.String(), val)
}
Expand Down

0 comments on commit 3e7f194

Please sign in to comment.