@@ -109,11 +109,14 @@ Use one of the following two ways to configure the connection string:
109
109
110
110
- Use configuration object :
111
111
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 );
117
120
118
121
```
119
122
@@ -209,21 +212,23 @@ To set the cloud role instance, see [cloud role instance](java-standalone-config
209
212
210
213
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).
211
214
212
- ```javascript
215
+ ```typescript
213
216
.. .
214
- const { ApplicationInsightsClient , ApplicationInsightsConfig } = require (" applicationinsights " );
217
+ const { useAzureMonitor , AzureMonitorOpenTelemetryOptions } = require (" @azure/monitor-opentelemetry " );
215
218
const { Resource } = require (" @opentelemetry/resources" );
216
219
const { SemanticResourceAttributes } = require (" @opentelemetry/semantic-conventions" );
217
220
// ----------------------------------------
218
221
// Setting role name and role instance
219
222
// ----------------------------------------
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" ,
223
225
[SemanticResourceAttributes .SERVICE_NAMESPACE ]: " my-namespace" ,
224
226
[SemanticResourceAttributes .SERVICE_INSTANCE_ID ]: " my-instance" ,
225
227
});
226
- const appInsights = new ApplicationInsightsClient (config );
228
+ const options : AzureMonitorOpenTelemetryOptions = {
229
+ resource : customResource
230
+ };
231
+ useAzureMonitor (options );
227
232
```
228
233
229
234
### [Python](#tab/python)
@@ -286,11 +291,15 @@ Starting from 3.4.0, rate-limited sampling is available and is now the default.
286
291
287
292
#### [Node.js](#tab/nodejs)
288
293
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 );
294
303
```
295
304
296
305
#### [Python](#tab/python)
@@ -393,15 +402,16 @@ For more information about Java, see the [Java supplemental documentation](java-
393
402
394
403
#### [Node.js](#tab/nodejs)
395
404
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).
399
406
400
- const credential = new ManagedIdentityCredential ();
407
+ ```typescript
408
+ const { useAzureMonitor , AzureMonitorOpenTelemetryOptions } = require (" @azure/monitor-opentelemetry" );
409
+ const { ManagedIdentityCredential } = require (" @azure/identity" );
401
410
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 );
405
415
```
406
416
407
417
#### [Python](#tab/python)
@@ -511,15 +521,19 @@ By default, the AzureMonitorExporter uses one of the following locations for off
511
521
To override the default directory , you should set `storageDirectory `.
512
522
513
523
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
+ }
521
535
};
522
- const appInsights = new ApplicationInsightsClient ( config );
536
+ useAzureMonitor ( options );
523
537
```
524
538
525
539
To disable this feature , you should set `disableOfflineStorage = true `.
@@ -621,16 +635,18 @@ For more information about Java, see the [Java supplemental documentation](java-
621
635
622
636
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).
623
637
624
- ```javascript
625
- const { ApplicationInsightsClient , ApplicationInsightsConfig } = require (" applicationinsights " );
638
+ ```typescript
639
+ const { useAzureMonitor , AzureMonitorOpenTelemetryOptions } = require (" @azure/monitor-opentelemetry " );
626
640
const { BatchSpanProcessor } = require ('@opentelemetry/sdk-trace-base' );
627
641
const { OTLPTraceExporter } = require ('@opentelemetry/exporter-trace-otlp-http' );
628
-
629
- const appInsights = new ApplicationInsightsClient ( new ApplicationInsightsConfig () );
642
+
643
+ useAzureMonitor ( );
630
644
const otlpExporter = new OTLPTraceExporter ();
631
- appInsights .getTraceHandler ().addSpanProcessor (new BatchSpanProcessor (otlpExporter ));
645
+ const tracerProvider = trace .getTracerProvider ().getDelegate ();
646
+ tracerProvider .addSpanProcessor (new BatchSpanProcessor (otlpExporter ));
632
647
```
633
648
649
+
634
650
#### [Python](#tab/python)
635
651
636
652
1 . Install the [opentelemetry - exporter - otlp ](https :// pypi.org/project/opentelemetry-exporter-otlp/) package.
0 commit comments