forked from pinpoint-apm/pinpoint-node-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data-sender.js
72 lines (61 loc) · 1.64 KB
/
data-sender.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
/**
* Pinpoint Node.js Agent
* Copyright 2020-present NAVER Corp.
* Apache License v2.0
*/
'use strict'
const log = require('../utils/logger')
const AgentInfo = require('../data/dto/agent-info')
const ApiMetaInfo = require('../data/dto/api-meta-info')
const StringMetaInfo = require('../data/dto/string-meta-info')
const Span = require('../context/span')
const SpanChunk = require('../context/span-chunk')
class DataSender {
constructor(config, dataSender) {
this.enabledDataSending = config.enabledDataSending
this.dataSender = dataSender
}
send(data) {
try {
if (data && this.enabledDataSending) {
this.sendByDataType(data)
}
} catch (error) {
if (error) {
log.error(`error: ${error}`)
}
}
}
sendByDataType(data) {
if (data instanceof AgentInfo) {
this.dataSender.sendAgentInfo(data)
} else if (data instanceof ApiMetaInfo) {
this.dataSender.sendApiMetaInfo(data)
} else if (data instanceof StringMetaInfo) {
this.dataSender.sendStringMetaInfo(data)
} else if (data instanceof Span) {
this.dataSender.sendSpan(data)
} else if (data instanceof SpanChunk) {
this.dataSender.sendSpanChunk(data)
}
}
sendControlHandshake(params) {
if (this.enabledDataSending) {
this.dataSender.sendControlHandshake(params)
}
}
sendPing() {
if (this.enabledDataSending) {
this.dataSender.sendPing()
}
}
sendStat(stats) {
if (this.enabledDataSending) {
this.dataSender.sendStat(stats)
}
}
// TODO Remove it after implementing grpc
sendActiveThreadCountRes() {
}
}
module.exports = DataSender