@@ -24,6 +24,9 @@ type Telemetry interface {
24
24
// Gets the time when this item was measured
25
25
Time () time.Time
26
26
27
+ // Sets the timestamp to the specified time.
28
+ SetTime (time.Time )
29
+
27
30
// Gets context data containing extra, optional tags. Overrides
28
31
// values found on client TelemetryContext.
29
32
ContextTags () map [string ]string
@@ -39,26 +42,40 @@ type Telemetry interface {
39
42
GetMeasurements () map [string ]float64
40
43
}
41
44
42
- // Common base struct for telemetry items.
45
+ // BaseTelemetry is the common base struct for telemetry items.
43
46
type BaseTelemetry struct {
44
47
// The time this when this item was measured
45
48
Timestamp time.Time
46
49
47
50
// Custom properties
48
51
Properties map [string ]string
49
52
53
+ // Telemetry Context containing extra, optional tags.
54
+ Tags contracts.ContextTags
55
+ }
56
+
57
+ // BaseTelemetryMeasurements provides the Measurements field for telemetry
58
+ // items that support it.
59
+ type BaseTelemetryMeasurements struct {
50
60
// Custom measurements
51
61
Measurements map [string ]float64
62
+ }
52
63
53
- // Telemetry Context containing extra, optional tags.
54
- Tags contracts.ContextTags
64
+ // BaseTelemetryNoMeasurements provides no Measurements field for telemetry
65
+ // items that omit it.
66
+ type BaseTelemetryNoMeasurements struct {
55
67
}
56
68
57
- // Gets the time when this item was measured
69
+ // Time returns the timestamp when this was measured.
58
70
func (item * BaseTelemetry ) Time () time.Time {
59
71
return item .Timestamp
60
72
}
61
73
74
+ // SetTime sets the timestamp to the specified time.
75
+ func (item * BaseTelemetry ) SetTime (t time.Time ) {
76
+ item .Timestamp = t
77
+ }
78
+
62
79
// Gets context data containing extra, optional tags. Overrides values
63
80
// found on client TelemetryContext.
64
81
func (item * BaseTelemetry ) ContextTags () map [string ]string {
@@ -71,14 +88,20 @@ func (item *BaseTelemetry) GetProperties() map[string]string {
71
88
}
72
89
73
90
// Gets custom measurements to submit with the telemetry item.
74
- func (item * BaseTelemetry ) GetMeasurements () map [string ]float64 {
91
+ func (item * BaseTelemetryMeasurements ) GetMeasurements () map [string ]float64 {
75
92
return item .Measurements
76
93
}
77
94
95
+ // GetMeasurements returns nil for telemetry items that do not support measurements.
96
+ func (item * BaseTelemetryNoMeasurements ) GetMeasurements () map [string ]float64 {
97
+ return nil
98
+ }
99
+
78
100
// Trace telemetry items represent printf-like trace statements that can be
79
101
// text searched.
80
102
type TraceTelemetry struct {
81
103
BaseTelemetry
104
+ BaseTelemetryNoMeasurements
82
105
83
106
// Trace message
84
107
Message string
@@ -113,6 +136,7 @@ func (trace *TraceTelemetry) TelemetryData() TelemetryData {
113
136
// Event telemetry items represent structured event records.
114
137
type EventTelemetry struct {
115
138
BaseTelemetry
139
+ BaseTelemetryMeasurements
116
140
117
141
// Event name
118
142
Name string
@@ -123,9 +147,11 @@ func NewEventTelemetry(name string) *EventTelemetry {
123
147
return & EventTelemetry {
124
148
Name : name ,
125
149
BaseTelemetry : BaseTelemetry {
126
- Timestamp : currentClock .Now (),
127
- Tags : make (contracts.ContextTags ),
128
- Properties : make (map [string ]string ),
150
+ Timestamp : currentClock .Now (),
151
+ Tags : make (contracts.ContextTags ),
152
+ Properties : make (map [string ]string ),
153
+ },
154
+ BaseTelemetryMeasurements : BaseTelemetryMeasurements {
129
155
Measurements : make (map [string ]float64 ),
130
156
},
131
157
}
@@ -143,6 +169,7 @@ func (event *EventTelemetry) TelemetryData() TelemetryData {
143
169
// Metric telemetry items each represent a single data point.
144
170
type MetricTelemetry struct {
145
171
BaseTelemetry
172
+ BaseTelemetryNoMeasurements
146
173
147
174
// Metric name
148
175
Name string
@@ -183,6 +210,7 @@ func (metric *MetricTelemetry) TelemetryData() TelemetryData {
183
210
// function.
184
211
type AggregateMetricTelemetry struct {
185
212
BaseTelemetry
213
+ BaseTelemetryNoMeasurements
186
214
187
215
// Metric name
188
216
Name string
@@ -323,6 +351,7 @@ func (agg *AggregateMetricTelemetry) TelemetryData() TelemetryData {
323
351
// application and contains a summary of that request execution and results.
324
352
type RequestTelemetry struct {
325
353
BaseTelemetry
354
+ BaseTelemetryMeasurements
326
355
327
356
// Identifier of a request call instance. Used for correlation between request
328
357
// and other telemetry items.
@@ -384,9 +413,11 @@ func NewRequestTelemetry(method, uri string, duration time.Duration, responseCod
384
413
ResponseCode : responseCode ,
385
414
Success : success ,
386
415
BaseTelemetry : BaseTelemetry {
387
- Timestamp : currentClock .Now ().Add (- duration ),
388
- Tags : make (contracts.ContextTags ),
389
- Properties : make (map [string ]string ),
416
+ Timestamp : currentClock .Now ().Add (- duration ),
417
+ Tags : make (contracts.ContextTags ),
418
+ Properties : make (map [string ]string ),
419
+ },
420
+ BaseTelemetryMeasurements : BaseTelemetryMeasurements {
390
421
Measurements : make (map [string ]float64 ),
391
422
},
392
423
}
@@ -423,6 +454,7 @@ func (request *RequestTelemetry) TelemetryData() TelemetryData {
423
454
// component with a remote component/service like SQL or an HTTP endpoint.
424
455
type RemoteDependencyTelemetry struct {
425
456
BaseTelemetry
457
+ BaseTelemetryMeasurements
426
458
427
459
// Name of the command that initiated this dependency call. Low cardinality
428
460
// value. Examples are stored procedure name and URL path template.
@@ -463,9 +495,11 @@ func NewRemoteDependencyTelemetry(name, dependencyType, target string, success b
463
495
Target : target ,
464
496
Success : success ,
465
497
BaseTelemetry : BaseTelemetry {
466
- Timestamp : currentClock .Now (),
467
- Tags : make (contracts.ContextTags ),
468
- Properties : make (map [string ]string ),
498
+ Timestamp : currentClock .Now (),
499
+ Tags : make (contracts.ContextTags ),
500
+ Properties : make (map [string ]string ),
501
+ },
502
+ BaseTelemetryMeasurements : BaseTelemetryMeasurements {
469
503
Measurements : make (map [string ]float64 ),
470
504
},
471
505
}
@@ -498,6 +532,7 @@ func (telem *RemoteDependencyTelemetry) TelemetryData() TelemetryData {
498
532
// test.
499
533
type AvailabilityTelemetry struct {
500
534
BaseTelemetry
535
+ BaseTelemetryMeasurements
501
536
502
537
// Identifier of a test run. Used to correlate steps of test run and
503
538
// telemetry generated by the service.
@@ -527,9 +562,11 @@ func NewAvailabilityTelemetry(name string, duration time.Duration, success bool)
527
562
Duration : duration ,
528
563
Success : success ,
529
564
BaseTelemetry : BaseTelemetry {
530
- Timestamp : currentClock .Now (),
531
- Tags : make (contracts.ContextTags ),
532
- Properties : make (map [string ]string ),
565
+ Timestamp : currentClock .Now (),
566
+ Tags : make (contracts.ContextTags ),
567
+ Properties : make (map [string ]string ),
568
+ },
569
+ BaseTelemetryMeasurements : BaseTelemetryMeasurements {
533
570
Measurements : make (map [string ]float64 ),
534
571
},
535
572
}
@@ -560,6 +597,7 @@ func (telem *AvailabilityTelemetry) TelemetryData() TelemetryData {
560
597
// click.
561
598
type PageViewTelemetry struct {
562
599
BaseTelemetry
600
+ BaseTelemetryMeasurements
563
601
564
602
// Request URL with all query string parameters
565
603
Url string
@@ -577,9 +615,11 @@ func NewPageViewTelemetry(name, url string) *PageViewTelemetry {
577
615
Name : name ,
578
616
Url : url ,
579
617
BaseTelemetry : BaseTelemetry {
580
- Timestamp : currentClock .Now (),
581
- Tags : make (contracts.ContextTags ),
582
- Properties : make (map [string ]string ),
618
+ Timestamp : currentClock .Now (),
619
+ Tags : make (contracts.ContextTags ),
620
+ Properties : make (map [string ]string ),
621
+ },
622
+ BaseTelemetryMeasurements : BaseTelemetryMeasurements {
583
623
Measurements : make (map [string ]float64 ),
584
624
},
585
625
}
0 commit comments