Skip to content

Define interfaces for annotating error information via RecordError #2591

@v3n

Description

@v3n

Problem Statement

The existing RecordError() method doesn't currently allow errors to propagate implementation-specific information back to the telemetry framework. Right now, the framework reflects the static typename of the error, but that's not enough to differentiate errors in many cases, for example:

  • RPC/REST errors which share a uniform type struct for RPC errors such as grpc.Status
  • Protocol errors such as MySQL Errors

Proposed Solution

Standardize on the definition of the type of an error (static) and the class of an error (runtime).

  • The type of the error remains the same–the type as returned by the Golang reflect package
  • The class of an error is implementation-defined and propagated to OpenTelemetry via interface implementation.
  • The place an error is recorded is not necessarily the same place that an error was captured (such as middleware), errors should be able to propogate the stack trace via an interface.
  • Errors should be able to propogate additional error-specific attributes.

Reference

  • Define the following interfaces:
type (
	// StackTracer propagates an error's class.
	StackTracer interface {
		OTStackTrace() []uintptr
	}

	// ErrorClasser propogates an error's class.
	ErrorClasser interface {
		OTErrorClass() string
	}

	// ErrorAttributer propogates an error's attributes.
	ErrorAttributer interface {
		OTErrorAttributes() []attribute.KeyValue
	}
)

Optionally, additionally provide the following interface to allow conversion from types that cannot implement the above.

type (
	ErrorConverter interface {
		OpenTelemetryError() error
	}
)

Alternatives

n/a

Prior Art

Additional Context

n/a

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:tracePart of OpenTelemetry tracingenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions