Skip to content

Commit cefb8af

Browse files
Merge pull request #249887 from hectorhdzg/hectorhdzg/distro
Update docs for Azure Monitor OpenTelemetry Node.js
2 parents 6e9d994 + bbd2367 commit cefb8af

File tree

2 files changed

+57
-42
lines changed

2 files changed

+57
-42
lines changed

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

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,14 @@ Use one of the following two ways to configure the connection string:
109109

110110
- Use configuration object:
111111

112-
```javascript
113-
const { ApplicationInsightsClient, ApplicationInsightsConfig } = require("applicationinsights");
114-
const config = new ApplicationInsightsConfig();
115-
config.azureMonitorExporterConfig.connectionString = "<Your Connection String>";
116-
const appInsights = new ApplicationInsightsClient(config);
112+
```typescript
113+
const { useAzureMonitor, AzureMonitorOpenTelemetryOptions } = require("@azure/monitor-opentelemetry");
114+
const options: AzureMonitorOpenTelemetryOptions = {
115+
azureMonitorExporterConfig: {
116+
connectionString: "<your connection string>"
117+
}
118+
};
119+
useAzureMonitor(options);
117120

118121
```
119122

@@ -209,21 +212,23 @@ To set the cloud role instance, see [cloud role instance](java-standalone-config
209212

210213
Set the Cloud Role Name and the Cloud Role Instance via [Resource](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/sdk.md#resource-sdk) attributes. Cloud Role Name uses `service.namespace` and `service.name` attributes, although it falls back to `service.name` if `service.namespace` isn't set. Cloud Role Instance uses the `service.instance.id` attribute value. For information on standard attributes for resources, see [Resource Semantic Conventions](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/README.md).
211214
212-
```javascript
215+
```typescript
213216
...
214-
const { ApplicationInsightsClient, ApplicationInsightsConfig } = require("applicationinsights");
217+
const { useAzureMonitor, AzureMonitorOpenTelemetryOptions } = require("@azure/monitor-opentelemetry");
215218
const { Resource } = require("@opentelemetry/resources");
216219
const { SemanticResourceAttributes } = require("@opentelemetry/semantic-conventions");
217220
// ----------------------------------------
218221
// Setting role name and role instance
219222
// ----------------------------------------
220-
const config = new ApplicationInsightsConfig();
221-
config.resource = new Resource({
222-
[SemanticResourceAttributes.SERVICE_NAME]: "my-helloworld-service",
223+
const customResource = new Resource({
224+
[SemanticResourceAttributes.SERVICE_NAME]: "my-service",
223225
[SemanticResourceAttributes.SERVICE_NAMESPACE]: "my-namespace",
224226
[SemanticResourceAttributes.SERVICE_INSTANCE_ID]: "my-instance",
225227
});
226-
const appInsights = new ApplicationInsightsClient(config);
228+
const options: AzureMonitorOpenTelemetryOptions = {
229+
resource: customResource
230+
};
231+
useAzureMonitor(options);
227232
```
228233

229234
### [Python](#tab/python)
@@ -286,11 +291,15 @@ Starting from 3.4.0, rate-limited sampling is available and is now the default.
286291

287292
#### [Node.js](#tab/nodejs)
288293

