-
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
update HttpSemanticConventions for Instrumentation.Http #4538
Changes from 4 commits
d55768a
08bc9d7
a313e92
e74a54f
f520aaa
53cfa60
2c72f8f
f05cb51
a3d4a9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -162,16 +162,44 @@ public void OnStartActivity(Activity activity, object payload) | |
ActivityInstrumentationHelper.SetKindProperty(activity, ActivityKind.Client); | ||
} | ||
|
||
activity.SetTag(SemanticConventions.AttributeHttpScheme, request.RequestUri.Scheme); | ||
activity.SetTag(SemanticConventions.AttributeHttpMethod, HttpTagHelper.GetNameForHttpMethod(request.Method)); | ||
activity.SetTag(SemanticConventions.AttributeNetPeerName, request.RequestUri.Host); | ||
if (!request.RequestUri.IsDefaultPort) | ||
// 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)) | ||
{ | ||
activity.SetTag(SemanticConventions.AttributeNetPeerPort, request.RequestUri.Port); | ||
activity.SetTag(SemanticConventions.AttributeHttpScheme, request.RequestUri.Scheme); | ||
activity.SetTag(SemanticConventions.AttributeHttpMethod, HttpTagHelper.GetNameForHttpMethod(request.Method)); | ||
activity.SetTag(SemanticConventions.AttributeNetPeerName, request.RequestUri.Host); | ||
if (!request.RequestUri.IsDefaultPort) | ||
{ | ||
activity.SetTag(SemanticConventions.AttributeNetPeerPort, request.RequestUri.Port); | ||
} | ||
|
||
activity.SetTag(SemanticConventions.AttributeHttpUrl, HttpTagHelper.GetUriTagValueFromRequestUri(request.RequestUri)); | ||
activity.SetTag(SemanticConventions.AttributeHttpFlavor, HttpTagHelper.GetFlavorTagValueFromProtocolVersion(request.Version)); | ||
} | ||
|
||
activity.SetTag(SemanticConventions.AttributeHttpUrl, HttpTagHelper.GetUriTagValueFromRequestUri(request.RequestUri)); | ||
activity.SetTag(SemanticConventions.AttributeHttpFlavor, HttpTagHelper.GetFlavorTagValueFromProtocolVersion(request.Version)); | ||
// see the spec https://github.com/open-telemetry/semantic-conventions/blob/main/specification/trace/semantic_conventions/http.md | ||
TimothyMothra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (this.httpSemanticConvention.HasFlag(HttpSemanticConvention.New)) | ||
{ | ||
activity.SetTag(SemanticConventions.AttributeUrlScheme, request.RequestUri.Scheme); | ||
activity.SetTag(SemanticConventions.AttributeHttpRequestMethod, HttpTagHelper.GetNameForHttpMethod(request.Method)); | ||
activity.SetTag(SemanticConventions.AttributeServerAddress, request.RequestUri.Host); | ||
if (!request.RequestUri.IsDefaultPort) | ||
{ | ||
activity.SetTag(SemanticConventions.AttributeServerPort, request.RequestUri.Port); | ||
} | ||
|
||
activity.SetTag(SemanticConventions.AttributeUrlFull, HttpTagHelper.GetUriTagValueFromRequestUri(request.RequestUri)); | ||
activity.SetTag(SemanticConventions.AttributeNetworkProtocolVersion, HttpTagHelper.GetFlavorTagValueFromProtocolVersion(request.Version)); | ||
|
||
if (request.Headers.TryGetValues("User-Agent", out var userAgentValues)) | ||
{ | ||
var userAgent = userAgentValues.FirstOrDefault(); | ||
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. This would cause an allocation. Refer to how AspNetCore instrumentation handles this: https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs#L217-L224 This should be done in a separate PR which updates the benchmarks as well. |
||
if (!string.IsNullOrEmpty(userAgent)) | ||
{ | ||
activity.SetTag(SemanticConventions.AttributeHttpUserAgent, userAgent); | ||
} | ||
} | ||
} | ||
|
||
try | ||
{ | ||
|
@@ -214,7 +242,15 @@ public void OnStopActivity(Activity activity, object payload) | |
|
||
if (this.stopResponseFetcher.TryFetch(payload, out HttpResponseMessage response) && response != null) | ||
{ | ||
activity.SetTag(SemanticConventions.AttributeHttpStatusCode, TelemetryHelper.GetBoxedStatusCode(response.StatusCode)); | ||
if (this.httpSemanticConvention.HasFlag(HttpSemanticConvention.Old)) | ||
{ | ||
activity.SetTag(SemanticConventions.AttributeHttpStatusCode, TelemetryHelper.GetBoxedStatusCode(response.StatusCode)); | ||
} | ||
|
||
if (this.httpSemanticConvention.HasFlag(HttpSemanticConvention.New)) | ||
{ | ||
activity.SetTag(SemanticConventions.AttributeHttpResponseStatusCode, TelemetryHelper.GetBoxedStatusCode(response.StatusCode)); | ||
} | ||
|
||
if (currentStatusCode == ActivityStatusCode.Unset) | ||
{ | ||
|
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.
What does this mean?
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 asked to separate the new attributes from the others and give it a descriptive comment.
The word "new" isn't needed here, sorry for the confusion.
I've updated this comment in the AspNetCore PR but forgot to update it here.
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.
What does v1.21.0 mean?
👍