public override void OnEvent()

in WEB/Src/DependencyCollector/DependencyCollector/Implementation/AzureSdk/AzureSdkDiagnosticsEventHandler.cs [37:119]


        public override void OnEvent(KeyValuePair<string, object> evnt, DiagnosticListener diagnosticListener)
        {
            try
            {
                if (SdkInternalOperationsMonitor.IsEntered())
                {
                    // Because we support AAD, we must to check if an internal operation is being caught here (type = "InProc | Microsoft.AAD").
                    return;
                }

                var currentActivity = Activity.Current;
                if (evnt.Key.EndsWith(".Start", StringComparison.Ordinal))
                {
                    OperationTelemetry telemetry = null;

                    foreach (var tag in currentActivity.Tags)
                    {
                        if (tag.Key == "kind" && (tag.Value == "server" || tag.Value == "consumer"))
                        {
                            telemetry = new RequestTelemetry();
                            break;
                        }
                    }

                    string type = GetType(currentActivity);

                    if (telemetry == null)
                    {
                        telemetry = new DependencyTelemetry { Type = type };
                    }

                    if (type != null && type.EndsWith(RemoteDependencyConstants.AzureEventHubs, StringComparison.Ordinal))
                    {
                        SetEventHubsProperties(currentActivity, telemetry);
                    }

                    if (this.linksPropertyFetcher.Fetch(evnt.Value) is IEnumerable<Activity> activityLinks)
                    {
                        PopulateLinks(activityLinks, telemetry);

                        if (telemetry is RequestTelemetry request &&
                            TryGetAverageTimeInQueueForBatch(activityLinks, currentActivity.StartTimeUtc, out long enqueuedTime))
                        {
                            request.Metrics["timeSinceEnqueued"] = enqueuedTime;
                        }
                    }

                    this.operationHolder.Store(currentActivity, Tuple.Create(telemetry, /* isCustomCreated: */ false));
                }
                else if (evnt.Key.EndsWith(".Stop", StringComparison.Ordinal))
                {
                    var telemetry = this.operationHolder.Get(currentActivity).Item1;

                    this.SetCommonProperties(evnt.Key, evnt.Value, currentActivity, telemetry);

                    if (telemetry is DependencyTelemetry dependency && dependency.Type == RemoteDependencyConstants.HTTP)
                    {
                        SetHttpProperties(currentActivity, dependency);
                        if (evnt.Value != null)
                        {
                            dependency.SetOperationDetail(evnt.Value.GetType().FullName, evnt.Value);
                        }
                    }

                    this.TelemetryClient.Track(telemetry);
                }
                else if (evnt.Key.EndsWith(".Exception", StringComparison.Ordinal))
                {
                    Exception ex = evnt.Value as Exception;

                    var telemetry = this.operationHolder.Get(currentActivity);
                    telemetry.Item1.Success = false;
                    if (ex != null)
                    {
                        telemetry.Item1.Properties[RemoteDependencyConstants.DependencyErrorPropertyKey] = ex.ToInvariantString();
                    }
                }
            }
            catch (Exception ex)
            {
                DependencyCollectorEventSource.Log.TelemetryDiagnosticSourceCallbackException(evnt.Key, ex.ToInvariantString());
            }
        }