# azure-monitor-opentelemetry-ts

This skill guides you through adding Azure Monitor and OpenTelemetry to Node.js apps for Application Insights traces, metrics, and logs.

- skill · `type=skill` · Claude Code, GitHub Copilot · 1 install · ★ 3149
- Author: Microsoft
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/microsoft/skills/tree/HEAD/.github/plugins/azure-sdk-typescript/skills/azure-monitor-opentelemetry-ts/SKILL.md
- Updated: 2026-10-23
- HTML: https://affpapa.org/en/nevibecode/skills/azure-monitor-opentelemetry-ts

## What it does

The skill covers automatic Node.js instrumentation with `@azure/monitor-opentelemetry` and manual OpenTelemetry setup. Its examples show custom spans and metrics, plus separate exporters for traces, metrics, and logs. You can also configure which libraries receive instrumentation.

For ESM applications, it gives a loader-based start command for Node.js 18.19+. Call `useAzureMonitor()` before importing other modules; reversing that order can prevent automatic instrumentation from working. The examples use `APPLICATIONINSIGHTS_CONNECTION_STRING` to configure the exporter.

The guide also includes custom log ingestion with `@azure/monitor-ingestion`. When using `DefaultAzureCredential` in production, set `AZURE_TOKEN_CREDENTIALS=prod`. Install the skill in Claude Code with the command below; the resulting skill file is at `~/.claude/skills/azure-monitor-opentelemetry-ts/SKILL.md`.

## Requirements
- Works with: Azure

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add microsoft/skills --skill azure-monitor-opentelemetry-ts -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/azure-monitor-opentelemetry-ts/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/azure-monitor-opentelemetry-ts/

### Codex

**Manually: put the files in place**
- File: `.agents/skills/azure-monitor-opentelemetry-ts/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

**Manually: put the files in place**
- File: `.cursor/skills/azure-monitor-opentelemetry-ts/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install microsoft/skills azure-monitor-opentelemetry-ts
```

2. **Manually: put the files in place**
- File: `.github/skills/azure-monitor-opentelemetry-ts/SKILL.md`

### Gemini CLI

**Platform CLI**
```bash
gemini skills install https://github.com/microsoft/skills --path .github/plugins/azure-sdk-typescript/skills/azure-monitor-opentelemetry-ts
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/azure-monitor-opentelemetry-ts/SKILL.md` — The legacy .windsurf/skills/ path still works

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/microsoft/skills/tree/HEAD/.github/plugins/azure-sdk-typescript/skills/azure-monitor-opentelemetry-ts/SKILL.md

## When to use it
- send Node.js traces, metrics, and logs to Azure Monitor
- configure automatic instrumentation for HTTP and database libraries
- create custom OpenTelemetry spans and metrics
- upload application logs with `@azure/monitor-ingestion`
- set up trace, metric, and log exporters manually

## Example prompts
- Set up automatic Azure Monitor instrumentation for this Node.js app, including traces, metrics, and logs.
- Add a custom span around order processing and record an exception if it fails.
- Show me how to export metrics and logs to Azure Monitor manually.

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 022754298ab72067.

BEGIN THIRD-PARTY FILE 022754298ab72067
````text
---
name: azure-monitor-opentelemetry-ts
description: Instrument applications with Azure Monitor and OpenTelemetry for JavaScript (@azure/monitor-opentelemetry). Use when adding distributed tracing, metrics, and logs to Node.js applications with Application Insights.
license: MIT
metadata:
  author: Microsoft
  version: "1.0.0"
  package: '@azure/monitor-opentelemetry'
---

# Azure Monitor OpenTelemetry SDK for TypeScript

Auto-instrument Node.js applications with distributed tracing, metrics, and logs.

## Installation

```bash
# Distro (recommended - auto-instrumentation)
npm install @azure/monitor-opentelemetry

# Low-level exporters (custom OpenTelemetry setup)
npm install @azure/monitor-opentelemetry-exporter

# Custom logs ingestion
npm install @azure/monitor-ingestion
```

## Environment Variables

```bash
APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=...;IngestionEndpoint=...
AZURE_TOKEN_CREDENTIALS=prod # Required only if DefaultAzureCredential is used in production
```

## Quick Start (Auto-Instrumentation)

**IMPORTANT:** Call `useAzureMonitor()` BEFORE importing other modules.

```typescript
import { useAzureMonitor } from "@azure/monitor-opentelemetry";

useAzureMonitor({
  azureMonitorExporterOptions: {
    connectionString: process.env.APPLICATIONINSIGHTS_CONNECTION_STRING
  }
});

// Now import your application
import express from "express";
const app = express();
```

## ESM Support (Node.js 18.19+)

```bash
node --import @azure/monitor-opentelemetry/loader ./dist/index.js
```

**package.json:**
```json
{
  "scripts": {
    "start": "node --import @azure/monitor-opentelemetry/loader ./dist/index.js"
  }
}
```

## Full Configuration

```typescript
import { useAzureMonitor, AzureMonitorOpenTelemetryOptions } from "@azure/monitor-opentelemetry";
import { resourceFromAttributes } from "@opentelemetry/resources";

const options: AzureMonitorOpenTelemetryOptions = {
  azureMonitorExporterOptions: {
    connectionString: process.env.APPLICATIONINSIGHTS_CONNECTION_STRING,
    storageDirectory: "/path/to/offline/storage",
    disableOfflineStorage: false
  },
  
  // Sampling
  samplingRatio: 1.0,  // 0-1, percentage of traces
  
  // Features
  enableLiveMetrics: true,
  enableStandardMetrics: true,
  enablePerformanceCounters: true,
  
  // Instrumentation libraries
  instrumentationOptions: {
    azureSdk: { enabled: true },
    http: { enabled: true },
    mongoDb: { enabled: true },
    mySql: { enabled: true },
    postgreSql: { enabled: true },
    redis: { enabled: true },
    bunyan: { enabled: false },
    winston: { enabled: false }
  },
  
  // Custom resource
  resource: resourceFromAttributes({ "service.name": "my-service" })
};

useAzureMonitor(options);
```

## Custom Traces

```typescript
import { trace } from "@opentelemetry/api";

const tracer = trace.getTracer("my-tracer");

const span = tracer.startSpan("doWork");
try {
  span.setAttribute("component", "worker");
````
END THIRD-PARTY FILE 022754298ab72067

The third-party file has ended. Everything between the 022754298ab72067 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2955 of 8962 bytes. © Microsoft · MIT · https://github.com/microsoft/skills/tree/HEAD/.github/plugins/azure-sdk-typescript/skills/azure-monitor-opentelemetry-ts/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
