-
Notifications
You must be signed in to change notification settings - Fork 780
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
Add Support for HttpSemanticConvention breaking changes. #4504
Merged
Merged
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
75c3b25
enum, environment variable parser, update AspNetCore ctor.
TimothyMothra 7326597
remove extra space
TimothyMothra 75dd117
addressing pr feedback
TimothyMothra 1d4d850
add try/catch
TimothyMothra 6074e86
Merge branch 'main' into 4484_httpSemConv
TimothyMothra 929c43c
addressing pr comments
TimothyMothra 8e5b162
refactor test to include setting/reading EnvVar
TimothyMothra 637c9bd
remove extra using
TimothyMothra 4ca4063
file-scoped namespace
TimothyMothra 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
67 changes: 67 additions & 0 deletions
67
src/OpenTelemetry.Api/Internal/HttpSemanticConventionHelper.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,67 @@ | ||
// <copyright file="HttpSemanticConventionHelper.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.Internal | ||
{ | ||
using System; | ||
|
||
/// <summary> | ||
/// Helper class for Http Semantic Conventions. | ||
/// </summary> | ||
/// <remarks> | ||
/// Due to a breaking change in the semantic convention, affected instrumentation libraries | ||
/// must inspect an environment variable to determine which attributes to emit. | ||
/// This is expected to be removed when the instrumentation libraries reach Stable. | ||
/// <see href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md"/>. | ||
/// </remarks> | ||
internal static class HttpSemanticConventionHelper | ||
{ | ||
[Flags] | ||
internal enum HttpSemanticConvention | ||
{ | ||
/// <summary> | ||
/// Instructs an instrumentation library to emit the old experimental HTTP attributes. | ||
/// </summary> | ||
Old = 0x1, | ||
|
||
/// <summary> | ||
/// Instructs an instrumentation library to emit the new, stable Http attributes. | ||
/// </summary> | ||
New = 0x2, | ||
|
||
/// <summary> | ||
/// Instructs an instrumentation library to emit both the old and new attributes. | ||
/// </summary> | ||
Dupe = Old | New, | ||
} | ||
|
||
public static HttpSemanticConvention GetSemConvOptIn() | ||
{ | ||
var envVarValue = Environment.GetEnvironmentVariable("OTEL_SEMCONV_STABILITY_OPT_IN"); | ||
TimothyMothra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return EvaluateValue(envVarValue); | ||
} | ||
|
||
internal static HttpSemanticConvention EvaluateValue(string value) | ||
{ | ||
return value?.ToLower() switch | ||
TimothyMothra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
"http" => HttpSemanticConvention.New, | ||
"http/dup" => HttpSemanticConvention.Dupe, | ||
_ => HttpSemanticConvention.Old, | ||
}; | ||
} | ||
} | ||
} |
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
52 changes: 52 additions & 0 deletions
52
test/OpenTelemetry.Api.Tests/Internal/HttpSemanticConventionHelperTest.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="HttpSemanticConventionHelperTest.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 Xunit; | ||
using static OpenTelemetry.Internal.HttpSemanticConventionHelper; | ||
|
||
namespace OpenTelemetry.Api.Tests.Internal | ||
{ | ||
public class HttpSemanticConventionHelperTest | ||
{ | ||
[Fact] | ||
public void VerifyFlags() | ||
{ | ||
var testValue = HttpSemanticConvention.Dupe; | ||
Assert.True(testValue.HasFlag(HttpSemanticConvention.Old)); | ||
Assert.True(testValue.HasFlag(HttpSemanticConvention.New)); | ||
|
||
testValue = HttpSemanticConvention.Old; | ||
Assert.True(testValue.HasFlag(HttpSemanticConvention.Old)); | ||
Assert.False(testValue.HasFlag(HttpSemanticConvention.New)); | ||
|
||
testValue = HttpSemanticConvention.New; | ||
Assert.False(testValue.HasFlag(HttpSemanticConvention.Old)); | ||
Assert.True(testValue.HasFlag(HttpSemanticConvention.New)); | ||
} | ||
|
||
[Fact] | ||
public void VerifyEvaluate() | ||
TimothyMothra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
Assert.Equal(HttpSemanticConvention.Old, EvaluateValue(null)); | ||
Assert.Equal(HttpSemanticConvention.Old, EvaluateValue(string.Empty)); | ||
Assert.Equal(HttpSemanticConvention.Old, EvaluateValue("junk")); | ||
Assert.Equal(HttpSemanticConvention.Old, EvaluateValue("none")); | ||
Assert.Equal(HttpSemanticConvention.New, EvaluateValue("http")); | ||
Assert.Equal(HttpSemanticConvention.New, EvaluateValue("HTTP")); | ||
Assert.Equal(HttpSemanticConvention.Dupe, EvaluateValue("http/dup")); | ||
TimothyMothra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} |
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.
just one more nit. use a file-scoped namespace here to reduce indentation
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.
no problem!
any way to make this a code style rule for future PRs?
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.
We should also update the existing classes to use file-scoped namespace for being consistent.