File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Load Diff This file was deleted.
Original file line number Diff line number Diff line change 55
66'use strict' ;
77
8- const log = require ( './log' ) ;
9-
108const pidStore = require ( '../pidStore/internalPidStore' ) ;
119
12- /** @type {NodeJS.WritableStream } */
10+ /** @type {import('../agentConnection') } */
11+ let downstreamConnection ;
12+
13+ /** @type {NodeJS.WritableStream & {
14+ * setDownstreamConnection: (downstreamConnection: import('../agentConnection')) => void
15+ * }} */
1316module . exports = {
1417 /**
1518 * @param {* } record
@@ -30,7 +33,14 @@ module.exports = {
3033 stack = record . err . stack ;
3134 }
3235
33- log ( logLevel , message , stack ) ;
36+ downstreamConnection . sendLogToAgent ( logLevel , message , stack ) ;
37+ } ,
38+
39+ /**
40+ * @param {import('../agentConnection') } _downstreamConnection
41+ */
42+ setDownstreamConnection : _downstreamConnection => {
43+ downstreamConnection = _downstreamConnection ;
3444 }
3545} ;
3646
Original file line number Diff line number Diff line change @@ -216,6 +216,52 @@ exports.checkWhetherAgentIsReadyToAcceptData = function checkWhetherAgentIsReady
216216 checkWhetherResponseForPathIsOkay ( `/com.instana.plugin.nodejs.${ pidStore . pid } ` , cb ) ;
217217} ;
218218
219+ /**
220+ * @param {* } logLevel
221+ * @param {* } message
222+ * @param {* } stackTrace
223+ */
224+ exports . sendLogToAgent = function sendLogToAgent ( logLevel , message , stackTrace ) {
225+ /** @type {{m: string, st?: string} } */
226+ const payloadObject = {
227+ m : message . trim ( )
228+ } ;
229+
230+ if ( stackTrace ) {
231+ payloadObject . st = stackTrace . trim ( ) ;
232+ }
233+
234+ const payload = Buffer . from ( JSON . stringify ( payloadObject ) , 'utf8' ) ;
235+
236+ const req = http . request (
237+ {
238+ host : agentOpts . host ,
239+ port : agentOpts . port ,
240+ path : '/com.instana.agent.logger' ,
241+ method : 'POST' ,
242+ agent : http . agent ,
243+ headers : {
244+ 'Content-Type' : 'application/json; charset=UTF-8' ,
245+ 'Content-Length' : payload . length ,
246+ 'x-log-level' : logLevel
247+ }
248+ } ,
249+ res => {
250+ res . resume ( ) ;
251+ }
252+ ) ;
253+
254+ function swallow ( ) {
255+ // swallow all errors
256+ }
257+
258+ req . setTimeout ( agentOpts . requestTimeout , swallow ) ;
259+ req . on ( 'error' , swallow ) ;
260+
261+ req . write ( payload ) ;
262+ req . end ( ) ;
263+ } ;
264+
219265/**
220266 * @param {string } path
221267 * @param {(...args: *) => * } cb
Original file line number Diff line number Diff line change @@ -113,6 +113,8 @@ function init(userConfig = {}) {
113113 const announceCycle = require ( './announceCycle' ) ;
114114 const metrics = require ( './metrics' ) ;
115115
116+ log . setDownstreamConnection ( agentConnection ) ;
117+
116118 pidStore . init ( config ) ;
117119 agentOpts . init ( config ) ;
118120 announceCycle . init ( config , pidStore ) ;
Original file line number Diff line number Diff line change @@ -158,6 +158,14 @@ exports.init = function init(userConfig = {}) {
158158
159159exports . getLogger = ( ) => instanaLogger ;
160160
161+ /**
162+ *
163+ * @param {import('./agentConnection') } downstreamConnection
164+ */
165+ exports . setDownstreamConnection = downstreamConnection => {
166+ loggerToAgentStream . setDownstreamConnection ( downstreamConnection ) ;
167+ } ;
168+
161169/**
162170 * @param {import('@instana/core/src/core').GenericLogger | * } _logger
163171 * @returns {boolean }
You can’t perform that action at this time.
0 commit comments