@azure/monitor-opentelemetry 1.0.0-beta.1 → 1.0.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -23,11 +23,11 @@ See our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUP
23
23
 
24
24
  ### Enable Azure Monitor OpenTelemetry Client
25
25
 
26
- > *Important:* `AzureMonitorOpenTelemetryClient` must be setup *and* started *before* you import anything else. There may be resulting telemetry loss if other libraries are imported first.
26
+ > *Important:* `useAzureMonitor` must be called *before* you import anything else. There may be resulting telemetry loss if other libraries are imported first.
27
27
 
28
28
 
29
29
  ```typescript
30
- const { AzureMonitorOpenTelemetryClient, AzureMonitorOpenTelemetryOptions } = require("@azure/monitor-opentelemetry");
30
+ const { useAzureMonitor, AzureMonitorOpenTelemetryOptions } = require("@azure/monitor-opentelemetry");
31
31
 
32
32
  const options: AzureMonitorOpenTelemetryOptions = {
33
33
  azureMonitorExporterConfig: {
@@ -35,7 +35,7 @@ const options: AzureMonitorOpenTelemetryOptions = {
35
35
  process.env["APPLICATIONINSIGHTS_CONNECTION_STRING"] || "<your connection string>",
36
36
  },
37
37
  }
38
- const azureMonitorClient = new AzureMonitorOpenTelemetryClient(options);
38
+ useAzureMonitor(options);
39
39
  ```
40
40
 
41
41
  * Connection String could be set using the environment variable APPLICATIONINSIGHTS\_CONNECTION\_STRING
@@ -70,8 +70,6 @@ const options: AzureMonitorOpenTelemetryOptions = {
70
70
  url: '<opentelemetry-collector-url>', // url is optional and can be omitted - default is http://localhost:4318/v1/logs
71
71
  },
72
72
  samplingRatio: 1,
