code: func (s *State) doFlush(c context.Context, state *tsmon.State, settings *tsmonSettings) error {
  	var mon monitor.Monitor
  	var err error
  
  	if s.testingMonitor != nil {
  		mon = s.testingMonitor
  	} else if s.IsDevMode || settings.ProdXAccount == "" {
  		mon = monitor.NewDebugMonitor("")
  	} else {
  		logging.Infof(c, "Sending metrics to ProdX using %s", settings.ProdXAccount)
  		transport, err := auth.GetRPCTransport(
  			c,
  			auth.AsActor,
  			auth.WithServiceAccount(settings.ProdXAccount),
  			auth.WithScopes(monitor.ProdxmonScopes...))
  		if err != nil {
  			return err
  		}
  		endpoint, err := url.Parse(prodXEndpoint)
  		if err != nil {
  			return err
  		}
  		mon, err = monitor.NewHTTPMonitor(c, &http.Client{Transport: transport}, endpoint)
  		if err != nil {
  			return err
  		}
  	}
  
  	defer mon.Close()
  	if err = state.Flush(c, mon); err != nil {
  		return err
  	}
  
  	return nil
  }
docs: // doFlush actually sends the metrics to the monitor.