| page_type | sample | |
|---|---|---|
| languages |
|
|
| products |
|
|
| urlFragment | microsoft-opentelemetry-typescript |
These sample programs show how to use the @microsoft/opentelemetry distribution in common scenarios.
| File Name | Description |
|---|---|
| basicConnection.ts | Demonstrates how to configure Microsoft OpenTelemetry using a connection string. |
| cloudRole.ts | Demonstrates how to set Cloud Role Name and Cloud Role Instance using OpenTelemetry Resource attributes. |
| customMetric.ts | Demonstrates how to generate custom metrics that will be sent to Azure Monitor. |
| customTrace.ts | Demonstrates how to generate custom traces that will be sent to Azure Monitor. |
| liveMetrics.ts | Demonstrates how to enable or disable Live Metrics for real-time monitoring. |
| offlineStorage.ts | Demonstrates how to configure offline storage and automatic retries for telemetry. |
| otlpExporter.ts | Demonstrates how to enable the OTLP exporter alongside Azure Monitor to send telemetry to two locations. |
| redactQueryStrings.ts | Demonstrates how to redact URL query strings from telemetry to protect sensitive information. |
| sampling.ts | Demonstrates how to enable sampling to reduce data ingestion volume and control costs. |
| langchainInstrumentation.ts | Demonstrates how to enable LangChain instrumentation to trace GenAI operations, including the enableSensitiveData toggle for capturing message content. |
| aks-langchain | Deploys a loader-based LangChain auto-instrumentation reproduction to AKS with a Dockerfile, Kubernetes manifest, and Azure Monitor walkthrough. |
| openaiInstrumentation.ts | Demonstrates how to enable OpenAI Agents SDK instrumentation to trace GenAI operations. |
| a365Export.ts | Demonstrates A365 observability export: token resolver setup, dual export with Azure Monitor, and span routing by tenant/agent. |
| a365ManualScopes.ts | Traces a full agent turn with manual scopes (InvokeAgent → Inference → ExecuteTool → Inference → Output) and cross-service context propagation. |
| a365HostingMiddleware.ts | Demonstrates A365 hosting middleware (BaggageMiddleware, OutputLoggingMiddleware, ObservabilityHostingManager, ScopeUtils). |
- Node.js LTS (>= 20.0.0)
- TypeScript (install via
npm install -g typescript) - An Azure subscription with an Application Insights resource
- Install dependencies:
npm install- Compile the samples:
npm run build- Copy
sample.envto.envand fill in the variables needed by the samples you want to run:
cp sample.env .env| Variable | Used by | Description |
|---|---|---|
APPLICATIONINSIGHTS_CONNECTION_STRING |
Most samples | Connection string from your Application Insights resource. |
OTEL_SERVICE_NAME |
cloudRole.ts | Service name mapped to Cloud Role Name. |
OTEL_SERVICE_NAMESPACE |
cloudRole.ts | Service namespace prepended to Cloud Role Name. |
OTEL_SERVICE_INSTANCE_ID |
cloudRole.ts | Service instance mapped to Cloud Role Instance. |
AZURE_OPENAI_API_KEY |
langchainInstrumentation.ts, openaiInstrumentation.ts | API key for your Azure OpenAI resource. |
AZURE_OPENAI_INSTANCE_NAME |
langchainInstrumentation.ts, openaiInstrumentation.ts | Azure OpenAI resource name (e.g. contoso). |
AZURE_OPENAI_DEPLOYMENT_NAME |
langchainInstrumentation.ts, openaiInstrumentation.ts | Model deployment name (e.g. gpt-4o). |
AZURE_OPENAI_API_VERSION |
langchainInstrumentation.ts, openaiInstrumentation.ts | Azure OpenAI API version (default 2024-06-01). |
A365_BEARER_TOKEN |
a365Export.ts, a365ManualScopes.ts | Auth token for the Agent365 observability API. In production you would acquire this via MSAL; the samples read it from this env var as a shortcut. |
- Run a sample:
node dist/basicConnection.jsOr pass the connection string directly:
APPLICATIONINSIGHTS_CONNECTION_STRING="<your connection string>" node dist/basicConnection.jsBy default, LangChain instrumentation hides sensitive GenAI message content — prompts, completions, tool call arguments/results, and system instructions — so telemetry carries only non-sensitive metadata (model, token counts, latency, tool names, etc.).
langchainInstrumentation.ts demonstrates the enableSensitiveData toggle. Set the top-level option to record message content:
useMicrosoftOpenTelemetry({
// Hidden by default. Only enable in trusted, non-production environments
// where capturing message content is intentional.
enableSensitiveData: true,
azureMonitor: {
/* ... */
},
instrumentationOptions: {
langchain: { enabled: true },
},
});Note:
enableSensitiveDatadefaults tofalse. Only enable it in trusted, non-production environments where capturing message content is intentional. This setting currently applies to LangChain instrumentation.