@inso_web/els-mcp
Version:
MCP-сервер поверх INSO Error Logs Service. Read-only tools (search, analytics, fingerprinting, correlations) для подключения Claude Desktop/Code и ChatGPT к логам ошибок. Streamable HTTP transport + stdio для npx-запуска.
56 lines • 2.21 kB
JavaScript
const NOOP = {
shutdown: async () => { },
enabled: false,
};
export async function setupTracing(opts = {}) {
const endpoint = process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
if (!endpoint) {
opts.log?.debug?.('OTel disabled (OTEL_EXPORTER_OTLP_ENDPOINT not set)');
return NOOP;
}
try {
const [{ NodeSDK }, autoInst, otlp, resourceModule] = await Promise.all([
import('@opentelemetry/sdk-node'),
import('@opentelemetry/auto-instrumentations-node'),
import('@opentelemetry/exporter-trace-otlp-proto'),
import('@opentelemetry/resources'),
]);
const sdkAny = NodeSDK;
// Resource API в @opentelemetry/resources может экспортироваться по-разному
// (Resource как класс или resourceFromAttributes-функция в новых версиях).
const resAny = resourceModule;
const attrs = {
'service.name': 'els-mcp',
'service.version': process.env.GIT_SHA ?? '0.1.0-alpha.0',
'deployment.environment': process.env.NODE_ENV ?? 'development',
};
const resource = resAny.resourceFromAttributes
? resAny.resourceFromAttributes(attrs)
: resAny.Resource
? new resAny.Resource(attrs)
: undefined;
const sdk = new sdkAny({
...(resource ? { resource } : {}),
traceExporter: new otlp.OTLPTraceExporter({ url: endpoint }),
instrumentations: [autoInst.getNodeAutoInstrumentations()],
});
sdk.start();
opts.log?.info?.({ endpoint }, 'OpenTelemetry tracing started');
return {
enabled: true,
shutdown: async () => {
try {
await sdk.shutdown();
}
catch (err) {
opts.log?.warn?.({ err: err.message }, 'OTel shutdown failed');
}
},
};
}
catch (err) {
opts.log?.warn?.({ err: err.message }, 'OTel setup failed; continuing without tracing');
return NOOP;
}
}
//# sourceMappingURL=tracing.js.map