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

CreateRequestTelemetryPrivate: System.ArgumentOutOfRangeException: Length cannot be less than zero. #1513

Closed
Dmitry-Matveev opened this issue Dec 19, 2019 · 7 comments
Assignees
Milestone

Comments

@Dmitry-Matveev
Copy link
Member

Repro Steps

SDK telemetry got the following exception trending:

AI (Internal): [Microsoft-ApplicationInsights-Extensibility-Web] Unknown error, message System.ArgumentOutOfRangeException: Length cannot be less than zero. Parameter name: length
    at System.String.Substring(Int32 startIndex, Int32 length)
    at Microsoft.ApplicationInsights.Web.Implementation.RequestTrackingExtensions.CreateRequestTelemetryPrivate(HttpContext platformContext)
    at Microsoft.ApplicationInsights.Web.Implementation.RequestTrackingExtensions.ReadOrCreateRequestTelemetryPrivate(HttpContext platformContext)
    at Microsoft.ApplicationInsights.Web.RequestTrackingTelemetryModule.OnBeginRequest(HttpContext context)
    at Microsoft.ApplicationInsights.Web.AspNetDiagnosticTelemetryModule.AspNetEventObserver.OnNext(KeyValuePair`2 value)

Version Info

SDK Version : 2.12.0-21496

@TimothyMothra
Copy link
Member

method is here:

internal static RequestTelemetry CreateRequestTelemetryPrivate(

I don't see an explicit call to String.Substring

@jakenuts
Copy link

I'm also getting this constantly now and it's a bit of a hassle as it swamps the rest of my trace telemetry.

It emerged for me at the 2.11.0-21474 version as an IndexOutOfRangeException and then evolved into ArgumentOutOfRangeException in 2.12.0-21496.

Version: dotnet:2.10.0-31626
No exceptions

Version: dotnet:2.11.0-21474
IndexOutOfRangeException
@ W3CUtilities.TryGetTraceId < CreateRequestTelemetryPrivate < ReadOrCreateRequestTelemetryPrivate

AI (Internal): [Microsoft-ApplicationInsights-Extensibility-Web] Unknown error, message System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at Microsoft.ApplicationInsights.W3C.Internal.W3CUtilities.TryGetTraceId(String legacyId, ReadOnlySpan`1& traceId)
   at Microsoft.ApplicationInsights.Web.Implementation.RequestTrackingExtensions.CreateRequestTelemetryPrivate(HttpContext platformContext)
   at Microsoft.ApplicationInsights.Web.Implementation.RequestTrackingExtensions.ReadOrCreateRequestTelemetryPrivate(HttpContext platformContext)
   at Microsoft.ApplicationInsights.Web.RequestTrackingTelemetryModule.OnBeginRequest(HttpContext context)
   at Microsoft.ApplicationInsights.Web.AspNetDiagnosticTelemetryModule.AspNetEventObserver.OnNext(KeyValuePair`2 value)

Version: dotnet:2.12.0-21496
ArgumentOutOfRangeException
@ String.Substring < CreateRequestTelemetryPrivate < ReadOrCreateRequestTelemetryPrivate

AI (Internal): [Microsoft-ApplicationInsights-Extensibility-Web] Unknown error, message System.ArgumentOutOfRangeException: Length cannot be less than zero.
Parameter name: length
   at System.String.Substring(Int32 startIndex, Int32 length)
   at Microsoft.ApplicationInsights.Web.Implementation.RequestTrackingExtensions.CreateRequestTelemetryPrivate(HttpContext platformContext)
   at Microsoft.ApplicationInsights.Web.Implementation.RequestTrackingExtensions.ReadOrCreateRequestTelemetryPrivate(HttpContext platformContext)
   at Microsoft.ApplicationInsights.Web.RequestTrackingTelemetryModule.OnBeginRequest(HttpContext context)
   at Microsoft.ApplicationInsights.Web.AspNetDiagnosticTelemetryModule.AspNetEventObserver.OnNext(KeyValuePair`2 value)

It's hard to find a consistent pattern between events just prior to the error especially as I'm always working with a sampled subset of the events data. Can't seem to reproduce outside of production which might be a clue (availability?).

SNAG-0112

@TimothyMothra TimothyMothra added this to the 2.13 milestone Jan 6, 2020
@TimothyMothra
Copy link
Member

@jakenuts thank you for the extra call stacks, this was a big help!

I think the ArgumentOutOfRangeException is coming from GetRootId.
IndexOf can return a value of -1 which would then throw from the call to Substring

internal static string GetRootId(string legacyId)
{
Debug.Assert(!string.IsNullOrEmpty(legacyId), "diagnosticId must not be null or empty");
if (legacyId[0] == '|')
{
var dot = legacyId.IndexOf('.');
return legacyId.Substring(1, dot - 1);
}
return StringUtilities.EnforceMaxLength(legacyId, InjectionGuardConstants.RequestHeaderMaxLength);
}

The IndexOutOfRangeException was coming from TryGetTraceId.
I don't see this in our internal telemetry for 2.12 so I think @lmolkova fixed this one already.

internal static bool TryGetTraceId(string legacyId, out ReadOnlySpan<char> traceId)

@ssa3512
Copy link

ssa3512 commented Jan 22, 2020

Is there any workaround for the issue until it is released? Our trace logs are filled with nothing but this error.

image

@TimothyMothra TimothyMothra reopened this Jan 27, 2020
@TimothyMothra TimothyMothra self-assigned this Jan 27, 2020
@TimothyMothra
Copy link
Member

TimothyMothra commented Jan 27, 2020

We had a fix for this in 2.13-beta1.
Telemetry shows that this exception is still occurring.

The plan is to disable compiler in-line optimization for this method only in the 2.13-beta2.
Our hope is that we can capture a full stack trace to see where this is occurring.
https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.methodimploptions?redirectedfrom=MSDN&view=netframework-4.8

@gplwhite
Copy link

FYI - 2.13-beta1 did seem to resolve this for us.

@TimothyMothra
Copy link
Member

we're no longer seeing this error so i'm going to close this as resolved.

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

No branches or pull requests

5 participants