MCPcopy Index your code
hub / github.com/coder/coder / reportHTMLFirstServedAt

Method reportHTMLFirstServedAt

site/site.go:302–332  ·  view source on GitHub ↗

reportHTMLFirstServedAt sends a telemetry report when the first HTML is ever served. The purpose is to track the first time the first user opens the site.

()

Source from the content-addressed store, hash-verified

300// reportHTMLFirstServedAt sends a telemetry report when the first HTML is ever served.
301// The purpose is to track the first time the first user opens the site.
302func (h *Handler) reportHTMLFirstServedAt() {
303 // nolint:gocritic // Manipulating telemetry items is system-restricted.
304 // TODO(hugodutka): Add a telemetry context in RBAC.
305 ctx := dbauthz.AsSystemRestricted(context.Background())
306 itemKey := string(telemetry.TelemetryItemKeyHTMLFirstServedAt)
307 _, err := h.opts.Database.GetTelemetryItem(ctx, itemKey)
308 if err == nil {
309 // If the value is already set, then we reported it before.
310 // We don't need to report it again.
311 return
312 }
313 if !errors.Is(err, sql.ErrNoRows) {
314 h.opts.Logger.Debug(ctx, "failed to get telemetry html first served at", slog.Error(err))
315 return
316 }
317 if err := h.opts.Database.InsertTelemetryItemIfNotExists(ctx, database.InsertTelemetryItemIfNotExistsParams{
318 Key: string(telemetry.TelemetryItemKeyHTMLFirstServedAt),
319 Value: time.Now().Format(time.RFC3339),
320 }); err != nil {
321 h.opts.Logger.Debug(ctx, "failed to set telemetry html first served at", slog.Error(err))
322 return
323 }
324 item, err := h.opts.Database.GetTelemetryItem(ctx, itemKey)
325 if err != nil {
326 h.opts.Logger.Debug(ctx, "failed to get telemetry html first served at", slog.Error(err))
327 return
328 }
329 h.opts.Telemetry.Report(&telemetry.Snapshot{
330 TelemetryItems: []telemetry.TelemetryItem{telemetry.ConvertTelemetryItem(item)},
331 })
332}
333
334func (h *Handler) serveHTML(resp http.ResponseWriter, request *http.Request, reqPath string, state htmlState) bool {
335 if data, err := h.renderHTMLWithState(request, reqPath, state); err == nil {

Callers 1

serveHTMLMethod · 0.95

Implementers 8

dispatchInterceptorcoderd/notifications/utils_test.go
chanHandlercoderd/notifications/utils_test.go
barrierHandlercoderd/notifications/metrics_test.go
fakeHandlercoderd/notifications/notifications_tes
santaHandlercoderd/notifications/manager_test.go
InboxHandlercoderd/notifications/dispatch/inbox.go
SMTPHandlercoderd/notifications/dispatch/smtp.go
WebhookHandlercoderd/notifications/dispatch/webhook.

Calls 8

AsSystemRestrictedFunction · 0.92
ConvertTelemetryItemFunction · 0.92
GetTelemetryItemMethod · 0.65
FormatMethod · 0.65
ReportMethod · 0.65
IsMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected