(ctx context.Context, tevent *telemetrydata.TEvent)
| 271 | } |
| 272 | |
| 273 | func RecordTEvent(ctx context.Context, tevent *telemetrydata.TEvent) error { |
| 274 | if tevent == nil { |
| 275 | return nil |
| 276 | } |
| 277 | if tevent.Uuid == "" { |
| 278 | tevent.Uuid = uuid.New().String() |
| 279 | } |
| 280 | err := tevent.Validate(true) |
| 281 | if err != nil { |
| 282 | return err |
| 283 | } |
| 284 | tevent.EnsureTimestamps() |
| 285 | |
| 286 | // Set AppFirstDay if on same calendar day as TOS agreement |
| 287 | tosAgreedTs := GetTosAgreedTs() |
| 288 | if tosAgreedTs == 0 { |
| 289 | tevent.Props.AppFirstDay = true |
| 290 | } else { |
| 291 | tosYear, tosMonth, tosDay := time.UnixMilli(tosAgreedTs).Date() |
| 292 | nowYear, nowMonth, nowDay := time.Now().Date() |
| 293 | if tosYear == nowYear && tosMonth == nowMonth && tosDay == nowDay { |
| 294 | tevent.Props.AppFirstDay = true |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | if tevent.Event == ActivityEventName { |
| 299 | return updateActivityTEvent(ctx, tevent) |
| 300 | } |
| 301 | if tevent.Event == WshRunEventName { |
| 302 | return updateWshRunTEvent(ctx, tevent) |
| 303 | } |
| 304 | return insertTEvent(ctx, tevent) |
| 305 | } |
| 306 | |
| 307 | func CleanOldTEvents(ctx context.Context) error { |
| 308 | daysToKeep := 7 |
no test coverage detected