Skip to content

Commit 34b5658

Browse files
mszekielory-bot
authored andcommitted
feat: improved events and identity recent activity
GitOrigin-RevId: 3ef8d9391a402381025baaf25ba3c8c199805b7e
1 parent a4c9c0f commit 34b5658

File tree

2 files changed

+43
-17
lines changed

2 files changed

+43
-17
lines changed

oryx/httpx/client_info.go

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ package httpx
66
import (
77
"net"
88
"net/http"
9+
"strconv"
910
"strings"
1011
)
1112

1213
type GeoLocation struct {
13-
City string
14-
Region string
15-
Country string
14+
City string
15+
Region string
16+
Country string
17+
Latitude *float64
18+
Longitude *float64
1619
}
1720

1821
func GetClientIPAddressesWithoutInternalIPs(ipAddresses []string) (string, error) {
@@ -45,10 +48,25 @@ func ClientIP(r *http.Request) string {
4548
}
4649
}
4750

51+
func parseFloatHeaderValue(headerValue string) *float64 {
52+
if headerValue == "" {
53+
return nil
54+
}
55+
56+
val, err := strconv.ParseFloat(headerValue, 64)
57+
if err != nil {
58+
return nil
59+
}
60+
61+
return &val
62+
}
63+
4864
func ClientGeoLocation(r *http.Request) *GeoLocation {
4965
return &GeoLocation{
50-
City: r.Header.Get("Cf-Ipcity"),
51-
Region: r.Header.Get("Cf-Region-Code"),
52-
Country: r.Header.Get("Cf-Ipcountry"),
66+
City: r.Header.Get("Cf-Ipcity"),
67+
Region: r.Header.Get("Cf-Region-Code"),
68+
Country: r.Header.Get("Cf-Ipcountry"),
69+
Longitude: parseFloatHeaderValue(r.Header.Get("Cf-Iplongitude")),
70+
Latitude: parseFloatHeaderValue(r.Header.Get("Cf-Iplatitude")),
5371
}
5472
}

oryx/otelx/semconv/events.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,19 @@ func (a AttributeKey) String() string {
2424
}
2525

2626
const (
27-
AttributeKeyIdentityID AttributeKey = "IdentityID"
28-
AttributeKeyNID AttributeKey = "ProjectID"
29-
AttributeKeyClientIP AttributeKey = "ClientIP"
30-
AttributeKeyGeoLocationCity AttributeKey = "GeoLocationCity"
31-
AttributeKeyGeoLocationRegion AttributeKey = "GeoLocationRegion"
32-
AttributeKeyGeoLocationCountry AttributeKey = "GeoLocationCountry"
33-
AttributeKeyWorkspace AttributeKey = "WorkspaceID"
34-
AttributeKeySubscriptionID AttributeKey = "SubscriptionID"
35-
AttributeKeyProjectEnvironment AttributeKey = "ProjectEnvironment"
36-
AttributeKeyWorkspaceAPIKeyID AttributeKey = "WorkspaceAPIKeyID"
37-
AttributeKeyProjectAPIKeyID AttributeKey = "ProjectAPIKeyID"
27+
AttributeKeyIdentityID AttributeKey = "IdentityID"
28+
AttributeKeyNID AttributeKey = "ProjectID"
29+
AttributeKeyClientIP AttributeKey = "ClientIP"
30+
AttributeKeyGeoLocationCity AttributeKey = "GeoLocationCity"
31+
AttributeKeyGeoLocationRegion AttributeKey = "GeoLocationRegion"
32+
AttributeKeyGeoLocationCountry AttributeKey = "GeoLocationCountry"
33+
AttributeKeyGeoLocationLatitude AttributeKey = "GeoLocationLatitude"
34+
AttributeKeyGeoLocationLongitude AttributeKey = "GeoLocationLongitude"
35+
AttributeKeyWorkspace AttributeKey = "WorkspaceID"
36+
AttributeKeySubscriptionID AttributeKey = "SubscriptionID"
37+
AttributeKeyProjectEnvironment AttributeKey = "ProjectEnvironment"
38+
AttributeKeyWorkspaceAPIKeyID AttributeKey = "WorkspaceAPIKeyID"
39+
AttributeKeyProjectAPIKeyID AttributeKey = "ProjectAPIKeyID"
3840
)
3941

4042
func AttrIdentityID[V string | uuid.UUID](val V) otelattr.KeyValue {
@@ -73,6 +75,12 @@ func AttrGeoLocation(val httpx.GeoLocation) []otelattr.KeyValue {
7375
if val.Region != "" {
7476
geoLocationAttributes = append(geoLocationAttributes, otelattr.String(AttributeKeyGeoLocationRegion.String(), val.Region))
7577
}
78+
if val.Latitude != nil {
79+
geoLocationAttributes = append(geoLocationAttributes, otelattr.Float64(AttributeKeyGeoLocationLatitude.String(), *val.Latitude))
80+
}
81+
if val.Longitude != nil {
82+
geoLocationAttributes = append(geoLocationAttributes, otelattr.Float64(AttributeKeyGeoLocationLongitude.String(), *val.Longitude))
83+
}
7684

7785
return geoLocationAttributes
7886
}

0 commit comments

Comments
 (0)