@@ -10,17 +10,7 @@ const { truncate } = require('../util/byte-limit')
10
10
const Config = require ( '../config' )
11
11
12
12
const { DESTINATIONS } = require ( '../config/attribute-filter' )
13
-
14
- const HTTP_LIBRARY = 'http'
15
- const CLIENT_KIND = 'client'
16
- const CATEGORIES = {
17
- HTTP : 'http' ,
18
- DATASTORE : 'datastore' ,
19
- GENERIC : 'generic'
20
- }
21
-
22
- const EXTERNAL_REGEX = / ^ (?: T r u n c a t e d \/ ) ? E x t e r n a l \/ /
23
- const DATASTORE_REGEX = / ^ (?: T r u n c a t e d \/ ) ? D a t a s t o r e \/ /
13
+ const { addSpanKind, HTTP_LIBRARY , REGEXS , SPAN_KIND , CATEGORIES } = require ( './helpers' )
24
14
25
15
/**
26
16
* Specialized span event class for use with infinite streaming.
@@ -59,7 +49,7 @@ class StreamingSpanEvent {
59
49
}
60
50
61
51
/**
62
- * Add a key/value pair to the Span's instrinisics collection.
52
+ * Add a key/value pair to the Span's intrinsics collection.
63
53
*
64
54
* @param {string } key Name of the attribute to be stored.
65
55
* @param {string|boolean|number } value Value of the attribute to be stored.
@@ -68,6 +58,10 @@ class StreamingSpanEvent {
68
58
this . _intrinsicAttributes . addAttribute ( key , value )
69
59
}
70
60
61
+ getIntrinsicAttributes ( ) {
62
+ return this . _intrinsicAttributes
63
+ }
64
+
71
65
/**
72
66
* Add a key/value pair to the Span's custom/user attributes collection.
73
67
*
@@ -169,6 +163,7 @@ class StreamingSpanEvent {
169
163
// Timestamp in milliseconds, duration in seconds. Yay consistency!
170
164
span . addIntrinsicAttribute ( 'timestamp' , segment . timer . start )
171
165
span . addIntrinsicAttribute ( 'duration' , segment . timer . getDurationInMillis ( ) / 1000 )
166
+ addSpanKind ( { segment, span } )
172
167
173
168
return span
174
169
}
@@ -196,7 +191,7 @@ class StreamingHttpSpanEvent extends StreamingSpanEvent {
196
191
197
192
this . addIntrinsicAttribute ( 'category' , CATEGORIES . HTTP )
198
193
this . addIntrinsicAttribute ( 'component' , library || HTTP_LIBRARY )
199
- this . addIntrinsicAttribute ( 'span.kind' , CLIENT_KIND )
194
+ this . addIntrinsicAttribute ( 'span.kind' , SPAN_KIND . CLIENT )
200
195
201
196
if ( url ) {
202
197
this . addAgentAttribute ( 'http.url' , url )
@@ -213,7 +208,7 @@ class StreamingHttpSpanEvent extends StreamingSpanEvent {
213
208
}
214
209
215
210
static isHttpSegment ( segment ) {
216
- return EXTERNAL_REGEX . test ( segment . name )
211
+ return REGEXS . CLIENT . EXTERNAL . test ( segment . name )
217
212
}
218
213
}
219
214
@@ -248,7 +243,7 @@ class StreamingDatastoreSpanEvent extends StreamingSpanEvent {
248
243
super ( traceId , agentAttrs , customAttributes )
249
244
250
245
this . addIntrinsicAttribute ( 'category' , CATEGORIES . DATASTORE )
251
- this . addIntrinsicAttribute ( 'span.kind' , CLIENT_KIND )
246
+ this . addIntrinsicAttribute ( 'span.kind' , SPAN_KIND . CLIENT )
252
247
253
248
if ( product ) {
254
249
this . addIntrinsicAttribute ( 'component' , product )
@@ -288,7 +283,7 @@ class StreamingDatastoreSpanEvent extends StreamingSpanEvent {
288
283
/* eslint-enable camelcase */
289
284
290
285
static isDatastoreSegment ( segment ) {
291
- return DATASTORE_REGEX . test ( segment . name )
286
+ return REGEXS . CLIENT . DATASTORE . test ( segment . name )
292
287
}
293
288
}
294
289
0 commit comments