-
Notifications
You must be signed in to change notification settings - Fork 591
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: add activity on connection #1734
base: main
Are you sure you want to change the base?
Conversation
@michaelklishin build seems broken due to some new CVE related to system text json ? |
dc89271
to
177ccbd
Compare
@eerhardt - do you have time to review this PR? Thanks! |
6587ffe
to
2a99147
Compare
@lukebakken when i implement the activity i create a new activity source but i m wondering if it s really usefull to have 3 ActivitySource and not use only one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any way to write some tests around this?
@@ -226,11 +226,10 @@ internal void TakeOver(Connection other) | |||
internal async ValueTask<IConnection> OpenAsync(CancellationToken cancellationToken) | |||
{ | |||
cancellationToken.ThrowIfCancellationRequested(); | |||
|
|||
Activity? connectionActivity = RabbitMQActivitySource.OpenConnection(_frameHandler); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How/where does this activity get completed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are totally right. Missing some using keyword.
By reading the experimental activity on dotnet 9 http client I don't know if at some point we should link producer and consumer activity to the connection activity?
if (!s_connectionSource.HasListeners()) | ||
{ | ||
return null; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!s_connectionSource.HasListeners()) | |
{ | |
return null; | |
} |
I don't think this is necessary. ActivitySource.CreateActivity
will do this check and return null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I take the same logic as the rest of the implem but you are right when I read the Microsoft code this line is useless
{ | ||
ActivityTagsCollection exceptionTags = new(); | ||
exceptionTags.Add(new KeyValuePair<string, object?>(ExceptionMessageTag, exception.Message)); | ||
exceptionTags.Add(new KeyValuePair<string, object?>(ExceptionStackTraceTag, exception.ToString())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exceptionTags.Add(new KeyValuePair<string, object?>(ExceptionStackTraceTag, exception.ToString())); | |
// Note that "exception.stacktrace" is the full exception detail, not just the StackTrace property. | |
// See https://opentelemetry.io/docs/specs/semconv/attributes-registry/exception/ | |
// and https://github.com/open-telemetry/opentelemetry-specification/pull/697#discussion_r453662519 | |
exceptionTags.Add(new KeyValuePair<string, object?>(ExceptionStackTraceTag, exception.ToString())); |
ActivityTagsCollection exceptionTags = new(); | ||
exceptionTags.Add(new KeyValuePair<string, object?>(ExceptionMessageTag, exception.Message)); | ||
exceptionTags.Add(new KeyValuePair<string, object?>(ExceptionStackTraceTag, exception.ToString())); | ||
exceptionTags.Add(new KeyValuePair<string, object?>(ExceptionTypeTag, exception.GetType().ToString())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exceptionTags.Add(new KeyValuePair<string, object?>(ExceptionTypeTag, exception.GetType().ToString())); | |
exceptionTags.Add(new KeyValuePair<string, object?>(ExceptionTypeTag, exception.GetType().FullName)); |
@@ -142,10 +177,22 @@ public static class RabbitMQActivitySource | |||
return activity; | |||
} | |||
|
|||
internal static void ReportException(this Activity activity, Exception exception) | |||
{ | |||
ActivityTagsCollection exceptionTags = new(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to just call .AddTag
on the current Activity for each tag instead of adding a new event.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opentelemetry spec states that exception should be recorded as event and not tag on the current activity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
System.Diagnostics.DiagnosticSource 9.0.0 adds a AddException
method to the Activity
class.
You can see the implementation here.
Although it's safe to add a dependency to version 9.0.0 of this package, if you don't want to risk that, you can add it as an extension method to this project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This recordException is basically a copy paste of the MCR method, I don't know if dependency bump is allowed
Thank you @eerhardt !!! |
2a99147
to
c9b91a2
Compare
@aygalinc just FYI, I rebased this on |
@eerhardt to the best of my knowledge Microsoft don't provide any testing support fort distributed tracing (contrary to metrics) . I do not find any test related to the other activity creation in rabbit. Maybe you have some resources that I miss to do this ? |
Proposed Changes
Add activity on connection creation.
In case of creation exception register an error event.
Types of Changes
What types of changes does your code introduce to this project?
Put an
x
in the boxes that applyRefer to #1731