<commit_before>package trace

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"golang.org/x/net/trace"
	"net/http"
)

type traceError *gin.Error

// add custom stringer method to gin error type
func (e traceError) String() string {
	return fmt.Sprintf("Error: %s\nMeta: %s", e.Err, e.Meta)
}

// Trace will gather information from the request and also add the trace methods to handlers
func Trace() gin.HandlerFunc {
	return func(c *gin.Context) {

		if gin.IsDebugging() {
			// a new trace
			tr := trace.New(c.HandlerName(), c.Request.URL.Path)

			c.Next()

			if len(c.Errors) != 0 {
				// loop through errors
				for _, err := range c.Errors {
					tr.LazyLog(traceError(err), false)
				}
				tr.SetError()
			}<commit_msg>add errors and gin debug flag check<commit_after>package trace

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"golang.org/x/net/trace"
	"net/http"
)

type traceError *gin.Error

// add custom stringer method to gin error type
func (e *traceError) String() string {
	return fmt.Sprintf("Error: %s\nMeta: %s", e.Err, e.Meta)
}

// Trace will gather information from the request and also add the trace methods to handlers
func Trace() gin.HandlerFunc {
	return func(c *gin.Context) {

		if gin.IsDebugging() {
			// a new trace
			tr := trace.New(c.HandlerName(), c.Request.URL.Path)

			c.Next()

			if len(c.Errors) != 0 {
				// loop through errors
				for _, err := range c.Errors {
					tr.LazyLog(traceError(err), false)
				}
				tr.SetError()
			}
{'fraction_non_alphanumeric': 0.13860716700473294, 'fraction_numerical': 0.001352265043948614, 'mean_word_length': 3.1225626740947074, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2663447', 'n_tokens_mistral': 591, 'n_tokens_neox': 514, 'n_words': 150}