< Summary

Class:Microsoft.Azure.ServiceBus.ServiceBusDiagnosticSource
Assembly:Microsoft.Azure.ServiceBus
File(s):C:\Git\azure-sdk-for-net\sdk\servicebus\Microsoft.Azure.ServiceBus\src\ServiceBusDiagnosticsSource.cs
Covered lines:4
Uncovered lines:388
Coverable lines:392
Total lines:783
Line coverage:1% (4 of 392)
Covered branches:0
Total branches:130
Branch coverage:0% (0 of 130)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.cctor()-0%100%
.ctor(...)-100%100%
IsEnabled()-0%100%
SendStart(...)-0%100%
SendStop(...)-0%0%
ProcessStart(...)-0%100%
ProcessStop(...)-0%0%
ProcessSessionStart(...)-0%100%
ProcessSessionStop(...)-0%0%
ScheduleStart(...)-0%100%
ScheduleStop(...)-0%0%
CancelStart(...)-0%100%
CancelStop(...)-0%0%
ReceiveStart(...)-0%100%
ReceiveStop(...)-0%0%
PeekStart(...)-0%100%
PeekStop(...)-0%0%
ReceiveDeferredStart(...)-0%100%
ReceiveDeferredStop(...)-0%0%
CompleteStart(...)-0%100%
CompleteStop(...)-0%0%
DisposeStart(...)-0%100%
DisposeStop(...)-0%0%
RenewLockStart(...)-0%100%
RenewLockStop(...)-0%0%
AddRuleStart(...)-0%100%
AddRuleStop(...)-0%0%
RemoveRuleStart(...)-0%100%
RemoveRuleStop(...)-0%0%
GetRulesStart()-0%100%
GetRulesStop(...)-0%0%
AcceptMessageSessionStart(...)-0%100%
AcceptMessageSessionStop(...)-0%0%
GetSessionStateStart(...)-0%100%
GetSessionStateStop(...)-0%0%
SetSessionStateStart(...)-0%100%
SetSessionStateStop(...)-0%0%
RenewSessionLockStart(...)-0%100%
RenewSessionLockStop(...)-0%0%
ReportException(...)-0%0%
Start(...)-0%0%
Inject(...)-0%0%
Inject(...)-0%0%
Inject(...)-0%0%
SerializeCorrelationContext(...)-0%0%
SetRelatedOperations(...)-0%0%
ProcessStart(...)-0%0%
SetTags(...)-0%0%
SetTags(...)-0%0%
SetSessionTag(...)-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\servicebus\Microsoft.Azure.ServiceBus\src\ServiceBusDiagnosticsSource.cs

