New constructs a reporter for telemetry data. Duplicate data will be sent, it's on the server-side to index by UUID. Data is anonymized prior to being sent!
(options Options)
| 69 | // Duplicate data will be sent, it's on the server-side to index by UUID. |
| 70 | // Data is anonymized prior to being sent! |
| 71 | func New(options Options) (Reporter, error) { |
| 72 | if options.Clock == nil { |
| 73 | options.Clock = quartz.NewReal() |
| 74 | } |
| 75 | if options.SnapshotFrequency == 0 { |
| 76 | options.SnapshotFrequency = DefaultSnapshotFrequency |
| 77 | } |
| 78 | snapshotURL, err := options.URL.Parse("/snapshot") |
| 79 | if err != nil { |
| 80 | return nil, xerrors.Errorf("parse snapshot url: %w", err) |
| 81 | } |
| 82 | deploymentURL, err := options.URL.Parse("/deployment") |
| 83 | if err != nil { |
| 84 | return nil, xerrors.Errorf("parse deployment url: %w", err) |
| 85 | } |
| 86 | |
| 87 | ctx, cancelFunc := context.WithCancel(context.Background()) |
| 88 | reporter := &remoteReporter{ |
| 89 | ctx: ctx, |
| 90 | closed: make(chan struct{}), |
| 91 | closeFunc: cancelFunc, |
| 92 | options: options, |
| 93 | deploymentURL: deploymentURL, |
| 94 | snapshotURL: snapshotURL, |
| 95 | startedAt: dbtime.Time(options.Clock.Now()).UTC(), |
| 96 | client: &http.Client{}, |
| 97 | } |
| 98 | go reporter.runSnapshotter() |
| 99 | return reporter, nil |
| 100 | } |
| 101 | |
| 102 | // NewNoop creates a new telemetry reporter that entirely discards all requests. |
| 103 | func NewNoop() Reporter { |