diff --git a/CommonServer/Utils/StartServer.ts b/CommonServer/Utils/StartServer.ts index a7603cad17..cc597791c8 100644 --- a/CommonServer/Utils/StartServer.ts +++ b/CommonServer/Utils/StartServer.ts @@ -33,7 +33,7 @@ import { DashboardApiRoute } from 'Common/ServiceRoute'; import HTTPResponse from 'Common/Types/API/HTTPResponse'; import HTTPErrorResponse from 'Common/Types/API/HTTPErrorResponse'; import ServerException from 'Common/Types/Exception/ServerException'; -import zlib from 'zlib'; +// import zlib from 'zlib'; // import OpenTelemetrySDK from "./OpenTelemetry"; const app: ExpressApplication = Express.getExpressApp(); @@ -98,19 +98,19 @@ app.use(setDefaultHeaders); */ app.use(function (req, res, next) { - if (req.headers['content-encoding'] === 'gzip') { - var gunzip = zlib.createGunzip(); - req.pipe(gunzip); - var buffer: any = []; - gunzip.on('data', function (data) { - buffer.push(data.toString()); - }).on('end', function () { - req.body = buffer; - next(); - }).on('error', function (e) { - next(e); - }); + // var gunzip = zlib.createGunzip(); + // req.pipe(gunzip); + // var buffer: any = []; + // gunzip.on('data', function (data) { + // buffer.push(data.toString()); + // }).on('end', function () { + // req.body = buffer.join(''); + // next(); + // }).on('error', function (e) { + // next(e); + // }); + next(); } else { jsonBodyParserMiddleware(req, res, next); } diff --git a/Ingestor/API/OTelIngest.ts b/Ingestor/API/OTelIngest.ts index aca86fb70e..6f2a347cb8 100644 --- a/Ingestor/API/OTelIngest.ts +++ b/Ingestor/API/OTelIngest.ts @@ -7,7 +7,7 @@ import Express, { import Response from 'CommonServer/Utils/Response'; import logger from 'CommonServer/Utils/Logger'; import protobuf from 'protobufjs'; - +import zlib from 'zlib'; // Load proto file for OTel // Create a root namespace @@ -32,29 +32,51 @@ router.post( ): Promise => { try { + let buffers: any = []; + req.on('data', (chunk) => { + buffers.push(chunk); + }); + + + req.on('end', () => { + let buffer = Buffer.concat(buffers); + zlib.gunzip(buffer, (err, decoded) => { + if (err) { + console.error(err); + res.status(500).send('Error decompressing data'); + return; + } + + + if (req.url === '/otel/v1/traces') { + const traces = TracesData.decode(decoded); + + logger.info('Traces: ', traces); + } + + if (req.url === '/otel/v1/logs') { + const logs = LogsData.decode(decoded); + + logger.info('Logs: ', logs); + } + + if (req.url === '/otel/v1/metrics') { + const metrics = MetricsData.decode(decoded); + + logger.info('Metrics: ', metrics); + } + + // middleware marks the probe as alive. + // so we don't need to do anything here. + return Response.sendEmptyResponse(req, res); + + + }); + }); + logger.info('OTelIngest URL: ', req.url); - if(req.url === '/otel/v1/traces') { - const traces = TracesData.decode(req.body); - - logger.info('Traces: ', traces); - } - - if(req.url === '/otel/v1/logs') { - const logs = LogsData.decode(req.body); - - logger.info('Logs: ', logs); - } - - if(req.url === '/otel/v1/metrics') { - const metrics = MetricsData.decode(req.body); - - logger.info('Metrics: ', metrics); - } - - // middleware marks the probe as alive. - // so we don't need to do anything here. - return Response.sendEmptyResponse(req, res); + } catch (err) { return next(err); } diff --git a/Ingestor/ProtoFiles/OTel/v1/logs.proto b/Ingestor/ProtoFiles/OTel/v1/logs.proto index 5480608bed..e94ee3dea2 100644 --- a/Ingestor/ProtoFiles/OTel/v1/logs.proto +++ b/Ingestor/ProtoFiles/OTel/v1/logs.proto @@ -16,8 +16,8 @@ syntax = "proto3"; package opentelemetry.proto.logs.v1; -import "opentelemetry/proto/common/v1/common.proto"; -import "opentelemetry/proto/resource/v1/resource.proto"; +import "./common.proto"; +import "./resource.proto"; option csharp_namespace = "OpenTelemetry.Proto.Logs.V1"; option java_multiple_files = true; diff --git a/Ingestor/ProtoFiles/OTel/v1/metrics.proto b/Ingestor/ProtoFiles/OTel/v1/metrics.proto index 5b749cb5f8..509d9c2360 100644 --- a/Ingestor/ProtoFiles/OTel/v1/metrics.proto +++ b/Ingestor/ProtoFiles/OTel/v1/metrics.proto @@ -16,8 +16,8 @@ syntax = "proto3"; package opentelemetry.proto.metrics.v1; -import "opentelemetry/proto/common/v1/common.proto"; -import "opentelemetry/proto/resource/v1/resource.proto"; +import "./common.proto"; +import "./resource.proto"; option csharp_namespace = "OpenTelemetry.Proto.Metrics.V1"; option java_multiple_files = true; diff --git a/Ingestor/ProtoFiles/OTel/v1/resource.proto b/Ingestor/ProtoFiles/OTel/v1/resource.proto index 70998446d7..c4cdfcbfa2 100644 --- a/Ingestor/ProtoFiles/OTel/v1/resource.proto +++ b/Ingestor/ProtoFiles/OTel/v1/resource.proto @@ -16,7 +16,7 @@ syntax = "proto3"; package opentelemetry.proto.resource.v1; -import "opentelemetry/proto/common/v1/common.proto"; +import "./common.proto"; option csharp_namespace = "OpenTelemetry.Proto.Resource.V1"; option java_multiple_files = true; diff --git a/Ingestor/ProtoFiles/OTel/v1/traces.proto b/Ingestor/ProtoFiles/OTel/v1/traces.proto index edb06ccf88..6e49cc5a5f 100644 --- a/Ingestor/ProtoFiles/OTel/v1/traces.proto +++ b/Ingestor/ProtoFiles/OTel/v1/traces.proto @@ -16,8 +16,8 @@ syntax = "proto3"; package opentelemetry.proto.trace.v1; -import "opentelemetry/proto/common/v1/common.proto"; -import "opentelemetry/proto/resource/v1/resource.proto"; +import "./common.proto"; +import "./resource.proto"; option csharp_namespace = "OpenTelemetry.Proto.Trace.V1"; option java_multiple_files = true;