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

update HttpSemanticConventions for Instrumentation.AspNetCore #4537

Merged
merged 29 commits into from
Jun 21, 2023
Merged

update HttpSemanticConventions for Instrumentation.AspNetCore #4537

merged 29 commits into from
Jun 21, 2023

Conversation

TimothyMothra
Copy link
Contributor

@TimothyMothra TimothyMothra commented Jun 1, 2023

Design discussion issue #4484

Http Semantic Convention is introducing breaking changes.
This PR makes the change in the Instrumentation.AspNetCore library.

Changes

  • add new attributes to SemanticConventions
  • update Instrumentation.AspNetCore classes HttpInListener and HttpInMetricsListener to emit new attributes.
    • net.host.name -> server.address
    • net.host.port -> server.port
    • NOT COLLECTED -> url.query
    • http.method -> http.request.method
    • http.scheme -> url.scheme
    • http.target -> url.path
    • http.url -> REMOVED
    • http.flavor -> network.protocol.version
    • http.user_agent -> user_agent.original
    • http.status_code -> http.response.status_code

Please provide a brief description of the changes here.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

@vishweshbankwar please review.

@TimothyMothra TimothyMothra requested a review from a team June 1, 2023 21:43
@codecov
Copy link

codecov bot commented Jun 7, 2023

Codecov Report

Merging #4537 (e02b8c7) into main (7333a55) will decrease coverage by 0.07%.
The diff coverage is 80.35%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    open-telemetry/opentelemetry-dotnet#4537      +/-   ##
==========================================
- Coverage   85.13%   85.06%   -0.07%     
==========================================
  Files         312      312              
  Lines       12532    12564      +32     
==========================================
+ Hits        10669    10688      +19     
- Misses       1863     1876      +13     
Impacted Files Coverage Δ
...AspNetCore/Implementation/HttpInMetricsListener.cs 64.00% <50.00%> (-11.00%) ⬇️
...tation.AspNetCore/Implementation/HttpInListener.cs 90.32% <94.73%> (+0.07%) ⬆️

... and 2 files with indirect coverage changes

Copy link
Member

@vishweshbankwar vishweshbankwar left a comment

Choose a reason for hiding this comment

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

LGTM overall with minor suggestion.


if (this.httpSemanticConvention.HasFlag(HttpSemanticConvention.New))
{
activity.SetTag(SemanticConventions.AttributeClientSocketPort, context.Connection.RemotePort);
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we clear on what this tag is meant for? And what does this value context.Connection.RemotePort represent?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Regarding the value of context.Connection.RemotePort, the documentation states:

Gets or sets the port of the remote target
https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.connectioninfo.remoteport?view=aspnetcore-7.0

This is not changed, it was mapped to the former attribute.

if (this.httpSemanticConvention.HasFlag(HttpSemanticConvention.Old))
{
activity.SetTag(SemanticConventions.AttributeNetPeerPort, context.Connection.RemotePort);
}

tags.Add(new KeyValuePair<string, object>(SemanticConventions.AttributeHttpMethod, context.Request.Method));
tags.Add(new KeyValuePair<string, object>(SemanticConventions.AttributeHttpStatusCode, TelemetryHelper.GetBoxedStatusCode(context.Response.StatusCode)));
// see the spec https://github.com/open-telemetry/opentelemetry-specification/blob/v1.20.0/specification/trace/semantic_conventions/http.md
if (this.httpSemanticConvention.HasFlag(HttpSemanticConvention.Old))
Copy link
Member

Choose a reason for hiding this comment

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

Some thoughts...

  • Just reading this work I found "New" and "Old" pretty confusing. Why not Legacy vs Stable or something along those lines?

  • This is probably an issue for some users:

    var envVarValue = Environment.GetEnvironmentVariable("OTEL_SEMCONV_STABILITY_OPT_IN");

    We should be using IConfiguration to get the switch.

  • Shouldn't the environment key have HTTP in the name like OTEL_HTTP_SEMCONV_STABILITY_OPT_IN?

Copy link
Member

Choose a reason for hiding this comment

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

  • Just reading this work I found "New" and "Old" pretty confusing. Why not Legacy vs Stable or something along those lines?

+1, I had similar concern here #4538 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Just reading this work I found "New" and "Old" pretty confusing. Why not Legacy vs Stable or something along those lines?

How strongly do you feel about this? :)
We can change the enum, but New and Old shipped as part of OpenTelemetry.Api v1.5.0.
It's internal so we CAN change it.
But this would require re-releasing the Api library. (ie Instrumentation.AspNetCore would require an OpenTelemetry.Api v1.5.1).

Also, this is meant to be short lived. When these instrumentation libraries go stable this enum and helper class will be removed.

  1. We should be using IConfiguration to get the switch.

Can you please share an example of this?

  1. Shouldn't the environment key have HTTP in the name like OTEL_HTTP_SEMCONV_STABILITY_OPT_IN?

That makes sense to me, but the spec defines OTEL_SEMCONV_STABILITY_OPT_IN

Copy link
Contributor

Choose a reason for hiding this comment

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

We can change the enum, but New and Old shipped as part of OpenTelemetry.Api v1.5.0.
It's internal so we CAN change it.
But this would require re-releasing the Api library. (ie Instrumentation.AspNetCore would require an OpenTelemetry.Api v1.5.1).

The instrumentation libraries do not use this enum from OpenTelemetry.Api. They link to the file so each of the libraries have their own copy of it. You should be able to make the necessary changes without worrying about version of OpenTelemetry.Api.

Note: This does not have to be done in this PR.

@@ -2,6 +2,11 @@

## Unreleased

* Updated [Http Semantic Conventions](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.21.0/specification/trace/semantic_conventions/http.md).
* This library can emit either old, new, or both attributes. Users can control
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need a sub-bullet here. This change is simple enough to be put under the same bullet.

@utpilla
Copy link
Contributor

utpilla commented Jun 21, 2023

Merging this PR to unblock progress.

As discussed in the SIG meeting today. @TimothyMothra would work on using IConfiguration and updating the enum in follow-up PRs.

@utpilla utpilla merged commit 8e5e7dd into open-telemetry:main Jun 21, 2023
public const string AttributeHttpResponseStatusCode = "http.response.status_code"; // replaces: "http.status_code" (AttributeHttpStatusCode)
public const string AttributeNetworkProtocolVersion = "network.protocol.version"; // replaces: "http.flavor" (AttributeHttpFlavor)
public const string AttributeServerAddress = "server.address"; // replaces: "net.host.name" (AttributeNetHostName)
public const string AttributeServerPort = "server.port"; // replaces: "net.host.port" (AttributeNetHostPort)
Copy link
Contributor

Choose a reason for hiding this comment

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

// replaces: "net.peer.port" and "net.host.port"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants