Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

page_type sample
languages
typescript
products
azure-monitor
urlFragment microsoft-opentelemetry-typescript

Microsoft OpenTelemetry distribution samples for 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.
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).

Prerequisites

Setup

  1. Install dependencies:
npm install
  1. Compile the samples:
npm run build
  1. Copy sample.env to .env and 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.
  1. Run a sample:
node dist/basicConnection.js

Or pass the connection string directly:

APPLICATIONINSIGHTS_CONNECTION_STRING="<your connection string>" node dist/basicConnection.js