@@ -33,6 +33,26 @@ import {
33
33
trace ,
34
34
ValueType ,
35
35
} from '@opentelemetry/api' ;
36
+ import {
37
+ hrTime ,
38
+ hrTimeDuration ,
39
+ hrTimeToMilliseconds ,
40
+ } from '@opentelemetry/core' ;
41
+ import {
42
+ ATTR_ERROR_TYPE ,
43
+ ATTR_HTTP_REQUEST_METHOD ,
44
+ ATTR_HTTP_REQUEST_METHOD_ORIGINAL ,
45
+ ATTR_HTTP_RESPONSE_STATUS_CODE ,
46
+ ATTR_NETWORK_PEER_ADDRESS ,
47
+ ATTR_NETWORK_PEER_PORT ,
48
+ ATTR_SERVER_ADDRESS ,
49
+ ATTR_SERVER_PORT ,
50
+ ATTR_URL_FULL ,
51
+ ATTR_URL_PATH ,
52
+ ATTR_URL_QUERY ,
53
+ ATTR_URL_SCHEME ,
54
+ ATTR_USER_AGENT_ORIGINAL ,
55
+ } from '@opentelemetry/semantic-conventions' ;
36
56
37
57
/** @knipignore */
38
58
import { PACKAGE_NAME , PACKAGE_VERSION } from './version' ;
@@ -45,12 +65,6 @@ import {
45
65
ResponseHeadersMessage ,
46
66
} from './internal-types' ;
47
67
import { UndiciInstrumentationConfig , UndiciRequest } from './types' ;
48
- import { SemanticAttributes } from './enums/SemanticAttributes' ;
49
- import {
50
- hrTime ,
51
- hrTimeDuration ,
52
- hrTimeToMilliseconds ,
53
- } from '@opentelemetry/core' ;
54
68
55
69
interface InstrumentationRecord {
56
70
span : Span ;
@@ -244,21 +258,21 @@ export class UndiciInstrumentation extends InstrumentationBase<UndiciInstrumenta
244
258
const urlScheme = requestUrl . protocol . replace ( ':' , '' ) ;
245
259
const requestMethod = this . getRequestMethod ( request . method ) ;
246
260
const attributes : Attributes = {
247
- [ SemanticAttributes . HTTP_REQUEST_METHOD ] : requestMethod ,
248
- [ SemanticAttributes . HTTP_REQUEST_METHOD_ORIGINAL ] : request . method ,
249
- [ SemanticAttributes . URL_FULL ] : requestUrl . toString ( ) ,
250
- [ SemanticAttributes . URL_PATH ] : requestUrl . pathname ,
251
- [ SemanticAttributes . URL_QUERY ] : requestUrl . search ,
252
- [ SemanticAttributes . URL_SCHEME ] : urlScheme ,
261
+ [ ATTR_HTTP_REQUEST_METHOD ] : requestMethod ,
262
+ [ ATTR_HTTP_REQUEST_METHOD_ORIGINAL ] : request . method ,
263
+ [ ATTR_URL_FULL ] : requestUrl . toString ( ) ,
264
+ [ ATTR_URL_PATH ] : requestUrl . pathname ,
265
+ [ ATTR_URL_QUERY ] : requestUrl . search ,
266
+ [ ATTR_URL_SCHEME ] : urlScheme ,
253
267
} ;
254
268
255
269
const schemePorts : Record < string , string > = { https : '443' , http : '80' } ;
256
270
const serverAddress = requestUrl . hostname ;
257
271
const serverPort = requestUrl . port || schemePorts [ urlScheme ] ;
258
272
259
- attributes [ SemanticAttributes . SERVER_ADDRESS ] = serverAddress ;
273
+ attributes [ ATTR_SERVER_ADDRESS ] = serverAddress ;
260
274
if ( serverPort && ! isNaN ( Number ( serverPort ) ) ) {
261
- attributes [ SemanticAttributes . SERVER_PORT ] = Number ( serverPort ) ;
275
+ attributes [ ATTR_SERVER_PORT ] = Number ( serverPort ) ;
262
276
}
263
277
264
278
// Get user agent from headers
@@ -272,7 +286,7 @@ export class UndiciInstrumentation extends InstrumentationBase<UndiciInstrumenta
272
286
const userAgent = Array . isArray ( userAgentValues )
273
287
? userAgentValues [ userAgentValues . length - 1 ]
274
288
: userAgentValues ;
275
- attributes [ SemanticAttributes . USER_AGENT_ORIGINAL ] = userAgent ;
289
+ attributes [ ATTR_USER_AGENT_ORIGINAL ] = userAgent ;
276
290
}
277
291
278
292
// Get attributes from the hook if present
@@ -355,8 +369,8 @@ export class UndiciInstrumentation extends InstrumentationBase<UndiciInstrumenta
355
369
const { span } = record ;
356
370
const { remoteAddress, remotePort } = socket ;
357
371
const spanAttributes : Attributes = {
358
- [ SemanticAttributes . NETWORK_PEER_ADDRESS ] : remoteAddress ,
359
- [ SemanticAttributes . NETWORK_PEER_PORT ] : remotePort ,
372
+ [ ATTR_NETWORK_PEER_ADDRESS ] : remoteAddress ,
373
+ [ ATTR_NETWORK_PEER_PORT ] : remotePort ,
360
374
} ;
361
375
362
376
// After hooks have been processed (which may modify request headers)
@@ -393,7 +407,7 @@ export class UndiciInstrumentation extends InstrumentationBase<UndiciInstrumenta
393
407
394
408
const { span, attributes } = record ;
395
409
const spanAttributes : Attributes = {
396
- [ SemanticAttributes . HTTP_RESPONSE_STATUS_CODE ] : response . statusCode ,
410
+ [ ATTR_HTTP_RESPONSE_STATUS_CODE ] : response . statusCode ,
397
411
} ;
398
412
399
413
const config = this . getConfig ( ) ;
@@ -487,7 +501,7 @@ export class UndiciInstrumentation extends InstrumentationBase<UndiciInstrumenta
487
501
this . _recordFromReq . delete ( request ) ;
488
502
489
503
// Record metrics (with the error)
490
- attributes [ SemanticAttributes . ERROR_TYPE ] = error . message ;
504
+ attributes [ ATTR_ERROR_TYPE ] = error . message ;
491
505
this . recordRequestDuration ( attributes , startTime ) ;
492
506
}
493
507
@@ -496,12 +510,12 @@ export class UndiciInstrumentation extends InstrumentationBase<UndiciInstrumenta
496
510
const metricsAttributes : Attributes = { } ;
497
511
// Get the attribs already in span attributes
498
512
const keysToCopy = [
499
- SemanticAttributes . HTTP_RESPONSE_STATUS_CODE ,
500
- SemanticAttributes . HTTP_REQUEST_METHOD ,
501
- SemanticAttributes . SERVER_ADDRESS ,
502
- SemanticAttributes . SERVER_PORT ,
503
- SemanticAttributes . URL_SCHEME ,
504
- SemanticAttributes . ERROR_TYPE ,
513
+ ATTR_HTTP_RESPONSE_STATUS_CODE ,
514
+ ATTR_HTTP_REQUEST_METHOD ,
515
+ ATTR_SERVER_ADDRESS ,
516
+ ATTR_SERVER_PORT ,
517
+ ATTR_URL_SCHEME ,
518
+ ATTR_ERROR_TYPE ,
505
519
] ;
506
520
keysToCopy . forEach ( key => {
507
521
if ( key in attributes ) {
0 commit comments