Skip to content

Commit fd4c400

Browse files
committed
Add documentation for aad env variable for Node.js
1 parent 360d721 commit fd4c400

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ services.AddApplicationInsightsTelemetry(new ApplicationInsightsServiceOptions
101101
102102
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).
103103

104+
- We recommend `DefaultAzureCredential` for local development.
105+
- We recommend `ManagedIdentityCredential` for system-assigned and user-assigned managed identities.
106+
- For system-assigned, use the default constructor without parameters.
107+
- For user-assigned, provide the client ID to the constructor.
108+
- We recommend `ClientSecretCredential` for service principals.
109+
- Provide the tenant ID, client ID, and client secret to the constructor.
110+
104111
#### DefaultAzureCredential
105112

106113
```javascript
@@ -113,6 +120,38 @@ appInsights.defaultClient.config.aadTokenCredential = credential;
113120

114121
```
115122

123+
#### ClientSecretCredential
124+
125+
```javascript
126+
import appInsights from "applicationinsights";
127+
import { ClientSecretCredential } from "@azure/identity";
128+
129+
const credential = new ClientSecretCredential(
130+
"<YOUR_TENANT_ID>",
131+
"<YOUR_CLIENT_ID>",
132+
"<YOUR_CLIENT_SECRET>"
133+
);
134+
appInsights.setup("InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://xxxx.applicationinsights.azure.com/").start();
135+
appInsights.defaultClient.config.aadTokenCredential = credential;
136+
137+
```
138+
139+
#### Environment variable configuration
140+
141+
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.
142+
143+
- For system-assigned identity:
144+
145+
| App setting | Value |
146+
| -------------- |--------- |
147+
| APPLICATIONINSIGHTS_AUTHENTICATION_STRING | `Authorization=AAD` |
148+
149+
- For user-assigned identity:
150+
151+
| App setting | Value |
152+
| ------------- | -------- |
153+
| APPLICATIONINSIGHTS_AUTHENTICATION_STRING | `Authorization=AAD;ClientId={Client id of the User-Assigned Identity}` |
154+
116155
### [Java](#tab/java)
117156

118157
> [!NOTE]

0 commit comments

Comments
 (0)