Skip to content

Commit e60c173

Browse files
committed
Add helpers for tracing attributes.
1 parent 93b2bde commit e60c173

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

.changeset/trace-attrs.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"github.com/livekit/protocol": patch
3+
---
4+
5+
Add helpers for tracing attributes.

livekit/types.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,31 @@ import (
2424

2525
"buf.build/go/protoyaml"
2626
"github.com/dennwc/iters"
27+
"go.opentelemetry.io/otel/attribute"
2728
proto "google.golang.org/protobuf/proto"
2829
"gopkg.in/yaml.v3"
2930
)
3031

32+
const (
33+
TraceKeyPref = "lk."
34+
35+
TraceKeyRoomPrefix = TraceKeyPref + "room."
36+
TraceKeyRoomID = attribute.Key(TraceKeyRoomPrefix + "id")
37+
TraceKeyRoomName = attribute.Key(TraceKeyRoomPrefix + "name")
38+
39+
TraceKeyParticipantPrefix = TraceKeyPref + "participant."
40+
TraceKeyParticipantID = attribute.Key(TraceKeyParticipantPrefix + "id")
41+
TraceKeyParticipantIdentity = attribute.Key(TraceKeyParticipantPrefix + "identity")
42+
43+
TraceKeyTrackPrefix = TraceKeyPref + "track."
44+
TraceKeyTrackID = attribute.Key(TraceKeyTrackPrefix + "id")
45+
46+
TraceKeySIPPrefix = TraceKeyPref + "sip."
47+
TraceKeySIPHeaderPrefix = TraceKeySIPPrefix + "h."
48+
TraceKeySIPCallID = attribute.Key(TraceKeySIPPrefix + "callID")
49+
TraceKeySIPCallIDHeader = attribute.Key(TraceKeySIPHeaderPrefix + "CallID")
50+
)
51+
3152
type TrackID string
3253
type ParticipantID string
3354
type ParticipantIdentity string
@@ -47,6 +68,8 @@ type ParticipantKey struct {
4768
type JobID string
4869
type DispatchID string
4970
type AgentName string
71+
type SIPCallID string
72+
type SIPCallIDHeader string
5073

5174
func (s TrackID) String() string { return string(s) }
5275
func (s ParticipantID) String() string { return string(s) }
@@ -59,10 +82,34 @@ func (s NodeID) String() string { return string(s) }
5982
func (s JobID) String() string { return string(s) }
6083
func (s DispatchID) String() string { return string(s) }
6184
func (s AgentName) String() string { return string(s) }
85+
func (s SIPCallID) String() string { return string(s) }
86+
func (s SIPCallIDHeader) String() string { return string(s) }
6287
func (s ParticipantKey) String() string {
6388
return fmt.Sprintf("%s_%s_%s", s.ProjectID, s.RoomName, s.Identity)
6489
}
6590

91+
func (s ParticipantID) Trace() attribute.KeyValue {
92+
return TraceKeyParticipantID.String(string(s))
93+
}
94+
func (s ParticipantIdentity) Trace() attribute.KeyValue {
95+
return TraceKeyParticipantIdentity.String(string(s))
96+
}
97+
func (s RoomID) Trace() attribute.KeyValue {
98+
return TraceKeyRoomID.String(string(s))
99+
}
100+
func (s RoomName) Trace() attribute.KeyValue {
101+
return TraceKeyRoomName.String(string(s))
102+
}
103+
func (s TrackID) Trace() attribute.KeyValue {
104+
return TraceKeyTrackID.String(string(s))
105+
}
106+
func (s SIPCallID) Trace() attribute.KeyValue {
107+
return TraceKeySIPCallID.String(string(s))
108+
}
109+
func (s SIPCallIDHeader) Trace() attribute.KeyValue {
110+
return TraceKeySIPCallIDHeader.String(string(s))
111+
}
112+
66113
type stringTypes interface {
67114
ParticipantID | RoomID | TrackID | ParticipantIdentity | ParticipantName | RoomName | ConnectionID | NodeID
68115
}

0 commit comments

Comments
 (0)