@@ -101,6 +101,13 @@ services.AddApplicationInsightsTelemetry(new ApplicationInsightsServiceOptions
101
101
102
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 ) .
103
103
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
+
104
111
#### DefaultAzureCredential
105
112
106
113
``` javascript
@@ -113,6 +120,38 @@ appInsights.defaultClient.config.aadTokenCredential = credential;
113
120
114
121
```
115
122
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
+
116
155
### [ Java] ( #tab/java )
117
156
118
157
> [ !NOTE]
0 commit comments