-
Notifications
You must be signed in to change notification settings - Fork 302
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
Updated MassTransit instrumentation to OpenTelemetry 1.0 #85
Merged
cijothomas
merged 5 commits into
open-telemetry:main
from
alexvaluyskiy:feature/masstransit_1_0
Mar 15, 2021
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
34964de
Updated MassTransit instrumentation
oleksii-valuiskyi 0985fa3
fixed unit tests
oleksii-valuiskyi e0978be
Assert only sampled traces
oleksii-valuiskyi d4754c0
Update CODEOWNERS
alexvaluyskiy 07ad6c6
Merge remote-tracking branch 'upstream/main' into feature/masstransit…
oleksii-valuiskyi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,48 +18,62 @@ | |
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Reflection; | ||
using OpenTelemetry.Instrumentation; | ||
using OpenTelemetry.Trace; | ||
|
||
namespace OpenTelemetry.Contrib.Instrumentation.MassTransit.Implementation | ||
{ | ||
internal class MassTransitDiagnosticListener : ListenerHandler | ||
{ | ||
private readonly ActivitySourceAdapter activitySource; | ||
internal static readonly AssemblyName AssemblyName = typeof(MassTransitDiagnosticListener).Assembly.GetName(); | ||
internal static readonly string ActivitySourceName = AssemblyName.Name; | ||
internal static readonly Version Version = AssemblyName.Version; | ||
internal static readonly ActivitySource ActivitySource = new ActivitySource(ActivitySourceName, Version.ToString()); | ||
|
||
private readonly MassTransitInstrumentationOptions options; | ||
|
||
public MassTransitDiagnosticListener(ActivitySourceAdapter activitySource, MassTransitInstrumentationOptions options) | ||
: base("MassTransit") | ||
public MassTransitDiagnosticListener(string name, MassTransitInstrumentationOptions options) | ||
: base(name) | ||
{ | ||
this.activitySource = activitySource; | ||
this.options = options; | ||
} | ||
|
||
public override void OnStartActivity(Activity activity, object payload) | ||
{ | ||
if (this.options.TracedOperations != null && !this.options.TracedOperations.Contains(activity.OperationName)) | ||
{ | ||
MassTransitInstrumentationEventSource.Log.RequestIsFilteredOut(activity.OperationName); | ||
activity.IsAllDataRequested = false; | ||
return; | ||
} | ||
|
||
activity.DisplayName = this.GetDisplayName(activity); | ||
|
||
this.activitySource.Start(activity, this.GetActivityKind(activity)); | ||
ActivityInstrumentationHelper.SetActivitySourceProperty(activity, ActivitySource); | ||
ActivityInstrumentationHelper.SetKindProperty(activity, this.GetActivityKind(activity)); | ||
} | ||
|
||
public override void OnStopActivity(Activity activity, object payload) | ||
{ | ||
if (this.options.TracedOperations != null && !this.options.TracedOperations.Contains(activity.OperationName)) | ||
{ | ||
MassTransitInstrumentationEventSource.Log.RequestIsFilteredOut(activity.OperationName); | ||
activity.IsAllDataRequested = false; | ||
return; | ||
} | ||
|
||
if (activity.IsAllDataRequested) | ||
{ | ||
this.TransformMassTransitTags(activity); | ||
try | ||
{ | ||
this.TransformMassTransitTags(activity); | ||
} | ||
catch (Exception ex) | ||
{ | ||
MassTransitInstrumentationEventSource.Log.EnrichmentException(ex); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: This error message seem to indicate an error occuring in some user defined Enrich function. Given this is an internal transformation error, please rename the method and log message accordingly. |
||
} | ||
} | ||
|
||
this.activitySource.Stop(activity); | ||
} | ||
|
||
private string GetDisplayName(Activity activity) | ||
|
@@ -94,8 +108,8 @@ private void TransformMassTransitTags(Activity activity) | |
|
||
this.RenameTag(activity, TagName.MessageId, SemanticConventions.AttributeMessagingMessageId); | ||
this.RenameTag(activity, TagName.ConversationId, SemanticConventions.AttributeMessagingConversationId); | ||
this.RenameTag(activity, TagName.InitiatorId, SemanticConventions.AttributeMessagingMassTransitInitiatorId); | ||
this.RenameTag(activity, TagName.CorrelationId, SemanticConventions.AttributeMessagingMassTransitCorrelationId); | ||
this.RenameTag(activity, TagName.InitiatorId, MassTransitSemanticConventions.AttributeMessagingMassTransitInitiatorId); | ||
this.RenameTag(activity, TagName.CorrelationId, MassTransitSemanticConventions.AttributeMessagingMassTransitCorrelationId); | ||
|
||
activity.SetTag(TagName.SourceAddress, null); | ||
} | ||
|
@@ -105,8 +119,8 @@ private void TransformMassTransitTags(Activity activity) | |
|
||
this.RenameTag(activity, TagName.MessageId, SemanticConventions.AttributeMessagingMessageId); | ||
this.RenameTag(activity, TagName.ConversationId, SemanticConventions.AttributeMessagingConversationId); | ||
this.RenameTag(activity, TagName.InitiatorId, SemanticConventions.AttributeMessagingMassTransitInitiatorId); | ||
this.RenameTag(activity, TagName.CorrelationId, SemanticConventions.AttributeMessagingMassTransitCorrelationId); | ||
this.RenameTag(activity, TagName.InitiatorId, MassTransitSemanticConventions.AttributeMessagingMassTransitInitiatorId); | ||
this.RenameTag(activity, TagName.CorrelationId, MassTransitSemanticConventions.AttributeMessagingMassTransitCorrelationId); | ||
|
||
activity.SetTag(TagName.MessageId, null); | ||
|
||
|
@@ -116,7 +130,7 @@ private void TransformMassTransitTags(Activity activity) | |
} | ||
else if (activity.OperationName == OperationName.Consumer.Consume) | ||
{ | ||
this.RenameTag(activity, TagName.ConsumerType, SemanticConventions.AttributeMessagingMassTransitConsumerType); | ||
this.RenameTag(activity, TagName.ConsumerType, MassTransitSemanticConventions.AttributeMessagingMassTransitConsumerType); | ||
} | ||
else if (activity.OperationName == OperationName.Consumer.Handle) | ||
{ | ||
|
52 changes: 52 additions & 0 deletions
52
...ntrib.Instrumentation.MassTransit/Implementation/MassTransitInstrumentationEventSource.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// <copyright file="MassTransitInstrumentationEventSource.cs" company="OpenTelemetry Authors"> | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// </copyright> | ||
|
||
using System; | ||
using System.Diagnostics.Tracing; | ||
using OpenTelemetry.Internal; | ||
|
||
namespace OpenTelemetry.Contrib.Instrumentation.MassTransit.Implementation | ||
{ | ||
/// <summary> | ||
/// EventSource events emitted from the project. | ||
/// </summary> | ||
[EventSource(Name = "OpenTelemetry-Instrumentation-MassTransit")] | ||
internal class MassTransitInstrumentationEventSource : EventSource | ||
{ | ||
public static MassTransitInstrumentationEventSource Log = new MassTransitInstrumentationEventSource(); | ||
|
||
[Event(1, Message = "Request is filtered out.", Level = EventLevel.Verbose)] | ||
public void RequestIsFilteredOut(string eventName) | ||
{ | ||
this.WriteEvent(1, eventName); | ||
} | ||
|
||
[NonEvent] | ||
public void EnrichmentException(Exception ex) | ||
{ | ||
if (this.IsEnabled(EventLevel.Error, (EventKeywords)(-1))) | ||
{ | ||
this.EnrichmentException(ex.ToInvariantString()); | ||
} | ||
} | ||
|
||
[Event(2, Message = "Enrich threw exception. Exception {0}.", Level = EventLevel.Error)] | ||
public void EnrichmentException(string exception) | ||
{ | ||
this.WriteEvent(2, exception); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...etry.Contrib.Instrumentation.MassTransit/Implementation/MassTransitSemanticConventions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// <copyright file="MassTransitSemanticConventions.cs" company="OpenTelemetry Authors"> | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// </copyright> | ||
|
||
namespace OpenTelemetry.Contrib.Instrumentation.MassTransit.Implementation | ||
{ | ||
internal class MassTransitSemanticConventions | ||
{ | ||
public const string AttributeMessagingMassTransitInitiatorId = "messaging.masstransit.initiator_id"; | ||
public const string AttributeMessagingMassTransitCorrelationId = "messaging.masstransit.correlation_id"; | ||
public const string AttributeMessagingMassTransitConsumerType = "messaging.masstransit.consumer_type"; | ||
} | ||
} |
46 changes: 0 additions & 46 deletions
46
src/OpenTelemetry.Contrib.Instrumentation.MassTransit/Implementation/SemanticConventions.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit:
RequestIsFilteredOut
doesn't sound the apt name here.