Repository navigation
Expand file tree
/
Copy pathAnalyticsEventSource.cs
More file actions
778 lines (736 loc) · 26 KB
/
Copy pathAnalyticsEventSource.cs
File metadata and controls
778 lines (736 loc) · 26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
// ----------------------------------------------------------------------------------
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------
namespace DurableTask.AzureStorage
{
using System;
using System.Diagnostics.Tracing;
using System.Threading;
/// <summary>
/// ETW Event Provider for the DurableTask.AzureStorage provider extension.
/// </summary>
/// <remarks>
/// The ETW Provider ID for this event source is {4c4ad4a2-f396-5e18-01b6-618c12a10433}.
/// </remarks>
[EventSource(Name = "DurableTask-AzureStorage")]
class AnalyticsEventSource : EventSource
{
#if NETSTANDARD2_0
static readonly AsyncLocal<Guid> ActivityIdState = new AsyncLocal<Guid>();
#else
const string TraceActivityIdSlot = "TraceActivityId";
#endif
/// <summary>
/// Singleton instance used for writing events.
/// </summary>
public static readonly AnalyticsEventSource Log = new AnalyticsEventSource();
[NonEvent]
public static void SetLogicalTraceActivityId(Guid activityId)
{
#if NETSTANDARD2_0
// We use AsyncLocal to preserve activity IDs across async/await boundaries.
ActivityIdState.Value = activityId;
#else
// We use LogicalSetData to preserve activity IDs across async/await boundaries.
System.Runtime.Remoting.Messaging.CallContext.LogicalSetData(TraceActivityIdSlot, activityId);
#endif
SetCurrentThreadActivityId(activityId);
}
[NonEvent]
private static void EnsureLogicalTraceActivityId()
{
#if NETSTANDARD2_0
Guid currentActivityId = ActivityIdState.Value;
if (currentActivityId != CurrentThreadActivityId)
{
SetCurrentThreadActivityId(currentActivityId);
}
#else
object data = System.Runtime.Remoting.Messaging.CallContext.LogicalGetData(TraceActivityIdSlot);
if (data != null)
{
Guid currentActivityId = (Guid)data;
if (currentActivityId != CurrentThreadActivityId)
{
SetCurrentThreadActivityId(currentActivityId);
}
}
#endif
}
[Event(101, Level = EventLevel.Informational, Opcode = EventOpcode.Send, Task = Tasks.Enqueue, Version = 2)]
public void SendingMessage(
Guid relatedActivityId,
string Account,
string TaskHub,
string EventType,
string InstanceId,
string ExecutionId,
long SizeInBytes,
string PartitionId,
string TargetInstanceId,
string TargetExecutionId,
string ExtensionVersion)
{
EnsureLogicalTraceActivityId();
this.WriteEventWithRelatedActivityId(
101,
relatedActivityId,
Account,
TaskHub,
EventType,
InstanceId ?? string.Empty,
ExecutionId ?? string.Empty,
SizeInBytes,
PartitionId,
TargetInstanceId,
TargetExecutionId ?? string.Empty,
ExtensionVersion);
}
[Event(102, Level = EventLevel.Informational, Opcode = EventOpcode.Receive, Task = Tasks.Dequeue, Version = 2)]
public void ReceivedMessage(
Guid relatedActivityId,
string Account,
string TaskHub,
string EventType,
string InstanceId,
string ExecutionId,
string MessageId,
int Age,
int DequeueCount,
string NextVisibleTime,
long SizeInBytes,
string PartitionId,
string ExtensionVersion)
{
EnsureLogicalTraceActivityId();
this.WriteEventWithRelatedActivityId(
102,
relatedActivityId,
Account,
TaskHub,
EventType,
InstanceId,
ExecutionId ?? string.Empty,
MessageId,
Age,
DequeueCount,
NextVisibleTime,
SizeInBytes,
PartitionId,
ExtensionVersion);
}
[Event(103, Level = EventLevel.Informational, Version = 2)]
public void DeletingMessage(
string Account,
string TaskHub,
string EventType,
string MessageId,
string InstanceId,
string ExecutionId,
string PartitionId,
string ExtensionVersion)
{
EnsureLogicalTraceActivityId();
this.WriteEvent(
103,
Account,
TaskHub,
EventType,
MessageId,
InstanceId,
ExecutionId ?? string.Empty,
PartitionId,
ExtensionVersion);
}
[Event(104, Level = EventLevel.Warning, Message = "Abandoning message of type {2} with ID = {3}. Orchestration ID = {4}.", Version = 2)]
public void AbandoningMessage(
string Account,
string TaskHub,
string EventType,
string MessageId,
string InstanceId,
string ExecutionId,
string PartitionId,
string ExtensionVersion)
{
EnsureLogicalTraceActivityId();
this.WriteEvent(
104,
Account,
TaskHub,
EventType,
MessageId,
InstanceId,
ExecutionId ?? string.Empty,
PartitionId,
ExtensionVersion);
}
[Event(105, Level = EventLevel.Warning, Message = "An unexpected condition was detected: {0}")]
public void AssertFailure(
string Account,
string TaskHub,
string Details,
string ExtensionVersion)
{
EnsureLogicalTraceActivityId();
this.WriteEvent(105, Account, TaskHub, Details, ExtensionVersion);
}
[Event(106, Level = EventLevel.Warning, Version = 2)]
public void MessageGone(
string Account,
string TaskHub,
string MessageId,
string InstanceId,
string ExecutionId,
string PartitionId,
string Details,
string ExtensionVersion)
{
EnsureLogicalTraceActivityId();
this.WriteEvent(106, Account, TaskHub, MessageId, InstanceId, ExecutionId ?? string.Empty, PartitionId, Details, ExtensionVersion);
}
[Event(107, Level = EventLevel.Error)]
public void GeneralError(string Account, string TaskHub, string Details, string ExtensionVersion)
{
EnsureLogicalTraceActivityId();
this.WriteEvent(107, Account, TaskHub, Details, ExtensionVersion);
}
[Event(108, Level = EventLevel.Warning, Message = "A duplicate message was detected. This can indicate a potential performance problem. Message ID = '{2}'. DequeueCount = {3}.")]
public void DuplicateMessageDetected(
string Account,
string TaskHub,
string MessageId,
int DequeueCount,
string ExtensionVersion)
{
EnsureLogicalTraceActivityId();
this.WriteEvent(108, Account, TaskHub, MessageId, DequeueCount, ExtensionVersion);
}
[Event(110, Level = EventLevel.Informational)]
public void FetchedInstanceHistory(
string Account,
string TaskHub,
string InstanceId,
string ExecutionId,
int EventCount,
int RequestCount,
long LatencyMs,
string ETag,
string ExtensionVersion)
{
EnsureLogicalTraceActivityId();
this.WriteEvent(
110,
Account,
TaskHub,
InstanceId,
ExecutionId ?? string.Empty,
EventCount,
RequestCount,
LatencyMs,
ETag ?? string.Empty,
ExtensionVersion);
}
[Event(111, Level = EventLevel.Informational, Version = 2)]
public void AppendedInstanceHistory(
string Account,
string TaskHub,
string InstanceId,
string ExecutionId,
int NewEventCount,
int TotalEventCount,
string NewEvents,
long LatencyMs,
int SizeInBytes,
string ETag,
string ExtensionVersion)
{
EnsureLogicalTraceActivityId();
this.WriteEvent(
111,
Account,
TaskHub,
InstanceId,
ExecutionId ?? string.Empty,
NewEventCount,
TotalEventCount,
NewEvents,
LatencyMs,
SizeInBytes,
ETag ?? string.Empty,
ExtensionVersion);
}
[Event(112, Level = EventLevel.Informational)]
public void OrchestrationServiceStats(
string Account,
string TaskHub,
long StorageRequests,
long MessagesSent,
long MessagesRead,
long MessagesUpdated,
long TableEntitiesWritten,
long TableEntitiesRead,
long PendingOrchestrators,
long PendingOrchestratorMessages,
long ActiveOrchestrators,
long ActiveActivities,
string ExtensionVersion)
{
this.WriteEvent(
112,
Account,
TaskHub,
StorageRequests,
MessagesSent,
MessagesRead,
MessagesUpdated,
TableEntitiesWritten,
TableEntitiesRead,
PendingOrchestrators,
PendingOrchestratorMessages,
ActiveOrchestrators,
ActiveActivities,
ExtensionVersion);
}
[Event(113, Level = EventLevel.Informational)]
public void RenewingMessage(
string Account,
string TaskHub,
string InstanceId,
string ExecutionId,
string PartitionId,
string EventType,
string MessageId,
int VisibilityTimeoutSeconds,
string ExtensionVersion)
{
EnsureLogicalTraceActivityId();
this.WriteEvent(
113,
Account,
TaskHub,
InstanceId,
ExecutionId ?? string.Empty,
PartitionId,
EventType,
MessageId,
VisibilityTimeoutSeconds,
ExtensionVersion);
}
[Event(114, Level = EventLevel.Error)]
public void MessageFailure(
string Account,
string TaskHub,
string InstanceId,
string ExecutionId,
string PartitionId,
string EventType,
string Details,
string ExtensionVersion)
{
EnsureLogicalTraceActivityId();
this.WriteEvent(
114,
Account,
TaskHub,
InstanceId,
ExecutionId ?? string.Empty,
PartitionId,
EventType,
Details,
ExtensionVersion);
}
[Event(115, Level = EventLevel.Error)]
public void TrackingStoreUpdateFailure(
string Account,
string TaskHub,
string InstanceId,
string ExecutionId,
string Details,
string ExtensionVersion)
{
EnsureLogicalTraceActivityId();
this.WriteEvent(
115,
Account,
TaskHub,
InstanceId,
ExecutionId ?? string.Empty,
Details,
ExtensionVersion);
}
[Event(120, Level = EventLevel.Informational)]
public void PartitionManagerInfo(
string Account,
string TaskHub,
string WorkerName,
string Details,
string ExtensionVersion)
{
EnsureLogicalTraceActivityId();
this.WriteEvent(120, Account, TaskHub, WorkerName ?? string.Empty, Details, ExtensionVersion);
}
[Event(121, Level = EventLevel.Warning)]
public void PartitionManagerWarning(
string Account,
string TaskHub,
string WorkerName,
string Details,
string ExtensionVersion)
{
EnsureLogicalTraceActivityId();
this.WriteEvent(121, Account, TaskHub, WorkerName ?? string.Empty, Details ?? string.Empty, ExtensionVersion);
}
[NonEvent]
public void PartitionManagerError(
string account,
string taskHub,
string workerName,
Exception exception,
string ExtensionVersion)
{
this.PartitionManagerError(account, taskHub, workerName, exception.ToString(), ExtensionVersion);
}
[Event(122, Level = EventLevel.Error)]
public void PartitionManagerError(
string Account,
string TaskHub,
string WorkerName,
string Details,
string ExtensionVersion)
{
EnsureLogicalTraceActivityId();
this.WriteEvent(122, Account, TaskHub, WorkerName ?? string.Empty, Details ?? string.Empty, ExtensionVersion);
}
[Event(123, Level = EventLevel.Verbose, Message = "Host '{2}' renewing lease for PartitionId '{3}' with lease token '{4}'.")]
public void StartingLeaseRenewal(
string Account,
string TaskHub,
string WorkerName,
string PartitionId,
string Token,
string ExtensionVersion)
{
EnsureLogicalTraceActivityId();
this.WriteEvent(
123,
Account,
TaskHub,
WorkerName ?? string.Empty,
PartitionId ?? string.Empty,
Token ?? string.Empty,
ExtensionVersion);
}
[Event(124, Level = EventLevel.Verbose)]
public void LeaseRenewalResult(
string Account,
string TaskHub,
string WorkerName,
string PartitionId,
bool Success,
string Token,
string Details,
string ExtensionVersion)
{
EnsureLogicalTraceActivityId();
this.WriteEvent(
124,
Account,
TaskHub,
WorkerName ?? string.Empty,
PartitionId ?? string.Empty,
Success,
Token ?? string.Empty,
Details ?? string.Empty,
ExtensionVersion);
}
[Event(125, Level = EventLevel.Informational)]
public void LeaseRenewalFailed(
string Account,
string TaskHub,
string WorkerName,
string PartitionId,
string Token,
string Details,
string ExtensionVersion)
{
EnsureLogicalTraceActivityId();
this.WriteEvent(
125,
Account,
TaskHub,
WorkerName ?? string.Empty,
PartitionId ?? string.Empty,
Token ?? string.Empty,
Details ?? string.Empty,
ExtensionVersion);
}
[Event(126, Level = EventLevel.Informational, Message = "Host '{2}' attempting to take lease for PartitionId '{3}'.")]
public void LeaseAcquisitionStarted(
string Account,
string TaskHub,
string WorkerName,
string PartitionId,
string ExtensionVersion)
{
EnsureLogicalTraceActivityId();
this.WriteEvent(126, Account, TaskHub, WorkerName ?? string.Empty, PartitionId ?? string.Empty, ExtensionVersion);
}
[Event(127, Level = EventLevel.Informational, Message = "Host '{2}' successfully acquired lease for PartitionId '{3}'.")]
public void LeaseAcquisitionSucceeded(
string Account,
string TaskHub,
string WorkerName,
string PartitionId,
string ExtensionVersion)
{
EnsureLogicalTraceActivityId();
this.WriteEvent(127, Account, TaskHub, WorkerName ?? string.Empty, PartitionId ?? string.Empty, ExtensionVersion);
}
[Event(128, Level = EventLevel.Informational, Message = "Host '{2}' failed to acquire lease for PartitionId '{3}' due to conflict.")]
public void LeaseAcquisitionFailed(
string Account,
string TaskHub,
string WorkerName,
string PartitionId,
string ExtensionVersion)
{
EnsureLogicalTraceActivityId();
this.WriteEvent(128, Account, TaskHub, WorkerName ?? string.Empty, PartitionId ?? string.Empty, ExtensionVersion);
}
[Event(129, Level = EventLevel.Informational, Message = "Host '{2} is attempting to steal a lease from '{3}' for PartitionId '{4}'.")]
public void AttemptingToStealLease(
string Account,
string TaskHub,
string WorkerName,
string FromWorkerName,
string PartitionId,
string ExtensionVersion)
{
EnsureLogicalTraceActivityId();
this.WriteEvent(
129,
Account,
TaskHub,
WorkerName ?? string.Empty,
FromWorkerName ?? string.Empty,
PartitionId ?? string.Empty,
ExtensionVersion);
}
[Event(130, Level = EventLevel.Informational, Message = "Host '{2}' stole lease from '{3}' for PartitionId '{4}'.")]
public void LeaseStealingSucceeded(
string Account,
string TaskHub,
string WorkerName,
string FromWorkerName,
string PartitionId,
string ExtensionVersion)
{
EnsureLogicalTraceActivityId();
this.WriteEvent(
130,
Account,
TaskHub,
WorkerName ?? string.Empty,
FromWorkerName ?? string.Empty,
PartitionId ?? string.Empty,
ExtensionVersion);
}
[Event(131, Level = EventLevel.Informational, Message = "Host '{2}' failed to steal lease for PartitionId '{3}' due to conflict.")]
public void LeaseStealingFailed(
string Account,
string TaskHub,
string WorkerName,
string PartitionId,
string ExtensionVersion)
{
EnsureLogicalTraceActivityId();
this.WriteEvent(131, Account, TaskHub, WorkerName ?? string.Empty, PartitionId ?? string.Empty, ExtensionVersion);
}
[Event(132, Level = EventLevel.Informational, Message = "Host '{2}' successfully removed PartitionId '{3}' with lease token '{4}' from currently owned partitions.")]
public void PartitionRemoved(
string Account,
string TaskHub,
string WorkerName,
string PartitionId,
string Token,
string ExtensionVersion)
{
EnsureLogicalTraceActivityId();
this.WriteEvent(
132,
Account,
TaskHub,
WorkerName ?? string.Empty,
PartitionId ?? string.Empty,
Token ?? string.Empty,
ExtensionVersion);
}
[Event(133, Level = EventLevel.Informational, Message = "Host '{2}' successfully released lease on PartitionId '{3}' with lease token '{4}'")]
public void LeaseRemoved(
string Account,
string TaskHub,
string WorkerName,
string PartitionId,
string Token,
string ExtensionVersion)
{
EnsureLogicalTraceActivityId();
this.WriteEvent(
133,
Account,
TaskHub,
WorkerName ?? string.Empty,
PartitionId ?? string.Empty,
Token ?? string.Empty,
ExtensionVersion);
}
[Event(134, Level = EventLevel.Warning, Message = "Host '{2}' failed to release lease for PartitionId '{3}' with lease token '{4}' due to conflict.")]
public void LeaseRemovalFailed(
string Account,
string TaskHub,
string WorkerName,
string PartitionId,
string Token,
string ExtensionVersion)
{
EnsureLogicalTraceActivityId();
this.WriteEvent(
134,
Account,
TaskHub,
WorkerName ?? string.Empty,
PartitionId ?? string.Empty,
Token ?? string.Empty,
ExtensionVersion);
}
[Event(135, Level = EventLevel.Informational)]
public void InstanceStatusUpdate(
string Account,
string TaskHub,
string InstanceId,
string ExecutionId,
string EventType,
long LatencyMs,
string ExtensionVersion)
{
EnsureLogicalTraceActivityId();
this.WriteEvent(135, Account, TaskHub, InstanceId, ExecutionId ?? string.Empty, EventType, LatencyMs, ExtensionVersion);
}
[Event(136, Level = EventLevel.Informational)]
public void FetchedInstanceStatus(
string Account,
string TaskHub,
string InstanceId,
string ExecutionId,
long LatencyMs,
string ExtensionVersion)
{
EnsureLogicalTraceActivityId();
this.WriteEvent(136, Account, TaskHub, InstanceId, ExecutionId ?? string.Empty, LatencyMs, ExtensionVersion);
}
[Event(137, Level = EventLevel.Warning)]
public void GeneralWarning(string Account, string TaskHub, string Details, string ExtensionVersion)
{
EnsureLogicalTraceActivityId();
this.WriteEvent(137, Account, TaskHub, Details, ExtensionVersion);
}
[Event(138, Level = EventLevel.Warning)]
public void SplitBrainDetected(
string Account,
string TaskHub,
string InstanceId,
string ExecutionId,
int NewEventCount,
int TotalEventCount,
string NewEvents,
long LatencyMs,
string ETag,
string ExtensionVersion)
{
EnsureLogicalTraceActivityId();
this.WriteEvent(
138,
Account,
TaskHub,
InstanceId,
ExecutionId ?? string.Empty,
NewEventCount,
TotalEventCount,
NewEvents,
LatencyMs,
ETag ?? string.Empty,
ExtensionVersion);
}
[Event(139, Level = EventLevel.Warning)]
public void DiscardingWorkItem(
string Account,
string TaskHub,
string InstanceId,
string ExecutionId,
int NewEventCount,
int TotalEventCount,
string NewEvents,
string Details,
string ExtensionVersion)
{
EnsureLogicalTraceActivityId();
this.WriteEvent(
139,
Account,
TaskHub,
InstanceId,
ExecutionId ?? string.Empty,
NewEventCount,
TotalEventCount,
NewEvents,
Details,
ExtensionVersion);
}
[Event(140, Level = EventLevel.Informational, Task = Tasks.Processing, Opcode = EventOpcode.Receive)]
public void ProcessingMessage(
Guid relatedActivityId,
string Account,
string TaskHub,
string EventType,
string InstanceId,
string ExecutionId,
string MessageId,
int Age,
bool IsExtendedSession,
string ExtensionVersion)
{
EnsureLogicalTraceActivityId();
this.WriteEventWithRelatedActivityId(
140,
relatedActivityId,
Account,
TaskHub,
EventType,
InstanceId,
ExecutionId ?? string.Empty,
MessageId,
Age,
IsExtendedSession,
ExtensionVersion);
}
// Specifying tasks is necessary when using WriteEventWithRelatedActivityId
// or else the "TaskName" property written to ETW is the name of the opcode instead
// of the name of the trace method.
static class Tasks
{
public const EventTask Enqueue = (EventTask)0x01;
public const EventTask Dequeue = (EventTask)0x02;
public const EventTask Processing = (EventTask)0x03;
}
}
}