1 import express from 'express'
2 import { OpenTelemetryMetrics } from '@server/lib/opentelemetry/metrics'
3 import { HttpStatusCode, PlaybackMetricCreate } from '@shared/models'
4 import { addPlaybackMetricValidator, asyncMiddleware } from '../../middlewares'
5 import { CONFIG } from '@server/initializers/config'
7 const metricsRouter = express.Router()
9 metricsRouter.post('/playback',
10 asyncMiddleware(addPlaybackMetricValidator),
14 // ---------------------------------------------------------------------------
20 // ---------------------------------------------------------------------------
22 function addPlaybackMetric (req: express.Request, res: express.Response) {
23 if (!CONFIG.OPEN_TELEMETRY.METRICS.ENABLED) {
24 return res.sendStatus(HttpStatusCode.FORBIDDEN_403)
27 const body: PlaybackMetricCreate = req.body
29 OpenTelemetryMetrics.Instance.observePlaybackMetric(res.locals.onlyImmutableVideo, body)
31 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)