Skip to content

Commit f00cd1a

Browse files
committed
chore(backend): add session start time attribute to events and spans
1 parent 219eea6 commit f00cd1a

File tree

5 files changed

+32
-0
lines changed

5 files changed

+32
-0
lines changed

backend/api/event/attribute.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"backend/api/opsys"
55
"fmt"
66
"slices"
7+
"time"
78

89
"github.com/google/uuid"
910
)
@@ -118,6 +119,10 @@ type Attribute struct {
118119
// - 5g
119120
// - unknown
120121
NetworkGeneration string `json:"network_generation"`
122+
123+
// SessionStartTime is the time when the session
124+
// containing this event started at.
125+
SessionStartTime *time.Time `json:"session_start_time"`
121126
}
122127

123128
// Validate validates an event's attributes.

backend/api/measure/event.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,11 @@ func (e eventreq) ingestEvents(ctx context.Context) error {
10161016
attachments = string(marshalledAttachments)
10171017
}
10181018

1019+
var sessionStartTime interface{}
1020+
if e.events[i].Attribute.SessionStartTime != nil {
1021+
sessionStartTime = e.events[i].Attribute.SessionStartTime.Format(chrono.MSTimeFormat)
1022+
}
1023+
10191024
row := stmt.NewRow().
10201025
Set(`id`, e.events[i].ID).
10211026
Set(`team_id`, e.teamId).
@@ -1057,6 +1062,7 @@ func (e eventreq) ingestEvents(ctx context.Context) error {
10571062
Set(`attribute.network_type`, e.events[i].Attribute.NetworkType).
10581063
Set(`attribute.network_generation`, e.events[i].Attribute.NetworkGeneration).
10591064
Set(`attribute.network_provider`, e.events[i].Attribute.NetworkProvider).
1065+
Set(`attribute.session_start_time`, sessionStartTime).
10601066

10611067
// user defined attribute
10621068
Set(`user_defined_attribute`, e.events[i].UserDefinedAttribute.Parameterize()).
@@ -1543,6 +1549,11 @@ func (e eventreq) ingestSpans(ctx context.Context) error {
15431549
b.WriteString("]")
15441550
formattedCheckpoints := b.String()
15451551

1552+
var spanSessionStartTime interface{}
1553+
if e.spans[i].Attributes.SessionStartTime != nil {
1554+
spanSessionStartTime = e.spans[i].Attributes.SessionStartTime.Format(chrono.MSTimeFormat)
1555+
}
1556+
15461557
stmt.NewRow().
15471558
Set(`team_id`, e.teamId).
15481559
Set(`app_id`, e.spans[i].AppID).
@@ -1573,6 +1584,7 @@ func (e eventreq) ingestSpans(ctx context.Context) error {
15731584
Set(`attribute.device_locale`, e.spans[i].Attributes.DeviceLocale).
15741585
Set(`attribute.device_low_power_mode`, e.spans[i].Attributes.LowPowerModeEnabled).
15751586
Set(`attribute.device_thermal_throttling_enabled`, e.spans[i].Attributes.ThermalThrottlingEnabled).
1587+
Set(`attribute.session_start_time`, spanSessionStartTime).
15761588
// user defined attribute
15771589
Set(`user_defined_attribute`, e.spans[i].UserDefinedAttribute.Parameterize())
15781590
}

backend/api/span/span.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ type SpanAttributes struct {
9999
DeviceLocale string `json:"device_locale"`
100100
LowPowerModeEnabled bool `json:"device_low_power_mode"`
101101
ThermalThrottlingEnabled bool `json:"device_thermal_throttling_enabled"`
102+
SessionStartTime *time.Time `json:"session_start_time"`
102103
}
103104

104105
type RootSpanDisplay struct {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- migrate:up
2+
alter table events
3+
add column if not exists `attribute.session_start_time` Nullable(DateTime64(3, 'UTC')) comment 'time when session this event belongs to started' CODEC(DoubleDelta, ZSTD(3)) after `attribute.network_provider`;
4+
5+
-- migrate:down
6+
alter table events
7+
drop column if exists `attribute.session_start_time`;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- migrate:up
2+
alter table spans
3+
add column if not exists `attribute.session_start_time` Nullable(DateTime64(3, 'UTC')) comment 'time when session this span belongs to started' CODEC(DoubleDelta, ZSTD(3)) after `attribute.network_provider`;
4+
5+
-- migrate:down
6+
alter table spans
7+
drop column if exists `attribute.session_start_time`;

0 commit comments

Comments
 (0)