diff --git a/otelx/semconv/context_test.go b/otelx/semconv/context_test.go index a68882fb..a1ea9f49 100644 --- a/otelx/semconv/context_test.go +++ b/otelx/semconv/context_test.go @@ -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{ @@ -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"), diff --git a/otelx/semconv/events.go b/otelx/semconv/events.go index 05e5e4b9..c1739191 100644 --- a/otelx/semconv/events.go +++ b/otelx/semconv/events.go @@ -30,6 +30,7 @@ const ( AttributeKeyGeoLocationCity AttributeKey = "GeoLocationCity" AttributeKeyGeoLocationRegion AttributeKey = "GeoLocationRegion" AttributeKeyGeoLocationCountry AttributeKey = "GeoLocationCountry" + AttributeKeyWorkspace AttributeKey = "WorkspaceID" ) func AttrIdentityID(val uuid.UUID) otelattr.KeyValue { @@ -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) }