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

ECS message field will be populated with the OTEL exception.message field instead of the body field #13603

Closed
HHobeck opened this issue Jul 5, 2024 · 0 comments
Assignees
Labels

Comments

@HHobeck
Copy link

HHobeck commented Jul 5, 2024

Describe the bug
I'm using a OTEL collector to forward the logging messages to elastic (via the APM module) and see that the message field is not filled correctly when providing exception details.

To Reproduce
Execute a dotnet core 6.0 application with the following C# code and send it with OpenTelemetry.Exporter.OpenTelemetryProtocol to the elastic APM server:

var logger = loggerFactory.CreateLogger(GetType());
try
{
    throw new InvalidOperationException();
}
catch (Exception exception)
{
    logger.LogError(exception, "Hello {World}", "Universe");
    throw;
}

I'm using elastic in version:
v 8.13.4

Actual behavior
The message of the log entry in elastic is of value: Operation is not valid due to the current state of the object.

Expected behavior
I would expect the value: Hello Universe

Debug logs
The resulting OTEL message send to the APM server is:

{
    "resourceLogs": [
        {
            "resource": {
                "attributes": [
                    {
                        "key": "deployment.environment",
                        "value": {
                            "stringValue": "Staging"
                        }
                    },
                    {
                        "key": "service.name",
                        "value": {
                            "stringValue": "LoggingExample"
                        }
                    },
                    {
                        "key": "service.namespace",
                        "value": {
                            "stringValue": "LoggingExample"
                        }
                    },
                    {
                        "key": "service.instance.id",
                        "value": {
                            "stringValue": "19d619b4-a623-45a4-97bb-62e59a14d7ef"
                        }
                    },
                    {
                        "key": "telemetry.sdk.name",
                        "value": {
                            "stringValue": "opentelemetry"
                        }
                    },
                    {
                        "key": "telemetry.sdk.language",
                        "value": {
                            "stringValue": "dotnet"
                        }
                    },
                    {
                        "key": "telemetry.sdk.version",
                        "value": {
                            "stringValue": "1.8.1"
                        }
                    }
                ]
            },
            "scopeLogs": [
                {
                    "scope": {
                        "name": "LoggingExample.Program"
                    },
                    "logRecords": [
                        {
                            "timeUnixNano": "1720176951757341200",
                            "observedTimeUnixNano": "1720176951757341200",
                            "severityNumber": 17,
                            "severityText": "Error",
                            "body": {
                                "stringValue": "Hello Universe"
                            },
                            "attributes": [
                                {
                                    "key": "exception.type",
                                    "value": {
                                        "stringValue": "InvalidOperationException"
                                    }
                                },
                                {
                                    "key": "exception.message",
                                    "value": {
                                        "stringValue": "Operation is not valid due to the current state of the object."
                                    }
                                },
                                {
                                    "key": "exception.stacktrace",
                                    "value": {
                                        "stringValue": "System.InvalidOperationException: Operation is not valid due to the current state of the object.\r\n   at LoggingExample.Program.CreateLogMessage(ILogger logger) in C:\\\\src\\LoggingExample\\CreateLogMessage.cs:line 11"
                                    }
                                },
                                {
                                    "key": "World",
                                    "value": {
                                        "stringValue": "Universe"
                                    }
                                },
                                {
                                    "key": "{OriginalFormat}",
                                    "value": {
                                        "stringValue": "Hello {World}"
                                    }
                                }
                            ],
                            "traceId": "",
                            "spanId": ""
                        }
                    ]
                }
            ]
        }
    ]
}

The converted ECS message is:

{
    "_index": ".ds-logs-LoggingExample-staging-2024.07.05-000001",
    "_id": "-W6MgpABF9Yym4iYb4mT",
    "_version": 1,
    "_score": 0,
    "_source": {
        "observer": {
            "hostname": "2630a8071eee",
            "type": "apm-server",
            "version": "8.13.4"
        },
        "agent": {
            "name": "opentelemetry/dotnet",
            "version": "1.8.1"
        },
        "@timestamp": "2024-07-05T10:59:19.037Z",
        "log": {
            "level": "Error"
        },
        "data_stream": {
            "namespace": "staging",
            "type": "logs",
            "dataset": "LoggingExample"
        },
        "service": {
            "node": {
                "name": "19d619b4-a623-45a4-97bb-62e59a14d7ef"
            },
            "environment": "Staging",
            "name": "LoggingExample",
            "language": {
                "name": "dotnet"
            }
        },
        "error": {
            "exception": [
                {
                    "handled": true,
                    "message": "Operation is not valid due to the current state of the object.",
                    "type": "InvalidOperationException"
                }
            ],
            "id": "d80e089e9f26956ba8280a475c2a2fe0",
            "stack_trace": "System.InvalidOperationException: Operation is not valid due to the current state of the object.\r\n   at LoggingExample.Program.CreateLogMessage(ILogger logger) in C:\\\\src\\LoggingExample\\CreateLogMessage.cs:line 11",
            "grouping_key": "b4fa1fdccaecf80e97197bb11377e589",
            "grouping_name": "Operation is not valid due to the current state of the object."
        },
        "event": {
            "severity": 17,
            "kind": "event",
            "type": "error"
        },
        "message": "Operation is not valid due to the current state of the object.",
        "labels": {
            "service_namespace": "LoggingExample",
            "{OriginalFormat}": "Hello {World}",
            "World": "Universe"
        },
        "timestamp": {
            "us": 1720177159037815
        }
    },
    "fields": {
        "error.grouping_key": [
            "b4fa1fdccaecf80e97197bb11377e589"
        ],
        "error.exception.type": [
            "InvalidOperationException"
        ],
        "service.node.name": [
            "19d619b4-a623-45a4-97bb-62e59a14d7ef"
        ],
        "service.language.name": [
            "dotnet"
        ],
        "service.node.name.text": [
            "19d619b4-a623-45a4-97bb-62e59a14d7ef"
        ],
        "agent.name.text": [
            "opentelemetry/dotnet"
        ],
        "log.level": [
            "Error"
        ],
        "agent.name": [
            "opentelemetry/dotnet"
        ],
        "labels.World": [
            "Universe"
        ],
        "event.kind": [
            "event"
        ],
        "event.severity": [
            17
        ],
        "service.environment": [
            "Staging"
        ],
        "service.name": [
            "LoggingExample"
        ],
        "data_stream.namespace": [
            "staging"
        ],
        "service.language.name.text": [
            "dotnet"
        ],
        "error.exception.handled": [
            true
        ],
        "message": [
            "Operation is not valid due to the current state of the object."
        ],
        "data_stream.type": [
            "logs"
        ],
        "observer.hostname": [
            "2630a8071eee"
        ],
        "timestamp.us": [
            1720177159037815
        ],
        "@timestamp": [
            "2024-07-05T10:59:19.037Z"
        ],
        "observer.type": [
            "apm-server"
        ],
        "observer.version": [
            "8.13.4"
        ],
        "service.name.text": [
            "LoggingExample"
        ],
        "data_stream.dataset": [
            "LoggingExample"
        ],
        "error.id": [
            "d80e089e9f26956ba8280a475c2a2fe0"
        ],
        "event.type": [
            "error"
        ],
        "agent.version": [
            "1.8.1"
        ],
        "error.grouping_name": [
            "Operation is not valid due to the current state of the object."
        ],
        "error.stack_trace": [
            "System.InvalidOperationException: Operation is not valid due to the current state of the object.\r\n   at LoggingExample.Program.CreateLogMessage(ILogger logger) in C:\\\\src\\LoggingExample\\CreateLogMessage.cs:line 11"
        ],
        "error.stack_trace.text": [
            "System.InvalidOperationException: Operation is not valid due to the current state of the object.\r\n   at LoggingExample.Program.CreateLogMessage(ILogger logger) in C:\\\\src\\LoggingExample\\CreateLogMessage.cs:line 11"
        ],
        "labels.service_namespace": [
            "LoggingExample"
        ],
        "error.exception.message": [
            "Operation is not valid due to the current state of the object."
        ],
        "labels.{OriginalFormat}": [
            "Hello {World}"
        ]
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants