opentelemetry-js icon indicating copy to clipboard operation
opentelemetry-js copied to clipboard

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

Open Ramemis opened this issue 2 years ago • 6 comments
trafficstars

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/@[email protected]/node_modules/@opentelemetry/api/build/src/internal/global-utils.js:32:21) clinical-content:dev: at PropagationAPI.setGlobalPropagator (/home/newApp/PatientNextGen/node_modules/.pnpm/@[email protected]/node_modules/@opentelemetry/api/build/src/api/propagation.js:52:50) clinical-content:dev: at NodeTracerProvider.register (/home/newApp/PatientNextGen/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@opentelemetry/sdk-trace-base/build/src/BasicTracerProvider.js:100:31) clinical-content:dev: at NodeTracerProvider.register (/home/newApp/PatientNextGen/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@opentelemetry/sdk-trace-node/build/src/NodeTracerProvider.js:43:15) clinical-content:dev: at new TraceHandler (/home/newApp/PatientNextGen/node_modules/.pnpm/@[email protected]/node_modules/@azure/monitor-opentelemetry/dist/index.js:955:30) clinical-content:dev: at useAzureMonitor (/home/newApp/PatientNextGen/node_modules/.pnpm/@[email protected]/node_modules/@azure/monitor-opentelemetry/dist/index.js:1136:20) clinical-content:dev: at useAzureMonitor (/home/newApp/PatientNextGen/node_modules/.pnpm/[email protected]/node_modules/applicationinsights/out/src/main.js:30:49) clinical-content:dev: at TelemetryClient.initialize (/home/newApp/PatientNextGen/node_modules/.pnpm/[email protected]/node_modules/applicationinsights/out/src/shim/telemetryClient.js:37:36) clinical-content:dev: at Configuration.start (/home/newApp/PatientNextGen/node_modules/.pnpm/[email protected]/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/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/next/dist/server/render.js:551:26 clinical-content:dev: at /home/newApp/PatientNextGen/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected][email protected][email protected]/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/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@opentelemetry/context-async-hooks/build/src/AsyncLocalStorageContextManager.js:33:40) clinical-content:dev: at ContextAPI.with (/home/newApp/PatientNextGen/node_modules/.pnpm/@[email protected]/node_modules/@opentelemetry/api/build/src/api/context.js:60:46) clinical-content:dev: at Tracer.startActiveSpan (/home/newApp/PatientNextGen/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@opentelemetry/sdk-trace-base/build/src/Tracer.js:122:32) clinical-content:dev: at /home/newApp/PatientNextGen/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected][email protected][email protected]/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/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@opentelemetry/context-async-hooks/build/src/AsyncLocalStorageContextManager.js:33:40) clinical-content:dev: at ContextAPI.with (/home/newApp/PatientNextGen/node_modules/.pnpm/@[email protected]/node_modules/@opentelemetry/api/build/src/api/context.js:60:46) clinical-content:dev: at NextTracerImpl.trace (/home/newApp/PatientNextGen/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/next/dist/server/lib/trace/tracer.js:106:32) clinical-content:dev: at renderToHTMLImpl (/home/newApp/PatientNextGen/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected][email protected][email protected]/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/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/next/dist/server/base-server.js:1140:26) clinical-content:dev: at async cacheEntry.responseCache.get.incrementalCache.incrementalCache (/home/newApp/PatientNextGen/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/next/dist/server/base-server.js:1300:28) clinical-content:dev: at async /home/newApp/PatientNextGen/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected][email protected][email protected]/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.

Ramemis avatar Oct 17 '23 02:10 Ramemis

Hi I'm facing the same issue with my development build.

jdbadilla avatar Oct 20 '23 15:10 jdbadilla

seems this is caused by either the application installs two OTel instances (one via applicationinsights => @azure/monitor-opentelemetry) or applicationinsights does something wrong.

I guess it's better to ask the azure team here.

Flarna avatar Oct 20 '23 19:10 Flarna

/cc @MSNev

dyladan avatar Nov 08 '23 08:11 dyladan

@hectorhdzg , @JacksonWeber can you please look at this

MSNev avatar Nov 08 '23 21:11 MSNev

@Ramemis which version of Application Insights are you using? this error is usually triggered when multiple global registrations occur in OpenTelemetry, that could be caused by having multiple telemetry clients being created, that would not be supported anymore very soon in applicationinsights beta package, I recommend you take a look at Azure Monitor OpenTelemetry Distro to have your data in Application Insights

hectorhdzg avatar Nov 08 '23 23:11 hectorhdzg

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

github-actions[bot] avatar Jan 29 '24 06:01 github-actions[bot]

This issue was closed because it has been stale for 14 days with no activity.

github-actions[bot] avatar Mar 11 '24 06:03 github-actions[bot]