@azure/opentelemetry-intrumentation-azure-sdk ['module @azure/core-tracing已在之前加载

问题描述 投票:0回答:1

@azure/opentelemetry-intrumentation-azure-sdk [ 'module @azure/core-tracing已在 @azure/opentelemetry-instermentation-azure-sdk之前加载,因此它可能不起作用,请在需要 @azure/core-tracing之前初始化它。 ]

@opentelemetry/instrumentation-winston [ 'Module Winston已在 @Opentelemetry/instrumentation-winston之前加载,因此它可能行不通,请在需要Winston之前初始化它 ]

@opentelemetry/instrumentation-winston [ 'Module Winston已在 @Opentelemetry/instrumentation-winston之前加载,因此它可能行不通,请在需要Winston之前初始化它 ]

我使用

"applicationinsights": "^3.5.0"

并获取上述警告。

app-insights.ts

import appInsights from "applicationinsights";

//Your Azure Application Insights connection string
const CONNECTION_STRING ="ABC";

//Initialize Application Insights SDK
appInsights
  .setup(CONNECTION_STRING)
  .setAutoCollectRequests(true)
  .setAutoCollectDependencies(true)
  .setAutoCollectConsole(true) //Sending All console logs to the azure application insights
  .setAutoCollectPerformance(true, true)
  .setDistributedTracingMode(appInsights.DistributedTracingModes.AI_AND_W3C) //Enabling distributed tracing
  .start(); //Start the SDK to work

在应用程序开始时对其进行了介绍。例如

index.ts

import "./src/app-insights.ts"; // Here it is
import express from "express";
import cors from "cors";

警告说,某些模块在其OpentElemetry仪器之前已加载,这可能会引起问题。我尝试了使用OpenTelemetry软件包的示例代码,并成功获得了输出,没有任何问题。
node.js azure warnings azure-monitor
1个回答
0
投票
package.json:

"dependencies": { "@azure/opentelemetry-instrumentation-azure-sdk": "^1.0.0-beta.7", "@opentelemetry/instrumentation-express": "^0.47.0", "@opentelemetry/instrumentation-winston": "^0.44.0", "applicationinsights": "^3.5.0", "cors": "^2.8.5", "express": "^4.21.2", "nodemon": "^3.1.9", "ts-node": "^10.9.2", "typescript": "^5.7.3", "winston": "^3.17.0" }

app-insights.ts:

import { AzureMonitorTraceExporter } from "@azure/monitor-opentelemetry-exporter"; import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node"; import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-base"; import { diag, DiagConsoleLogger, DiagLogLevel } from "@opentelemetry/api"; import { registerInstrumentations } from "@opentelemetry/instrumentation"; import { HttpInstrumentation } from "@opentelemetry/instrumentation-http"; import { ExpressInstrumentation } from "@opentelemetry/instrumentation-express"; import { WinstonInstrumentation } from "@opentelemetry/instrumentation-winston"; diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.INFO); const provider = new NodeTracerProvider(); const exporter = new AzureMonitorTraceExporter({ connectionString: "<AppInsightsConneString>", }); provider.addSpanProcessor(new BatchSpanProcessor(exporter)); provider.register(); registerInstrumentations({ instrumentations: [ new HttpInstrumentation(), new ExpressInstrumentation(), new WinstonInstrumentation(), ], }); console.log("OpenTelemetry tracing successfully configured."); service.ts:

import "./app-insights"; 
import winston from "winston"; 
import express from "express";
import cors from "cors";
import { trace, context } from "@opentelemetry/api";

const logger = winston.createLogger({
  level: "info",
  format: winston.format.json(),
  transports: [new winston.transports.Console()],
});

const app = express();
app.use(cors());
app.use(express.json());

app.use((req, res, next) => {
  const originalSend = res.send;
  res.send = function (body) {
    const span = trace.getSpan(context.active());
    if (span) {
      span.addEvent("response", { body });
    }
    return originalSend.call(this, body);
  };
  next();
});

app.get("", (req, res) => {
  res.send("Welcome to my world Kamali!");  
});

const PORT = 3000;
app.listen(PORT, () => {
  logger.info(`Server running on http://localhost:${PORT}`);
});

输出:

我在浏览器中的输出低于输出。

transaction搜索:enter image description here

enter image description here

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.