Add OpenTelemetry error handling in StartServer.ts

This commit is contained in:
Simon Larsen 2024-04-09 15:11:15 +01:00
parent 4b5cc40542
commit e0bcfd31bf
No known key found for this signature in database
GPG Key ID: AB45983AA9C81CDE

View File

@ -27,6 +27,7 @@ import { AppVersion } from '../EnvironmentConfig';
import ServerException from 'Common/Types/Exception/ServerException';
import zlib from 'zlib';
import CookieParser from 'cookie-parser';
import { api } from '@opentelemetry/sdk-node';
// Make sure we have stack trace for debugging.
Error.stackTraceLimit = Infinity;
@ -186,6 +187,18 @@ const init: InitFunction = async (
) => {
logger.error(err);
// Mark span as error.
if (err) {
const span = api.trace.getSpan(api.context.active());
if (span) {
span.setStatus({
code: api.SpanStatusCode.ERROR,
message: err.message,
});
}
}
if (res.headersSent) {
return next(err);
}