microsoft / ApplicationInsights-node.js

Microsoft Application Insights SDK for Node.js
MIT License
320 stars 138 forks source link

ApplicationInsights:Error: @opentelemetry/api: Attempted duplicate registration of API: propagation #1229

Open Ramemis opened 8 months ago

Ramemis commented 8 months ago

Facing issue when I'm using the Application Insights-Node package in the page.

import Container from 'components/core/container/Container';
import { GetServerSideProps } from 'next';

const Page = () => {
  return (
    <Container>
      <div className="page-wrapper">P+ Landing Page - Under construction</div>
    </Container>
  );
};

export const getServerSideProps: GetServerSideProps<any> = async () => {
  if (process.env.NEXT_RUNTIME === 'nodejs') {
    let appInsights = require("applicationinsights");
    appInsights.setup("connectionstring from azure").start();
    let client = appInsights.defaultClient;
    client.trackEvent({name: "my custom event", properties: {customProperty: "custom property value"}});
  }
  try {
    await fetch('exception');
  } catch (e: any) {
    // appInsights.defaultClient.trackException({ exception: e });
  }
  return { props: { success: false } };
};

export default Page;

Also I'm not seeing any logs in the azure app insights.

Error:

clinical-content:dev: ApplicationInsights:Error: @opentelemetry/api: Attempted duplicate registration of API: propagation clinical-content:dev: at registerGlobal (/home/newApp/PatientNextGen/node_modules/.pnpm/@opentelemetry+api@1.6.0/node_modules/@opentelemetry/api/build/src/internal/global-utils.js:32:21) clinical-content:dev: at PropagationAPI.setGlobalPropagator (/home/newApp/PatientNextGen/node_modules/.pnpm/@opentelemetry+api@1.6.0/node_modules/@opentelemetry/api/build/src/api/propagation.js:52:50) clinical-content:dev: at NodeTracerProvider.register (/home/newApp/PatientNextGen/nodemodules/.pnpm/@opentelemetry+sdk-trace-base@1.17.1@opentelemetry+api@1.6.0/node_modules/@opentelemetry/sdk-trace-base/build/src/BasicTracerProvider.js:100:31) clinical-content:dev: at NodeTracerProvider.register (/home/newApp/PatientNextGen/nodemodules/.pnpm/@opentelemetry+sdk-trace-node@1.17.1@opentelemetry+api@1.6.0/node_modules/@opentelemetry/sdk-trace-node/build/src/NodeTracerProvider.js:43:15) clinical-content:dev: at new TraceHandler (/home/newApp/PatientNextGen/node_modules/.pnpm/@azure+monitor-opentelemetry@1.1.0/node_modules/@azure/monitor-opentelemetry/dist/index.js:955:30) clinical-content:dev: at useAzureMonitor (/home/newApp/PatientNextGen/node_modules/.pnpm/@azure+monitor-opentelemetry@1.1.0/node_modules/@azure/monitor-opentelemetry/dist/index.js:1136:20) clinical-content:dev: at useAzureMonitor (/home/newApp/PatientNextGen/node_modules/.pnpm/applicationinsights@3.0.0-beta.10/node_modules/applicationinsights/out/src/main.js:30:49) clinical-content:dev: at TelemetryClient.initialize (/home/newApp/PatientNextGen/node_modules/.pnpm/applicationinsights@3.0.0-beta.10/node_modules/applicationinsights/out/src/shim/telemetryClient.js:37:36) clinical-content:dev: at Configuration.start (/home/newApp/PatientNextGen/node_modules/.pnpm/applicationinsights@3.0.0-beta.10/node_modules/applicationinsights/out/src/shim/applicationinsights.js:36:31) clinical-content:dev: at getServerSideProps (webpack-internal:///./pages/doctor/index.tsx:30:220) clinical-content:dev: at /home/newApp/PatientNextGen/nodemodules/.pnpm/next@13.4.19@babel+core@7.22.9_@opentelemetry+api@1.6.0_react-dom@18.2.0_react@18.2.0_sass@1.66.1/node_modules/next/dist/server/render.js:551:26 clinical-content:dev: at /home/newApp/PatientNextGen/nodemodules/.pnpm/next@13.4.19@babel+core@7.22.9_@opentelemetry+api@1.6.0_react-dom@18.2.0_react@18.2.0_sass@1.66.1/node_modules/next/dist/server/lib/trace/tracer.js:117:36 clinical-content:dev: at AsyncLocalStorage.run (node:async_hooks:346:14) clinical-content:dev: at AsyncLocalStorageContextManager.with (/home/newApp/PatientNextGen/nodemodules/.pnpm/@opentelemetry+context-async-hooks@1.17.1@opentelemetry+api@1.6.0/node_modules/@opentelemetry/context-async-hooks/build/src/AsyncLocalStorageContextManager.js:33:40) clinical-content:dev: at ContextAPI.with (/home/newApp/PatientNextGen/node_modules/.pnpm/@opentelemetry+api@1.6.0/node_modules/@opentelemetry/api/build/src/api/context.js:60:46) clinical-content:dev: at Tracer.startActiveSpan (/home/newApp/PatientNextGen/nodemodules/.pnpm/@opentelemetry+sdk-trace-base@1.17.1@opentelemetry+api@1.6.0/node_modules/@opentelemetry/sdk-trace-base/build/src/Tracer.js:122:32) clinical-content:dev: at /home/newApp/PatientNextGen/nodemodules/.pnpm/next@13.4.19@babel+core@7.22.9_@opentelemetry+api@1.6.0_react-dom@18.2.0_react@18.2.0_sass@1.66.1/node_modules/next/dist/server/lib/trace/tracer.js:106:107 clinical-content:dev: at AsyncLocalStorage.run (node:async_hooks:346:14) clinical-content:dev: at AsyncLocalStorageContextManager.with (/home/newApp/PatientNextGen/nodemodules/.pnpm/@opentelemetry+context-async-hooks@1.17.1@opentelemetry+api@1.6.0/node_modules/@opentelemetry/context-async-hooks/build/src/AsyncLocalStorageContextManager.js:33:40) clinical-content:dev: at ContextAPI.with (/home/newApp/PatientNextGen/node_modules/.pnpm/@opentelemetry+api@1.6.0/node_modules/@opentelemetry/api/build/src/api/context.js:60:46) clinical-content:dev: at NextTracerImpl.trace (/home/newApp/PatientNextGen/nodemodules/.pnpm/next@13.4.19@babel+core@7.22.9_@opentelemetry+api@1.6.0_react-dom@18.2.0_react@18.2.0_sass@1.66.1/node_modules/next/dist/server/lib/trace/tracer.js:106:32) clinical-content:dev: at renderToHTMLImpl (/home/newApp/PatientNextGen/nodemodules/.pnpm/next@13.4.19@babel+core@7.22.9_@opentelemetry+api@1.6.0_react-dom@18.2.0_react@18.2.0_sass@1.66.1/node_modules/next/dist/server/render.js:546:51) clinical-content:dev: at process.processTicksAndRejections (node:internal/process/task_queues:95:5) clinical-content:dev: at async doRender (/home/newApp/PatientNextGen/nodemodules/.pnpm/next@13.4.19@babel+core@7.22.9_@opentelemetry+api@1.6.0_react-dom@18.2.0_react@18.2.0_sass@1.66.1/node_modules/next/dist/server/base-server.js:1140:26) clinical-content:dev: at async cacheEntry.responseCache.get.incrementalCache.incrementalCache (/home/newApp/PatientNextGen/nodemodules/.pnpm/next@13.4.19@babel+core@7.22.9_@opentelemetry+api@1.6.0_react-dom@18.2.0_react@18.2.0_sass@1.66.1/node_modules/next/dist/server/base-server.js:1300:28) clinical-content:dev: at async /home/newApp/PatientNextGen/nodemodules/.pnpm/next@13.4.19@babel+core@7.22.9_@opentelemetry+api@1.6.0_react-dom@18.2.0_react@18.2.0_sass@1.66.1/node_modules/next/dist/server/response-cache/index.js:99:36 [] clinical-content:dev: ApplicationInsights:@azure/opentelemetry-instrumentation-azure-sdk [ clinical-content:dev: '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' clinical-content:dev: ] clinical-content:dev: ApplicationInsights:Invalid metric name: "\ASP.NET Applications(??APP_W3SVC_PROC??)\Request Execution Time". The metric name should be a ASCII string with a length no greater than 255 characters. [] clinical-content:dev: ApplicationInsights:Invalid metric name: "\ASP.NET Applications(??APP_W3SVC_PROC??)\Requests/Sec". The metric name should be a ASCII string with a length no greater than 255 characters. [] clinical-content:dev: ApplicationInsights:Invalid metric name: "\Process(??APP_WIN32_PROC??)\Private Bytes". The metric name should be a ASCII string with a length no greater than 255 characters. [] clinical-content:dev: ApplicationInsights:Invalid metric name: "\Memory\Available Bytes". The metric name should be a ASCII string with a length no greater than 255 characters. [] clinical-content:dev: ApplicationInsights:Invalid metric name: "\Processor(_Total)\% Processor Time". The metric name should be a ASCII string with a length no greater than 255 characters. [] clinical-content:dev: ApplicationInsights:Invalid metric name: "\Process(??APP_WIN32_PROC??)\% Processor Time". The metric name should be a ASCII string with a length no greater than 255 characters.

JacksonWeber commented 8 months ago

@Ramemis What version of the ApplicationInsights SDK are you using?

lapa182 commented 7 months ago

@JacksonWeber I have the same issue and I'm running 3.0.0-beta.10

JacksonWeber commented 7 months ago

@lapa182 @Ramemis If you are using the Application Insights shim in the beta and the TelemetryClient, you'll get this error. What's happening is that OpenTelemetry is trying to register two global providers. In this case only the first provider will win. There's a paradigm shift in how handling what would have been handled by two TelemetryClients in the past should be handled now. With OpenTelemetry you should be able to create multiple span processors in order to achieve effectively the same as the multiple TelemetryClients.