thibsc
thibsc

Reputation: 4049

AppInsight not showing details for 408 response code

I have an AppInsights that works perfectly, but this morning I see a 408 response code in the Failures section. My problem is that I'm not able to see the details or why this is happening.

If I click on the 500 response code, I can see the 2 calls to the endpoint. enter image description here

I also tried to find the 408 in the transaction search section but there is no existing transaction with a 408 request response code. Someone already experimented this behavior ?

EDIT: Here the way my AppInsight is configured in my program.cs

builder.Services.AddApplicationInsightsTelemetry(builder.Configuration);
builder.Services.AddApplicationInsightsTelemetryProcessor<HealthCheckTelemetryFilter>();
builder.Services.AddApplicationInsightsTelemetryProcessor<StatusTelemetryFilter>();

HealthCheckTelemetryFilter and StatusTelemetryFilter are just a filter to not log traces, dependencies or request to the /status and /api/health endpoints

And the appsettings.json contains the connection string

"ApplicationInsights": {
  "ConnectionString": "my-connection-string"
},

Upvotes: 0

Views: 53

Answers (1)

Suresh Chikkam
Suresh Chikkam

Reputation: 3332

Validate HealthCheckTelemetryFilter and StatusTelemetryFilter logic to check it doesn't exclude telemetry for 408 responses.

Custom Telemetry Filters:

public class HealthCheckTelemetryFilter : ITelemetryProcessor
{
    private readonly ITelemetryProcessor _next;

    public HealthCheckTelemetryFilter(ITelemetryProcessor next)
    {
        _next = next;
    }

    public void Process(ITelemetry item)
    {
        if (item is RequestTelemetry request &&
            (request.Url.AbsolutePath.Contains("/status") ||
             request.Url.AbsolutePath.Contains("/api/health")))
        {
            if (request.ResponseCode != "408") // Allow logging for 408 responses
            {
                return; // Exclude only non-408 responses
            }
        }

        _next.Process(item);
    }
}
  • Use Application Insights Logs (Analytics) to directly query and confirm if 408 responses are being logged.
requests
| where resultCode == "408"
| order by timestamp desc
  • Check if the logs contain any telemetry for 408 responses and correlate it with timestamps in the Failures section.

Application Insights may apply adaptive sampling, which could exclude some telemetry. Disable sampling temporarily for debugging by updating appsettings.json

"ApplicationInsights": {
  "EnableAdaptiveSampling": false
}

Complete Logs for a 408 Response:

Timestamp: 2024-12-05T09:12:31Z
Operation Name: GET /api/data
Client IP: 192.168.1.30
Response Code: 408
Duration: 30 seconds
Telemetry Type: RequestTelemetry
Custom Properties:
    - RequestStartTime: 2024-12-05T09:12:01Z
    - User-Agent: Mozilla/5.0
    - Endpoint: /api/data
    - TimeoutSource: Client-side
    - DebugInfo: Request reached server but did not complete processing.

enter image description here

Successful Request:

Timestamp: 2024-12-05T08:42:01Z
Operation Name: GET /api/data
Client IP: 192.168.1.10
Response Code: 200
Duration: 120ms
Telemetry Type: RequestTelemetry
Custom Properties:
    - User-Agent: Mozilla/5.0
    - Endpoint: /api/data

Upvotes: 0

Related Questions