Skip to content

Duplicate telemetry events when integrating Application Insights with @azure/monitor-opentelemetry in Next.js #6057

@samnagaraj

Description

@samnagaraj

What happened?

Steps to Reproduce

In a nextjs application, when we install @azure/monitor-opentelemetry and use the useAzureMonitor. Every telemetry is tracked twice

Expected Result

Single request and list of unique telemetry Events

Actual Result

  1. Request get tracked twice, (even in azure webapp)
  2. Each event inside the request telemetry is tracked twice (even in azure webapp)

OpenTelemetry Setup Code

export async function register() {
  if (process.env.NEXT_RUNTIME === 'nodejs') {
    console.log("Initializing Azure Application Insights for server-side telemetry...");
    
    
    const connectionString = "<con string"
    
    if (!connectionString) {
      if (process.env.NODE_ENV === 'development') {
        console.warn('⚠ Azure Monitor connection string not configured');
      }
      return;
    }
    
    const { useAzureMonitor } = await import('@azure/monitor-opentelemetry');
    
    
    // eslint-disable-next-line react-hooks/rules-of-hooks
    useAzureMonitor({
      azureMonitorExporterOptions: {
        connectionString,        
      }
    });

  }
}

package.json

"dependencies": {
    "@azure/monitor-opentelemetry": "^1.14.0",
    "next": "^15.5.6",
    "react": "^18.3.1",
    "react-dom": "^18.3.1"
  },
  "devDependencies": {
    "@tailwindcss/postcss": "^4",
    "@types/node": "^20",
    "@types/react": "^18.3.26",
    "@types/react-dom": "^18.3.7",
    "eslint": "^9",
    "eslint-config-next": "16.0.0",
    "tailwindcss": "^4",
    "typescript": "^5"
  }
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions