// backtrace returns an error message annotated with a backtrace.
352118
func backtrace(err error, t *builtins.CapturedStacktrace) string {
	return t.String() + "Error: " + err.Error()
}
988602
func RecordTrace(w io.Writer, trace *RequestTrace) {
	attempt := AttemptReport{
		Reused:     trace.Reused,
		Latency:    trace.Finish.Sub(trace.Start),
		ReqWritten: trace.RequestWritten.Sub(trace.Start),
	}

	if !trace.FirstResponseByte.IsZero() {
		attempt.RespFirstByte = trace.FirstResponseByte.Sub(trace.Start)
		attempt.WaitRespFirstByte = trace.FirstResponseByte.Sub(trace.RequestWritten)
	}

	if !trace.Reused {
		attempt.DNSStart = trace.DNSStart.Sub(trace.Start)
		attempt.DNSDone = trace.DNSDone.Sub(trace.Start)
		attempt.DNS = trace.DNSDone.Sub(trace.DNSStart)

		attempt.ConnectStart = trace.ConnectStart.Sub(trace.Start)
		attempt.ConnectDone = trace.ConnectDone.Sub(trace.Start)
		attempt.Connect = trace.ConnectDone.Sub(trace.ConnectStart)

		attempt.TLSHandshakeStart = trace.TLSHandshakeStart.Sub(trace.Start)
		attempt.TLSHandshakeDone = trace.TLSHandshakeDone.Sub(trace.Start)
		attempt.TLSHandshake = trace.TLSHandshakeDone.Sub(trace.TLSHandshakeStart)
	}

	_, err := fmt.Fprintln(w,
		"Latency:",
		attempt.Latency,

		"ConnectionReused:",
		fmt.Sprintf("%t", attempt.Reused),

		"DNSStartAt:",
		fmt.Sprintf("%s", attempt.DNSStart),
		"DNSDoneAt:",
		fmt.Sprintf("%s", attempt.DNSDone),
		"DNSDur:",
		fmt.Sprintf("%s", attempt.DNS),

		"ConnectStartAt:",
		fmt.Sprintf("%s", attempt.ConnectStart),
		"ConnectDoneAt:",
		fmt.Sprintf("%s", attempt.ConnectDone),
		"ConnectDur:",
		fmt.Sprintf("%s", attempt.Connect),

		"TLSStatAt:",
		fmt.Sprintf("%s", attempt.TLSHandshakeStart),
		"TLSDoneAt:",
		fmt.Sprintf("%s", attempt.TLSHandshakeDone),
		"TLSDur:",
		fmt.Sprintf("%s", attempt.TLSHandshake),

		"RequestWritten",
		fmt.Sprintf("%s", attempt.ReqWritten),
		"RespFirstByte:",
		fmt.Sprintf("%s", attempt.RespFirstByte),
		"WaitRespFirstByte:",
		fmt.Sprintf("%s", attempt.WaitRespFirstByte),
	)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to write request trace, %v\n", err)
	}
}
183615
func WithTrace(ctx context.Context, traceID, spanID, parentID string) context.Context {
	if parentID != "" {
		ctx = context.WithValue(ctx, parentSpanKey, parentID)
	}
	ctx = context.WithValue(ctx, traceKey, traceID)
	ctx = context.WithValue(ctx, spanKey, spanID)
	return ctx
}
1103468
func (t LoggerType) Trace(errin error) {
	if errin == nil {
		return
	}

	msgopts, err := t.options.Formatter.formatSkip(errin.Error(), 1, true)
	if err != nil {
		t.options.FallbackLogger.Trace(ErrSlackFormatFailed1.New(err, errin.Error()))
		t.options.FallbackLogger.Trace(errin)
		return
	}

	t.sendMessage(t.options.ChannelError, msgopts...)
}
437421
func (e *Error) Error() string {
	message := strings.TrimRight(e.err.Error(), "\n ")
	if strings.Contains(message, "\n") {
		message = fmt.Sprintf("%s:\n  %s", e.class.String(),
			strings.Replace(message, "\n", "\n  ", -1))
	} else {
		message = fmt.Sprintf("%s: %s", e.class.String(), message)
	}
	if stack := e.Stack(); stack != "" {
		message = fmt.Sprintf(
			"%s\n\"%s\" backtrace:\n%s", message, e.class, stack)
	}
	if exits := e.Exits(); exits != "" {
		message = fmt.Sprintf(
			"%s\n\"%s\" exits:\n%s", message, e.class, exits)
	}
	return message
}
909488
func Stacktrace(e error) string {
	s := Stack(e)
	if len(s) > 0 {
		buf := bytes.Buffer{}
		frames := runtime.CallersFrames(s)
		for {
			frame, more := frames.Next()
			buf.WriteString(frame.Function)
			buf.WriteString(fmt.Sprintf("\n\t%s:%d\n", frame.File, frame.Line))
			if !more {
				break
			}

		}
		return buf.String()
	}
	return ""
}
571440
func LogTracef(logLvl int, format string, v ...interface{}) {
	if LogLevel >= logLvl {
		// grab a stack trace
		stackBuf := make([]byte, 6000)
		stackBufLen := runtime.Stack(stackBuf, false)
		stackTraceStr := string(stackBuf[0:stackBufLen])
		parts := strings.Split(stackTraceStr, "\n")
		if len(parts) > 1 {
			v = append(v, strings.Join(parts[3:], "\n"))
		}
		DoLog(3, logLvl, fmt.Sprintf(format+"\n%v", v...))
	}
}
818555
func getBacktrace(e interface{}, skip int) (string, []StackFrame) {
	if err, ok := e.(stackTracer); ok {
		return backtraceFromErrorWithStackTrace(err)
	}

	const depth = 32
	var pcs [depth]uintptr
	n := runtime.Callers(skip+1, pcs[:])
	ff := runtime.CallersFrames(pcs[:n])

	var firstPkg string
	frames := make([]StackFrame, 0)
	for {
		f, ok := ff.Next()
		if !ok {
			break
		}

		pkg, fn := splitPackageFuncName(f.Function)
		if firstPkg == "" && pkg != "runtime" {
			firstPkg = pkg
		}

		if stackFilter(pkg, fn, f.File, f.Line) {
			frames = frames[:0]
			continue
		}

		frames = append(frames, StackFrame{
			File: f.File,
			Line: f.Line,
			Func: fn,
		})
	}

	return firstPkg, frames
}
42158
func (e Error) Error() string {
	if e.error == nil {
		return "<nil>"
	}
	return e.error.Error()
}
965008
func ErrorHandler(h utils.ErrorHandler) Option {
	return func(t *Tracer) error {
		t.errHandler = h
		return nil
	}
}
867260
func (dl *DefaultLogger) Trace(message string, params ...interface{}) {
	dl.logger.Tracef(message, params...)
}
651559
func stacktrace() []string {
	ret := make([]string, 0, 2)

	for skip := 2; skip < maxStackFrames; skip++ {
		_, file, line, ok := runtime.Caller(skip)
		if !ok {
			break
		}

		ret = append(ret, fmt.Sprintf("at %s:%d", stripDirectories(file, 1), line))
	}

	return ret
}
1160552
func ValidateTrace(span *ssf.SSFSpan) error {
	if !ValidTrace(span) {
		return &InvalidTrace{span}
	}
	return nil
}
154500
func Annotate(err error, msg string) error {
	if err == nil {
		return nil
	}
	return Wrap(errors.New(msg), err)
}
459521
func (err *cmnError) Stacktrace() Error {
	if err.stacktrace == nil {
		var offset = 3
		var depth = 32
		err.stacktrace = captureStacktrace(offset, depth)
	}
	return err
}
1288117
func (cl *CallbackLogger) Error(err error) {
	cl.ErrorDepth(1, fmt.Sprintf("%+v", err))
}
1194437
func DefaultStacktracePred(status int) bool {
	return (status < http.StatusOK || status >= http.StatusInternalServerError) && status != http.StatusSwitchingProtocols
}