Some checks failed
CI / Run tests and lints (push) Failing after 29s
CI / Build CLI docs (push) Has been skipped
CI / Run Playwright end-to-end tests (mysql) (push) Failing after 3s
CI / Run Playwright end-to-end tests (postgres) (push) Failing after 2s
CI / Run Playwright end-to-end tests (sqlite) (push) Failing after 3s
CodeQL / Analyze (go) (push) Failing after 4s
CodeQL / Analyze (javascript) (push) Failing after 3s
Docker Image Scanners / scanners (push) Failing after 4s
Synchronize Issue Labels / Synchronize Issue Labels (push) Has been skipped
CI / Run end-to-end tests (postgres) (push) Failing after 19s
CI / Run end-to-end tests (sqlite) (push) Failing after 2s
CI / Run Playwright end-to-end tests (cockroach) (push) Failing after 2s
CI / Draft newsletter (push) Has been skipped
CI / Generate release (push) Has been skipped
CI / Pending approval Slack notification (push) Has been skipped
CI / Send newsletter (push) Has been skipped
105 lines
3.4 KiB
Go
105 lines
3.4 KiB
Go
// Copyright © 2023 Ory Corp
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// Package semconv contains OpenTelemetry semantic convention constants.
|
|
package semconv
|
|
|
|
import (
|
|
"github.com/gofrs/uuid"
|
|
otelattr "go.opentelemetry.io/otel/attribute"
|
|
|
|
"github.com/ory/x/httpx"
|
|
)
|
|
|
|
type Event string
|
|
|
|
func (e Event) String() string {
|
|
return string(e)
|
|
}
|
|
|
|
type AttributeKey string
|
|
|
|
func (a AttributeKey) String() string {
|
|
return string(a)
|
|
}
|
|
|
|
const (
|
|
AttributeKeyIdentityID AttributeKey = "IdentityID"
|
|
AttributeKeyNID AttributeKey = "ProjectID"
|
|
AttributeKeyClientIP AttributeKey = "ClientIP"
|
|
AttributeKeyGeoLocationCity AttributeKey = "GeoLocationCity"
|
|
AttributeKeyGeoLocationRegion AttributeKey = "GeoLocationRegion"
|
|
AttributeKeyGeoLocationCountry AttributeKey = "GeoLocationCountry"
|
|
AttributeKeyGeoLocationLatitude AttributeKey = "GeoLocationLatitude"
|
|
AttributeKeyGeoLocationLongitude AttributeKey = "GeoLocationLongitude"
|
|
AttributeKeyWorkspace AttributeKey = "WorkspaceID"
|
|
AttributeKeySubscriptionID AttributeKey = "SubscriptionID"
|
|
AttributeKeyProjectEnvironment AttributeKey = "ProjectEnvironment"
|
|
AttributeKeyWorkspaceAPIKeyID AttributeKey = "WorkspaceAPIKeyID"
|
|
AttributeKeyProjectAPIKeyID AttributeKey = "ProjectAPIKeyID"
|
|
)
|
|
|
|
func AttrIdentityID[V string | uuid.UUID](val V) otelattr.KeyValue {
|
|
return otelattr.String(AttributeKeyIdentityID.String(), uuidOrString(val))
|
|
}
|
|
|
|
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 AttrSubscription(val uuid.UUID) otelattr.KeyValue {
|
|
return otelattr.String(AttributeKeySubscriptionID.String(), val.String())
|
|
}
|
|
|
|
func AttrProjectEnvironment(val string) otelattr.KeyValue {
|
|
return otelattr.String(AttributeKeyProjectEnvironment.String(), val)
|
|
}
|
|
|
|
func AttrClientIP(val string) otelattr.KeyValue {
|
|
return otelattr.String(AttributeKeyClientIP.String(), val)
|
|
}
|
|
|
|
func AttrGeoLocation(val httpx.GeoLocation) []otelattr.KeyValue {
|
|
geoLocationAttributes := make([]otelattr.KeyValue, 0, 3)
|
|
|
|
if val.City != "" {
|
|
geoLocationAttributes = append(geoLocationAttributes, otelattr.String(AttributeKeyGeoLocationCity.String(), val.City))
|
|
}
|
|
if val.Country != "" {
|
|
geoLocationAttributes = append(geoLocationAttributes, otelattr.String(AttributeKeyGeoLocationCountry.String(), val.Country))
|
|
}
|
|
if val.Region != "" {
|
|
geoLocationAttributes = append(geoLocationAttributes, otelattr.String(AttributeKeyGeoLocationRegion.String(), val.Region))
|
|
}
|
|
if val.Latitude != nil {
|
|
geoLocationAttributes = append(geoLocationAttributes, otelattr.Float64(AttributeKeyGeoLocationLatitude.String(), *val.Latitude))
|
|
}
|
|
if val.Longitude != nil {
|
|
geoLocationAttributes = append(geoLocationAttributes, otelattr.Float64(AttributeKeyGeoLocationLongitude.String(), *val.Longitude))
|
|
}
|
|
|
|
return geoLocationAttributes
|
|
}
|
|
|
|
func AttrWorkspaceAPIKeyID[V string | uuid.UUID](val V) otelattr.KeyValue {
|
|
return otelattr.String(AttributeKeyWorkspaceAPIKeyID.String(), uuidOrString(val))
|
|
}
|
|
|
|
func AttrProjectAPIKeyID[V string | uuid.UUID](val V) otelattr.KeyValue {
|
|
return otelattr.String(AttributeKeyProjectAPIKeyID.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")
|
|
}
|