73
- enableAutoCollectStandardMetrics: true,
74
- enableAutoCollectPerformance: true,
75
73
  instrumentationOptions: {
76
74
  azureSdk: { enabled: true },
77
75
  http: { enabled: true },
@@ -84,7 +82,7 @@ const options: AzureMonitorOpenTelemetryOptions = {
84
82
  resource: resource
85
83
  };
86
84
 
87
- const azureMonitorClient = new AzureMonitorOpenTelemetryClient(options);
85
+ useAzureMonitor(options);
88
86
 
89
87
  ```
90
88
 
@@ -96,8 +94,6 @@ const azureMonitorClient = new AzureMonitorOpenTelemetryClient(options);
96
94
  | otlpMetricExporterConfig | OTLP Trace Exporter Configuration. [More info here](https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-exporter-metrics-otlp-http)
97
95
  | otlpLogExporterConfig | OTLP Trace Exporter Configuration. [More info here](https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/exporter-logs-otlp-http) | |
98
96
  | samplingRatio | Sampling ratio must take a value in the range [0,1], 1 meaning all data will sampled and 0 all Tracing data will be sampled out. | 1|
99
- | enableAutoCollectPerformance | Sets the state of performance tracking. If true performance counters will be collected every minute. | true|
100
- | enableAutoCollectStandardMetrics | Sets the state of Standard Metrics tracking. If true Standard Metrics will be collected every minute. | true|
101
97
  | instrumentationOptions| Allow configuration of OpenTelemetry Instrumentations. | {"http": { enabled: true },"azureSdk": { enabled: false },"mongoDb": { enabled: false },"mySql": { enabled: false },"postgreSql": { enabled: false },"redis": { enabled: false }}|
102
98
  | resource | Opentelemetry Resource. [More info here](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-resources) ||
103
99
 
@@ -148,17 +144,18 @@ The following OpenTelemetry Instrumentation libraries are included as part of Az
148
144
  Other OpenTelemetry Instrumentations are available [here](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node) and could be added using TracerProvider in AzureMonitorOpenTelemetryClient.
149
145
 
150
146
  ```typescript
151
- const { AzureMonitorOpenTelemetryClient } = require("@azure/monitor-opentelemetry");
147
+ const { useAzureMonitor } = require("@azure/monitor-opentelemetry");
148
+ const { metrics, trace } = require("@opentelemetry/api");
152
149
  const { registerInstrumentations } = require("@opentelemetry/instrumentation");
153
150
  const { ExpressInstrumentation } = require('@opentelemetry/instrumentation-express');
154
151
 
155
- const azureMonitorClient = new AzureMonitorOpenTelemetryClient();
152
+ useAzureMonitor();
156
153
  const instrumentations = [
157
154
  new ExpressInstrumentation(),
158
155
  ];
159
156
  registerInstrumentations({
160
- tracerProvider: azureMonitorClient.getTracerProvider(),
161
- meterProvider: azureMonitorClient.getMeterProvider(),
157
+ tracerProvider: trace.getTracerProvider(),
158
+ meterProvider: metrics.getMeterProvider(),
162
159
  instrumentations: instrumentations,
163
160
  });
164
161
 
@@ -171,7 +168,7 @@ You might set the Cloud Role Name and the Cloud Role Instance via [OpenTelemetry
171
168
 
172
169
 
173
170
  ```typescript
174
- const { AzureMonitorOpenTelemetryClient, AzureMonitorOpenTelemetryOptions } = require("@azure/monitor-opentelemetry");
171
+ const { useAzureMonitor, AzureMonitorOpenTelemetryOptions } = require("@azure/monitor-opentelemetry");
175
172
  const { Resource } = require("@opentelemetry/resources");
176
173
  const { SemanticResourceAttributes } = require("@opentelemetry/semantic-conventions");
177
174
 
@@ -184,7 +181,7 @@ customResource.attributes[SemanticResourceAttributes.SERVICE_NAMESPACE] = "my-na
184
181
  customResource.attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID] = "my-instance";
185
182
 
186
183
  const options: AzureMonitorOpenTelemetryOptions = { resource : customResource }
187
- const azureMonitorClient = new AzureMonitorOpenTelemetryClient(options);
184
+ useAzureMonitor(options);
188
185
  ```
189
186
 
190
187
  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).
@@ -212,28 +209,31 @@ Any [attributes](#add-span-attributes) you add to spans are exported as custom p
212
209
  Use a custom processor:
213
210
 
214
211
  ```typescript
215
- const { AzureMonitorOpenTelemetryClient } = require("@azure/monitor-opentelemetry");
212
+ const { useAzureMonitor } = require("@azure/monitor-opentelemetry");
213
+ const { trace } = require("@opentelemetry/api");
216
214
  const { ReadableSpan, Span, SpanProcessor } = require("@opentelemetry/sdk-trace-base");
215
+ const { NodeTracerProvider } = require("@opentelemetry/sdk-trace-node");
217
216
  const { SemanticAttributes } = require("@opentelemetry/semantic-conventions");
218
217
 
219
- const azureMonitorClient = new AzureMonitorOpenTelemetryClient();
218
+ useAzureMonitor();
220
219
 
221
220
  class SpanEnrichingProcessor implements SpanProcessor{
222
- forceFlush(): Promise<void>{
223
- return Promise.resolve();
224
- }
225
- shutdown(): Promise<void>{
226
- return Promise.resolve();
227
- }
228
- onStart(_span: Span): void{}
229
- onEnd(span: ReadableSpan){
230
- span.attributes["CustomDimension1"] = "value1";
231
- span.attributes["CustomDimension2"] = "value2";
232
- span.attributes[SemanticAttributes.HTTP_CLIENT_IP] = "<IP Address>";
233
- }
221
+ forceFlush(): Promise<void>{
222
+ return Promise.resolve();
223
+ }
224
+ shutdown(): Promise<void>{
225
+ return Promise.resolve();
226
+ }
227
+ onStart(_span: Span): void{}
228
+ onEnd(span: ReadableSpan){
229
+ span.attributes["CustomDimension1"] = "value1";
230
+ span.attributes["CustomDimension2"] = "value2";
231
+ span.attributes[SemanticAttributes.HTTP_CLIENT_IP] = "<IP Address>";
232
+ }
234
233
  }
235
234
 
236
- azureMonitorClient.getTracerProvider().addSpanProcessor(new SpanEnrichingProcessor());
235
+ const tracerProvider = trace.getTracerProvider().getDelegate();
236
+ tracerProvider.addSpanProcessor(new SpanEnrichingProcessor());
237
237
  ```
238
238
 
239
239
  ### Filter telemetry
@@ -245,7 +245,7 @@ You might use the following ways to filter out telemetry before it leaves your a
245
245
  The following example shows how to exclude a certain URL from being tracked by using the [HTTP/HTTPS instrumentation library](https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-instrumentation-http):
246
246
 
247
247
  ```typescript
248
- const { AzureMonitorOpenTelemetryClient, AzureMonitorOpenTelemetryOptions } = require("@azure/monitor-opentelemetry");
248
+ const { useAzureMonitor, AzureMonitorOpenTelemetryOptions } = require("@azure/monitor-opentelemetry");
249
249
  const { IncomingMessage } = require("http");
250
250
  const { RequestOptions } = require("https");
251
251
  const { HttpInstrumentationConfig }= require("@opentelemetry/instrumentation-http");
@@ -272,7 +272,7 @@ You might use the following ways to filter out telemetry before it leaves your a
272
272
  http: httpInstrumentationConfig,
273
273
  }
274
274
  };
275
- const azureMonitorClient = new AzureMonitorOpenTelemetryClient(options);
275
+ useAzureMonitor(options);
276
276
 
277
277
  ```
278
278
 
@@ -322,10 +322,11 @@ The [OpenTelemetry Specification](https://github.com/open-telemetry/opentelemetr
322
322
  describes the instruments and provides examples of when you might use each one.
323
323
 
324
324
  ```typescript
325
- const { AzureMonitorOpenTelemetryClient } = require("@azure/monitor-opentelemetry");
325
+ const { useAzureMonitor } = require("@azure/monitor-opentelemetry");
326
+ const { metrics } = require("@opentelemetry/api");
326
327
 
327
- const azureMonitorClient = new AzureMonitorOpenTelemetryClient();
328
- const meter = azureMonitorClient.getMeter();
328
+ useAzureMonitor();
329
+ const meter = metrics.getMeter("testMeter");
329
330
 
330
331
  let histogram = meter.createHistogram("histogram");
331
332
  let counter = meter.createCounter("counter");
@@ -353,10 +354,12 @@ For instance, exceptions caught by your code are *not* ordinarily not reported,
353
354
  and thus draw attention to them in relevant experiences including the failures blade and end-to-end transaction view.
354
355
 
355
356
  ```typescript
356
- const { AzureMonitorOpenTelemetryClient } = require("@azure/monitor-opentelemetry");
357
+ const { useAzureMonitor } = require("@azure/monitor-opentelemetry");
358
+ const { trace } = require("@opentelemetry/api");
359
+
360
+ useAzureMonitor();
361
+ const tracer = trace.getTracer("testMeter");
357
362
 
358
- const azureMonitorClient = new AzureMonitorOpenTelemetryClient();
359
- const tracer = azureMonitorClient.getTracer();
360
363
  let span = tracer.startSpan("hello");
361
364
  try{
362
365
  throw new Error("Test Error");
@@ -373,27 +376,20 @@ catch(error){
373
376
  Azure Monitor OpenTelemetry uses the OpenTelemetry API Logger for internal logs. To enable it, use the following code:
374
377
 
375
378
  ```typescript
376
- const { AzureMonitorOpenTelemetryClient } = require("@azure/monitor-opentelemetry");
379
+ const { useAzureMonitor } = require("@azure/monitor-opentelemetry");
377
380
  const { DiagLogLevel } = require("@opentelemetry/api");
378
381
 
379
- const azureMonitor = new AzureMonitorOpenTelemetryClient();
380
- const logger = azureMonitorClient.getLogger();
381
- logger.updateLogLevel(DiagLogLevel.DEBUG);
382
- ```
382
+ process.env.APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_LEVEL = "VERBOSE";
383
+ process.env.APPLICATIONINSIGHTS_LOG_DESTINATION = "file";
384
+ process.env.APPLICATIONINSIGHTS_LOGDIR = "C:/applicationinsights/logs";
383
385
 
386
+ useAzureMonitor();
387
+ ```
384
388
 
385
389
  `APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_LEVEL` environment varialbe could be used to set desired log level, supporting the following values: `NONE`, `ERROR`, `WARN`, `INFO`, `DEBUG`, `VERBOSE` and `ALL`.
386
390
 
387
-
388
391
  Logs could be put into local file using `APPLICATIONINSIGHTS_LOG_DESTINATION` environment variable, supported values are `file` and `file+console`, a file named `applicationinsights.log` will be generated on tmp folder by default, including all logs, `/tmp` for *nix and `USERDIR/AppData/Local/Temp` for Windows. Log directory could be configured using `APPLICATIONINSIGHTS_LOGDIR` environment variable.
389
392
 
390
- ```javascript
391
- process.env.APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_LEVEL = "VERBOSE";
392
- process.env.APPLICATIONINSIGHTS_LOG_DESTINATION = "file";
393
- process.env.APPLICATIONINSIGHTS_LOGDIR = "C:/applicationinsights/logs";
394
-
395
- // Azure Monitor OpenTelemetry setup....
396
- ```
397
393
 
398
394
  ## Examples
399
395
 
@@ -403,20 +399,6 @@ For complete samples of a few champion scenarios, see the [`samples/`](https://g
403
399
 
404
400
  For more information on the OpenTelemetry project, please review the [**OpenTelemetry Specifications**](https://github.com/open-telemetry/opentelemetry-specification#opentelemetry-specification).
405
401
 
406
- ## Troubleshooting
407
-
408
- ### Enable debug logging
409
-
410
- You can enable debug logging by changing the logging level of your provider.
411
-
412
- ```js
413
- const { DiagConsoleLogger, DiagLogLevel, diag } = require("@opentelemetry/api");
414
- const { NodeTracerProvider } = require("@opentelemetry/sdk-trace-node");
415
-
416
- const provider = new NodeTracerProvider();
417
- diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.ALL);
418
- provider.register();
419
- ```
420
402
 
421
403
  ### Plugin Registry
422
404