chore(P14-8): 完成运营化与验收收口
这个提交包含在:
@@ -0,0 +1,42 @@
|
||||
const { NodeSDK } = require('@opentelemetry/sdk-node');
|
||||
const { ConsoleSpanExporter } = require('@opentelemetry/sdk-trace-node');
|
||||
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node');
|
||||
const { Resource } = require('@opentelemetry/resources');
|
||||
const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventions');
|
||||
|
||||
let sdk = null;
|
||||
|
||||
function initTracing(config) {
|
||||
if (config.otelTracesEnabled !== true) {
|
||||
return;
|
||||
}
|
||||
|
||||
const exporter = new ConsoleSpanExporter();
|
||||
|
||||
sdk = new NodeSDK({
|
||||
resource: new Resource({
|
||||
[SemanticResourceAttributes.SERVICE_NAME]: 'hyb-oa-server',
|
||||
}),
|
||||
traceExporter: exporter,
|
||||
instrumentations: [getNodeAutoInstrumentations({
|
||||
'@opentelemetry/instrumentation-fs': { enabled: false },
|
||||
})]
|
||||
});
|
||||
|
||||
try {
|
||||
sdk.start();
|
||||
console.log('OTel tracing initialized');
|
||||
} catch (error) {
|
||||
console.error('Error initializing OTel tracing', error);
|
||||
}
|
||||
|
||||
process.on('SIGTERM', () => {
|
||||
if (sdk) {
|
||||
sdk.shutdown()
|
||||
.then(() => console.log('OTel tracing terminated'))
|
||||
.catch((error) => console.log('Error terminating OTel tracing', error));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = { initTracing };
|
||||
在新工单中引用
屏蔽一个用户