#LineLine coverage
 1// Copyright (c) Microsoft. All rights reserved.
 2// Licensed under the MIT license. See LICENSE file in the project root for full license information.
 3
 4namespace Microsoft.Azure.ServiceBus
 5{
 6    using System;
 7    using System.Collections.Generic;
 8    using System.Diagnostics;
 9    using System.Linq;
 10    using System.Threading.Tasks;
 11
 12    using Microsoft.Azure.ServiceBus.Diagnostics;
 13
 14    internal class ServiceBusDiagnosticSource
 15    {
 16        public const string DiagnosticListenerName = "Microsoft.Azure.ServiceBus";
 17        public const string BaseActivityName = "Microsoft.Azure.ServiceBus.";
 18
 19        public const string ExceptionEventName = BaseActivityName + "Exception";
 20        public const string ProcessActivityName =  BaseActivityName + "Process";
 21
 22        public const string ActivityIdPropertyName = "Diagnostic-Id";
 23        public const string CorrelationContextPropertyName = "Correlation-Context";
 24        public const string RelatedToTag = "RelatedTo";
 25        public const string MessageIdTag = "MessageId";
 26        public const string SessionIdTag = "SessionId";
 27
 028        private static readonly DiagnosticListener DiagnosticListener = new DiagnosticListener(DiagnosticListenerName);
 29        private readonly string entityPath;
 30        private readonly Uri endpoint;
 31
 1232        public ServiceBusDiagnosticSource(string entityPath, Uri endpoint)
 33        {
 1234            this.entityPath = entityPath;
 1235            this.endpoint = endpoint;
 1236        }
 37
 38        public static bool IsEnabled()
 39        {
 040            return DiagnosticListener.IsEnabled();
 41        }
 42
 43
 44        #region Send
 45
 46        internal Activity SendStart(IList<Message> messageList)
 47        {
 048            Activity activity = Start("Send", () => new
 049                {
 050                    Messages = messageList,
 051                    Entity = this.entityPath,
 052                    Endpoint = this.endpoint
 053                },
 054                a => SetTags(a, messageList)
 055            );
 56
 057            Inject(messageList);
 58
 059            return activity;
 60        }
 61
 62        internal void SendStop(Activity activity, IList<Message> messageList, TaskStatus? status)
 63        {
 064            if (activity != null)
 65            {
 066                DiagnosticListener.StopActivity(activity, new
 067                {
 068                    Messages = messageList,
 069                    Entity = this.entityPath,
 070                    Endpoint = this.endpoint,
 071                    Status = status ?? TaskStatus.Faulted
 072                });
 73            }
 074        }
 75
 76        #endregion
 77
 78
 79        #region Process
 80
 81        internal Activity ProcessStart(Message message)
 82        {
 083            return ProcessStart("Process", message, () => new
 084                {
 085                    Message = message,
 086                    Entity = this.entityPath,
 087                    Endpoint = this.endpoint
 088                },
 089                a => SetTags(a, message));
 90        }
 91
 92        internal void ProcessStop(Activity activity, Message message, TaskStatus? status)
 93        {
 094            if (activity != null)
 95            {
 096                DiagnosticListener.StopActivity(activity, new
 097                {
 098                    Message = message,
 099                    Entity = this.entityPath,
 0100                    Endpoint = this.endpoint,
 0101                    Status = status ?? TaskStatus.Faulted
 0102                });
 103            }
 0104        }
 105
 106        #endregion
 107
 108
 109        #region ProcessSession
 110
 111        internal Activity ProcessSessionStart(IMessageSession session, Message message)
 112        {
 0113            return ProcessStart("ProcessSession", message, () => new
 0114                {
 0115                    Session = session,
 0116                    Message = message,
 0117                    Entity = this.entityPath,
 0118                    Endpoint = this.endpoint
 0119                },
 0120                a => SetTags(a, message));
 121        }
 122
 123        internal void ProcessSessionStop(Activity activity, IMessageSession session, Message message, TaskStatus? status
 124        {
 0125            if (activity != null)
 126            {
 0127                DiagnosticListener.StopActivity(activity, new
 0128                {
 0129                    Session = session,
 0130                    Message = message,
 0131                    Entity = this.entityPath,
 0132                    Endpoint = this.endpoint,
 0133                    Status = status ?? TaskStatus.Faulted
 0134                });
 135            }
 0136        }
 137
 138        #endregion
 139
 140
 141        #region Schedule
 142
 143        internal Activity ScheduleStart(Message message, DateTimeOffset scheduleEnqueueTimeUtc)
 144        {
 0145            Activity activity = Start("Schedule", () => new
 0146                {
 0147                    Message = message,
 0148                    ScheduleEnqueueTimeUtc = scheduleEnqueueTimeUtc,
 0149                    Entity = this.entityPath,
 0150                    Endpoint = this.endpoint
 0151                },
 0152                a => SetTags(a, message));
 153
 0154            Inject(message);
 155
 0156            return activity;
 157        }
 158
 159        internal void ScheduleStop(Activity activity, Message message, DateTimeOffset scheduleEnqueueTimeUtc, TaskStatus
 160        {
 0161            if (activity != null)
 162            {
 0163                DiagnosticListener.StopActivity(activity, new
 0164                {
 0165                    Message = message,
 0166                    ScheduleEnqueueTimeUtc = scheduleEnqueueTimeUtc,
 0167                    Entity = this.entityPath,
 0168                    Endpoint = this.endpoint,
 0169                    SequenceNumber = sequenceNumber,
 0170                    Status = status ?? TaskStatus.Faulted
 0171                });
 172            }
 0173        }
 174
 175        #endregion
 176
 177
 178        #region Cancel
 179
 180        internal Activity CancelStart(long sequenceNumber)
 181        {
 0182            return Start("Cancel", () => new
 0183            {
 0184                SequenceNumber = sequenceNumber,
 0185                Entity = this.entityPath,
 0186                Endpoint = this.endpoint
 0187            },
 0188            null);
 189        }
 190
 191        internal void CancelStop(Activity activity, long sequenceNumber, TaskStatus? status)
 192        {
 0193            if (activity != null)
 194            {
 0195                DiagnosticListener.StopActivity(activity, new
 0196                {
 0197                    SequenceNumber = sequenceNumber,
 0198                    Entity = this.entityPath,
 0199                    Endpoint = this.endpoint,
 0200                    Status = status ?? TaskStatus.Faulted
 0201                });
 202            }
 0203        }
 204
 205        #endregion
 206
 207
 208        #region Receive
 209
 210        internal Activity ReceiveStart(int messageCount)
 211        {
 0212            return Start("Receive", () => new
 0213            {
 0214                RequestedMessageCount = messageCount,
 0215                Entity = this.entityPath,
 0216                Endpoint = this.endpoint
 0217            },
 0218            null);
 219        }
 220
 221        internal void ReceiveStop(Activity activity, int messageCount, TaskStatus? status, IList<Message> messageList)
 222        {
 0223            if (activity != null)
 224            {
 0225                SetRelatedOperations(activity, messageList);
 0226                SetTags(activity, messageList);
 0227                DiagnosticListener.StopActivity(activity, new
 0228                {
 0229                    RequestedMessageCount = messageCount,
 0230                    Entity = this.entityPath,
 0231                    Endpoint = this.endpoint,
 0232                    Status = status ?? TaskStatus.Faulted,
 0233                    Messages = messageList
 0234                });
 235            }
 0236        }
 237
 238        #endregion
 239
 240
 241        #region Peek
 242
 243        internal Activity PeekStart(long fromSequenceNumber, int messageCount)
 244        {
 0245            return Start("Peek", () => new
 0246            {
 0247                FromSequenceNumber = fromSequenceNumber,
 0248                RequestedMessageCount = messageCount,
 0249                Entity = this.entityPath,
 0250                Endpoint = this.endpoint
 0251            },
 0252            null);
 253        }
 254
 255        internal void PeekStop(Activity activity, long fromSequenceNumber, int messageCount, TaskStatus? status, IList<M
 256        {
 0257            if (activity != null)
 258            {
 0259                SetRelatedOperations(activity, messageList);
 0260                SetTags(activity, messageList);
 261
 0262                DiagnosticListener.StopActivity(activity, new
 0263                {
 0264                    FromSequenceNumber = fromSequenceNumber,
 0265                    RequestedMessageCount = messageCount,
 0266                    Entity = this.entityPath,
 0267                    Endpoint = this.endpoint,
 0268                    Status = status ?? TaskStatus.Faulted,
 0269                    Messages = messageList
 0270                });
 271            }
 0272        }
 273
 274        #endregion
 275
 276
 277        #region ReceiveDeferred
 278
 279        internal Activity ReceiveDeferredStart(IEnumerable<long> sequenceNumbers)
 280        {
 0281            return Start("ReceiveDeferred", () => new
 0282            {
 0283                SequenceNumbers = sequenceNumbers,
 0284                Entity = this.entityPath,
 0285                Endpoint = this.endpoint
 0286            },
 0287            null);
 288        }
 289
 290        internal void ReceiveDeferredStop(Activity activity, IEnumerable<long> sequenceNumbers, TaskStatus? status, ILis
 291        {
 0292            if (activity != null)
 293            {
 0294                SetRelatedOperations(activity, messageList);
 0295                SetTags(activity, messageList);
 296
 0297                DiagnosticListener.StopActivity(activity, new
 0298                {
 0299                    SequenceNumbers = sequenceNumbers,
 0300                    Entity = this.entityPath,
 0301                    Endpoint = this.endpoint,
 0302                    Messages = messageList,
 0303                    Status = status ?? TaskStatus.Faulted
 0304                });
 305            }
 0306        }
 307
 308        #endregion
 309
 310
 311        #region  Complete
 312
 313        internal Activity CompleteStart(IList<string> lockTokens)
 314        {
 0315            return Start("Complete", () => new
 0316            {
 0317                LockTokens = lockTokens,
 0318                Entity = this.entityPath,
 0319                Endpoint = this.endpoint
 0320            },
 0321            null);
 322        }
 323
 324        internal void CompleteStop(Activity activity, IList<string> lockTokens, TaskStatus? status)
 325        {
 0326            if (activity != null)
 327            {
 0328                DiagnosticListener.StopActivity(activity, new
 0329                {
 0330                    LockTokens = lockTokens,
 0331                    Entity = this.entityPath,
 0332                    Endpoint = this.endpoint,
 0333                    Status = status ?? TaskStatus.Faulted
 0334                });
 335            }
 0336        }
 337
 338        #endregion
 339
 340
 341        #region Dispose
 342
 343        internal Activity DisposeStart(string operationName, string lockToken)
 344        {
 0345            return Start(operationName, () => new
 0346            {
 0347                LockToken = lockToken,
 0348                Entity = this.entityPath,
 0349                Endpoint = this.endpoint
 0350            },
 0351            null);
 352        }
 353
 354        internal void DisposeStop(Activity activity, string lockToken, TaskStatus? status)
 355        {
 0356            if (activity != null)
 357            {
 0358                DiagnosticListener.StopActivity(activity, new
 0359                {
 0360                    LockToken = lockToken,
 0361                    Entity = this.entityPath,
 0362                    Endpoint = this.endpoint,
 0363                    Status = status ?? TaskStatus.Faulted
 0364                });
 365            }
 0366        }
 367
 368        #endregion
 369
 370
 371        #region RenewLock
 372
 373        internal Activity RenewLockStart(string lockToken)
 374        {
 0375            return Start("RenewLock", () => new
 0376            {
 0377                LockToken = lockToken,
 0378                Entity = this.entityPath,
 0379                Endpoint = this.endpoint
 0380            },
 0381            null);
 382        }
 383
 384        internal void RenewLockStop(Activity activity, string lockToken, TaskStatus? status, DateTime lockedUntilUtc)
 385        {
 0386            if (activity != null)
 387            {
 0388                DiagnosticListener.StopActivity(activity, new
 0389                {
 0390                    LockToken = lockToken,
 0391                    Entity = this.entityPath,
 0392                    Endpoint = this.endpoint,
 0393                    Status = status ?? TaskStatus.Faulted,
 0394                    LockedUntilUtc = lockedUntilUtc
 0395                });
 396            }
 0397        }
 398
 399        #endregion
 400
 401
 402        #region AddRule
 403
 404        internal Activity AddRuleStart(RuleDescription description)
 405        {
 0406            return Start("AddRule", () => new
 0407            {
 0408                Rule = description,
 0409                Entity = this.entityPath,
 0410                Endpoint = this.endpoint
 0411            },
 0412            null);
 413        }
 414
 415        internal void AddRuleStop(Activity activity, RuleDescription description, TaskStatus? status)
 416        {
 0417            if (activity != null)
 418            {
 0419                DiagnosticListener.StopActivity(activity, new
 0420                {
 0421                    Rule = description,
 0422                    Entity = this.entityPath,
 0423                    Endpoint = this.endpoint,
 0424                    Status = status ?? TaskStatus.Faulted
 0425                });
 426            }
 0427        }
 428
 429        #endregion
 430
 431
 432        #region RemoveRule
 433
 434        internal Activity RemoveRuleStart(string ruleName)
 435        {
 0436            return Start("RemoveRule", () => new
 0437            {
 0438                RuleName = ruleName,
 0439                Entity = this.entityPath,
 0440                Endpoint = this.endpoint
 0441            },
 0442            null);
 443        }
 444
 445        internal void RemoveRuleStop(Activity activity, string ruleName, TaskStatus? status)
 446        {
 0447            if (activity != null)
 448            {
 0449                DiagnosticListener.StopActivity(activity, new
 0450                {
 0451                    RuleName = ruleName,
 0452                    Entity = this.entityPath,
 0453                    Endpoint = this.endpoint,
 0454                    Status = status ?? TaskStatus.Faulted
 0455                });
 456            }
 0457        }
 458
 459        #endregion
 460
 461
 462        #region GetRules
 463
 464        internal Activity GetRulesStart()
 465        {
 0466            return Start("GetRules", () => new
 0467            {
 0468                Entity = this.entityPath,
 0469                Endpoint = this.endpoint
 0470            },
 0471            null);
 472        }
 473
 474        internal void GetRulesStop(Activity activity, IEnumerable<RuleDescription> rules, TaskStatus? status)
 475        {
 0476            if (activity != null)
 477            {
 0478                DiagnosticListener.StopActivity(activity, new
 0479                {
 0480                    Rules = rules,
 0481                    Entity = this.entityPath,
 0482                    Endpoint = this.endpoint,
 0483                    Status = status ?? TaskStatus.Faulted
 0484                });
 485            }
 0486        }
 487
 488        #endregion
 489
 490
 491        #region AcceptMessageSession
 492
 493        internal Activity AcceptMessageSessionStart(string sessionId)
 494        {
 0495            return Start("AcceptMessageSession", () => new
 0496                {
 0497                    SessionId = sessionId,
 0498                    Entity = this.entityPath,
 0499                    Endpoint = this.endpoint
 0500                },
 0501                a => SetSessionTag(a, sessionId)
 0502            );
 503        }
 504
 505        internal void AcceptMessageSessionStop(Activity activity, string sessionId, TaskStatus? status)
 506        {
 0507            if (activity != null)
 508            {
 0509                DiagnosticListener.StopActivity(activity, new
 0510                {
 0511                    SessionId = sessionId,
 0512                    Entity = this.entityPath,
 0513                    Endpoint = this.endpoint,
 0514                    Status = status ?? TaskStatus.Faulted
 0515                });
 516            }
 0517        }
 518
 519        #endregion
 520
 521
 522        #region GetSessionStateAsync
 523
 524        internal Activity GetSessionStateStart(string sessionId)
 525        {
 0526            return Start("GetSessionState", () => new
 0527                {
 0528                    SessionId = sessionId,
 0529                    Entity = this.entityPath,
 0530                    Endpoint = this.endpoint
 0531                },
 0532                a => SetSessionTag(a, sessionId));
 533        }
 534
 535        internal void GetSessionStateStop(Activity activity, string sessionId, byte[] state, TaskStatus? status)
 536        {
 0537            if (activity != null)
 538            {
 0539                DiagnosticListener.StopActivity(activity, new
 0540                {
 0541                    SessionId = sessionId,
 0542                    Entity = this.entityPath,
 0543                    Endpoint = this.endpoint,
 0544                    Status = status ?? TaskStatus.Faulted,
 0545                    State = state
 0546                });
 547            }
 0548        }
 549
 550        #endregion
 551
 552
 553        #region SetSessionState
 554
 555        internal Activity SetSessionStateStart(string sessionId, byte[] state)
 556        {
 0557            return Start("SetSessionState", () => new
 0558                {
 0559                    State = state,
 0560                    SessionId = sessionId,
 0561                    Entity = this.entityPath,
 0562                    Endpoint = this.endpoint
 0563                },
 0564                a => SetSessionTag(a, sessionId));
 565        }
 566
 567        internal void SetSessionStateStop(Activity activity, byte[] state, string sessionId, TaskStatus? status)
 568        {
 0569            if (activity != null)
 570            {
 0571                DiagnosticListener.StopActivity(activity, new
 0572                {
 0573                    State = state,
 0574                    SessionId = sessionId,
 0575                    Entity = this.entityPath,
 0576                    Endpoint = this.endpoint,
 0577                    Status = status ?? TaskStatus.Faulted
 0578                });
 579            }
 0580        }
 581
 582        #endregion
 583
 584
 585        #region RenewSessionLock
 586
 587        internal Activity RenewSessionLockStart(string sessionId)
 588        {
 0589            return Start("RenewSessionLock", () => new
 0590            {
 0591                SessionId = sessionId,
 0592                Entity = this.entityPath,
 0593                Endpoint = this.endpoint
 0594            },
 0595            a => SetSessionTag(a, sessionId));
 596        }
 597
 598        internal void RenewSessionLockStop(Activity activity, string sessionId, TaskStatus? status)
 599        {
 0600            if (activity != null)
 601            {
 0602                DiagnosticListener.StopActivity(activity, new
 0603                {
 0604                    SessionId = sessionId,
 0605                    Entity = this.entityPath,
 0606                    Endpoint = this.endpoint,
 0607                    Status = status ?? TaskStatus.Faulted
 0608                });
 609            }
 0610        }
 611
 612        #endregion
 613
 614        internal void ReportException(Exception ex)
 615        {
 0616            if (DiagnosticListener.IsEnabled(ExceptionEventName))
 617            {
 0618                DiagnosticListener.Write(ExceptionEventName,
 0619                    new
 0620                    {
 0621                        Exception = ex,
 0622                        Entity = this.entityPath,
 0623                        Endpoint = this.endpoint
 0624                    });
 625            }
 0626        }
 627
 628        private Activity Start(string operationName, Func<object> getPayload, Action<Activity> setTags)
 629        {
 0630            Activity activity = null;
 0631            string activityName = BaseActivityName + operationName;
 0632            if (DiagnosticListener.IsEnabled(activityName, this.entityPath))
 633            {
 0634                activity = new Activity(activityName);
 0635                setTags?.Invoke(activity);
 636
 0637                if (DiagnosticListener.IsEnabled(activityName + ".Start"))
 638                {
 0639                    DiagnosticListener.StartActivity(activity, getPayload());
 640                }
 641                else
 642                {
 0643                    activity.Start();
 644                }
 645            }
 646
 0647            return activity;
 648        }
 649
 650        private void Inject(IList<Message> messageList)
 651        {
 0652            var currentActivity = Activity.Current;
 0653            if (currentActivity != null && messageList != null)
 654            {
 0655                var correlationContext = SerializeCorrelationContext(currentActivity.Baggage.ToList());
 656
 0657                foreach (var message in messageList)
 658                {
 0659                    Inject(message, currentActivity.Id, correlationContext);
 660                }
 661            }
 0662        }
 663
 664        private void Inject(Message message)
 665        {
 0666            var currentActivity = Activity.Current;
 0667            if (currentActivity != null)
 668            {
 0669                Inject(message, currentActivity.Id, SerializeCorrelationContext(currentActivity.Baggage.ToList()));
 670            }
 0671        }
 672
 673        private void Inject(Message message, string id, string correlationContext)
 674        {
 0675            if (message != null && !message.UserProperties.ContainsKey(ActivityIdPropertyName))
 676            {
 0677                message.UserProperties[ActivityIdPropertyName] = id;
 0678                if (correlationContext != null)
 679                {
 0680                    message.UserProperties[CorrelationContextPropertyName] = correlationContext;
 681                }
 682            }
 0683        }
 684
 685        private string SerializeCorrelationContext(IList<KeyValuePair<string,string>> baggage)
 686        {
 0687            if (baggage != null && baggage.Count > 0)
 688            {
 0689                return string.Join(",", baggage.Select(kvp => kvp.Key + "=" + kvp.Value));
 690            }
 0691            return null;
 692        }
 693
 694        private void SetRelatedOperations(Activity activity, IList<Message> messageList)
 695        {
 0696            if (messageList != null && messageList.Count > 0)
 697            {
 0698                var relatedTo = new List<string>();
 0699                foreach (var message in messageList)
 700                {
 0701                    if (message.TryExtractId(out string id))
 702                    {
 0703                        relatedTo.Add(id);
 704                    }
 705                }
 706
 0707                if (relatedTo.Count > 0)
 708                {
 0709                    activity.AddTag(RelatedToTag, string.Join(",", relatedTo.Distinct()));
 710                }
 711            }
 0712        }
 713
 714        private Activity ProcessStart(string operationName, Message message, Func<object> getPayload, Action<Activity> s
 715        {
 0716            Activity activity = null;
 0717            string activityName = BaseActivityName + operationName;
 718
 0719            if (message != null && DiagnosticListener.IsEnabled(activityName, entityPath))
 720            {
 0721                var tmpActivity = message.ExtractActivity(activityName);
 0722                setTags?.Invoke(tmpActivity);
 723
 0724                if (DiagnosticListener.IsEnabled(activityName, entityPath, tmpActivity))
 725                {
 0726                    activity = tmpActivity;
 0727                    if (DiagnosticListener.IsEnabled(activityName + ".Start"))
 728                    {
 0729                        DiagnosticListener.StartActivity(activity, getPayload());
 730                    }
 731                    else
 732                    {
 0733                        activity.Start();
 734                    }
 735                }
 736            }
 0737            return activity;
 738        }
 739
 740        private void SetTags(Activity activity, IList<Message> messageList)
 741        {
 0742            if (messageList == null)
 743            {
 0744                return;
 745            }
 746
 0747            var messageIds = messageList.Where(m => m.MessageId != null).Select(m => m.MessageId).ToArray();
 0748            if (messageIds.Any())
 749            {
 0750                activity.AddTag(MessageIdTag, string.Join(",", messageIds));
 751            }
 752
 0753            var sessionIds = messageList.Where(m => m.SessionId != null).Select(m => m.SessionId).Distinct().ToArray();
 0754            if (sessionIds.Any())
 755            {
 0756                activity.AddTag(SessionIdTag, string.Join(",", sessionIds));
 757            }
 0758        }
 759
 760        private void SetTags(Activity activity, Message message)
 761        {
 0762            if (message == null)
 763            {
 0764                return;
 765            }
 766
 0767            if (message.MessageId != null)
 768            {
 0769                activity.AddTag(MessageIdTag, message.MessageId);
 770            }
 771
 0772            SetSessionTag(activity, message.SessionId);
 0773        }
 774
 775        private void SetSessionTag(Activity activity, string sessionId)
 776        {
 0777            if (sessionId != null)
 778            {
 0779                activity.AddTag(SessionIdTag, sessionId);
 780            }
 0781        }
 782    }
 783}