Skip to content

Commit b6d9363

Browse files
Merge pull request #281793 from hectorhdzg/hectorhdzg/aadauto
[Azure Monitor] Add documentation for aad env variable for Node.js
2 parents 4c6c612 + 141523f commit b6d9363

File tree

2 files changed

+49
-7
lines changed

2 files changed

+49
-7
lines changed

articles/azure-monitor/app/azure-ad-authentication.md

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,23 +96,63 @@ services.AddApplicationInsightsTelemetry(new ApplicationInsightsServiceOptions
9696

9797
### [Node.js](#tab/nodejs)
9898

99-
> [!NOTE]
100-
> Support for Microsoft Entra ID in the Application Insights Node.JS is included starting with [version 2.1.0-beta.1](https://www.npmjs.com/package/applicationinsights/v/2.1.0-beta.1).
10199

102-
Application Insights Node.JS supports the credential classes provided by [Azure Identity](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#credential-classes).
103100

104-
#### DefaultAzureCredential
101+
Azure Monitor OpenTelemetry and Application Insights Node.JS supports the credential classes provided by [Azure Identity](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#credential-classes).
105102

106-
```javascript
107-
import appInsights from "applicationinsights";
108-
import { DefaultAzureCredential } from "@azure/identity";
103+
- We recommend `DefaultAzureCredential` for local development.
104+
- We recommend `ManagedIdentityCredential` for system-assigned and user-assigned managed identities.
105+
- For system-assigned, use the default constructor without parameters.
106+
- For user-assigned, provide the client ID to the constructor.
107+
- We recommend `ClientSecretCredential` for service principals.
108+
- Provide the tenant ID, client ID, and client secret to the constructor.
109+
110+
If using @azure/monitor-opentelemetry
111+
```typescript
112+
const { useAzureMonitor, AzureMonitorOpenTelemetryOptions } = require("@azure/monitor-opentelemetry");
113+
const { ManagedIdentityCredential } = require("@azure/identity");
114+
115+
const credential = new ManagedIdentityCredential();
116+
const options: AzureMonitorOpenTelemetryOptions = {
117+
azureMonitorExporterOptions: {
118+
connectionString:
119+
process.env["APPLICATIONINSIGHTS_CONNECTION_STRING"] || "<your connection string>",
120+
credential: credential
121+
}
122+
};
123+
useAzureMonitor(options);
124+
```
125+
126+
> [!NOTE]
127+
> Support for Microsoft Entra ID in the Application Insights Node.JS is included starting with [version 2.1.0-beta.1](https://www.npmjs.com/package/applicationinsights/v/2.1.0-beta.1).
128+
129+
If using applicationinsights npm package.
130+
```typescript
131+
const appInsights = require("applicationinsights");
132+
const { DefaultAzureCredential } = require("@azure/identity");
109133

110134
const credential = new DefaultAzureCredential();
111135
appInsights.setup("InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://xxxx.applicationinsights.azure.com/").start();
112136
appInsights.defaultClient.config.aadTokenCredential = credential;
113137

114138
```
115139

140+
#### Environment variable configuration
141+
142+
When using [Azure App Services autoinstrumentation](./azure-web-apps-nodejs.md) The `APPLICATIONINSIGHTS_AUTHENTICATION_STRING` environment variable lets Application Insights authenticate to Microsoft Entra ID and send telemetry.
143+
144+
- For system-assigned identity:
145+
146+
| App setting | Value |
147+
| -------------- |--------- |
148+
| APPLICATIONINSIGHTS_AUTHENTICATION_STRING | `Authorization=AAD` |
149+
150+
- For user-assigned identity:
151+
152+
| App setting | Value |
153+
| ------------- | -------- |
154+
| APPLICATIONINSIGHTS_AUTHENTICATION_STRING | `Authorization=AAD;ClientId={Client id of the User-Assigned Identity}` |
155+
116156
### [Java](#tab/java)
117157

118158
> [!NOTE]

articles/azure-monitor/app/opentelemetry-configuration.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,8 @@ const credential = new ManagedIdentityCredential();
615615
// Create a new AzureMonitorOpenTelemetryOptions object and set the credential property to the credential object.
616616
const options: AzureMonitorOpenTelemetryOptions = {
617617
azureMonitorExporterOptions: {
618+
connectionString:
619+
process.env["APPLICATIONINSIGHTS_CONNECTION_STRING"] || "<your connection string>",
618620
credential: credential
619621
}
620622
};

0 commit comments

Comments
 (0)