@azure/monitor-opentelemetry 1.0.0 → 1.1.0

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
@@ -30,7 +30,7 @@ See our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUP
30
30
  const { useAzureMonitor, AzureMonitorOpenTelemetryOptions } = require("@azure/monitor-opentelemetry");
31
31
 
32
32
  const options: AzureMonitorOpenTelemetryOptions = {
33
- azureMonitorExporterConfig: {
33
+ azureMonitorExporterOptions: {
34
34
  connectionString:
35
35
  process.env["APPLICATIONINSIGHTS_CONNECTION_STRING"] || "<your connection string>",
36
36
  },
@@ -49,7 +49,7 @@ const { Resource } = require("@opentelemetry/resources");
49
49
 
50
50
  const resource = new Resource({ "testAttribute": "testValue" });
51
51
  const options: AzureMonitorOpenTelemetryOptions = {
52
- azureMonitorExporterConfig: {
52
+ azureMonitorExporterOptions: {
53
53
  // Offline storage
54
54
  storageDirectory: "c://azureMonitor",
55
55
  // Automatic retries
@@ -89,7 +89,7 @@ useAzureMonitor(options);
89
89
 
90
90
  |Property|Description|Default|
91
91
  | ------------------------------- |------------------------------------------------------------------------------------------------------------|-------|
92
- | azureMonitorExporterConfig | Azure Monitor OpenTelemetry Exporter Configuration. [More info here](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/monitor/monitor-opentelemetry-exporter) | |
92
+ | azureMonitorExporterOptions | Azure Monitor OpenTelemetry Exporter Configuration. [More info here](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/monitor/monitor-opentelemetry-exporter) | |
93
93
  | otlpTraceExporterConfig | OTLP Trace Exporter Configuration. [More info here](https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/exporter-trace-otlp-http)
94
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)
95
95
  | otlpLogExporterConfig | OTLP Trace Exporter Configuration. [More info here](https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/exporter-logs-otlp-http) | |
@@ -184,7 +184,7 @@ const options: AzureMonitorOpenTelemetryOptions = { resource : customResource }
184
184
  useAzureMonitor(options);
185
185
  ```
186
186
 
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).
187
+ For information on standard attributes for resources, see [Resource Semantic Conventions](https://github.com/open-telemetry/semantic-conventions/tree/main/docs/resource).
188
188
 
189
189
 
190
190
  ## Modify telemetry
package/dist/index.js CHANGED
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var api = require('@opentelemetry/api');
6
4
  var apiLogs = require('@opentelemetry/api-logs');
7
5
  var resources = require('@opentelemetry/resources');
@@ -23,8 +21,7 @@ var sdkMetrics = require('@opentelemetry/sdk-metrics');
23
21
  var semanticConventions = require('@opentelemetry/semantic-conventions');
24
22
  var sdkLogs = require('@opentelemetry/sdk-logs');
25
23
 
26
- function _interopNamespace(e) {
27
- if (e && e.__esModule) return e;
24
+ function _interopNamespaceDefault(e) {
28
25
  var n = Object.create(null);
29
26
  if (e) {
30
27
  Object.keys(e).forEach(function (k) {
@@ -37,15 +34,16 @@ function _interopNamespace(e) {
37
34
  }
38
35
  });
39
36
  }
40
- n["default"] = e;
37
+ n.default = e;
41
38
  return Object.freeze(n);
42
39
  }
43
40
 
44
- var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
45
- var path__namespace = /*#__PURE__*/_interopNamespace(path);
46
- var os__namespace = /*#__PURE__*/_interopNamespace(os);
41
+ var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
42
+ var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
43
+ var os__namespace = /*#__PURE__*/_interopNamespaceDefault(os);
47
44
 
48
45
  // Copyright (c) Microsoft Corporation.
46
+ // Licensed under the MIT license.
49
47
  const statAsync = util.promisify(fs__namespace.stat);
50
48
  const lstatAsync = util.promisify(fs__namespace.lstat);
51
49
  const mkdirAsync = util.promisify(fs__namespace.mkdir);
@@ -109,6 +107,7 @@ function ignoreOutgoingRequestHook(request) {
109
107
  }
110
108
 
111
109
  // Copyright (c) Microsoft Corporation.
110
+ // Licensed under the MIT license.
112
111
  class InternalAzureLogger {
113
112
  constructor() {
114
113
  this._TAG = "InternalLogger:";
@@ -116,11 +115,11 @@ class InternalAzureLogger {
116
115
  this._fileCleanupTimer = null;
117
116
  this._logToFile = false;
118
117
  this._logToConsole = true;
119
- const logDestination = process.env.APPLICATIONINSIGHTS_LOG_DESTINATION; // destination can be one of file, console or file+console
120
- if (logDestination === "file+console") {
118
+ this._logDestination = process.env.APPLICATIONINSIGHTS_LOG_DESTINATION; // destination can be one of file, console or file+console
119
+ if (this._logDestination === "file+console") {
121
120
  this._logToFile = true;
122
121
  }
123
- if (logDestination === "file") {
122
+ if (this._logDestination === "file") {
124
123
  this._logToFile = true;
125
124
  this._logToConsole = false;
126
125
  }
@@ -246,6 +245,7 @@ class InternalAzureLogger {
246
245
  }
247
246
 
248
247
  // Copyright (c) Microsoft Corporation.
248
+ // Licensed under the MIT license.
249
249
  class Logger {
250
250
  static getInstance() {
251
251
  if (!Logger._instance) {
@@ -324,6 +324,7 @@ class Logger {
324
324
  }
325
325
 
326
326
  // Copyright (c) Microsoft Corporation.
327
+ // Licensed under the MIT license.
327
328
  const ENV_CONFIGURATION_FILE = "APPLICATIONINSIGHTS_CONFIGURATION_FILE";
328
329
  const ENV_CONTENT = "APPLICATIONINSIGHTS_CONFIGURATION_CONTENT";
329
330
  /**
@@ -385,6 +386,7 @@ class JsonConfig {
385
386
  }
386
387
 
387
388
  // Copyright (c) Microsoft Corporation.
389
+ // Licensed under the MIT license.
388
390
  /**
389
391
  * Azure Monitor OpenTelemetry Client Configuration
390
392
  */
@@ -415,10 +417,6 @@ class InternalConfig {
415
417
  redis4: { enabled: false },
416
418
  };
417
419
  this._resource = this._getDefaultResource();
418
- // Merge JSON configuration file if available
419
- this._mergeConfig();
420
- // Check for explicitly passed options when instantiating client
421
- // This will take precedence over other settings
422
420
  if (options) {
423
421
  // Merge default with provided options
424
422
  this.azureMonitorExporterOptions = Object.assign(this.azureMonitorExporterOptions, options.azureMonitorExporterOptions);
@@ -426,6 +424,8 @@ class InternalConfig {
426
424
  this.resource = Object.assign(this.resource, options.resource);
427
425
  this.samplingRatio = options.samplingRatio || this.samplingRatio;
428
426
  }
427
+ // JSON configuration will take precedence over other settings
428
+ this._mergeConfig();
429
429
  }
430
430
  _mergeConfig() {
431
431
  try {
@@ -452,6 +452,7 @@ class InternalConfig {
452
452
  }
453
453
 
454
454
  // Copyright (c) Microsoft Corporation.
455
+ // Licensed under the MIT license.
455
456
  /**
456
457
  * Azure Monitor Standard Metrics
457
458
  * @internal
@@ -688,6 +689,7 @@ var PerformanceCounterMetricNames;
688
689
  })(PerformanceCounterMetricNames || (PerformanceCounterMetricNames = {}));
689
690
 
690
691
  // Copyright (c) Microsoft Corporation.
692
+ // Licensed under the MIT license.
691
693
  /**
692
694
  * Azure Monitor OpenTelemetry Metric Handler
693
695
  */
@@ -698,13 +700,38 @@ class MetricHandler {
698
700
  * @param options - Metric Handler options.
699
701
  */
700
702
  constructor(config, options) {
703
+ var _a, _b, _c, _d, _e, _f, _g;
701
704
  this._collectionInterval = 60000; // 60 seconds
702
705
  this._config = config;
703
706
  if (!process.env[APPLICATION_INSIGHTS_NO_STANDARD_METRICS]) {
704
707
  this._standardMetrics = new StandardMetrics(this._config);
705
708
  }
709
+ // Adding Views of instrumentations will allow customer to add Metric Readers after, and get access to previously created metrics using the views shared state
710
+ const views = [];
711
+ if ((_a = config.instrumentationOptions.azureSdk) === null || _a === void 0 ? void 0 : _a.enabled) {
712
+ views.push(new sdkMetrics.View({ meterName: "@azure/opentelemetry-instrumentation-azure-sdk" }));
713
+ }
714
+ if ((_b = config.instrumentationOptions.http) === null || _b === void 0 ? void 0 : _b.enabled) {
715
+ views.push(new sdkMetrics.View({ meterName: "@azure/opentelemetry-instrumentation-http" }));
716
+ }
717
+ if ((_c = config.instrumentationOptions.mongoDb) === null || _c === void 0 ? void 0 : _c.enabled) {
718
+ views.push(new sdkMetrics.View({ meterName: "@azure/opentelemetry-instrumentation-mongodb" }));
719
+ }
720
+ if ((_d = config.instrumentationOptions.mySql) === null || _d === void 0 ? void 0 : _d.enabled) {
721
+ views.push(new sdkMetrics.View({ meterName: "@opentelemetry/instrumentation-mysql" }));
722
+ }
723
+ if ((_e = config.instrumentationOptions.postgreSql) === null || _e === void 0 ? void 0 : _e.enabled) {
724
+ views.push(new sdkMetrics.View({ meterName: "@opentelemetry/instrumentation-pg" }));
725
+ }
726
+ if ((_f = config.instrumentationOptions.redis4) === null || _f === void 0 ? void 0 : _f.enabled) {
727
+ views.push(new sdkMetrics.View({ meterName: "@opentelemetry/instrumentation-redis-4" }));
728
+ }
729
+ if ((_g = config.instrumentationOptions.redis) === null || _g === void 0 ? void 0 : _g.enabled) {
730
+ views.push(new sdkMetrics.View({ meterName: "@azure/opentelemetry-instrumentation-redis" }));
731
+ }
706
732
  const meterProviderConfig = {
707
733
  resource: this._config.resource,
734
+ views: views,
708
735
  };
709
736
  this._meterProvider = new sdkMetrics.MeterProvider(meterProviderConfig);
710
737
  this._azureExporter = new monitorOpentelemetryExporter.AzureMonitorMetricExporter(this._config.azureMonitorExporterOptions);
@@ -771,6 +798,7 @@ class AzureMonitorSpanProcessor {
771
798
  }
772
799
 
773
800
  // Copyright (c) Microsoft Corporation.
801
+ // Licensed under the MIT license.
774
802
  class AzureFunctionsHook {
775
803
  constructor() {
776
804
  try {
@@ -894,6 +922,7 @@ class ApplicationInsightsSampler {
894
922
  }
895
923
 
896
924
  // Copyright (c) Microsoft Corporation.
925
+ // Licensed under the MIT license.
897
926
  /**
898
927
  * Azure Monitor OpenTelemetry Trace Handler
899
928
  */
@@ -1023,6 +1052,7 @@ class AzureLogRecordProcessor {
1023
1052
  }
1024
1053
 
1025
1054
  // Copyright (c) Microsoft Corporation.
1055
+ // Licensed under the MIT license.
1026
1056
  /**
1027
1057
  * Azure Monitor OpenTelemetry Log Handler
1028
1058
  */
@@ -1064,25 +1094,28 @@ class LogHandler {
1064
1094
 
1065
1095
  // Copyright (c) Microsoft Corporation.
1066
1096
  // Licensed under the MIT license.
1067
- const AZURE_MONITOR_OPENTELEMETRY_VERSION = "1.0.0";
1097
+ const AZURE_MONITOR_OPENTELEMETRY_VERSION = "1.1.0";
1068
1098
  const AZURE_MONITOR_STATSBEAT_FEATURES = "AZURE_MONITOR_STATSBEAT_FEATURES";
1069
1099
  var StatsbeatFeature;
1070
1100
  (function (StatsbeatFeature) {
1071
- StatsbeatFeature[StatsbeatFeature["DISK_RETRY"] = 0] = "DISK_RETRY";
1072
- StatsbeatFeature[StatsbeatFeature["AAD_HANDLING"] = 1] = "AAD_HANDLING";
1073
- StatsbeatFeature[StatsbeatFeature["WEB_SNIPPET"] = 2] = "WEB_SNIPPET";
1074
- StatsbeatFeature[StatsbeatFeature["DISTRO"] = 4] = "DISTRO";
1101
+ StatsbeatFeature[StatsbeatFeature["NONE"] = 0] = "NONE";
1102
+ StatsbeatFeature[StatsbeatFeature["DISK_RETRY"] = 1] = "DISK_RETRY";
1103
+ StatsbeatFeature[StatsbeatFeature["AAD_HANDLING"] = 2] = "AAD_HANDLING";
1104
+ StatsbeatFeature[StatsbeatFeature["WEB_SNIPPET"] = 4] = "WEB_SNIPPET";
1105
+ StatsbeatFeature[StatsbeatFeature["DISTRO"] = 8] = "DISTRO";
1075
1106
  })(StatsbeatFeature || (StatsbeatFeature = {}));
1076
1107
  var StatsbeatInstrumentation;
1077
1108
  (function (StatsbeatInstrumentation) {
1078
- StatsbeatInstrumentation[StatsbeatInstrumentation["AZURE_CORE_TRACING"] = 0] = "AZURE_CORE_TRACING";
1079
- StatsbeatInstrumentation[StatsbeatInstrumentation["MONGODB"] = 1] = "MONGODB";
1080
- StatsbeatInstrumentation[StatsbeatInstrumentation["MYSQL"] = 2] = "MYSQL";
1081
- StatsbeatInstrumentation[StatsbeatInstrumentation["REDIS"] = 4] = "REDIS";
1082
- StatsbeatInstrumentation[StatsbeatInstrumentation["POSTGRES"] = 8] = "POSTGRES";
1109
+ StatsbeatInstrumentation[StatsbeatInstrumentation["NONE"] = 0] = "NONE";
1110
+ StatsbeatInstrumentation[StatsbeatInstrumentation["AZURE_CORE_TRACING"] = 1] = "AZURE_CORE_TRACING";
1111
+ StatsbeatInstrumentation[StatsbeatInstrumentation["MONGODB"] = 2] = "MONGODB";
1112
+ StatsbeatInstrumentation[StatsbeatInstrumentation["MYSQL"] = 4] = "MYSQL";
1113
+ StatsbeatInstrumentation[StatsbeatInstrumentation["REDIS"] = 8] = "REDIS";
1114
+ StatsbeatInstrumentation[StatsbeatInstrumentation["POSTGRES"] = 16] = "POSTGRES";
1083
1115
  })(StatsbeatInstrumentation || (StatsbeatInstrumentation = {}));
1084
1116
 
1085
1117
  // Copyright (c) Microsoft Corporation.
1118
+ // Licensed under the MIT license.
1086
1119
  process.env["AZURE_MONITOR_DISTRO_VERSION"] = AZURE_MONITOR_OPENTELEMETRY_VERSION;
1087
1120
  let metricHandler;
1088
1121
  let traceHandler;
@@ -1113,7 +1146,7 @@ function shutdownAzureMonitor() {
1113
1146
  }
1114
1147
  function _setStatsbeatFeatures(config) {
1115
1148
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
1116
- let instrumentationBitMap = 0;
1149
+ let instrumentationBitMap = StatsbeatInstrumentation.NONE;
1117
1150
  if ((_b = (_a = config.instrumentationOptions) === null || _a === void 0 ? void 0 : _a.azureSdk) === null || _b === void 0 ? void 0 : _b.enabled) {
1118
1151
  instrumentationBitMap |= StatsbeatInstrumentation.AZURE_CORE_TRACING;
1119
1152
  }
@@ -1129,9 +1162,13 @@ function _setStatsbeatFeatures(config) {
1129
1162
  if ((_k = (_j = config.instrumentationOptions) === null || _j === void 0 ? void 0 : _j.redis) === null || _k === void 0 ? void 0 : _k.enabled) {
1130
1163
  instrumentationBitMap |= StatsbeatInstrumentation.REDIS;
1131
1164
  }
1132
- let featureBitMap = 0;
1165
+ let featureBitMap = StatsbeatFeature.NONE;
1133
1166
  featureBitMap |= StatsbeatFeature.DISTRO;
1134
1167
  try {
1168
+ const currentFeaturesBitMap = Number(process.env[AZURE_MONITOR_STATSBEAT_FEATURES]);
1169
+ if (!isNaN(currentFeaturesBitMap)) {
1170
+ featureBitMap |= currentFeaturesBitMap;
1171
+ }
1135
1172
  process.env[AZURE_MONITOR_STATSBEAT_FEATURES] = JSON.stringify({
1136
1173
  instrumentation: instrumentationBitMap,
1137
1174
  feature: featureBitMap,
@@ -38,7 +38,7 @@ export function shutdownAzureMonitor() {
38
38
  }
39
39
  function _setStatsbeatFeatures(config) {
40
40
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
41
- let instrumentationBitMap = 0;
41
+ let instrumentationBitMap = StatsbeatInstrumentation.NONE;
42
42
  if ((_b = (_a = config.instrumentationOptions) === null || _a === void 0 ? void 0 : _a.azureSdk) === null || _b === void 0 ? void 0 : _b.enabled) {
43
43
  instrumentationBitMap |= StatsbeatInstrumentation.AZURE_CORE_TRACING;
44
44
  }
@@ -54,9 +54,13 @@ function _setStatsbeatFeatures(config) {
54
54
  if ((_k = (_j = config.instrumentationOptions) === null || _j === void 0 ? void 0 : _j.redis) === null || _k === void 0 ? void 0 : _k.enabled) {
55
55
  instrumentationBitMap |= StatsbeatInstrumentation.REDIS;
56
56
  }
57
- let featureBitMap = 0;
57
+ let featureBitMap = StatsbeatFeature.NONE;
58
58
  featureBitMap |= StatsbeatFeature.DISTRO;
59
59
  try {
60
+ const currentFeaturesBitMap = Number(process.env[AZURE_MONITOR_STATSBEAT_FEATURES]);
61
+ if (!isNaN(currentFeaturesBitMap)) {
62
+ featureBitMap |= currentFeaturesBitMap;
63
+ }
60
64
  process.env[AZURE_MONITOR_STATSBEAT_FEATURES] = JSON.stringify({
61
65
  instrumentation: instrumentationBitMap,
62
66
  feature: featureBitMap,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,MAAM,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAE5D,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EACL,mCAAmC,EACnC,gCAAgC,EAChC,gBAAgB,EAChB,wBAAwB,GACzB,MAAM,SAAS,CAAC;AAIjB,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,GAAG,mCAAmC,CAAC;AAElF,IAAI,aAA4B,CAAC;AACjC,IAAI,YAA0B,CAAC;AAC/B,IAAI,UAAsB,CAAC;AAE3B;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,OAA0C;IACxE,MAAM,MAAM,GAAG,IAAI,cAAc,CAAC,OAAO,CAAC,CAAC;IAC3C,qBAAqB,CAAC,MAAM,CAAC,CAAC;IAC9B,gFAAgF;IAChF,OAAO,CAAC,OAAO,EAAE,CAAC;IAClB,KAAK,CAAC,OAAO,EAAE,CAAC;IAChB,IAAI,CAAC,OAAO,EAAE,CAAC;IACf,2BAA2B;IAC3B,aAAa,GAAG,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC;IAC1C,YAAY,GAAG,IAAI,YAAY,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACvD,UAAU,GAAG,IAAI,UAAU,CAAC,MAAM,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AC,gCAAgC,EAAE,KAAK,CAAC,CAAC;KAC7E;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { metrics, trace } from \"@opentelemetry/api\";\nimport { logs } from \"@opentelemetry/api-logs\";\nimport { InternalConfig } from \"./shared/config\";\nimport { MetricHandler } from \"./metrics\";\nimport { TraceHandler } from \"./traces/handler\";\nimport { Logger as InternalLogger } from \"./shared/logging\";\nimport { AzureMonitorOpenTelemetryOptions } from \"./shared/types\";\nimport { LogHandler } from \"./logs\";\nimport {\n AZURE_MONITOR_OPENTELEMETRY_VERSION,\n AZURE_MONITOR_STATSBEAT_FEATURES,\n StatsbeatFeature,\n StatsbeatInstrumentation,\n} from \"./types\";\n\nexport { AzureMonitorOpenTelemetryOptions, InstrumentationOptions } from \"./shared/types\";\n\nprocess.env[\"AZURE_MONITOR_DISTRO_VERSION\"] = AZURE_MONITOR_OPENTELEMETRY_VERSION;\n\nlet metricHandler: MetricHandler;\nlet traceHandler: TraceHandler;\nlet logHandler: LogHandler;\n\n/**\n * Initialize Azure Monitor Distro\n * @param options Azure Monitor OpenTelemetry Options\n */\nexport function useAzureMonitor(options?: AzureMonitorOpenTelemetryOptions) {\n const config = new InternalConfig(options);\n _setStatsbeatFeatures(config);\n // Remove global providers in OpenTelemetry, these would be overriden if present\n metrics.disable();\n trace.disable();\n logs.disable();\n // Create internal handlers\n metricHandler = new MetricHandler(config);\n traceHandler = new TraceHandler(config, metricHandler);\n logHandler = new LogHandler(config, metricHandler);\n}\n\n/**\n * Shutdown Azure Monitor Distro\n */\nexport function shutdownAzureMonitor() {\n metricHandler.shutdown();\n traceHandler.shutdown();\n logHandler.shutdown();\n}\n\nfunction _setStatsbeatFeatures(config: InternalConfig) {\n let instrumentationBitMap = 0;\n if (config.instrumentationOptions?.azureSdk?.enabled) {\n instrumentationBitMap |= StatsbeatInstrumentation.AZURE_CORE_TRACING;\n }\n if (config.instrumentationOptions?.mongoDb?.enabled) {\n instrumentationBitMap |= StatsbeatInstrumentation.MONGODB;\n }\n if (config.instrumentationOptions?.mySql?.enabled) {\n instrumentationBitMap |= StatsbeatInstrumentation.MYSQL;\n }\n if (config.instrumentationOptions?.postgreSql?.enabled) {\n instrumentationBitMap |= StatsbeatInstrumentation.POSTGRES;\n }\n if (config.instrumentationOptions?.redis?.enabled) {\n instrumentationBitMap |= StatsbeatInstrumentation.REDIS;\n }\n\n let featureBitMap = 0;\n featureBitMap |= StatsbeatFeature.DISTRO;\n\n try {\n process.env[AZURE_MONITOR_STATSBEAT_FEATURES] = JSON.stringify({\n instrumentation: instrumentationBitMap,\n feature: featureBitMap,\n });\n } catch (error) {\n InternalLogger.getInstance().error(\"Failed call to JSON.stringify.\", error);\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,MAAM,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAE5D,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EACL,mCAAmC,EACnC,gCAAgC,EAChC,gBAAgB,EAChB,wBAAwB,GACzB,MAAM,SAAS,CAAC;AAIjB,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,GAAG,mCAAmC,CAAC;AAElF,IAAI,aAA4B,CAAC;AACjC,IAAI,YAA0B,CAAC;AAC/B,IAAI,UAAsB,CAAC;AAE3B;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,OAA0C;IACx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AM,CAAC,sBAAsB,0CAAE,KAAK,0CAAE,OAAO,EAAE;QACjD,qBAAqB,IAAI,wBAAwB,CAAC,KAAK,CAAC;KACzD;IAED,IAAI,aAAa,GAAG,gBAAgB,CAAC,IAAI,CAAC;IAC1C,aAAa,IAAI,gBAAgB,CAAC,MAAM,CAAC;IAEzC,IAAI;QACF,MAAM,qBAAqB,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC,CAAC;QACpF,IAAI,CAAC,KAAK,CAAC,qBAAqB,CAAC,EAAE;YACjC,aAAa,IAAI,qBAAqB,CAAC;SACxC;QACD,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC;YAC7D,eAAe,EAAE,qBAAqB;YACtC,OAAO,EAAE,aAAa;SACvB,CAAC,CAAC;KACJ;IAAC,OAAO,KAAK,EAAE;QACd,cAAc,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,gCAAgC,EAAE,KAAK,CAAC,CAAC;KAC7E;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { metrics, trace } from \"@opentelemetry/api\";\nimport { logs } from \"@opentelemetry/api-logs\";\nimport { InternalConfig } from \"./shared/config\";\nimport { MetricHandler } from \"./metrics\";\nimport { TraceHandler } from \"./traces/handler\";\nimport { Logger as InternalLogger } from \"./shared/logging\";\nimport { AzureMonitorOpenTelemetryOptions } from \"./shared/types\";\nimport { LogHandler } from \"./logs\";\nimport {\n AZURE_MONITOR_OPENTELEMETRY_VERSION,\n AZURE_MONITOR_STATSBEAT_FEATURES,\n StatsbeatFeature,\n StatsbeatInstrumentation,\n} from \"./types\";\n\nexport { AzureMonitorOpenTelemetryOptions, InstrumentationOptions } from \"./shared/types\";\n\nprocess.env[\"AZURE_MONITOR_DISTRO_VERSION\"] = AZURE_MONITOR_OPENTELEMETRY_VERSION;\n\nlet metricHandler: MetricHandler;\nlet traceHandler: TraceHandler;\nlet logHandler: LogHandler;\n\n/**\n * Initialize Azure Monitor Distro\n * @param options Azure Monitor OpenTelemetry Options\n */\nexport function useAzureMonitor(options?: AzureMonitorOpenTelemetryOptions) {\n const config = new InternalConfig(options);\n _setStatsbeatFeatures(config);\n // Remove global providers in OpenTelemetry, these would be overriden if present\n metrics.disable();\n trace.disable();\n logs.disable();\n // Create internal handlers\n metricHandler = new MetricHandler(config);\n traceHandler = new TraceHandler(config, metricHandler);\n logHandler = new LogHandler(config, metricHandler);\n}\n\n/**\n * Shutdown Azure Monitor Distro\n */\nexport function shutdownAzureMonitor() {\n metricHandler.shutdown();\n traceHandler.shutdown();\n logHandler.shutdown();\n}\n\nfunction _setStatsbeatFeatures(config: InternalConfig) {\n let instrumentationBitMap = StatsbeatInstrumentation.NONE;\n if (config.instrumentationOptions?.azureSdk?.enabled) {\n instrumentationBitMap |= StatsbeatInstrumentation.AZURE_CORE_TRACING;\n }\n if (config.instrumentationOptions?.mongoDb?.enabled) {\n instrumentationBitMap |= StatsbeatInstrumentation.MONGODB;\n }\n if (config.instrumentationOptions?.mySql?.enabled) {\n instrumentationBitMap |= StatsbeatInstrumentation.MYSQL;\n }\n if (config.instrumentationOptions?.postgreSql?.enabled) {\n instrumentationBitMap |= StatsbeatInstrumentation.POSTGRES;\n }\n if (config.instrumentationOptions?.redis?.enabled) {\n instrumentationBitMap |= StatsbeatInstrumentation.REDIS;\n }\n\n let featureBitMap = StatsbeatFeature.NONE;\n featureBitMap |= StatsbeatFeature.DISTRO;\n\n try {\n const currentFeaturesBitMap = Number(process.env[AZURE_MONITOR_STATSBEAT_FEATURES]);\n if (!isNaN(currentFeaturesBitMap)) {\n featureBitMap |= currentFeaturesBitMap;\n }\n process.env[AZURE_MONITOR_STATSBEAT_FEATURES] = JSON.stringify({\n instrumentation: instrumentationBitMap,\n feature: featureBitMap,\n });\n } catch (error) {\n InternalLogger.getInstance().error(\"Failed call to JSON.stringify.\", error);\n }\n}\n"]}
@@ -2,7 +2,7 @@
2
2
  // Licensed under the MIT license.
3
3
  import { AzureMonitorMetricExporter } from "@azure/monitor-opentelemetry-exporter";
4
4
  import { metrics } from "@opentelemetry/api";
5
- import { MeterProvider, PeriodicExportingMetricReader, } from "@opentelemetry/sdk-metrics";
5
+ import { MeterProvider, PeriodicExportingMetricReader, View, } from "@opentelemetry/sdk-metrics";
6
6
  import { StandardMetrics } from "./standardMetrics";
7
7
  import { APPLICATION_INSIGHTS_NO_STANDARD_METRICS } from "./types";
8
8
  /**
@@ -15,13 +15,38 @@ export class MetricHandler {
15
15
  * @param options - Metric Handler options.
16
16
  */
17
17
  constructor(config, options) {
18
+ var _a, _b, _c, _d, _e, _f, _g;
18
19
  this._collectionInterval = 60000; // 60 seconds
19
20
  this._config = config;
20
21
  if (!process.env[APPLICATION_INSIGHTS_NO_STANDARD_METRICS]) {
21
22
  this._standardMetrics = new StandardMetrics(this._config);
22
23
  }
24
+ // Adding Views of instrumentations will allow customer to add Metric Readers after, and get access to previously created metrics using the views shared state
25
+ const views = [];
26
+ if ((_a = config.instrumentationOptions.azureSdk) === null || _a === void 0 ? void 0 : _a.enabled) {
27
+ views.push(new View({ meterName: "@azure/opentelemetry-instrumentation-azure-sdk" }));
28
+ }
29
+ if ((_b = config.instrumentationOptions.http) === null || _b === void 0 ? void 0 : _b.enabled) {
30
+ views.push(new View({ meterName: "@azure/opentelemetry-instrumentation-http" }));
31
+ }
32
+ if ((_c = config.instrumentationOptions.mongoDb) === null || _c === void 0 ? void 0 : _c.enabled) {
33
+ views.push(new View({ meterName: "@azure/opentelemetry-instrumentation-mongodb" }));
34
+ }
35
+ if ((_d = config.instrumentationOptions.mySql) === null || _d === void 0 ? void 0 : _d.enabled) {
36
+ views.push(new View({ meterName: "@opentelemetry/instrumentation-mysql" }));
37
+ }
38
+ if ((_e = config.instrumentationOptions.postgreSql) === null || _e === void 0 ? void 0 : _e.enabled) {
39
+ views.push(new View({ meterName: "@opentelemetry/instrumentation-pg" }));
40
+ }
41
+ if ((_f = config.instrumentationOptions.redis4) === null || _f === void 0 ? void 0 : _f.enabled) {
42
+ views.push(new View({ meterName: "@opentelemetry/instrumentation-redis-4" }));
43
+ }
44
+ if ((_g = config.instrumentationOptions.redis) === null || _g === void 0 ? void 0 : _g.enabled) {
45
+ views.push(new View({ meterName: "@azure/opentelemetry-instrumentation-redis" }));
46
+ }
23
47
  const meterProviderConfig = {
24
48
  resource: this._config.resource,
49
+ views: views,
25
50
  };
26
51
  this._meterProvider = new MeterProvider(meterProviderConfig);
27
52
  this._azureExporter = new AzureMonitorMetricExporter(this._config.azureMonitorExporterOptions);
@@ -1 +1 @@
1
- {"version":3,"file":"handler.js","sourceRoot":"","sources":["../../../src/metrics/handler.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,0BAA0B,EAAE,MAAM,uCAAuC,CAAC;AACnF,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EACL,aAAa,EAEb,6BAA6B,GAE9B,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD,OAAO,EAAE,wCAAwC,EAAE,MAAM,SAAS,CAAC;AAEnE;;GAEG;AACH,MAAM,OAAO,aAAa;IAQxB;;;;OAIG;IACH,YAAY,MAAsB,EAAE,OAAwC;QAZpE,wBAAmB,GAAG,KAAK,CAAC,CAAC,aAAa;QAahD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,wCAAwC,CAAC,EAAE;YAC1D,IAAI,CAAC,gBAAgB,GAAG,IAAI,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SAC3D;QACD,MAAM,mBAAmB,GAAyB;YAChD,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ;SAChC,CAAC;QACF,IAAI,CAAC,cAAc,GAAG,IAAI,aAAa,CAAC,mBA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\n\nimport { AzureMonitorMetricExporter } from \"@azure/monitor-opentelemetry-exporter\";\nimport { metrics } from \"@opentelemetry/api\";\nimport {\n MeterProvider,\n MeterProviderOptions,\n PeriodicExportingMetricReader,\n PeriodicExportingMetricReaderOptions,\n} from \"@opentelemetry/sdk-metrics\";\nimport { InternalConfig } from \"../shared/config\";\nimport { StandardMetrics } from \"./standardMetrics\";\nimport { ReadableSpan, Span } from \"@opentelemetry/sdk-trace-base\";\nimport { LogRecord } from \"@opentelemetry/sdk-logs\";\nimport { APPLICATION_INSIGHTS_NO_STANDARD_METRICS } from \"./types\";\n\n/**\n * Azure Monitor OpenTelemetry Metric Handler\n */\nexport class MetricHandler {\n private _collectionInterval = 60000; // 60 seconds\n private _meterProvider: MeterProvider;\n private _azureExporter: AzureMonitorMetricExporter;\n private _metricReader: PeriodicExportingMetricReader;\n private _standardMetrics?: StandardMetrics;\n private _config: InternalConfig;\n\n /**\n * Initializes a new instance of the MetricHandler class.\n * @param config - Distro configuration.\n * @param options - Metric Handler options.\n */\n constructor(config: InternalConfig, options?: { collectionInterval: number }) {\n this._config = config;\n if (!process.env[APPLICATION_INSIGHTS_NO_STANDARD_METRICS]) {\n this._standardMetrics = new StandardMetrics(this._config);\n }\n const meterProviderConfig: MeterProviderOptions = {\n resource: this._config.resource,\n };\n this._meterProvider = new MeterProvider(meterProviderConfig);\n this._azureExporter = new AzureMonitorMetricExporter(this._config.azureMonitorExporterOptions);\n let metricReaderOptions: PeriodicExportingMetricReaderOptions = {\n exporter: this._azureExporter as any,\n exportIntervalMillis: options?.collectionInterval || this._collectionInterval,\n };\n this._metricReader = new PeriodicExportingMetricReader(metricReaderOptions);\n this._meterProvider.addMetricReader(this._metricReader);\n metrics.setGlobalMeterProvider(this._meterProvider);\n }\n\n public markSpanAsProcessed(span: Span): void {\n this._standardMetrics?.markSpanAsProcessed(span);\n }\n\n public recordSpan(span: ReadableSpan): void {\n this._standardMetrics?.recordSpan(span);\n }\n\n public recordLog(logRecord: LogRecord): void {\n this._standardMetrics?.recordLog(logRecord);\n }\n\n /**\n * Shutdown handler, all Meter providers will return no-op Meters\n */\n public async shutdown(): Promise<void> {\n this._meterProvider.shutdown();\n this._standardMetrics?.shutdown();\n }\n\n /**\n * Force flush all Meter Providers\n */\n public async flush(): Promise<void> {\n await this._meterProvider.forceFlush();\n await this._standardMetrics?.flush();\n }\n}\n"]}
1
+ {"version":3,"file":"handler.js","sourceRoot":"","sources":["../../../src/metrics/handler.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,0BAA0B,EAAE,MAAM,uCAAuC,CAAC;AACnF,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EACL,aAAa,EAEb,6BAA6B,EAE7B,IAAI,GACL,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD,OAAO,EAAE,wCAAwC,EAAE,MAAM,SAAS,CAAC;AAEnE;;GAEG;AACH,MAAM,OAAO,aAAa;IAQxB;;;;OAIG;IACH,YAAY,MAAsB,EAAE,OAAwC;;QAZpE,wBAAmB,GAAG,KAAK,CAAC,CAAC,aAAa;QAahD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,wCAAwC,CAAC,EAAE;YAC1D,IAAI,CAAC,gBAAgB,GAAG,IAAI,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SAC3D;QACD,8JAA8J;QAC9J,MAAM,KAAK,GAAW,EAAE,CAAC;QACzB,IAAI,MAAA,MAAM,CAAC,sBAAsB,CAAC,QAAQ,0CAAE,OAAO,EAAE;YACnD,KAAK,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,EAAE,SAAS,EAAE,gDAAgD,EAAE,CAAC,CAAC,CAAC;SACvF;QACD,IAAI,MAAA,MAAM,CAAC,sBAAsB,CAAC,IAAI,0CAAE,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OAAO,CAAC,2BAA2B,CAAC,CAAC;QAC/F,IAAI,mBAAmB,GAAyC;YAC9D,QAAQ,EAAE,IAAI,CAAC,cAAqB;YACpC,oBAAoB,EAAE,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,kBAAkB,KAAI,IAAI,CAAC,mBAAmB;SAC9E,CAAC;QACF,IAAI,CAAC,aAAa,GAAG,IAAI,6BAA6B,CAAC,mBAAmB,CAAC,CAAC;QAC5E,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QACxD,OAAO,CAAC,sBAAsB,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IACtD,CAAC;IAEM,mBAAmB,CAAC,IAAU;;QACnC,MAAA,IAAI,CAAC,gBAAgB,0CAAE,mBAAmB,CAAC,IAAI,CAAC,CAAC;IACnD,CAAC;IAEM,UAAU,CAAC,IAAkB;;QAClC,MAAA,IAAI,CAAC,gBAAgB,0CAAE,UAAU,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;IAEM,SAAS,CAAC,SAAoB;;QACnC,MAAA,IAAI,CAAC,gBAAgB,0CAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC9C,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,QAAQ;;QACnB,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC;QAC/B,MAAA,IAAI,CAAC,gBAAgB,0CAAE,QAAQ,EAAE,CAAC;IACpC,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,KAAK;;QAChB,MAAM,IAAI,CAAC,cAAc,CAAC,UAAU,EAAE,CAAC;QACvC,MAAM,CAAA,MAAA,IAAI,CAAC,gBAAgB,0CAAE,KAAK,EAAE,CAAA,CAAC;IACvC,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AzureMonitorMetricExporter } from \"@azure/monitor-opentelemetry-exporter\";\nimport { metrics } from \"@opentelemetry/api\";\nimport {\n MeterProvider,\n MeterProviderOptions,\n PeriodicExportingMetricReader,\n PeriodicExportingMetricReaderOptions,\n View,\n} from \"@opentelemetry/sdk-metrics\";\nimport { InternalConfig } from \"../shared/config\";\nimport { StandardMetrics } from \"./standardMetrics\";\nimport { ReadableSpan, Span } from \"@opentelemetry/sdk-trace-base\";\nimport { LogRecord } from \"@opentelemetry/sdk-logs\";\nimport { APPLICATION_INSIGHTS_NO_STANDARD_METRICS } from \"./types\";\n\n/**\n * Azure Monitor OpenTelemetry Metric Handler\n */\nexport class MetricHandler {\n private _collectionInterval = 60000; // 60 seconds\n private _meterProvider: MeterProvider;\n private _azureExporter: AzureMonitorMetricExporter;\n private _metricReader: PeriodicExportingMetricReader;\n private _standardMetrics?: StandardMetrics;\n private _config: InternalConfig;\n\n /**\n * Initializes a new instance of the MetricHandler class.\n * @param config - Distro configuration.\n * @param options - Metric Handler options.\n */\n constructor(config: InternalConfig, options?: { collectionInterval: number }) {\n this._config = config;\n if (!process.env[APPLICATION_INSIGHTS_NO_STANDARD_METRICS]) {\n this._standardMetrics = new StandardMetrics(this._config);\n }\n // Adding Views of instrumentations will allow customer to add Metric Readers after, and get access to previously created metrics using the views shared state\n const views: View[] = [];\n if (config.instrumentationOptions.azureSdk?.enabled) {\n views.push(new View({ meterName: \"@azure/opentelemetry-instrumentation-azure-sdk\" }));\n }\n if (config.instrumentationOptions.http?.enabled) {\n views.push(new View({ meterName: \"@azure/opentelemetry-instrumentation-http\" }));\n }\n if (config.instrumentationOptions.mongoDb?.enabled) {\n views.push(new View({ meterName: \"@azure/opentelemetry-instrumentation-mongodb\" }));\n }\n if (config.instrumentationOptions.mySql?.enabled) {\n views.push(new View({ meterName: \"@opentelemetry/instrumentation-mysql\" }));\n }\n if (config.instrumentationOptions.postgreSql?.enabled) {\n views.push(new View({ meterName: \"@opentelemetry/instrumentation-pg\" }));\n }\n if (config.instrumentationOptions.redis4?.enabled) {\n views.push(new View({ meterName: \"@opentelemetry/instrumentation-redis-4\" }));\n }\n if (config.instrumentationOptions.redis?.enabled) {\n views.push(new View({ meterName: \"@azure/opentelemetry-instrumentation-redis\" }));\n }\n const meterProviderConfig: MeterProviderOptions = {\n resource: this._config.resource,\n views: views,\n };\n this._meterProvider = new MeterProvider(meterProviderConfig);\n this._azureExporter = new AzureMonitorMetricExporter(this._config.azureMonitorExporterOptions);\n let metricReaderOptions: PeriodicExportingMetricReaderOptions = {\n exporter: this._azureExporter as any,\n exportIntervalMillis: options?.collectionInterval || this._collectionInterval,\n };\n this._metricReader = new PeriodicExportingMetricReader(metricReaderOptions);\n this._meterProvider.addMetricReader(this._metricReader);\n metrics.setGlobalMeterProvider(this._meterProvider);\n }\n\n public markSpanAsProcessed(span: Span): void {\n this._standardMetrics?.markSpanAsProcessed(span);\n }\n\n public recordSpan(span: ReadableSpan): void {\n this._standardMetrics?.recordSpan(span);\n }\n\n public recordLog(logRecord: LogRecord): void {\n this._standardMetrics?.recordLog(logRecord);\n }\n\n /**\n * Shutdown handler, all Meter providers will return no-op Meters\n */\n public async shutdown(): Promise<void> {\n this._meterProvider.shutdown();\n this._standardMetrics?.shutdown();\n }\n\n /**\n * Force flush all Meter Providers\n */\n public async flush(): Promise<void> {\n await this._meterProvider.forceFlush();\n await this._standardMetrics?.flush();\n }\n}\n"]}
@@ -33,10 +33,6 @@ export class InternalConfig {
33
33
  redis4: { enabled: false },
34
34
  };
35
35
  this._resource = this._getDefaultResource();
36
- // Merge JSON configuration file if available
37
- this._mergeConfig();
38
- // Check for explicitly passed options when instantiating client
39
- // This will take precedence over other settings
40
36
  if (options) {
41
37
  // Merge default with provided options
42
38
  this.azureMonitorExporterOptions = Object.assign(this.azureMonitorExporterOptions, options.azureMonitorExporterOptions);
@@ -44,6 +40,8 @@ export class InternalConfig {
44
40
  this.resource = Object.assign(this.resource, options.resource);
45
41
  this.samplingRatio = options.samplingRatio || this.samplingRatio;
46
42
  }
43
+ // JSON configuration will take precedence over other settings
44
+ this._mergeConfig();
47
45
  }
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AAmB,CAAC,oBAAoB,CAAC,CAAC;QAC9D,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QACvC,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n Resource,\n ResourceDetectionConfig,\n detectResourcesSync,\n envDetectorSync,\n} from \"@opentelemetry/resources\";\nimport { AzureMonitorOpenTelemetryOptions, InstrumentationOptions } from \"./types\";\nimport { AzureMonitorExporterOptions } from \"@azure/monitor-opentelemetry-exporter\";\nimport { JsonConfig } from \"./jsonConfig\";\nimport { Logger } from \"./logging\";\n\n/**\n * Azure Monitor OpenTelemetry Client Configuration\n */\nexport class InternalConfig implements AzureMonitorOpenTelemetryOptions {\n /** The rate of telemetry items tracked that should be transmitted (Default 1.0) */\n public samplingRatio: number;\n /** Azure Monitor Exporter Configuration */\n public azureMonitorExporterOptions: AzureMonitorExporterOptions;\n /**\n * OpenTelemetry Instrumentations configuration included as part of Azure Monitor (azureSdk, http, mongoDb, mySql, postgreSql, redis, redis4)\n */\n public instrumentationOptions: InstrumentationOptions;\n\n private _resource: Resource;\n\n public set resource(resource: Resource) {\n this._resource = this._resource.merge(resource);\n }\n\n /**\n *Get OpenTelemetry Resource\n */\n public get resource(): Resource {\n return this._resource;\n }\n\n /**\n * Initializes a new instance of the AzureMonitorOpenTelemetryOptions class.\n */\n constructor(options?: AzureMonitorOpenTelemetryOptions) {\n // Default values\n this.azureMonitorExporterOptions = {};\n this.samplingRatio = 1;\n this.instrumentationOptions = {\n http: { enabled: true },\n azureSdk: { enabled: false },\n mongoDb: { enabled: false },\n mySql: { enabled: false },\n postgreSql: { enabled: false },\n redis: { enabled: false },\n redis4: { enabled: false },\n };\n this._resource = this._getDefaultResource();\n // Merge JSON configuration file if available\n this._mergeConfig();\n // Check for explicitly passed options when instantiating client\n // This will take precedence over other settings\n if (options) {\n // Merge default with provided options\n this.azureMonitorExporterOptions = Object.assign(\n this.azureMonitorExporterOptions,\n options.azureMonitorExporterOptions\n );\n this.instrumentationOptions = Object.assign(\n this.instrumentationOptions,\n options.instrumentationOptions\n );\n this.resource = Object.assign(this.resource, options.resource);\n this.samplingRatio = options.samplingRatio || this.samplingRatio;\n }\n }\n\n private _mergeConfig() {\n try {\n const jsonConfig = JsonConfig.getInstance();\n this.samplingRatio =\n jsonConfig.samplingRatio !== undefined ? jsonConfig.samplingRatio : this.samplingRatio;\n\n this.azureMonitorExporterOptions = Object.assign(\n this.azureMonitorExporterOptions,\n jsonConfig.azureMonitorExporterOptions\n );\n this.instrumentationOptions = Object.assign(\n this.instrumentationOptions,\n jsonConfig.instrumentationOptions\n );\n } catch (error) {\n Logger.getInstance().error(\"Failed to load JSON config file values.\", error);\n }\n }\n\n private _getDefaultResource(): Resource {\n let resource = Resource.default();\n // Load resource attributes from env\n const detectResourceConfig: ResourceDetectionConfig = {\n detectors: [envDetectorSync],\n };\n const envResource = detectResourcesSync(detectResourceConfig);\n resource = resource.merge(envResource);\n return resource;\n }\n}\n"]}
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/shared/config.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EACL,QAAQ,EAER,mBAAmB,EACnB,eAAe,GAChB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC;;GAEG;AACH,MAAM,OAAO,cAAc;IAYzB,IAAW,QAAQ,CAAC,QAAkB;QACpC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAClD,CAAC;IAED;;OAEG;IACH,IAAW,QAAQ;QACjB,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,YAAY,OAA0C;QACpD,iBAAiB;QACjB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aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC;YAEzF,IAAI,CAAC,2BAA2B,GAAG,MAAM,CAAC,MAAM,CAC9C,IAAI,CAAC,2BAA2B,EAChC,UAAU,CAAC,2BAA2B,CACvC,CAAC;YACF,IAAI,CAAC,sBAAsB,GAAG,MAAM,CAAC,MAAM,CACzC,IAAI,CAAC,sBAAsB,EAC3B,UAAU,CAAC,sBAAsB,CAClC,CAAC;SACH;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,yCAAyC,EAAE,KAAK,CAAC,CAAC;SAC9E;IACH,CAAC;IAEO,mBAAmB;QACzB,IAAI,QAAQ,GAAG,QAAQ,CAAC,OAAO,EAAE,CAAC;QAClC,oCAAoC;QACpC,MAAM,oBAAoB,GAA4B;YACpD,SAAS,EAAE,CAAC,eAAe,CAAC;SAC7B,CAAC;QACF,MAAM,WAAW,GAAG,mBAAmB,CAAC,oBAAoB,CAAC,CAAC;QAC9D,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QACvC,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n Resource,\n ResourceDetectionConfig,\n detectResourcesSync,\n envDetectorSync,\n} from \"@opentelemetry/resources\";\nimport { AzureMonitorOpenTelemetryOptions, InstrumentationOptions } from \"./types\";\nimport { AzureMonitorExporterOptions } from \"@azure/monitor-opentelemetry-exporter\";\nimport { JsonConfig } from \"./jsonConfig\";\nimport { Logger } from \"./logging\";\n\n/**\n * Azure Monitor OpenTelemetry Client Configuration\n */\nexport class InternalConfig implements AzureMonitorOpenTelemetryOptions {\n /** The rate of telemetry items tracked that should be transmitted (Default 1.0) */\n public samplingRatio: number;\n /** Azure Monitor Exporter Configuration */\n public azureMonitorExporterOptions: AzureMonitorExporterOptions;\n /**\n * OpenTelemetry Instrumentations configuration included as part of Azure Monitor (azureSdk, http, mongoDb, mySql, postgreSql, redis, redis4)\n */\n public instrumentationOptions: InstrumentationOptions;\n\n private _resource: Resource;\n\n public set resource(resource: Resource) {\n this._resource = this._resource.merge(resource);\n }\n\n /**\n *Get OpenTelemetry Resource\n */\n public get resource(): Resource {\n return this._resource;\n }\n\n /**\n * Initializes a new instance of the AzureMonitorOpenTelemetryOptions class.\n */\n constructor(options?: AzureMonitorOpenTelemetryOptions) {\n // Default values\n this.azureMonitorExporterOptions = {};\n this.samplingRatio = 1;\n this.instrumentationOptions = {\n http: { enabled: true },\n azureSdk: { enabled: false },\n mongoDb: { enabled: false },\n mySql: { enabled: false },\n postgreSql: { enabled: false },\n redis: { enabled: false },\n redis4: { enabled: false },\n };\n this._resource = this._getDefaultResource();\n\n if (options) {\n // Merge default with provided options\n this.azureMonitorExporterOptions = Object.assign(\n this.azureMonitorExporterOptions,\n options.azureMonitorExporterOptions\n );\n this.instrumentationOptions = Object.assign(\n this.instrumentationOptions,\n options.instrumentationOptions\n );\n this.resource = Object.assign(this.resource, options.resource);\n this.samplingRatio = options.samplingRatio || this.samplingRatio;\n }\n // JSON configuration will take precedence over other settings\n this._mergeConfig();\n }\n\n private _mergeConfig() {\n try {\n const jsonConfig = JsonConfig.getInstance();\n this.samplingRatio =\n jsonConfig.samplingRatio !== undefined ? jsonConfig.samplingRatio : this.samplingRatio;\n\n this.azureMonitorExporterOptions = Object.assign(\n this.azureMonitorExporterOptions,\n jsonConfig.azureMonitorExporterOptions\n );\n this.instrumentationOptions = Object.assign(\n this.instrumentationOptions,\n jsonConfig.instrumentationOptions\n );\n } catch (error) {\n Logger.getInstance().error(\"Failed to load JSON config file values.\", error);\n }\n }\n\n private _getDefaultResource(): Resource {\n let resource = Resource.default();\n // Load resource attributes from env\n const detectResourceConfig: ResourceDetectionConfig = {\n detectors: [envDetectorSync],\n };\n const envResource = detectResourcesSync(detectResourceConfig);\n resource = resource.merge(envResource);\n return resource;\n }\n}\n"]}
@@ -11,11 +11,11 @@ export class InternalAzureLogger {
11
11
  this._fileCleanupTimer = null;
12
12
  this._logToFile = false;
13
13
  this._logToConsole = true;
14
- const logDestination = process.env.APPLICATIONINSIGHTS_LOG_DESTINATION; // destination can be one of file, console or file+console
15
- if (logDestination === "file+console") {
14
+ this._logDestination = process.env.APPLICATIONINSIGHTS_LOG_DESTINATION; // destination can be one of file, console or file+console
15
+ if (this._logDestination === "file+console") {
16
16
  this._logToFile = true;
17
17
  }
18
- if (logDestination === "file") {
18
+ if (this._logDestination === "file") {
19
19
  this._logToFile = true;
20
20
  this._logToConsole = false;
21
21
  }
@@ -1 +1 @@
1
- {"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../../src/shared/logging/internal.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EACL,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,cAAc,EACd,WAAW,GACZ,MAAM,aAAa,CAAC;AAErB,MAAM,OAAO,mBAAmB;IAa9B;QAZQ,SAAI,GAAG,iBAAiB,CAAC;QACzB,oBAAe,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,cAAc;QAChD,sBAAiB,GAAwB,IAAI,CAAC;QAK9C,eAAU,GAAG,KAAK,CAAC;QACnB,kBAAa,GAAG,IAAI,CAAC;QAK3B,MAAM,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC,0DAA0D;QAClI,IAAI,cAAc,KAAK,cAAc,EAAE;YACrC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;SACxB;QACD,IAAI,cAAc,KAAK,MAAM,EAAE;YAC7B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;YACv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IAAI,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBACnF,MAAM,aAAa,GAAS,IAAI,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBACnF,IAAI,aAAa,GAAG,aAAa,EAAE;oBACjC,OAAO,CAAC,CAAC,CAAC;iBACX;qBAAM;oBACL,OAAO,CAAC,CAAC;iBACV;YACH,CAAC,CAAC,CAAC;YACH,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC;YAChC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,EAAE,EAAE;gBACtD,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;gBACxD,MAAM,WAAW,CAAC,YAAY,CAAC,CAAC;aACjC;SACF;QAAC,OAAO,GAAQ,EAAE;YACjB,sCAAsC;YACtC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,gCAAgC,GAAG,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;SAC9E;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport * as fs from \"fs\";\nimport * as os from \"os\";\nimport * as path from \"path\";\nimport {\n accessAsync,\n appendFileAsync,\n confirmDirExists,\n getShallowFileSize,\n readdirAsync,\n readFileAsync,\n writeFileAsync,\n unlinkAsync,\n} from \"../../utils\";\n\nexport class InternalAzureLogger {\n private _TAG = \"InternalLogger:\";\n private _cleanupTimeOut = 60 * 30 * 1000; // 30 minutes;\n private _fileCleanupTimer: NodeJS.Timer | null = null;\n private _tempDir: string;\n private _logFileName: string;\n private _fileFullPath: string;\n private _backUpNameFormat: string;\n private _logToFile = false;\n private _logToConsole = true;\n private _maxHistory: number;\n private _maxSizeBytes: number;\n\n constructor() {\n const logDestination = process.env.APPLICATIONINSIGHTS_LOG_DESTINATION; // destination can be one of file, console or file+console\n if (logDestination === \"file+console\") {\n this._logToFile = true;\n }\n if (logDestination === \"file\") {\n this._logToFile = true;\n this._logToConsole = false;\n }\n this._maxSizeBytes = 50000;\n this._maxHistory = 1;\n this._logFileName = \"applicationinsights.log\";\n\n // If custom path not provided use temp folder, /tmp for *nix and USERDIR/AppData/Local/Temp for Windows\n const logFilePath = process.env.APPLICATIONINSIGHTS_LOGDIR;\n if (!logFilePath) {\n this._tempDir = path.join(os.tmpdir(), \"appInsights-node\");\n } else {\n if (path.isAbsolute(logFilePath)) {\n this._tempDir = logFilePath;\n } else {\n this._tempDir = path.join(process.cwd(), logFilePath);\n }\n }\n this._fileFullPath = path.join(this._tempDir, this._logFileName);\n this._backUpNameFormat = `.${this._logFileName}`; // {currentime}.applicationinsights.log\n\n if (this._logToFile) {\n if (!this._fileCleanupTimer) {\n this._fileCleanupTimer = setInterval(() => {\n this._fileCleanupTask();\n }, this._cleanupTimeOut);\n this._fileCleanupTimer.unref();\n }\n }\n }\n\n public async logMessage(message?: any, ...optionalParams: any[]) {\n try {\n const args = message ? [message, ...optionalParams] : optionalParams;\n if (this._logToFile) {\n await this._storeToDisk(args);\n }\n if (this._logToConsole) {\n // eslint-disable-next-line no-console\n console.log(...args);\n }\n } catch (err: any) {\n // eslint-disable-next-line no-console\n console.log(this._TAG, `Failed to log to file: ${err && err.message}`);\n }\n }\n\n private async _storeToDisk(args: any): Promise<void> {\n const data = `${args}\\r\\n`;\n\n try {\n await confirmDirExists(this._tempDir);\n } catch (err: any) {\n // eslint-disable-next-line no-console\n console.log(this._TAG, `Failed to create directory for log file: ${err && err.message}`);\n return;\n }\n try {\n await accessAsync(this._fileFullPath, fs.constants.F_OK);\n } catch (err: any) {\n // No file create one\n try {\n await appendFileAsync(this._fileFullPath, data);\n } catch (appendError: any) {\n // eslint-disable-next-line no-console\n console.log(\n this._TAG,\n `Failed to put log into file: ${appendError && appendError.message}`\n );\n return;\n }\n }\n // Check size\n const size = await getShallowFileSize(this._fileFullPath);\n if (size && size > this._maxSizeBytes) {\n await this._createBackupFile(data);\n } else {\n await appendFileAsync(this._fileFullPath, data);\n }\n }\n\n private async _createBackupFile(data: string): Promise<void> {\n try {\n const buffer = await readFileAsync(this._fileFullPath);\n const backupPath = path.join(this._tempDir, `${new Date().getTime()}.${this._logFileName}`);\n await writeFileAsync(backupPath, buffer);\n } catch (err: any) {\n // eslint-disable-next-line no-console\n console.log(\"Failed to generate backup log file\", err);\n } finally {\n // Store logs\n writeFileAsync(this._fileFullPath, data);\n }\n }\n\n private async _fileCleanupTask(): Promise<void> {\n try {\n let files = await readdirAsync(this._tempDir);\n // Filter only backup files\n files = files.filter((f) => path.basename(f).indexOf(this._backUpNameFormat) > -1);\n // Sort by creation date\n files.sort((a: string, b: string) => {\n // Check expiration\n const aCreationDate: Date = new Date(parseInt(a.split(this._backUpNameFormat)[0]));\n const bCreationDate: Date = new Date(parseInt(b.split(this._backUpNameFormat)[0]));\n if (aCreationDate < bCreationDate) {\n return -1;\n } else {\n return 1;\n }\n });\n const totalFiles = files.length;\n for (let i = 0; i < totalFiles - this._maxHistory; i++) {\n const pathToDelete = path.join(this._tempDir, files[i]);\n await unlinkAsync(pathToDelete);\n }\n } catch (err: any) {\n // eslint-disable-next-line no-console\n console.log(this._TAG, `Failed to cleanup log files: ${err && err.message}`);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../../src/shared/logging/internal.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM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,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;gBACxD,MAAM,WAAW,CAAC,YAAY,CAAC,CAAC;aACjC;SACF;QAAC,OAAO,GAAQ,EAAE;YACjB,sCAAsC;YACtC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,gCAAgC,GAAG,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;SAC9E;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport * as fs from \"fs\";\nimport * as os from \"os\";\nimport * as path from \"path\";\nimport {\n accessAsync,\n appendFileAsync,\n confirmDirExists,\n getShallowFileSize,\n readdirAsync,\n readFileAsync,\n writeFileAsync,\n unlinkAsync,\n} from \"../../utils\";\n\nexport class InternalAzureLogger {\n private _TAG = \"InternalLogger:\";\n private _cleanupTimeOut = 60 * 30 * 1000; // 30 minutes;\n private _fileCleanupTimer: NodeJS.Timer | null = null;\n private _tempDir: string;\n private _logFileName: string;\n private _fileFullPath: string;\n private _backUpNameFormat: string;\n private _logToFile = false;\n private _logToConsole = true;\n private _maxHistory: number;\n private _maxSizeBytes: number;\n private _logDestination: string | undefined;\n\n constructor() {\n this._logDestination = process.env.APPLICATIONINSIGHTS_LOG_DESTINATION; // destination can be one of file, console or file+console\n if (this._logDestination === \"file+console\") {\n this._logToFile = true;\n }\n if (this._logDestination === \"file\") {\n this._logToFile = true;\n this._logToConsole = false;\n }\n this._maxSizeBytes = 50000;\n this._maxHistory = 1;\n this._logFileName = \"applicationinsights.log\";\n\n // If custom path not provided use temp folder, /tmp for *nix and USERDIR/AppData/Local/Temp for Windows\n const logFilePath = process.env.APPLICATIONINSIGHTS_LOGDIR;\n if (!logFilePath) {\n this._tempDir = path.join(os.tmpdir(), \"appInsights-node\");\n } else {\n if (path.isAbsolute(logFilePath)) {\n this._tempDir = logFilePath;\n } else {\n this._tempDir = path.join(process.cwd(), logFilePath);\n }\n }\n this._fileFullPath = path.join(this._tempDir, this._logFileName);\n this._backUpNameFormat = `.${this._logFileName}`; // {currentime}.applicationinsights.log\n\n if (this._logToFile) {\n if (!this._fileCleanupTimer) {\n this._fileCleanupTimer = setInterval(() => {\n this._fileCleanupTask();\n }, this._cleanupTimeOut);\n this._fileCleanupTimer.unref();\n }\n }\n }\n\n public async logMessage(message?: any, ...optionalParams: any[]) {\n try {\n const args = message ? [message, ...optionalParams] : optionalParams;\n if (this._logToFile) {\n await this._storeToDisk(args);\n }\n if (this._logToConsole) {\n // eslint-disable-next-line no-console\n console.log(...args);\n }\n } catch (err: any) {\n // eslint-disable-next-line no-console\n console.log(this._TAG, `Failed to log to file: ${err && err.message}`);\n }\n }\n\n private async _storeToDisk(args: any): Promise<void> {\n const data = `${args}\\r\\n`;\n\n try {\n await confirmDirExists(this._tempDir);\n } catch (err: any) {\n // eslint-disable-next-line no-console\n console.log(this._TAG, `Failed to create directory for log file: ${err && err.message}`);\n return;\n }\n try {\n await accessAsync(this._fileFullPath, fs.constants.F_OK);\n } catch (err: any) {\n // No file create one\n try {\n await appendFileAsync(this._fileFullPath, data);\n } catch (appendError: any) {\n // eslint-disable-next-line no-console\n console.log(\n this._TAG,\n `Failed to put log into file: ${appendError && appendError.message}`\n );\n return;\n }\n }\n // Check size\n const size = await getShallowFileSize(this._fileFullPath);\n if (size && size > this._maxSizeBytes) {\n await this._createBackupFile(data);\n } else {\n await appendFileAsync(this._fileFullPath, data);\n }\n }\n\n private async _createBackupFile(data: string): Promise<void> {\n try {\n const buffer = await readFileAsync(this._fileFullPath);\n const backupPath = path.join(this._tempDir, `${new Date().getTime()}.${this._logFileName}`);\n await writeFileAsync(backupPath, buffer);\n } catch (err: any) {\n // eslint-disable-next-line no-console\n console.log(\"Failed to generate backup log file\", err);\n } finally {\n // Store logs\n writeFileAsync(this._fileFullPath, data);\n }\n }\n\n private async _fileCleanupTask(): Promise<void> {\n try {\n let files = await readdirAsync(this._tempDir);\n // Filter only backup files\n files = files.filter((f) => path.basename(f).indexOf(this._backUpNameFormat) > -1);\n // Sort by creation date\n files.sort((a: string, b: string) => {\n // Check expiration\n const aCreationDate: Date = new Date(parseInt(a.split(this._backUpNameFormat)[0]));\n const bCreationDate: Date = new Date(parseInt(b.split(this._backUpNameFormat)[0]));\n if (aCreationDate < bCreationDate) {\n return -1;\n } else {\n return 1;\n }\n });\n const totalFiles = files.length;\n for (let i = 0; i < totalFiles - this._maxHistory; i++) {\n const pathToDelete = path.join(this._tempDir, files[i]);\n await unlinkAsync(pathToDelete);\n }\n } catch (err: any) {\n // eslint-disable-next-line no-console\n console.log(this._TAG, `Failed to cleanup log files: ${err && err.message}`);\n }\n }\n}\n"]}
@@ -1,20 +1,22 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT license.
3
- export const AZURE_MONITOR_OPENTELEMETRY_VERSION = "1.0.0";
3
+ export const AZURE_MONITOR_OPENTELEMETRY_VERSION = "1.1.0";
4
4
  export const AZURE_MONITOR_STATSBEAT_FEATURES = "AZURE_MONITOR_STATSBEAT_FEATURES";
5
5
  export var StatsbeatFeature;
6
6
  (function (StatsbeatFeature) {
7
- StatsbeatFeature[StatsbeatFeature["DISK_RETRY"] = 0] = "DISK_RETRY";
8
- StatsbeatFeature[StatsbeatFeature["AAD_HANDLING"] = 1] = "AAD_HANDLING";
9
- StatsbeatFeature[StatsbeatFeature["WEB_SNIPPET"] = 2] = "WEB_SNIPPET";
10
- StatsbeatFeature[StatsbeatFeature["DISTRO"] = 4] = "DISTRO";
7
+ StatsbeatFeature[StatsbeatFeature["NONE"] = 0] = "NONE";
8
+ StatsbeatFeature[StatsbeatFeature["DISK_RETRY"] = 1] = "DISK_RETRY";
9
+ StatsbeatFeature[StatsbeatFeature["AAD_HANDLING"] = 2] = "AAD_HANDLING";
10
+ StatsbeatFeature[StatsbeatFeature["WEB_SNIPPET"] = 4] = "WEB_SNIPPET";
11
+ StatsbeatFeature[StatsbeatFeature["DISTRO"] = 8] = "DISTRO";
11
12
  })(StatsbeatFeature || (StatsbeatFeature = {}));
12
13
  export var StatsbeatInstrumentation;
13
14
  (function (StatsbeatInstrumentation) {
14
- StatsbeatInstrumentation[StatsbeatInstrumentation["AZURE_CORE_TRACING"] = 0] = "AZURE_CORE_TRACING";
15
- StatsbeatInstrumentation[StatsbeatInstrumentation["MONGODB"] = 1] = "MONGODB";
16
- StatsbeatInstrumentation[StatsbeatInstrumentation["MYSQL"] = 2] = "MYSQL";
17
- StatsbeatInstrumentation[StatsbeatInstrumentation["REDIS"] = 4] = "REDIS";
18
- StatsbeatInstrumentation[StatsbeatInstrumentation["POSTGRES"] = 8] = "POSTGRES";
15
+ StatsbeatInstrumentation[StatsbeatInstrumentation["NONE"] = 0] = "NONE";
16
+ StatsbeatInstrumentation[StatsbeatInstrumentation["AZURE_CORE_TRACING"] = 1] = "AZURE_CORE_TRACING";
17
+ StatsbeatInstrumentation[StatsbeatInstrumentation["MONGODB"] = 2] = "MONGODB";
18
+ StatsbeatInstrumentation[StatsbeatInstrumentation["MYSQL"] = 4] = "MYSQL";
19
+ StatsbeatInstrumentation[StatsbeatInstrumentation["REDIS"] = 8] = "REDIS";
20
+ StatsbeatInstrumentation[StatsbeatInstrumentation["POSTGRES"] = 16] = "POSTGRES";
19
21
  })(StatsbeatInstrumentation || (StatsbeatInstrumentation = {}));
20
22
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,MAAM,CAAC,MAAM,mCAAmC,GAAG,OAAO,CAAC;AAC3D,MAAM,CAAC,MAAM,gCAAgC,GAAG,kCAAkC,CAAC;AAEnF,MAAM,CAAN,IAAY,gBAKX;AALD,WAAY,gBAAgB;IAC1B,mEAAc,CAAA;IACd,uEAAgB,CAAA;IAChB,qEAAe,CAAA;IACf,2DAAU,CAAA;AACZ,CAAC,EALW,gBAAgB,KAAhB,gBAAgB,QAK3B;AAED,MAAM,CAAN,IAAY,wBAMX;AAND,WAAY,wBAAwB;IAClC,mGAAsB,CAAA;IACtB,6EAAW,CAAA;IACX,yEAAS,CAAA;IACT,yEAAS,CAAA;IACT,+EAAY,CAAA;AACd,CAAC,EANW,wBAAwB,KAAxB,wBAAwB,QAMnC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport const AZURE_MONITOR_OPENTELEMETRY_VERSION = \"1.0.0\";\nexport const AZURE_MONITOR_STATSBEAT_FEATURES = \"AZURE_MONITOR_STATSBEAT_FEATURES\";\n\nexport enum StatsbeatFeature {\n DISK_RETRY = 0,\n AAD_HANDLING = 1,\n WEB_SNIPPET = 2,\n DISTRO = 4,\n}\n\nexport enum StatsbeatInstrumentation {\n AZURE_CORE_TRACING = 0,\n MONGODB = 1,\n MYSQL = 2,\n REDIS = 4,\n POSTGRES = 8,\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,MAAM,CAAC,MAAM,mCAAmC,GAAG,OAAO,CAAC;AAC3D,MAAM,CAAC,MAAM,gCAAgC,GAAG,kCAAkC,CAAC;AAEnF,MAAM,CAAN,IAAY,gBAMX;AAND,WAAY,gBAAgB;IAC1B,uDAAQ,CAAA;IACR,mEAAc,CAAA;IACd,uEAAgB,CAAA;IAChB,qEAAe,CAAA;IACf,2DAAU,CAAA;AACZ,CAAC,EANW,gBAAgB,KAAhB,gBAAgB,QAM3B;AAED,MAAM,CAAN,IAAY,wBAOX;AAPD,WAAY,wBAAwB;IAClC,uEAAQ,CAAA;IACR,mGAAsB,CAAA;IACtB,6EAAW,CAAA;IACX,yEAAS,CAAA;IACT,yEAAS,CAAA;IACT,gFAAa,CAAA;AACf,CAAC,EAPW,wBAAwB,KAAxB,wBAAwB,QAOnC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport const AZURE_MONITOR_OPENTELEMETRY_VERSION = \"1.1.0\";\nexport const AZURE_MONITOR_STATSBEAT_FEATURES = \"AZURE_MONITOR_STATSBEAT_FEATURES\";\n\nexport enum StatsbeatFeature {\n NONE = 0,\n DISK_RETRY = 1,\n AAD_HANDLING = 2,\n WEB_SNIPPET = 4,\n DISTRO = 8,\n}\n\nexport enum StatsbeatInstrumentation {\n NONE = 0,\n AZURE_CORE_TRACING = 1,\n MONGODB = 2,\n MYSQL = 4,\n REDIS = 8,\n POSTGRES = 16,\n}\n"]}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@azure/monitor-opentelemetry",
3
3
  "author": "Microsoft Corporation",
4
4
  "sdk-type": "client",
5
- "version": "1.0.0",
5
+ "version": "1.1.0",
6
6
  "description": "Azure Monitor OpenTelemetry (Node.js)",
7
7
  "main": "dist/index.js",
8
8
  "module": "dist-esm/src/index.js",
@@ -25,21 +25,20 @@
25
25
  "test:node": "npm run unit-test:node",
26
26
  "test:browser": "npm run unit-test:browser",
27
27
  "unit-test:browser": "echo skipped",
28
- "unit-test:node": "mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace \"dist-esm/test/internal/unit/**/*.test.js\"",
29
- "unit-test:node:debug": "mocha --inspect-brk -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace \"dist-esm/test/internal/unit/**/*.test.js\"",
28
+ "unit-test:node": "mocha -r ../../../common/tools/esm-workaround -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace \"dist-esm/test/internal/unit/**/*.test.js\"",
29
+ "unit-test:node:debug": "mocha --inspect-brk -r ../../../common/tools/esm-workaround -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace \"dist-esm/test/internal/unit/**/*.test.js\"",
30
30
  "unit-test:node:no-timeout": "echo skipped",
31
31
  "unit-test": "npm run unit-test:node && npm run unit-test:browser",
32
- "functional-test": "mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace \"dist-esm/test/internal/functional/*.test.js\"",
32
+ "functional-test": "mocha -r ../../../common/tools/esm-workaround -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace \"dist-esm/test/internal/functional/*.test.js\"",
33
33
  "integration-test:browser": "echo skipped",
34
34
  "integration-test:node": "npm run functional-test",
35
35
  "integration-test": "npm run integration-test:node && npm run integration-test:browser",
36
36
  "report": "nyc report --reporter=json",
37
37
  "test-opentelemetry-versions": "node test-opentelemetry-versions.js 2>&1",
38
- "prepare": "npm run build",
39
38
  "pack": "npm pack 2>&1"
40
39
  },
41
40
  "engines": {
42
- "node": ">=14.0.0"
41
+ "node": ">=16.0.0"
43
42
  },
44
43
  "files": [
45
44
  "dist-esm/src/",
@@ -70,28 +69,29 @@
70
69
  "@azure/dev-tool": "^1.0.0",
71
70
  "@azure/eslint-plugin-azure-sdk": "^3.0.0",
72
71
  "@microsoft/api-extractor": "^7.31.1",
73
- "@types/mocha": "^7.0.2",
74
- "@types/node": "^14.0.0",
72
+ "@types/mocha": "^10.0.0",
73
+ "@types/node": "^16.0.0",
75
74
  "@types/sinon": "^10.0.0",
76
75
  "dotenv": "^16.0.0",
77
76
  "eslint": "^8.0.0",
78
77
  "eslint-plugin-node": "^11.1.0",
79
- "mocha": "^7.1.1",
78
+ "mocha": "^10.0.0",
80
79
  "nock": "^12.0.3",
81
80
  "nyc": "^15.0.0",
82
81
  "prettier": "^2.5.1",
83
82
  "rimraf": "^3.0.0",
84
83
  "sinon": "^15.0.0",
85
84
  "ts-node": "^10.0.0",
86
- "typescript": "~5.0.0"
85
+ "typescript": "~5.0.0",
86
+ "esm": "^3.2.18"
87
87
  },
88
88
  "dependencies": {
89
89
  "@azure/functions": "^3.2.0",
90
- "@azure/monitor-opentelemetry-exporter": "1.0.0-beta.16",
91
- "@azure/opentelemetry-instrumentation-azure-sdk": "^1.0.0-beta.3",
92
- "@opentelemetry/api": "^1.5.0",
90
+ "@azure/monitor-opentelemetry-exporter": "1.0.0-beta.17",
91
+ "@azure/opentelemetry-instrumentation-azure-sdk": "^1.0.0-beta.5",
92
+ "@opentelemetry/api": "^1.6.0",
93
93
  "@opentelemetry/api-logs": "^0.43.0",
94
- "@opentelemetry/core": "^1.16.0",
94
+ "@opentelemetry/core": "^1.17.0",
95
95
  "@opentelemetry/instrumentation": "^0.43.0",
96
96
  "@opentelemetry/instrumentation-http": "^0.43.0",
97
97
  "@opentelemetry/instrumentation-mongodb": "^0.37.0",
@@ -99,12 +99,12 @@
99
99
  "@opentelemetry/instrumentation-pg": "^0.36.1",
100
100
  "@opentelemetry/instrumentation-redis": "^0.35.1",
101
101
  "@opentelemetry/instrumentation-redis-4": "^0.35.1",
102
- "@opentelemetry/resources": "^1.16.0",
102
+ "@opentelemetry/resources": "^1.17.0",
103
103
  "@opentelemetry/sdk-logs": "^0.43.0",
104
- "@opentelemetry/sdk-metrics": "^1.16.0",
105
- "@opentelemetry/sdk-trace-base": "^1.16.0",
106
- "@opentelemetry/sdk-trace-node": "^1.16.0",
107
- "@opentelemetry/semantic-conventions": "^1.16.0",
104
+ "@opentelemetry/sdk-metrics": "^1.17.0",
105
+ "@opentelemetry/sdk-trace-base": "^1.17.0",
106
+ "@opentelemetry/sdk-trace-node": "^1.17.0",
107
+ "@opentelemetry/semantic-conventions": "^1.17.0",
108
108
  "tslib": "^2.2.0"
109
109
  },
110
110
  "sideEffects": false,