289-
```javascript
290-
const { ApplicationInsightsClient, ApplicationInsightsConfig } = require("applicationinsights");
291-
const config = new ApplicationInsightsConfig();
292-
config.samplingRatio = 0.75;
293-
const appInsights = new ApplicationInsightsClient(config);
294+
The sampler expects a sample rate of between 0 and 1 inclusive. A rate of 0.1 means approximately 10% of your traces are sent.
295+
296+
```typescript
297+
const { useAzureMonitor, AzureMonitorOpenTelemetryOptions } = require("@azure/monitor-opentelemetry");
298+
299+
const options: AzureMonitorOpenTelemetryOptions = {
300+
samplingRatio: 0.1
301+
};
302+
useAzureMonitor(options);
294303
```
295304

296305
#### [Python](#tab/python)
@@ -393,15 +402,16 @@ For more information about Java, see the [Java supplemental documentation](java-
393402

394403
#### [Node.js](#tab/nodejs)
395404

396-
```javascript
397-
const { ApplicationInsightsClient, ApplicationInsightsConfig } = require("applicationinsights");
398-
const { ManagedIdentityCredential } = require("@azure/identity");
405+
We support the credential classes provided by [Azure Identity](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#credential-classes).
399406
400-
const credential = new ManagedIdentityCredential();
407+
```typescript
408+
const { useAzureMonitor, AzureMonitorOpenTelemetryOptions } = require("@azure/monitor-opentelemetry");
409+
const { ManagedIdentityCredential } = require("@azure/identity");
401410

402-
const config = new ApplicationInsightsConfig();
403-
config.azureMonitorExporterConfig.aadTokenCredential = credential;
404-
const appInsights = new ApplicationInsightsClient(config);
411+
const options: AzureMonitorOpenTelemetryOptions = {
412+
credential: new ManagedIdentityCredential()
413+
};
414+
useAzureMonitor(options);
405415
```
406416

407417
#### [Python](#tab/python)
@@ -511,15 +521,19 @@ By default, the AzureMonitorExporter uses one of the following locations for off
511521
To override the default directory, you should set `storageDirectory`.
512522

513523
For example:
514-
```javascript
515-
const { ApplicationInsightsClient, ApplicationInsightsConfig } = require("applicationinsights");
516-
const config = new ApplicationInsightsConfig();
517-
config.azureMonitorExporterConfig = {
518-
connectionString: "<Your Connection String>",
519-
storageDirectory: "C:\\SomeDirectory",
520-
disableOfflineStorage: false
524+
525+
526+
```typescript
527+
const { useAzureMonitor, AzureMonitorOpenTelemetryOptions } = require("@azure/monitor-opentelemetry");
528+
529+
const options: AzureMonitorOpenTelemetryOptions = {
530+
azureMonitorExporterConfig = {
531+
connectionString: "<Your Connection String>",
532+
storageDirectory: "C:\\SomeDirectory",
533+
disableOfflineStorage: false
534+
}
521535
};
522-
const appInsights = new ApplicationInsightsClient(config);
536+
useAzureMonitor(options);
523537
```
524538

525539
To disable this feature, you should set `disableOfflineStorage = true`.
@@ -621,16 +635,18 @@ For more information about Java, see the [Java supplemental documentation](java-
621635

622636
2. Add the following code snippet. This example assumes you have an OpenTelemetry Collector with an OTLP receiver running. For details, see the [example on GitHub](https://github.com/open-telemetry/opentelemetry-js/tree/main/examples/otlp-exporter-node).
623637
624-
```javascript
625-
const { ApplicationInsightsClient, ApplicationInsightsConfig } = require("applicationinsights");
638+
```typescript
639+
const { useAzureMonitor, AzureMonitorOpenTelemetryOptions } = require("@azure/monitor-opentelemetry");
626640
const { BatchSpanProcessor } = require('@opentelemetry/sdk-trace-base');
627641
const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-http');
628-
629-
const appInsights = new ApplicationInsightsClient(new ApplicationInsightsConfig());
642+
643+
useAzureMonitor();
630644
const otlpExporter = new OTLPTraceExporter();
631-
appInsights.getTraceHandler().addSpanProcessor(new BatchSpanProcessor(otlpExporter));
645+
const tracerProvider = trace.getTracerProvider().getDelegate();
646+
tracerProvider.addSpanProcessor(new BatchSpanProcessor(otlpExporter));
632647
```
633648

649+
634650
#### [Python](#tab/python)
635651

636652
1. Install the [opentelemetry-exporter-otlp](https://pypi.org/project/opentelemetry-exporter-otlp/) package.

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ Download the [applicationinsights-agent-3.4.16.jar](https://github.com/microsoft
101101

102102
Install these packages:
103103

104-
- [applicationinsights](https://www.npmjs.com/package/applicationinsights/v/beta)
104+
- [@azure/monitor-opentelemetry](https://www.npmjs.com/package/@azure/monitor-opentelemetry)
105105

106106
```sh
107-
npm install applicationinsights@beta
107+
npm install @azure/monitor-opentelemetry
108108
```
109109

110110
The following packages are also used for some specific scenarios described later in this article:
@@ -190,10 +190,9 @@ Point the JVM to the jar file by adding `-javaagent:"path/to/applicationinsights
190190
191191
##### [Node.js](#tab/nodejs)
192192

193-
```javascript
194-
const { ApplicationInsightsClient, ApplicationInsightsConfig } = require("applicationinsights");
195-
const config = new ApplicationInsightsConfig();
196-
const appInsights = new ApplicationInsightsClient(config);
193+
```typescript
194+
const { useAzureMonitor } = require("@azure/monitor-opentelemetry");
195+
useAzureMonitor();
197196
```
198197

199198
##### [Python](#tab/python)

0 commit comments

Comments
 (0)