elastic / apm-agent-dotnet

https://www.elastic.co/guide/en/apm/agent/dotnet/current/index.html
Apache License 2.0
584 stars 209 forks source link

[BUG] #2478

Open Vaahik opened 1 day ago

Vaahik commented 1 day ago

APM Agent version

The version of the Elastic.Apm nuget package used 1.0.30 linux profiler

Environment

Operating system and version: Centos 9

.NET Framework/Core name and version (e.g. .NET 4.6.2, NET Core 3.1.100) : Net Core 8.0.8

Application Target Framework(s) (e.g. net462, netcoreapp3.1):

Describe the bug

APM 8.15.3

[2024-11-06 19:53:38.768 +04:00][4][Error] - {PayloadSenderV2} Failed sending event. Events intake API absolute URL: http://localhost:8200/intake/v2/events. APM Server response: status code: BadRequest, reasons: decode error: data read error: v2.transactionRoot.Transaction: v2.transaction.Context: v2.context.Request: v2.contextRequest.HTTPVersion: Headers: invalid input for HTTPHeader:

To Reproduce

Steps to reproduce the behavior:

  1. Use this config '...'
  2. Then call '....'
  3. Then do '....'
  4. See error

Expected behavior

A clear and concise description of what you expected to happen.

Actual behavior

Sing303 commented 23 hours ago

I confirm, I had the same problem {"PayloadSenderV2"} Failed sending event. Events intake API absolute URL: http://localhost:8200/intake/v2/events. APM Server response: status code: BadRequest, reasons: "decode error: data read error: v2.transactionRoot.Transaction: v2.transaction.Context: v2.context.Request: v2.contextRequest.HTTPVersion: Headers: invalid input for HTTPHeader: <nil>"

Sing303 commented 5 hours ago

The problem was in the header, which has a value of NULL. So far I have fixed it like this

        Agent.AddFilter((ITransaction transaction) =>
        {
            if (transaction.Context?.Request?.Headers != null)
            {
                var headersWithNullValues = transaction.Context.Request.Headers
                    .Where(header => header.Value == null)
                    .ToList();
                foreach (var header in headersWithNullValues)
                {
                    transaction.Context.Request.Headers[header.Key] = "[REDACTED_NULL]";
                }
            }
            return transaction;
        });

Example of a problem query in APM from tracing

{
    "context": {
        "request": {
            "body": "[REDACTED]",
            "headers": {
                "Authorization": "[REDACTED]",
                "Cookie": null, <---- The problem was here
                "elastic-apm-traceparent": "...",
                "Host": "...",
                "traceparent": "..."
            },
            "http_version": "1.1",
            "method": "GET",
            "socket": {
                "remote_address": "..."
            },
            "url": {
                "full": "...",
                "hostname": "...",
                "pathname": "...",
                "protocol": "HTTP",
                "raw": "...",
                "search": ""
            }
        },
        "response": {
            "finished": true,
            "headers": {
                "api-file-version": "1.0.0.0",
                "api-supported-versions": "1.0",
                "api-version": "1.0",
                "Content-Type": "application/json; charset=utf-8",
                "Date": "Thu, 07 Nov 2024 16:54:11 GMT",
                "Server": "Kestrel",
                "Set-Cookie": "[REDACTED]",
                "Transfer-Encoding": "chunked"
            },
            "status_code": 200
        },
        "user": {
            "email": "...",
            "id": "...",
            "username": "..."
        }
    },
    "duration": 14.034,
    "id": "...",
    "name": "GET ...",
    "outcome": "success",
    "parent_id": "...",
    "result": "HTTP 2xx",
    "sampled": true,
    "span_count": {
        "dropped": 0,
        "started": 1
    },
    "timestamp": ...,
    "trace_id": "...",
    "type": "request"
}