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

feat(otelx): add workspace attribute #735

Merged
merged 1 commit into from
Oct 12, 2023
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
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
Loading