@azure/opentelemetry-instrumentation-azure-sdk [ 'Module @azure/core-tracing has been loaded before @azure/opentelemetry-instrumentation-azure-sdk so it might not work, please initialize it before requiring @azure/core-tracing' ]
@opentelemetry/instrumentation-winston [ 'Module winston has been loaded before @opentelemetry/instrumentation-winston so it might not work, please initialize it before requiring winston' ]
@opentelemetry/instrumentation-winston [ 'Module winston has been loaded before @opentelemetry/instrumentation-winston so it might not work, please initialize it before requiring winston' ]
I'm using "applicationinsights": "^3.5.0"
and getting the above warnings.
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
Importing it in the start of the application. e.g
index.ts
import "./src/app-insights.ts"; // Here it is
import express from "express";
import cors from "cors";
@azure/opentelemetry-instrumentation-azure-sdk [ 'Module @azure/core-tracing has been loaded before @azure/opentelemetry-instrumentation-azure-sdk so it might not work, please initialize it before requiring @azure/core-tracing' ]
@opentelemetry/instrumentation-winston [ 'Module winston has been loaded before @opentelemetry/instrumentation-winston so it might not work, please initialize it before requiring winston' ]
@opentelemetry/instrumentation-winston [ 'Module winston has been loaded before @opentelemetry/instrumentation-winston so it might not work, please initialize it before requiring winston' ]
I'm using "applicationinsights": "^3.5.0"
and getting the above warnings.
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
Importing it in the start of the application. e.g
index.ts
import "./src/app-insights.ts"; // Here it is
import express from "express";
import cors from "cors";
Share
Improve this question
edited 12 hours ago
Muhammad Faraz Ali
asked yesterday
Muhammad Faraz AliMuhammad Faraz Ali
97011 silver badges15 bronze badges
2
- Can you share your code in the question? – Dasari Kamali Commented 16 hours ago
- 1 @DasariKamali I have shared the code. – Muhammad Faraz Ali Commented 12 hours ago
1 Answer
Reset to default 0The warnings say that some modules are loaded before their OpenTelemetry instrumentations, which may cause issues. I tried the sample code with OpenTelemetry packages and successfully obtained the output without any issues.
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}`);
});
Output :
I got below output in the browser.
Transaction search :