Azure / azure-functions-dotnet-worker

Azure Functions out-of-process .NET language worker
MIT License
412 stars 176 forks source link

Message body overrides metadata in ServiceBusTrigger function, dotnet-isolated #991

Open eKipod opened 2 years ago

eKipod commented 2 years ago

Properties from message body override metadata properties when using ServiceBusTrigger function in dotnet-isolated. This does not happen in inproc mode. This affects logging, correlations (e.g. when resending messages, or sending related messages), processing (when information from message envelope is needed).

Example:

Given the function:

    [Function("ServiceBusFunction")]
    public static void Run(
        [ServiceBusTrigger("mytopic", "mysubscription", Connection = "AzureServiceBus", IsSessionsEnabled = true)] string message,
        string messageId,
        string label,
        string sessionId,
        FunctionContext context)
    {
        var logger = context.GetLogger("ServiceBusFunction");
        logger.LogInformation("C# ServiceBus topic trigger function processed message: {MessageId}\nLabel: {Label}\nSession: {SessionId}\n{Message}",
            messageId,
            label,
            sessionId,
            message);
    }

When sending the message:

MessageId=[f7e7186e-196b-43f2-8fe2-407c9c829416]
SessionId=[session-1]
Label=[message-label]
Payload:
{
    "name": "value",
    "messageId": "override-message-id",
    "label": "override-label",
    "sessionId": "override-session-id"
}

The actual result is:

C# ServiceBus topic trigger function processed message: override-message-id
Label: override-label
Session: override-session-id
{
  "name": "value",
  "messageId": "override-message-id",
  "label": "override-label",
  "sessionId": "override-session-id"
}

The expected result is:

C# ServiceBus topic trigger function processed message: f7e7186e-196b-43f2-8fe2-407c9c829416
Label: message-label
Session: session-1
{
  "name": "value",
  "messageId": "override-message-id",
  "label": "override-label",
  "sessionId": "override-session-id"
}
fabiocav commented 2 years ago

Thanks for reporting the issue.

This will need additional investigation so we can identify the component causing the problem (likely the OOP layer in the host).

Once we identify the cause, we'll discuss next steps here.