Skip to content

Commit

Permalink
feat(otelx): add API key attribute keys
Browse files Browse the repository at this point in the history
  • Loading branch information
zepatrik committed Sep 16, 2024
1 parent a2d35e9 commit 0156c13
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion otelx/attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
const nullString = "<null>"

func StringAttrs(attrs map[string]string) []attribute.KeyValue {
s := []attribute.KeyValue{}
s := make([]attribute.KeyValue, 0, len(attrs))
for k, v := range attrs {
s = append(s, attribute.String(k, v))
}
Expand Down
24 changes: 22 additions & 2 deletions otelx/semconv/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ const (
AttributeKeyWorkspace AttributeKey = "WorkspaceID"
AttributeKeySubscriptionID AttributeKey = "SubscriptionID"
AttributeKeyProjectEnvironment AttributeKey = "ProjectEnvironment"
AttributeProjectKeyAPIKeyID AttributeKey = "ProjectAPIKeyID"
AttributeWorkspaceKeyAPIKeyID AttributeKey = "WorkspaceAPIKeyID"
)

func AttrIdentityID(val uuid.UUID) otelattr.KeyValue {
return otelattr.String(AttributeKeyIdentityID.String(), val.String())
func AttrIdentityID[V string | uuid.UUID](val V) otelattr.KeyValue {
return otelattr.String(AttributeKeyIdentityID.String(), uuidOrString(val))
}

func AttrNID(val uuid.UUID) otelattr.KeyValue {
Expand Down Expand Up @@ -74,3 +76,21 @@ func AttrGeoLocation(val httpx.GeoLocation) []otelattr.KeyValue {

return geoLocationAttributes
}

func AttrProjectAPIKey[V string | uuid.UUID](val V) otelattr.KeyValue {
return otelattr.String(AttributeProjectKeyAPIKeyID.String(), uuidOrString(val))
}

func AttrWorkspaceAPIKey[V string | uuid.UUID](val V) otelattr.KeyValue {
return otelattr.String(AttributeWorkspaceKeyAPIKeyID.String(), uuidOrString(val))
}

func uuidOrString[V string | uuid.UUID](val V) string {
switch val := any(val).(type) {
case string:
return val
case uuid.UUID:
return val.String()
}
panic("unreachable")
}

0 comments on commit 0156c13

Please sign in to comment.