Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.
This repository was archived by the owner on May 23, 2023. It is now read-only.

Treat errors as objects not strings to allow more detailed error information #187

@robdefeo

Description

@robdefeo

Use Case

I am using open-tracing for all distributed tracing.

Problem

When I log an error with

errors.WithStack(err) 
ext.Error.Set(span, true) 
span.LogFields(log.Error(e))

It just gives the error string rather than stack trace or any supporting information.

Proposal

Treat errors as objects not strings
github.com/opentracing/opentracing-go/log/field.go
replace

case errorType:
		if err, ok := lf.interfaceVal.(error); ok {
			visitor.EmitString(lf.key, err.Error())
		} else {
			visitor.EmitString(lf.key, "<nil>")
		}

with

case errorType:
		if err, ok := lf.interfaceVal.(error); ok {
			visitor.EmitObject(lf.key, err)
		} else {
			visitor.EmitString(lf.key, "<nil>")
		}

the implementers are then free to use https://godoc.org/github.com/pkg/errors#hdr-Formatted_printing_of_errors just like is used in jaeger for EmitObject

func (ml fieldsAsMap) EmitObject(key string, value interface{}) {
	ml[key] = fmt.Sprintf("%+v", value)
}

Which will give all the information

Questions to address (if any)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions