8
8
const EventEmitter = require ( 'events' ) . EventEmitter
9
9
const logger = require ( '../logger' ) . child ( { component : 'base_aggregator' } )
10
10
11
+ /**
12
+ * Triggered when the aggregator has finished sending data to the
13
+ * `analytic_event_data` collector endpoint.
14
+ *
15
+ * @event Aggregator#finished_data_send-analytic_event_data
16
+ */
17
+
18
+ /**
19
+ * Triggered when an aggregator is sending data to the `analytic_event_data`
20
+ * collector endpoint.
21
+ *
22
+ * @event Aggregator#starting_data_send-analytic_event_data
23
+ */
24
+
25
+ /**
26
+ * Triggered when the aggregator has finished sending data to the
27
+ * `custom_event_data` collector endpoint.
28
+ *
29
+ * @event Aggregator#finished_data_send-custom_event_data
30
+ */
31
+
32
+ /**
33
+ * Triggered when an aggregator is sending data to the `custom_event_data`
34
+ * collector endpoint.
35
+ *
36
+ * @event Aggregator#starting_data_send-custom_event_data
37
+ */
38
+
39
+ /**
40
+ * Triggered when the aggregator has finished sending data to the
41
+ * `error_data` collector endpoint.
42
+ *
43
+ * @event Aggregator#finished_data_send-error_data
44
+ */
45
+
46
+ /**
47
+ * Triggered when an aggregator is sending data to the `error_data`
48
+ * collector endpoint.
49
+ *
50
+ * @event Aggregator#starting_data_send-error_data
51
+ */
52
+
53
+ /**
54
+ * Triggered when the aggregator has finished sending data to the
55
+ * `error_event_data` collector endpoint.
56
+ *
57
+ * @event Aggregator#finished_data_send-error_event_data
58
+ */
59
+
60
+ /**
61
+ * Triggered when an aggregator is sending data to the `error_event_data`
62
+ * collector endpoint.
63
+ *
64
+ * @event Aggregator#starting_data_send-error_event_data
65
+ */
66
+
67
+ /**
68
+ * Triggered when the aggregator has finished sending data to the
69
+ * `log_event_data` collector endpoint.
70
+ *
71
+ * @event Aggregator#finished_data_send-log_event_data
72
+ */
73
+
74
+ /**
75
+ * Triggered when an aggregator is sending data to the `log_event_data`
76
+ * collector endpoint.
77
+ *
78
+ * @event Aggregator#starting_data_send-log_event_data
79
+ */
80
+
81
+ /**
82
+ * Triggered when the aggregator has finished sending data to the
83
+ * `metric_data` collector endpoint.
84
+ *
85
+ * @event Aggregator#finished_data_send-metric_data
86
+ */
87
+
88
+ /**
89
+ * Triggered when an aggregator is sending data to the `metric_data`
90
+ * collector endpoint.
91
+ *
92
+ * @event Aggregator#starting_data_send-metric_data
93
+ */
94
+
95
+ /**
96
+ * Triggered when the aggregator has finished sending data to the
97
+ * `span_event_data` collector endpoint.
98
+ *
99
+ * @event Aggregator#finished_data_send-span_event_data
100
+ */
101
+
102
+ /**
103
+ * Triggered when an aggregator is sending data to the `span_event_data`
104
+ * collector endpoint.
105
+ *
106
+ * @event Aggregator#starting_data_send-span_event_data
107
+ */
108
+
109
+ /**
110
+ * Triggered when the aggregator has finished sending data to the
111
+ * `sql_trace_data` collector endpoint.
112
+ *
113
+ * @event Aggregator#finished_data_send-sql_trace_data
114
+ */
115
+
116
+ /**
117
+ * Triggered when an aggregator is sending data to the `sql_trace_data`
118
+ * collector endpoint.
119
+ *
120
+ * @event Aggregator#starting_data_send-sql_trace_data
121
+ */
122
+
123
+ /**
124
+ * Triggered when the aggregator has finished sending data to the
125
+ * `transaction_sample_data` collector endpoint.
126
+ *
127
+ * @event Aggregator#finished_data_send-transaction_sample_data
128
+ */
129
+
130
+ /**
131
+ * Triggered when an aggregator is sending data to the `transaction_sample_data`
132
+ * collector endpoint.
133
+ *
134
+ * @event Aggregator#starting_data_send-transaction_sample_data
135
+ */
136
+
137
+ /**
138
+ * Baseline data aggregator that is used to ship data to the New Relic
139
+ * data collector. Specific data aggregators, e.g. an errors aggregator,
140
+ * extend this base object.
141
+ *
142
+ * Aggregators fire of several events. The events are named according to the
143
+ * pattern `<finished|starting>_data_send-<endpoint_name>`. As an example,
144
+ * if the aggregator is collecting data to send to the `error_event_data`
145
+ * endpoint, there will be two events:
146
+ *
147
+ * + `starting_data_send-error_event_data`
148
+ * + `finished_data_send-error_event_data`
149
+ *
150
+ * For a list of possible endpoints, see
151
+ * {@link https://source.datanerd.us/agents/agent-specs/tree/main/endpoints/protocol-version-17}.
152
+ *
153
+ * Note: effort has been made to document the events for every endpoint this
154
+ * agent interacts with, but due to the dynamic nature of the event names we
155
+ * may have missed some.
156
+ */
11
157
class Aggregator extends EventEmitter {
12
158
constructor ( opts , collector , harvester ) {
13
159
super ( )
@@ -23,6 +169,16 @@ class Aggregator extends EventEmitter {
23
169
return true
24
170
}
25
171
this . enabled = this . isEnabled ( opts . config )
172
+
173
+ /**
174
+ * The name of the collector endpoint that the
175
+ * aggregator will communicate with.
176
+ *
177
+ * @see https://source.datanerd.us/agents/agent-specs/tree/main/endpoints/protocol-version-17
178
+ *
179
+ * @type {string }
180
+ * @memberof Aggregator
181
+ */
26
182
this . method = opts . method
27
183
this . collector = collector
28
184
this . sendTimer = null
@@ -90,7 +246,7 @@ class Aggregator extends EventEmitter {
90
246
_runSend ( data , payload ) {
91
247
if ( ! payload ) {
92
248
this . _afterSend ( false )
93
- this . emit ( `finished ${ this . method } data send. ` )
249
+ this . emit ( `finished_data_send- ${ this . method } ` )
94
250
return
95
251
}
96
252
@@ -102,13 +258,36 @@ class Aggregator extends EventEmitter {
102
258
103
259
// TODO: Log?
104
260
this . _afterSend ( true )
105
- this . emit ( `finished ${ this . method } data send. ` )
261
+ this . emit ( `finished_data_send- ${ this . method } ` )
106
262
} )
107
263
}
108
264
265
+ /**
266
+ * Serialize all collected data and ship it off to the New Relic data
267
+ * collector. The target endpoint is defined by {@link Aggregator#method}.
268
+ *
269
+ * @fires Aggregator#finished_data_send-analytic_event_data
270
+ * @fires Aggregator#starting_data_send-analytic_event_data
271
+ * @fires Aggregator#finished_data_send-custom_event_data
272
+ * @fires Aggregator#starting_data_send-custom_event_data
273
+ * @fires Aggregator#finished_data_send-error_data
274
+ * @fires Aggregator#starting_data_send-error_data
275
+ * @fires Aggregator#finished_data_send-error_event_data
276
+ * @fires Aggregator#starting_data_send-error_event_data
277
+ * @fires Aggregator#finished_data_send-log_event_data
278
+ * @fires Aggregator#starting_data_send-log_event_data
279
+ * @fires Aggregator#finished_data_send-metric_data
280
+ * @fires Aggregator#starting_data_send-metric_data
281
+ * @fires Aggregator#finished_data_send-span_event_data
282
+ * @fires Aggregator#starting_data_send-span_event_data
283
+ * @fires Aggregator#finished_data_send-sql_trace_data
284
+ * @fires Aggregator#starting_data_send-sql_trace_data
285
+ * @fires Aggregator#finished_data_send-transaction_sample_data
286
+ * @fires Aggregator#starting_data_send-transaction_sample_data
287
+ */
109
288
send ( ) {
110
289
logger . debug ( `${ this . method } Aggregator data send.` )
111
- this . emit ( `starting ${ this . method } data send. ` )
290
+ this . emit ( `starting_data_send- ${ this . method } ` )
112
291
113
292
const data = this . _getMergeData ( )
114
293
if ( this . isAsync ) {
0 commit comments