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

SkyApm.Diagnostics for Masstransit #531

Merged
merged 4 commits into from
Feb 19, 2023
Merged

SkyApm.Diagnostics for Masstransit #531

merged 4 commits into from
Feb 19, 2023

Conversation

BoydenYubin
Copy link
Contributor

SkyApm.Diagnostics for Masstransit

a) Add Publish/Receive/Consumer Observer for tracking b) Use ActivityListener to get the operation name for tracking

Note that:
We need use ASPNETCORE_HOSTINGSTARTUPASSEMBLIES=SkyApm.Diagnnostics.MassTransit instead of ASPNETCORE_HOSTINGSTARTUPASSEMBLIES=SkyAPM.Agent.AspNetCore

Next Step:
a) Saga Statemachine
b) Request and Respond
c) More test

Please answer these questions before submitting pull request

  • Why submit this pull request?
  • Bug fix
  • New feature provided
  • Improve performance

New feature or improvement

  • Describe the details and related test reports.
  • SkyApm.Diagnostics.Masstransit
  • Just for Publish/Receive/Consumer part
  • No injection for your program
  • Need improvement for Saga and Request/Response...

…sstransit

a) Add Publish/Receive/Consumer Observer for tracking
b) Use ActivityListener to get the operation name for trackig

Note that:
We need use ASPNETCORE_HOSTINGSTARTUPASSEMBLIES=SkyApm.Diagnnostics.MassTransit
instead of ASPNETCORE_HOSTINGSTARTUPASSEMBLIES=SkyAPM.Agent.AspNetCore

Next Step:
a) Saga Statemachine
b) Request and Respond
c) More test
@BoydenYubin
Copy link
Contributor Author

Just add a new branch for masstransit and let's complete that

@wu-sheng wu-sheng requested a review from liuhaoyang January 3, 2023 15:44
{
if (ContainsRabbitmq(host))
return 52; //rabbitmq-producer
return 51; //rabbitmq
Copy link
Collaborator

Choose a reason for hiding this comment

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

what is the definition of these numbers ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As component-libraries.yml in Skywalking mentioned, each component has it's int value, and it can be regonized as the rabbitmq-producer rabbitmq-consumer and so on.

I will need add more IComponentIdChecker to regonize the detail marker.

context.Span.Peer = $"{consumeContext.DestinationAddress.Host}";
context.Span.AddTag(Tags.MQ_TOPIC, activity.OperationName);
context.Span.AddTag(Tags.MQ_BROKER, consumeContext.DestinationAddress.Host);
context.Span.AddTag(MassTags.ExpirationTime, consumeContext.ExpirationTime?.ToString("yyyy-MM-dd HH:mm:ss-fff"));
Copy link
Collaborator

Choose a reason for hiding this comment

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

ExpirationTime is a high cardinality tag, best to use logging

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your comments, will replace that with logging.

var activity = Activity.Current ?? default;

var operationName = OperateNamePrefix + activity.OperationName;
var context = _tracingContext.CreateLocalSegmentContext(operationName);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would be more appropriate to use entryspan

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 have created the entryspan in ReceiveObserver that happened before the ConsumerObserver. If ConsumerObserver created the localspan which can GetParentSegmentContext created by ReceiveObserver.


var segContext = _tracingContext.CreateEntrySegmentContext("Masstransit Receiving/ " + activity.OperationName,
new MasstransitCarrierHeaderCollection(context.TransportHeaders));
segContext.Span.SpanLayer = SpanLayer.DB;
Copy link
Collaborator

Choose a reason for hiding this comment

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

The DB call cannot be an entry span, and an exit span should be used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any more pre-cautions to use the Span.SpanLayer? Just fount how to use Span.Component. Thanks.

{
public class ObserverSegmentContextDictionary
{
public static readonly ConcurrentDictionary<Guid, SegmentContext> Contexts = new ConcurrentDictionary<Guid, SegmentContext>();
Copy link
Collaborator

Choose a reason for hiding this comment

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

not recommended usage

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, let me seperate that in each Observer to solve the Concurrent conflict.

@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

Copy link
Collaborator

Choose a reason for hiding this comment

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

Need to import build\common.props

a) All observers
  - Removed ObserverSegmentContextDictionary.cs
  - Added the activity tags
b) MasstransitConsumerObserver.cs
  - Used logging instead of the ExpirationTime tag
c) MasstransitReceiveObserver.cs
  - Changed the Span.SpanLayer to Span.SpanLayer.MQ
d) Project
  - Added the build\common.props
@wu-sheng wu-sheng added this to the 2.2.0 milestone Jan 4, 2023
@BoydenYubin BoydenYubin requested a review from liuhaoyang January 5, 2023 00:54
@BoydenYubin
Copy link
Contributor Author

Demo for Courier
Just finished the test for Courier in masstransit, it looks great will update soon.

@wu-sheng wu-sheng changed the title feature(SkyApm.Diagnostics.MassTransit):Add SkyApm.Diagnostics for Ma… SkyApm.Diagnostics for Masstransit Jan 6, 2023
a) Combine PublishObserver and SendObserver

Plan: StateMachine could use logging instead of Tracing
Copy link
Collaborator

@liuhaoyang liuhaoyang left a comment

Choose a reason for hiding this comment

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

You also need to add copyright header to each code file.

@wu-sheng wu-sheng added the enhancement New feature or request label Feb 19, 2023
@liuhaoyang liuhaoyang merged commit 8b6b0d9 into SkyAPM:main Feb 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants