forked from pinpoint-apm/pinpoint-node-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspan-recorder.js
85 lines (71 loc) · 1.8 KB
/
span-recorder.js
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
/**
* Pinpoint Node.js Agent
* Copyright 2020-present NAVER Corp.
* Apache License v2.0
*/
'use strict'
const Annotation = require('./annotation')
const ServiceType = require('./service-type')
const DefaultAnnotationKey = require('../constant/annotation-key').DefaultAnnotationKey
class SpanRecorder {
constructor (span) {
this.span = span
}
recordServiceType (code, ...properties) {
if (this.span && code) {
// this.span.serviceType = new ServiceType(code, properties)
this.span.serviceType = code
}
}
recordApiId (apiId) {
if (this.span && apiId) {
this.span.apiId = apiId
}
}
recordApi (methodDescriptor) {
if (this.span && methodDescriptor) {
if (methodDescriptor.apiId === 0) {
this.recordAttribute(DefaultAnnotationKey.API, methodDescriptor.fullName)
this.recordApiId(0)
} else {
this.recordApiId(methodDescriptor.apiId)
}
}
}
recordAttribute (key, value) {
if (this.span && key && value) {
this.span.annotations.push(new Annotation(key, value))
}
}
recordRpc (rpc) {
if (this.span && rpc) {
(this.span.rpc = rpc)
}
}
recordEndPoint (endPoint) {
if (this.span && endPoint) {
this.span.endPoint = endPoint
}
}
recordRemoteAddr (remoteAddr) {
if (this.span && remoteAddr) {
(this.span.remoteAddr = remoteAddr)
}
}
recordException (error) {
if (this.span && error) {
const metaInfo = StringMetaCache.get(error.name || 'Error')
this.span.exceptionInfo = {
intValue: metaInfo.stringId,
stringValue: error.toString()
}
this.span.err = 1
}
}
recordSpanEvent (spanEvent) {
if (this.span && spanEvent) {
this.span.spanEventList.push(spanEvent)
}
}
}
module.exports = SpanRecorder