Skip to content

Commit 9c88e24

Browse files
Merge pull request #107761 from ramthi/main
Add Snippet injection reference to JavaScript
2 parents 37e62da + baa5dbd commit 9c88e24

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

articles/azure-monitor/app/javascript-sdk.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,18 @@ ms.reviewer: mmcc
2121
## Get started
2222

2323
The Application Insights JavaScript SDK is implemented with a runtime snippet for out-of-the-box web analytics.
24+
The JavaScript snippet can be added to your webpages manually or via the automatic snippet injection.
2425

25-
### Enable Application Insights SDK for JavaScript
26+
### Enable Application Insights SDK for JavaScript automatically
27+
28+
The automatic Snippet injection feature available in the Application Insights .NET core SDK and the Application Insights Node.js SDK (preview)
29+
allows you to automatically inject the Application Insights JavaScript SDK into every webpage of your web application.
30+
For more information, see [Application Insights .NET core SDK Snippet Injection](./asp-net-core.md?tabs=netcorenew%2Cnetcore6#enable-client-side-telemetry-for-web-applications)
31+
and [Application Insights Node.js SDK Snippet Injection (preview)](./nodejs.md#automatic-web-instrumentationpreview).
32+
However, if you want more control over which pages to add the Application Insights JavaScript SDK
33+
or if you're using a programming language other than .NET and Node.js, please follow the manual configuration steps below.
34+
35+
### Enable Application Insights SDK for JavaScript manually
2636

2737
Only two steps are required to enable the Application Insights SDK for JavaScript.
2838

articles/azure-monitor/app/nodejs.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,33 @@ appInsights.defaultClient.context.tags[appInsights.defaultClient.context.keys.cl
174174
appInsights.start();
175175
```
176176

177-
### Automatic web snippet injection (preview)
177+
### Automatic web Instrumentation[Preview]
178178

179-
You can use automatic web snippet injection to enable [Application Insights usage experiences](usage-overview.md) and browser diagnostic experiences with a simple configuration. It's an easier alternative to manually adding the JavaScript snippet or npm package to your JavaScript web code.
179+
Automatic web Instrumentation can be enabled for node server via configuration
180180

181-
For node server with configuration, set `enableAutoWebSnippetInjection` to `true`. Alternatively, set the environment variable as `APPLICATIONINSIGHTS_WEB_SNIPPET_ENABLED = true`. Automatic web snippet injection is available in Application Insights Node.js SDK version 2.3.0 or greater. For more information, see [Application Insights Node.js GitHub Readme](https://github.com/microsoft/ApplicationInsights-node.js#automatic-web-snippet-injectionpreview).
181+
```javascript
182+
let appInsights = require("applicationinsights");
183+
appInsights.setup("<connection_string>")
184+
.enableWebInstrumentation(true)
185+
.start();
186+
```
187+
188+
or by setting environment variable `APPLICATIONINSIGHTS_WEB_INSTRUMENTATION_ENABLED = true`.
189+
190+
Web Instrumentation will be enabled on node server responses when all of the following requirements are met:
191+
192+
- Response has status code `200`.
193+
- Response method is `GET`.
194+
- Sever response has `Content-Type` html.
195+
- Server response contains both `<head>` and `</head>` Tags.
196+
- If response is compressed, it must have only one `Content-Encoding` type, and encoding type must be one of `gzip`, `br` or `deflate`.
197+
- Response does not contain current /backup web Instrumentation CDN endpoints. (current and backup Web Instrumentation CDN endpoints [here](https://github.com/microsoft/ApplicationInsights-JS#active-public-cdn-endpoints))
198+
199+
web Instrumentation CDN endpoint can be changed by setting environment variable `APPLICATIONINSIGHTS_WEB_INSTRUMENTATION_SOURCE = "web Instrumentation CDN endpoints"`.
200+
web Instrumentation connection string can be changed by setting environment variable `APPLICATIONINSIGHTS_WEB_INSTRUMENTATION_CONNECTION_STRING = "web Instrumentation connection string"`
201+
202+
> [!Note]
203+
> Web Instrumentation may slow down server response time, especially when response size is large or response is compressed. For the case in which some middle layers are applied, it may result in web Instrumentation not working and original response will be returned.
182204
183205
### Automatic third-party instrumentation
184206

0 commit comments

Comments
 (0)