-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new file 'telemetry.guard.ts' in 'src/api/guards' directory. Modified 'index.router.ts' in 'src/api/routes' directory to integrate the new telemetry system. This change improves the monitoring and data gathering capabilities of the application, allowing for better performance analysis and potential issue detection.
- Loading branch information
1 parent
7a675e7
commit e33893d
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import axios from 'axios'; | ||
import { NextFunction, Request, Response } from 'express'; | ||
import fs from 'fs'; | ||
|
||
const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8')); | ||
|
||
interface TelemetryData { | ||
route: string; | ||
apiVersion: string; | ||
timestamp: Date; | ||
} | ||
|
||
class Telemetry { | ||
public collectTelemetry(req: Request, res: Response, next: NextFunction): void { | ||
const telemetry: TelemetryData = { | ||
route: req.path, | ||
apiVersion: `${packageJson.version}`, | ||
timestamp: new Date(), | ||
}; | ||
|
||
axios | ||
.post('https://log.evolution-api.com/telemetry', telemetry) | ||
.then(() => {}) | ||
.catch((error) => { | ||
console.error('Telemetry error', error); | ||
}); | ||
|
||
next(); | ||
} | ||
} | ||
|
||
export default Telemetry; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters