C#C
C#5mo ago
Pan!cKk

Distributed Observability with Open Telemetry and Azure Monitor (Application Insights)

Hello,

Is anyone experienced with Open Telemetry and Azure Monitor in .NET C#?
I am trying to "migrate" from Application Insights (SDK) to Open Telemetry with Azure Monitor, but I am facing some "issues"...
Here is the code with Application Insights SDK:

using (var operation = _telemetryClient.StartOperation<RequestTelemetry>("MessageStoreEvent"))
        {   var trackingProps = new Dictionary<string, string> { { "MessageId", @event.MessageId.ToString() }, { "TenantId", @event.TenantId } };
            operation.Telemetry.Context.Operation.Name = @event.MessageType;
            _telemetryClient.TrackTrace("Started processing MessageStoreEvent", trackingProps);

            try { ... .TrackTrace("Completed processing MessageStoreEvent", trackingProps); }
            catch (Exception ex)
            { _logger.LogError(ex, "MessageStoreEventHandler");
              operation.Telemetry.Success = false;
              operation.Telemetry.ResponseCode = "500";
              _telemetryClient.TrackException(ex);
              ...
            }}}


Here is the in-progress code migrating to Open Telemetry:
using (var activity = _activitySource.StartActivity(MessageStoreTelemetry.ActivitySourceName, ActivityKind.Consumer))
        {   activity.AddTag("MessageId", @event.MessageId);            
            ValidateMessageStoreEvent(@event);
            try { ... activity.SetStatus(ActivityStatusCode.Ok); }
            catch (Exception ex)
            { logger.LogError(ex, "MessageStoreEventHandler");                
              activity.SetExceptionTags(ex);                
              ...
            }}}


The "issue" I am facing is that the operation_Name and name (request) are both populated from activity.DisplayName, I want the operation_Name to be the MessageStoreTelemetry.ActivitySourceName and the request name to be @event.MessageType?

Is there a way to override the default behavior?
Was this page helpful?