Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(otelgin): enhance gin error tracking with span recording #6346

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

flc1125
Copy link
Contributor

@flc1125 flc1125 commented Nov 19, 2024

No description provided.

@flc1125 flc1125 requested a review from a team as a code owner November 19, 2024 16:10
@dmathieu
Copy link
Member

Could you test this change?
By checking there's indeed an error here for example: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/instrumentation/github.com/gin-gonic/gin/otelgin/test/gintrace_test.go#L123

Also, I wonder if we need to keep the gin.errors attribute. While removing it is a breaking change, keeping it is redundant.

@dmathieu
Copy link
Member

Side note that otelgin has no owner, so it may be removed soon.
#6190

@flc1125
Copy link
Contributor Author

flc1125 commented Nov 20, 2024

Side note that otelgin has no owner, so it may be removed soon. #6190

Okay, will this package still accept new PRs at present?

@dmathieu
Copy link
Member

It does.

Copy link

codecov bot commented Nov 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 66.9%. Comparing base (9d3f756) to head (a690136).
Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #6346   +/-   ##
=====================================
  Coverage   66.9%   66.9%           
=====================================
  Files        193     193           
  Lines      15652   15654    +2     
=====================================
+ Hits       10480   10482    +2     
  Misses      4881    4881           
  Partials     291     291           
Files with missing lines Coverage Δ
...ation/github.com/gin-gonic/gin/otelgin/gintrace.go 84.3% <100.0%> (+0.3%) ⬆️

@flc1125
Copy link
Contributor Author

flc1125 commented Nov 20, 2024

#6190

I think I can give it a try.

If I come to maintain it, what do I need to do?

@dmathieu
Copy link
Member

That's documented in the issue, as well as in https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/CONTRIBUTING.md#code-owners.

CHANGELOG.md Outdated Show resolved Hide resolved
@flc1125
Copy link
Contributor Author

flc1125 commented Nov 21, 2024

Could you test this change? By checking there's indeed an error here for example: main/instrumentation/github.com/gin-gonic/gin/otelgin/test/gintrace_test.go#L123

Also, I wonder if we need to keep the gin.errors attribute. While removing it is a breaking change, keeping it is redundant.

It's done.

@flc1125
Copy link
Contributor Author

flc1125 commented Nov 21, 2024

Side note that otelgin has no owner, so it may be removed soon.

I spent some time reading through the requirements. I understand that I may still need to make some contributions before applying. If so, I need some time.

.golangci.yml Outdated Show resolved Hide resolved
@flc1125
Copy link
Contributor Author

flc1125 commented Nov 21, 2024

link: #5252

@dmathieu dmathieu dismissed their stale review November 21, 2024 13:23

Changes made

Copy link
Member

@dmathieu dmathieu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is starting to look good 😸

Copy link
Member

@pellared pellared left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just nit comments. Can you please address them before we merge?

CHANGELOG.md Outdated Show resolved Hide resolved
flc1125 and others added 3 commits November 25, 2024 19:13
Co-authored-by: Robert Pająk <pellared@hotmail.com>
…_test.go

Co-authored-by: Robert Pająk <pellared@hotmail.com>
@dmathieu
Copy link
Member

Could you resolve the conflicts?

…ace-recorderror

# Conflicts:
#	instrumentation/github.com/gin-gonic/gin/otelgin/gintrace_test.go
#	instrumentation/github.com/gin-gonic/gin/otelgin/test/gintrace_test.go
@github-actions github-actions bot requested a review from akats7 November 25, 2024 15:24
@flc1125
Copy link
Contributor Author

flc1125 commented Nov 25, 2024

Could you resolve the conflicts?

It's done.

@dmathieu dmathieu removed the request for review from akats7 November 25, 2024 15:28
@akats7
Copy link
Contributor

akats7 commented Nov 25, 2024

@dmathieu I could pick up ownership of this module so that it isn't removed, should I just open a PR on the codeowners file?

@dmathieu
Copy link
Member

Yes, that should be enough (link the otelgin deprecation issue in that PR).

@@ -95,7 +95,10 @@ func Middleware(service string, opts ...Option) gin.HandlerFunc {
span.SetAttributes(semconv.HTTPStatusCode(status))
}
if len(c.Errors) > 0 {
span.SetAttributes(attribute.String("gin.errors", c.Errors.String()))
span.SetStatus(codes.Error, "gin error")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gin error isn't very meaningful.

Suggested change
span.SetStatus(codes.Error, "gin error")
span.SetStatus(codes.Error, c.Errors.String())

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wont this duplicate, in a less useful flattened string from, the information being added as events below?

Copy link
Contributor Author

@flc1125 flc1125 Nov 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akats7 We can discuss it here. It should be the same issue here.

r: #6346 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend using this method to record: span.SetStatus(codes.Error, c.Errors.String())

I would like to hear everyone's suggestions.

@pellared
Copy link
Member

@dmathieu I could pick up ownership of this module so that it isn't removed, should I just open a PR on the codeowners file?

Could you review this PR if you want to be an code owner? 😉

@MrAlias
Copy link
Contributor

MrAlias commented Nov 25, 2024

@dmathieu I could pick up ownership of this module so that it isn't removed, should I just open a PR on the codeowners file?

Could you review this PR if you want to be an code owner? 😉

cc @akats7 (I think)

@akats7
Copy link
Contributor

akats7 commented Nov 25, 2024

lgtm, my only real thought is I personally always find it convenient to have the error message at least partially included directly on the span instead of only having the span events. Since span events are sometimes (always?) stored in separate table it could becomes an additional step to view the message depending on the platform you use.

For example I know a lot of the java instrumentation just adds error: true as an attribute and then creates a span event, and we've had teams complain that the error message has no contextual info

@flc1125
Copy link
Contributor Author

flc1125 commented Nov 26, 2024

lgtm, my only real thought is I personally always find it convenient to have the error message at least partially included directly on the span instead of only having the span events. Since span events are sometimes (always?) stored in separate table it could becomes an additional step to view the message depending on the platform you use.

For example I know a lot of the java instrumentation just adds error: true as an attribute and then creates a span event, and we've had teams complain that the error message has no contextual info

This is indeed a problem, and it usually depends on what backend tools we are using.

Fortunately, when the entire span contains some abnormal events, the tool I am currently using allows me to see the exception information directly in the span interface. Of course, for more detailed information, I still need to switch to view it in Events.

——

Back to this PR, due to the OTEL standard specifications, I suggest we still maintain storing exceptions in Events. After all, this project is for the majority of users, and we need to present ourselves as professionally as possible and in accordance with the standards. 😁

@akats7
Copy link
Contributor

akats7 commented Nov 26, 2024

Yes we need to record the errors as a span event, what I'm getting at is when it comes to:

	span.SetAttributes(attribute.String("gin.errors", c.Errors.String()))

or

	span.SetStatus(codes.Error, "gin error")

I do find including the error string to have value

…_test.go

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants