mirror of
https://github.com/OneUptime/oneuptime
synced 2024-11-21 14:49:07 +00:00
Refactor OTelIngest and TelemetryIngest modules
This commit is contained in:
parent
e8e735d8d2
commit
899422812d
@ -22,7 +22,9 @@ import LogService from 'CommonServer/Services/LogService';
|
||||
import { JSONArray, JSONObject } from 'Common/Types/JSON';
|
||||
import OTelIngestService from '../Service/OTelIngest';
|
||||
import { ProductType } from 'Model/Models/UsageBilling';
|
||||
import TelemetryIngest, { TelemetryRequest } from '../Middleware/TelemetryIngest';
|
||||
import TelemetryIngest, {
|
||||
TelemetryRequest,
|
||||
} from '../Middleware/TelemetryIngest';
|
||||
|
||||
// Load proto file for OTel
|
||||
|
||||
@ -46,7 +48,6 @@ const MetricsData: protobuf.Type = MetricsProto.lookupType('MetricsData');
|
||||
|
||||
const router: ExpressRouter = Express.getRouter();
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Otel Middleware
|
||||
@ -54,8 +55,12 @@ const router: ExpressRouter = Express.getRouter();
|
||||
*/
|
||||
|
||||
class OpenTelemetryRequestMiddleware {
|
||||
public static async getProductType (req: ExpressRequest, _res: ExpressResponse, next: NextFunction) {
|
||||
try{
|
||||
public static async getProductType(
|
||||
req: ExpressRequest,
|
||||
_res: ExpressResponse,
|
||||
next: NextFunction
|
||||
): Promise<void> {
|
||||
try {
|
||||
let productType: ProductType;
|
||||
|
||||
if (req.baseUrl === '/otlp/v1/traces') {
|
||||
@ -72,18 +77,15 @@ class OpenTelemetryRequestMiddleware {
|
||||
}
|
||||
|
||||
(req as TelemetryRequest).productType = productType;
|
||||
|
||||
}catch(err){
|
||||
} catch (err) {
|
||||
return next(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
router.post(
|
||||
'/otlp/v1/traces',
|
||||
OpenTelemetryRequestMiddleware.getProductType,
|
||||
OpenTelemetryRequestMiddleware.getProductType,
|
||||
TelemetryIngest.isAuthorizedServiceMiddleware,
|
||||
async (
|
||||
req: ExpressRequest,
|
||||
@ -155,7 +157,7 @@ router.post(
|
||||
|
||||
router.post(
|
||||
'/otlp/v1/metrics',
|
||||
OpenTelemetryRequestMiddleware.getProductType,
|
||||
OpenTelemetryRequestMiddleware.getProductType,
|
||||
TelemetryIngest.isAuthorizedServiceMiddleware,
|
||||
async (
|
||||
req: ExpressRequest,
|
||||
@ -397,7 +399,7 @@ router.post(
|
||||
|
||||
router.post(
|
||||
'/otlp/v1/logs',
|
||||
OpenTelemetryRequestMiddleware.getProductType,
|
||||
OpenTelemetryRequestMiddleware.getProductType,
|
||||
TelemetryIngest.isAuthorizedServiceMiddleware,
|
||||
async (
|
||||
req: ExpressRequest,
|
||||
|
@ -1,4 +1,8 @@
|
||||
import { ExpressRequest, ExpressResponse, NextFunction } from 'CommonServer/Utils/Express';
|
||||
import {
|
||||
ExpressRequest,
|
||||
ExpressResponse,
|
||||
NextFunction,
|
||||
} from 'CommonServer/Utils/Express';
|
||||
import { ProbeExpressRequest } from '../Types/Request';
|
||||
import BadRequestException from 'Common/Types/Exception/BadRequestException';
|
||||
import GlobalCache from 'CommonServer/Infrastructure/GlobalCache';
|
||||
@ -13,7 +17,7 @@ import logger from 'CommonServer/Utils/Logger';
|
||||
export interface TelemetryRequest extends ExpressRequest {
|
||||
serviceId: ObjectID; // Service ID
|
||||
projectId: ObjectID; // Project ID
|
||||
productType: ProductType; // what is the product type of the request - logs, metrics or traces.
|
||||
productType: ProductType; // what is the product type of the request - logs, metrics or traces.
|
||||
}
|
||||
|
||||
export default class TelemetryIngest {
|
||||
@ -85,7 +89,8 @@ export default class TelemetryIngest {
|
||||
);
|
||||
|
||||
(req as TelemetryRequest).serviceId = service.id as ObjectID;
|
||||
(req as TelemetryRequest).projectId = service.projectId as ObjectID;
|
||||
(req as TelemetryRequest).projectId =
|
||||
service.projectId as ObjectID;
|
||||
}
|
||||
|
||||
(req as TelemetryRequest).serviceId = ObjectID.fromString(
|
||||
@ -110,4 +115,4 @@ export default class TelemetryIngest {
|
||||
return next(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user