skywalking-apache
Version:
The NodeJS agent for Apache SkyWalking
74 lines • 3.35 kB
JavaScript
;
/*!
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var AgentConfig_1 = tslib_1.__importDefault(require("../../../../config/AgentConfig"));
var grpc = tslib_1.__importStar(require("grpc"));
var grpc_1 = require("grpc");
var logging_1 = require("../../../../logging");
var Tracing_grpc_pb_1 = require("../../../../proto/language-agent/Tracing_grpc_pb");
var AuthInterceptor_1 = tslib_1.__importDefault(require("../AuthInterceptor"));
var Buffer_1 = tslib_1.__importDefault(require("../../../../agent/Buffer"));
var SegmentObjectAdapter_1 = tslib_1.__importDefault(require("../SegmentObjectAdapter"));
var logger = logging_1.createLogger(__filename);
var TraceReportClient = /** @class */ (function () {
function TraceReportClient() {
this.reporterClient = new Tracing_grpc_pb_1.TraceSegmentReportServiceClient(AgentConfig_1.default.collectorAddress, grpc.credentials.createInsecure(), { interceptors: [AuthInterceptor_1.default] });
}
Object.defineProperty(TraceReportClient.prototype, "isConnected", {
get: function () {
return this.reporterClient.getChannel().getConnectivityState(true) === grpc_1.connectivityState.READY;
},
enumerable: false,
configurable: true
});
TraceReportClient.prototype.start = function () {
var _this = this;
var reportFunction = function () {
try {
if (Buffer_1.default.length === 0) {
return;
}
var stream = _this.reporterClient.collect(function (error, _) {
if (error) {
logger.error('Failed to report trace data', error);
}
});
while (Buffer_1.default.buffer.length > 0) {
var segment = Buffer_1.default.buffer.pop();
if (segment) {
if (logger.isDebugEnabled()) {
logger.debug('Sending segment ', { segment: segment });
}
stream.write(new SegmentObjectAdapter_1.default(segment));
}
}
stream.end();
}
finally {
setTimeout(reportFunction, 1000).unref();
}
};
setTimeout(reportFunction, 1000).unref();
};
return TraceReportClient;
}());
exports.default = new TraceReportClient();
//# sourceMappingURL=TraceReportClient.js.map