Fix Remote IP Address - NULL reference exception (#3481)

This commit is contained in:
nayang7 2022-07-29 13:36:19 +08:00 committed by GitHub
parent 82e041c27c
commit 0a4a625158
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -2,6 +2,8 @@
## Unreleased
* Fix Remote IP Address - NULL reference exception.
([#3481](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3481))
* Metrics instrumentation to correctly populate `http.flavor` tag.
(1.1 instead of HTTP/1.1 etc.)
([#3379](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3379))

View File

@ -360,7 +360,11 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Implementation
activity.DisplayName = grpcMethod.TrimStart('/');
activity.SetTag(SemanticConventions.AttributeRpcSystem, GrpcTagHelper.RpcSystemGrpc);
activity.SetTag(SemanticConventions.AttributeNetPeerIp, context.Connection.RemoteIpAddress.ToString());
if (context.Connection.RemoteIpAddress != null)
{
activity.SetTag(SemanticConventions.AttributeNetPeerIp, context.Connection.RemoteIpAddress.ToString());
}
activity.SetTag(SemanticConventions.AttributeNetPeerPort, context.Connection.RemotePort);
bool validConversion = GrpcTagHelper.TryGetGrpcStatusCodeFromActivity(activity, out int status);