(name string, meta Metadata)
| 35 | } |
| 36 | |
| 37 | func newTrackMessage(name string, meta Metadata) *segment.Track { |
| 38 | nixVersion := cmp.Or(nix.Version(), "unknown") |
| 39 | |
| 40 | dur := time.Since(procStartTime) |
| 41 | if !meta.EventStart.IsZero() { |
| 42 | dur = time.Since(meta.EventStart) |
| 43 | } |
| 44 | uid := userID() |
| 45 | track := &segment.Track{ |
| 46 | MessageId: newEventID(), |
| 47 | Type: "track", |
| 48 | // Only set anonymous ID if user ID is not set. Otherwise segment will |
| 49 | // drop the UserId. |
| 50 | AnonymousId: lo.Ternary(uid == "", deviceID, ""), |
| 51 | UserId: uid, |
| 52 | Timestamp: time.Now(), |
| 53 | Event: name, |
| 54 | Context: &segment.Context{ |
| 55 | Device: segment.DeviceInfo{ |
| 56 | Id: deviceID, |
| 57 | }, |
| 58 | App: segment.AppInfo{ |
| 59 | Name: appName, |
| 60 | Version: build.Version, |
| 61 | }, |
| 62 | OS: segment.OSInfo{ |
| 63 | Name: build.OS(), |
| 64 | }, |
| 65 | }, |
| 66 | Properties: segment.Properties{ |
| 67 | "command": meta.Command, |
| 68 | "command_args": meta.CommandFlags, |
| 69 | "duration": dur.Milliseconds(), |
| 70 | "nix_version": nixVersion, |
| 71 | "org_id": orgID(), |
| 72 | "packages": meta.Packages, |
| 73 | "shell": os.Getenv(envir.Shell), |
| 74 | "shell_access": shellAccess(), |
| 75 | }, |
| 76 | } |
| 77 | |
| 78 | // Property keys match the API events. |
| 79 | insertEnv := func(envKey, propKey string) { |
| 80 | v, ok := os.LookupEnv(envKey) |
| 81 | if ok { |
| 82 | track.Properties[propKey] = v |
| 83 | } |
| 84 | } |
| 85 | insertEnv("_JETIFY_SANDBOX_ID", "devspace") |
| 86 | insertEnv("_JETIFY_GH_REPO", "repo") |
| 87 | insertEnv("_JETIFY_GIT_REF", "ref") |
| 88 | insertEnv("_JETIFY_GIT_SUBDIR", "subdir") |
| 89 | |
| 90 | return track |
| 91 | } |
| 92 | |
| 93 | // bufferSegmentMessage buffers a Segment message to disk so that Report can |
| 94 | // upload it later. |
no test coverage detected