/agents-for-js:agents-sdk-typescript-otelfrom agents-for-js
Configures OpenTelemetry observability for Microsoft 365 Agents SDK apps in JS/TS. Handles traces, metrics, logs, OTLP exporters, Aspire Dashboard, and Azure Monitor integration.
Ships in agents-for-js. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Configure traces, metrics, and logs for an Agents SDK application, including the SDK's built-in telemetry and a local Aspire Dashboard. Make the smallest complete change that fits the project's module system, build process, package manager, and existing observability architecture.
--import or --require option.service.name.0.x
exporter/instrumentation versions. Install a compatible set together and
preserve the lockfile.OTEL_TRACES_SAMPLER and OTEL_TRACES_SAMPLER_ARG.Complete these steps in order.
Find:
package.json, the lockfile, Node engine version, and package manager."type": "module") or CommonJS.startServer(), Express, or
another host.@opentelemetry/*,
@microsoft/agents-telemetry, or logging integrations.NodeSDK, tracer provider, meter provider, logger provider,
exporters, processors, instrumentations, and shutdown hooks..env templates, deployment manifests,
container definitions, and CI/CD configuration.If observability already exists, add the missing Agents SDK-compatible global providers and keep the existing exporters and instrumentations unless the user requested a change.
Use the repository's package manager. For npm:
npm install @opentelemetry/api @opentelemetry/api-logs `
@microsoft/agents-telemetry `
@opentelemetry/sdk-node @opentelemetry/sdk-metrics `
@opentelemetry/sdk-logs @opentelemetry/sdk-trace-base `
@opentelemetry/exporter-trace-otlp-grpc `
@opentelemetry/exporter-metrics-otlp-grpc `
@opentelemetry/exporter-logs-otlp-grpc `
@opentelemetry/instrumentation-http `
@opentelemetry/resources @opentelemetry/semantic-conventions
Adapt the command for pnpm or yarn. Install the packages in one operation so the package manager can resolve compatible peers. Do not manually rewrite the resolved versions into one shared version number.
@microsoft/agents-telemetry is required as a direct dependency when
application code imports SpanNames or MetricNames; do not rely on the
Agents SDK's transitive copy.
Use OTLP/HTTP exporter packages instead of the gRPC exporters only when the
collector requires http/protobuf.
Create src/instrumentation.ts or the equivalent path. Adapt the default
service name and version:
import { randomUUID } from 'node:crypto'
import { OTLPLogExporter } from '@opentelemetry/exporter-logs-otlp-grpc'
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-grpc'
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc'
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http'
import { resourceFromAttributes } from '@opentelemetry/resources'
import {
BatchLogRecordProcessor,
type LogRecordExporter
} from '@opentelemetry/sdk-logs'
import {
PeriodicExportingMetricReader,
type PushMetricExporter
} from '@opentelemetry/sdk-metrics'
import { NodeSDK } from '@opentelemetry/sdk-node'
import type { SpanExporter } from '@opentelemetry/sdk-trace-base'
import {
ATTR_SERVICE_INSTANCE_ID,
ATTR_SERVICE_NAME,
ATTR_SERVICE_VERSION
} from '@opentelemetry/semantic-conventions'
const serviceName =
process.env.OTEL_SERVICE_NAME ?? 'contoso-support-agent'
const serviceVersion =
process.env.npm_package_version ?? '1.0.0'
const traceExporter: SpanExporter = new OTLPTraceExporter()
const metricExporter: PushMetricExporter = new OTLPMetricExporter()
const logExporter: LogRecordExporter = new OTLPLogExporter()
export const otelSdk = new NodeSDK({
resource: resourceFromAttributes({
[ATTR_SERVICE_NAME]: serviceName,
[ATTR_SERVICE_VERSION]: serviceVersion,
[ATTR_SERVICE_INSTANCE_ID]: randomUUID()
}),
traceExporter,
metricReader: new PeriodicExportingMetricReader({
exporter: metricExporter
}),
logRecordProcessors: [
new BatchLogRecordProcessor(logExporter)
],
instrumentations: [
new HttpInstrumentation({
ignoreIncomingRequestHook: request =>
request.url?.startsWith('/health') === true
})
]
})
otelSdk.start()
let shutdownStarted = false
const shutdown = async (signal: NodeJS.Signals): Promise<void> => {
if (shutdownStarted) {
return
}
shutdownStarted = true
try {
await otelSdk.shutdown()
} catch (error) {
console.error('Failed to shut down OpenTelemetry', error)
process.exitCode = 1
} finally {
process.kill(process.pid, signal)
}
}
process.once('SIGTERM', signal => {
void shutdown(signal)
})
process.once('SIGINT', signal => {
void shutdown(signal)
})
Before using the signal-handler example, check the application's existing
shutdown behavior. Prefer integrating otelSdk.shutdown() into the existing
graceful shutdown path so the HTTP server, storage, and telemetry all close in
the correct order. Do not register duplicate signal handlers.
If the installed semantic-conventions package does not expose
ATTR_SERVICE_INSTANCE_ID, use the literal stable semantic key
'service.instance.id'.
The NodeSDK installs global trace, metric, context, propagation, and log
providers. Agents SDK telemetry uses those global APIs automatically; no
Agents-specific instrumentation registration is required.
For an ESM TypeScript project that compiles to dist:
{
"scripts": {
"build": "tsc --build",
"prestart": "npm run build",
"start": "node --env-file .env --import ./dist/instrumentation.js ./dist/agent.js"
}
}
For CommonJS, use --require:
"start": "node --require ./dist/instrumentation.cjs ./dist/agent.cjs"
Do not import instrumentation.ts from the bottom of the application entry
point. By then, HTTP or framework modules may already be loaded and cannot be
patched reliably.
If a test runner, worker, background process, or alternate start script executes the agent independently, preload instrumentation there too when that process should emit telemetry.
For the local Aspire Dashboard using OTLP/gRPC, add non-secret defaults to the
uncommitted .env and document them in .env.example or env.TEMPLATE:
OTEL_SERVICE_NAME=contoso-support-agent
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317
OTEL_EXPORTER_OTLP_PROTOCOL=grpc
Standard environment variables to support:
| Variable | Purpose |
|---|---|
OTEL_SERVICE_NAME | Stable application service name |
OTEL_RESOURCE_ATTRIBUTES | Stable resource metadata |
OTEL_EXPORTER_OTLP_ENDPOINT | Base OTLP collector endpoint |
OTEL_EXPORTER_OTLP_PROTOCOL | Usually grpc or http/protobuf |
OTEL_EXPORTER_OTLP_HEADERS | Collector authentication headers; keep secret |
OTEL_TRACES_SAMPLER | Trace sampling strategy |
OTEL_TRACES_SAMPLER_ARG | Sampling strategy argument |
OTEL_METRIC_EXPORT_INTERVAL | Metric export interval in milliseconds |
Use deployment secrets for OTEL_EXPORTER_OTLP_HEADERS and Azure Monitor
connection strings. Do not commit populated .env files.
The Agents SDK already emits adapter, application, turn, connector, storage, authentication, authorization, proactive, dialog, and Copilot Studio signals. Add custom telemetry only for application-specific operations.
Create one shared helper:
import { metrics, trace } from '@opentelemetry/api'
import { logs, SeverityNumber } from '@opentelemetry/api-logs'
const sourceName = 'Contoso.SupportAgent'
const version = process.env.npm_package_version
export const agentTracer = trace.getTracer(sourceName, version)
export const agentMeter = metrics.getMeter(sourceName, version)
export const agentLogger = logs.getLogger(sourceName, version)
export const routeExecutions = agentMeter.createCounter(
'agent.route.executions',
{
unit: '{execution}',
description: 'Number of application route executions.'
})
export const routeDuration = agentMeter.createHistogram(
'agent.route.duration',
{
unit: 'ms',
description: 'Application route execution duration.'
})
export const emitErrorLog = (
message: string,
attributes: Record<string, string | number | boolean>
): void => {
agentLogger.emit({
severityNumber: SeverityNumber.ERROR,
severityText: 'ERROR',
body: message,
attributes
})
}
Instrument a route with bounded attributes:
import { SpanStatusCode } from '@opentelemetry/api'
return agentTracer.startActiveSpan(
'agent.route.execute',
async span => {
const started = performance.now()
let status = 'ok'
try {
await handleMessage(context)
} catch (error) {
status = 'error'
const exception =
error instanceof Error ? error : new Error(String(error))
span.recordException(exception)
span.setStatus({
code: SpanStatusCode.ERROR,
message: exception.message
})
throw error
} finally {
const attributes = {
'route.type': 'message',
status
}
routeExecutions.add(1, attributes)
routeDuration.record(performance.now() - started, attributes)
span.end()
}
})
Do not add conversation, activity, user, prompt, response, URL, or exception message values to custom metrics. Use the standard application logger or the OpenTelemetry Logs API for operational messages, but keep sensitive content out of both.
Copy assets/start-aspire-dashboard.ps1 from this skill into a local scripts
directory and run:
.\start-aspire-dashboard.ps1
Open http://localhost:18888. The script:
127.0.0.1.4317 and OTLP/HTTP on 4318.mcr.microsoft.com/dotnet/aspire-dashboard:latest.Do not start a second container if aspire-dashboard already exists. Reuse or
stop the existing container:
docker stop aspire-dashboard
service.name.agents.adapter.process or agents.app.run.agents.activities.received, agents.turn.count, or
another exercised SDK operation.See references/sdk-signals.md for the canonical Agents SDK spans, metrics, constants, and Aspire smoke test.
Use the OTLP exporter packages matching the collector protocol. gRPC is the default for the included Aspire Dashboard setup.
When requested, use the current supported Azure Monitor OpenTelemetry exporter for Node.js and load its connection string from a secret source. Check the exporter's current initialization and compatibility documentation before editing because Azure Monitor's JavaScript OpenTelemetry integration evolves independently from the core OTel packages. Preserve OTLP only when dual export is intentional.
OpenTelemetry does not automatically export every console, pino, Winston, or
other logger record. Use a compatible instrumentation/transport for the
project's logger, or emit selected structured records through
@opentelemetry/api-logs. Do not replace the application's logging framework
solely to add telemetry.
| Symptom | Check |
|---|---|
| No SDK spans or metrics | NodeSDK.start() ran before the Agents SDK was imported |
| HTTP spans missing | Instrumentation was preloaded before node:http, Express, and the application |
| Custom telemetry missing | The tracer, meter, and logger are obtained after the global SDK starts |
| Logs missing | A log record processor/exporter exists and the app emits through an integrated logger |
| Dashboard empty | Endpoint is http://localhost:4317; exporter and protocol are both gRPC |
| Traces appear but metrics do not | Metrics can take one or more OTEL_METRIC_EXPORT_INTERVAL periods plus dashboard processing time to appear; wait and refresh before troubleshooting |
| OTLP protocol error | Exporter package, endpoint port, and protocol do not match |
| Duplicate telemetry | More than one SDK/provider or duplicate instrumentation preload exists |
| Process hangs during shutdown | Integrate OTel shutdown with the server's existing graceful shutdown |
| Last spans or logs are absent | Await sdk.shutdown() before process exit |
| High telemetry cost | Remove high-cardinality attributes and reduce trace sampling |
If SDK signals differ from references/sdk-signals.md, the sample no longer builds, or the Aspire setup changes, draft an issue containing the module system, Node and package versions, start command, expected signal, actual result, and any workaround: https://github.com/microsoft/agents/issues/new
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
6 skills in this plugin
/agents-sdk-to-prodUse when a user wants to assess, create, harden, deploy, or review the production readiness of JavaScript or TypeScript code built with the Microsoft 365 Agents SDK. Do not use for unrelated applications, services, or code that does not run or support an Agents SDK agent.
/agents-sdk-typescriptUse when any code imports @microsoft/agents-hosting, @microsoft/agents-hosting-express, or related Agents SDK packages, or when the user is building, configuring, or asking questions about a Microsoft 365 Agents SDK agent in TypeScript. Trigger on questions about environment variables, connection configuration, AgentApplication patterns, OAuth sign-in flows, storage backends, cards, streaming, or local testing with the Agents Playground — even if no code exists yet and the user is planning or asking how to get started.
/agents-sdk-typescript-debuggingUse when troubleshooting an agent built with the Microsoft Agents SDK (@microsoft/agents-hosting and related packages). Trigger on any of these symptoms: build or TypeScript errors, crashes on startup, 401 or auth errors on incoming requests, the bot not responding to messages, .env configuration problems, Azure AD credential failures (AADSTS errors), port conflicts, or the agent not connecting in Teams or the Agents Playground. Use even if the user doesn't mention the SDK by name — trigger on symptoms like "my bot won't start", "getting 401s", or "bot isn't responding."
npx claudepluginhub microsoft/agents --plugin agents-for-jsOther plugins' skills for the same job