@@ -17,6 +17,8 @@ function CollectorApi (options) {
1717 this . COLLECTOR_API_INCOMING_EDGE_METRICS = url . resolve ( options . collectorApiUrl , options . collectorApiIncomingEdgeMetricsEndpoint )
1818 this . COLLECTOR_API_EXTERNAL_EDGE_METRICS = url . resolve ( options . collectorApiUrl , options . collectorApiExternalEdgeMetricsEndpoint )
1919 this . COLLECTOR_API_HEALTHCHECK = url . resolve ( options . collectorApiUrl , options . collectorApiHealthcheckEndpoint )
20+ this . COLLECTOR_API_PROFILER_MEMORY_HEAPDUMP = url . resolve ( options . collectorApiUrl , options . collectorApiProfilerMemoryHeapdumpEndpoint )
21+ this . COLLECTOR_API_CONTROL = url . resolve ( options . collectorApiUrl , options . collectorApiControlEndpoint )
2022
2123 this . collectorLanguage = options . collectorLanguage
2224 this . apiKey = options . apiKey
@@ -48,10 +50,12 @@ CollectorApi.prototype._withInstanceInfo = function (data) {
4850 } , data )
4951}
5052
51- CollectorApi . prototype . _send = function ( destinationUrl , data ) {
53+ CollectorApi . prototype . _send = function ( destinationUrl , data , callback ) {
5254 var opts = url . parse ( destinationUrl )
5355 var payload = JSON . stringify ( data )
5456
57+ callback = callback || function ( ) { }
58+
5559 var req = https . request ( {
5660 hostname : opts . hostname ,
5761 port : opts . port ,
@@ -66,12 +70,13 @@ CollectorApi.prototype._send = function (destinationUrl, data) {
6670 }
6771 } , function ( res ) {
6872 res . setEncoding ( 'utf8' )
69- res . pipe ( bl ( function ( err ) {
73+ res . pipe ( bl ( function ( err , result ) {
7074 if ( err ) {
7175 debug ( 'There was an error when connecting to the Trace API' , err )
7276 return
7377 }
7478
79+ callback ( null , result )
7580 debug ( 'HTTP Traces sent successfully' )
7681 } ) )
7782 } )
@@ -81,6 +86,7 @@ CollectorApi.prototype._send = function (destinationUrl, data) {
8186 req . on ( 'error' , function ( error ) {
8287 console . error ( 'error: [trace]' , 'There was an error connecting to the Trace servers. Make sure your servers can reach' , opts . hostname )
8388 debug ( 'error connecting to the Trace servers' , error )
89+ callback ( error )
8490 } )
8591 req . write ( payload )
8692 req . end ( )
@@ -116,6 +122,16 @@ CollectorApi.prototype.sendApmMetrics = function (data) {
116122 this . _send ( url , this . _withInstanceInfo ( data ) )
117123}
118124
125+ CollectorApi . prototype . sendMemorySnapshot = function ( data ) {
126+ if ( ! isNumber ( this . serviceKey ) ) {
127+ debug ( 'Service id not present, cannot send heapdump' )
128+ return
129+ }
130+
131+ var url = util . format ( this . COLLECTOR_API_PROFILER_MEMORY_HEAPDUMP , this . serviceKey )
132+ this . _send ( url , this . _withInstanceInfo ( data ) )
133+ }
134+
119135CollectorApi . prototype . sendExternalEdgeMetrics = function ( data ) {
120136 if ( ! isNumber ( this . serviceKey ) ) {
121137 debug ( 'Service id not present, cannot send metrics' )
@@ -139,6 +155,29 @@ CollectorApi.prototype.sendIncomingEdgeMetrics = function (data) {
139155 } ) )
140156}
141157
158+ CollectorApi . prototype . getUpdates = function ( data , callback ) {
159+ if ( ! isNumber ( this . serviceKey ) ) {
160+ debug ( 'Service id not present, cannot get updates' )
161+ return
162+ }
163+
164+ var url = util . format ( this . COLLECTOR_API_CONTROL , this . serviceKey )
165+
166+ this . _send ( url , this . _withInstanceInfo ( {
167+ latestCommandId : data . latestCommandId
168+ } ) , function ( err , response ) {
169+ if ( err ) {
170+ return callback ( err )
171+ }
172+
173+ try {
174+ callback ( null , JSON . parse ( response . toString ( 'utf8' ) ) )
175+ } catch ( ex ) {
176+ return callback ( ex )
177+ }
178+ } )
179+ }
180+
142181CollectorApi . prototype . sendSamples = function ( samples , sync ) {
143182 var url = this . COLLECTOR_API_SAMPLE
144183 var metadata = {
0 commit comments