Skip to content

Commit

Permalink
feat(otelx): add API key attribute key (#810)
Browse files Browse the repository at this point in the history
  • Loading branch information
zepatrik authored Sep 16, 2024
1 parent a2d35e9 commit f03cb99
Show file tree
Hide file tree
Showing 2 changed files with 18 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
19 changes: 17 additions & 2 deletions otelx/semconv/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ const (
AttributeKeyWorkspace AttributeKey = "WorkspaceID"
AttributeKeySubscriptionID AttributeKey = "SubscriptionID"
AttributeKeyProjectEnvironment AttributeKey = "ProjectEnvironment"
AttributeKeyAPIKeyID AttributeKey = "APIKeyID"
)

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 +75,17 @@ func AttrGeoLocation(val httpx.GeoLocation) []otelattr.KeyValue {

return geoLocationAttributes
}

func AttrAPIKeyID[V string | uuid.UUID](val V) otelattr.KeyValue {
return otelattr.String(AttributeKeyAPIKeyID.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 f03cb99

Please sign in to comment.