Skip to content
This repository has been 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

Open
robdefeo opened this issue May 22, 2018 · 4 comments

Comments

@robdefeo
Copy link

robdefeo commented May 22, 2018

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)

@yurishkuro
Copy link
Member

visitor.EmitString(lf.key, err) will not compile, did you mean EmitObject?

@robdefeo
Copy link
Author

robdefeo commented May 23, 2018

@yurishkuro yes you are correct thanks, i'll update the description. Thanks

@yurishkuro
Copy link
Member

+1

@yurishkuro
Copy link
Member

Related issue #199

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants