azure-sdk-for-net: [BUG] Logging Exception with Outer Message shows Outermessage and inner message to be the same

Library name and version

Azure.Monitor.OpenTelemetry.Exporter Version=“1.0.0”

Describe the bug

When logging an exception to Log Analytics using the Azure.Monitor.OpenTelemetry.Exporter, with an additional message, the additional message should appear in the outer message field, and the exception in the inner message, but the outer message is always set to the inner message.

                        try
                        {
                               throw new ArgumentNullException("Test");
                        }
                        catch (Exception ex)
                        {
                            Logger.LogError(ex, "This should be the outer message {MessageValue}", "test");
                        }

Expected behavior

The additional message should appear in the outer message field, and the exception in the inner message

Actual behavior

The outer message is always set to the exception message

A sample from out Azure Monitor logs. image

Reproduction Steps

                        try
                        {
                               throw new ArgumentNullException("Test");
                        }
                        catch (Exception ex)
                        {
                            Logger.LogError(ex, "This should be the outer message {MessageValue}", "test");
                        }

Environment

No response

About this issue

  • Original URL
  • State: closed
  • Created 7 months ago
  • Comments: 15 (7 by maintainers)

Most upvoted comments

As always happens, as soon as you get the professionals involved, you find the root cause of the issue…

We had a CustomLogEnrichmentProcessor hidden under the covers that was doing the following:

    public override void OnEnd(LogRecord data)
    {
        data.Attributes = _contextValues;
    }

Which was replacing all of the existing attributes with only the context attributes.

It should have been

    public override void OnEnd(LogRecord data)
    {
        var attributes = data.Attributes?.ToList() ?? [];
        attributes.AddRange(_contextValues!);

        data.Attributes = attributes!;
    }

Thank you for helping me with this one. I’ll close this issue and consider it user error.

^ This looks like a bug. @rajkumar-rangaraj can you confirm if you see this behavior where the logger message is not even in the Properties?