Skip to content

[FEATURE]: Enable Error Capture for Functions Returning Types Implementing error #3168

Open
@korECM

Description

@korECM

Package Name

No response

Package Version(s)

No response

Describe the feature you'd like

I would like the dd-trace-go instrumentation to support error capture for functions whose return types implement the error interface, even if the return type is not explicitly defined as error.
This would involve extending the template helper (e.g., creating a helper like ResultHasError) to check whether a type implements error using something like types.Implements, rather than doing a strict type equality check.

Is your feature request related to a problem?

Yes, it is. Currently, when using the //dd:span tag, the error capture functionality only activates if the function’s return type is strictly error.

{{ with .Function.ResultOfType "error" -}}
  defer func(){
    span.Finish(tracer.WithError({{ . }}))
  }()
{{ else -}}
  defer span.Finish()
{{- end -}}

This causes issues when a function returns a different type (or an interface implementing error) since the error is not captured, leading to missing error reporting in spans.
As a workaround, users are forced to either change the function signature to return error explicitly or resort to manually handling errors with the dd-trace-go API.

Describe alternatives you've considered

No response

Additional context

This feature request was sparked by a discussion on the Orchestrion GitHub discussions.
I believe that modifying the dd-trace-go templates to allow error capture for types that implement error will improve usability for a broader range of scenarios.

I would be happy to work on this change if it's considered a worthwhile improvement by the maintainers.

Metadata

Metadata

Assignees

Labels

enhancementquick change/addition that does not need full team approval

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions