code: func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
  	defer func() {
  		if err := recover(); err != nil {
  			w.WriteHeader(http.StatusInternalServerError)
  			stack := debug.Stack()
  			msg := "PANIC: %s\n%s"
  			h.logger.Printf(msg, err, stack)
  			fmt.Fprintf(w, msg, err, stack)
  		}
  	}()
  
  	t := time.Now()
  	h.Handler.ServeHTTP(w, r)
  	dif := time.Since(t)
  
  	// Calculate per request StatsD metrics when the handler is fully configured.
  	statsTags := make([]string, 0, 3)
  
  	longQueryTime := h.api.LongQueryTime()
  	if longQueryTime > 0 && dif > longQueryTime {
  		h.logger.Printf("%s %s %v", r.Method, r.URL.String(), dif)
  		statsTags = append(statsTags, "slow_query")
  	}
  
  	pathParts := strings.Split(r.URL.Path, "/")
  	endpointName := strings.Join(pathParts, "_")
  
  	if externalPrefixFlag[pathParts[1]] {
  		statsTags = append(statsTags, "external")
  	}
  
  	// useragent tag identifies internal/external endpoints
  	statsTags = append(statsTags, "useragent:"+r.UserAgent())
  	stats := h.api.StatsWithTags(statsTags)
  	if stats != nil {
  		stats.Histogram("http."+endpointName, float64(dif), 0.1)
  	}
  }
docs: // ServeHTTP handles an HTTP request.