ApplicationInsights-dotnet icon indicating copy to clipboard operation
ApplicationInsights-dotnet copied to clipboard

RequestTelemetry.Url is sometimes `null` while the typing says is should not

Open 304NotModified opened this issue 3 years ago • 4 comments

Describe the bug

RequestTelemetry.Url is sometimes null, but the typing says it's a non-nullable Uri

https://github.com/microsoft/ApplicationInsights-dotnet/blob/c739fdd6a6ec6687911ccc3de8baff0d669af899/BASE/src/Microsoft.ApplicationInsights/DataContracts/RequestTelemetry.cs#L222

To Reproduce

See for example the first RequestTelemetry constructor, the Url property isn't set.

https://github.com/microsoft/ApplicationInsights-dotnet/blob/c739fdd6a6ec6687911ccc3de8baff0d669af899/BASE/src/Microsoft.ApplicationInsights/DataContracts/RequestTelemetry.cs#L39-L47

See also https://github.com/microsoft/ApplicationInsights-dotnet/issues/932

Needed change

  • Mark the Url property as nullable, or never set null. (e.g. \)
  • Or set [System.Diagnostics.CodeAnalysis.MaybeNull]. See also https://github.com/microsoft/ApplicationInsights-dotnet/pull/2544/files

304NotModified avatar May 23 '22 19:05 304NotModified

Same heere. We recently updated our codebase from Microsoft.ApplicationInsights 2.4 and are now getting URLs that are null. We previously had a TelemetryProcessor that converted the item into a RequestTelemetry and checked the Url without null checks and that is now blowing up.

Greg15153 avatar Jul 29 '22 22:07 Greg15153

The Application Insights .NET SDK is not compiled with "#nullable enable". Therefore, that Url property may be null by default. (System.Uri is a class) Indeed, the doc-comments in the source say that the property is "optional".

pharring avatar Apr 05 '23 16:04 pharring

This issue is stale because it has been open 300 days with no activity. Remove stale label or this will be closed in 7 days. Commenting will instruct the bot to automatically remove the label.

github-actions[bot] avatar Jan 31 '24 00:01 github-actions[bot]

A fix is still needed

304NotModified avatar Jan 31 '24 00:01 304NotModified