Azure / azure-webjobs-sdk

Azure WebJobs SDK
MIT License
739 stars 358 forks source link

Fix distributed tracing for custom System.Diagnostics.DiagnosticSource #2828

Open alrod opened 2 years ago

alrod commented 2 years ago

Please provide a succinct description of the issue.

Repro steps

  1. EventHub message has property “Diagonstic-Id”(distributed tracing is enabled)
  2. EventHub extension > 4.0.1 and < 5.0.0
  3. Function runtime V3
  4. Customer added his own “System.Diagnostics.DiagnosticSource” reference

Expected behavior

EventHub trigger should not break.

Actual behavior

EventHub trigger breaks with:

Exception type System.AggregateException
Exception message Unable to cast object of type 'System.Collections.Generic.List1[System.Diagnostics.Activity]' to type 'System.Collections.Generic.IEnumerable1[System.Diagnostics.Activity]'.

in Microsoft.Azure.WebJobs.Logging.ApplicationInsights/ApplicationInsightsLogger and caused by Microsoft.Azure.WebJobs.Extensions.EventHubs/Listeners/EventHubListener.cs passing a different Activity type

Known workarounds

  1. Using EventHub extension EventHub extension <= 4.0.1 or >= 5.0.0
  2. Using V4 function runtime,

Related information

Related EventHub trigger issue: https://github.com/Azure/azure-functions-eventhubs-extension/issues/55

The fix should be done in webjobs sdk in the distributed tracing path:

  1. Add try/catch block for the line Microsoft.Azure.WebJobs.Logging.ApplicationInsights/ApplicationInsightsLogger and catch Exception type System.AggregateException Exception message Unable to cast object of type
  2. Avoid this code path and fallback to
alrod commented 2 years ago

cc @gzuber, @RohitRanjanMS