-
Notifications
You must be signed in to change notification settings - Fork 782
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
Added EnumerateTagValues Activity Extension #1236
Merged
CodeBlanch
merged 4 commits into
open-telemetry:master
from
CodeBlanch:activity-enumeratetagvalues
Sep 6, 2020
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// <copyright file="IActivityTagEnumerator.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.Collections.Generic; | ||
using System.Diagnostics; | ||
|
||
namespace OpenTelemetry.Trace | ||
{ | ||
/// <summary> | ||
/// An interface used to perform zero-allocation enumeration of <see cref="Activity"/> tags. Implementation must be a struct. | ||
/// </summary> | ||
public interface IActivityTagEnumerator | ||
{ | ||
/// <summary> | ||
/// Called for each <see cref="Activity"/> tag while the enumeration is executing. | ||
/// </summary> | ||
/// <param name="item">Tag key/value pair.</param> | ||
/// <returns><see langword="true"/> to continue the enumeration of records or <see langword="false"/> to stop (break) the enumeration.</returns> | ||
bool ForEach(KeyValuePair<string, object> item); | ||
} | ||
} |
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.
Minor: consider the stock
Assert.IsNotNull
.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 want me to add Xunit to API? 🤣 I don't think there's a similar method on System.Diagnostics.Debug, but there should be!
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.
Not familiar with .NET, I thought Assert.IsNotNull is a common thing and am surprised that it is not (so it looks like a compile time trick).
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.
Sorry didn't mean to poke fun 😄 Ya it's common to unit test frameworks but I don't think there's anything in the BCL.
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 took a look at the doc and it makes me wonder if we should use it or throw normal exception.
It seems in C++ the general trend is to avoid https://en.cppreference.com/w/c/error/assert from a library.
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 can switch them to regular null checks if you would like. My thinking with the Debug.Assert was... user will have to work really hard to call these extensions with a null Activity. You have to go out of your way and do
OpenTelemetry.Trace.ActivityExtensions.GetTagValue(null, "myTag")
. If you are set on shooting yourself in the foot, who are we to stop you? 🤣 But for the 99.99% of callers who are doingactivity.GetTagValue("myTag")
it really will never be null, so I was trying to save the perf of doing an unnecessary check.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 was trying to get your perspective and see if I need to change this
opentelemetry-dotnet/src/OpenTelemetry/Trace/TracerProviderExtensions.cs
Line 25 in 4993ec6
Based on the discussion, I think we should remove the null check for extension methods?
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.
It is kind of a risk/reward thing. That particular extension would only be called a handful of times (?) so it's probably fine to leave the check in there. If we don't have the check, static analysis tools like FxCop get upset so then we end up with suppressions which are kind of a maintainability headache. IMO we should only do this on hot-path stuff where we know there is a compelling benefit to justify the suppression. Assuming we get to turning FxCop on 😄 Poor @eddynaka has been trying to do that for a while.
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.
its getting harder and harder :(
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.
Coming into the middle of this conversation, though reminds me of System.Diagnostics.Contracts.