@azure/monitor-opentelemetry 1.1.0 → 1.1.1

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/dist/index.js CHANGED
@@ -1,7 +1,10 @@
1
1
  'use strict';
2
2
 
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
3
5
  var api = require('@opentelemetry/api');
4
6
  var apiLogs = require('@opentelemetry/api-logs');
7
+ var sdkNode = require('@opentelemetry/sdk-node');
5
8
  var resources = require('@opentelemetry/resources');
6
9
  var fs = require('fs');
7
10
  var path = require('path');
@@ -9,7 +12,6 @@ var os = require('os');
9
12
  var util = require('util');
10
13
  var opentelemetryInstrumentationAzureSdk = require('@azure/opentelemetry-instrumentation-azure-sdk');
11
14
  var monitorOpentelemetryExporter = require('@azure/monitor-opentelemetry-exporter');
12
- var sdkTraceNode = require('@opentelemetry/sdk-trace-node');
13
15
  var sdkTraceBase = require('@opentelemetry/sdk-trace-base');
14
16
  var instrumentationHttp = require('@opentelemetry/instrumentation-http');
15
17
  var instrumentationMongodb = require('@opentelemetry/instrumentation-mongodb');
@@ -703,45 +705,44 @@ class MetricHandler {
703
705
  var _a, _b, _c, _d, _e, _f, _g;
704
706
  this._collectionInterval = 60000; // 60 seconds
705
707
  this._config = config;
706
- if (!process.env[APPLICATION_INSIGHTS_NO_STANDARD_METRICS]) {
707
- this._standardMetrics = new StandardMetrics(this._config);
708
- }
709
708
  // 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 = [];
709
+ this._views = [];
711
710
  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" }));
711
+ this._views.push(new sdkMetrics.View({ meterName: "@azure/opentelemetry-instrumentation-azure-sdk" }));
713
712
  }
714
713
  if ((_b = config.instrumentationOptions.http) === null || _b === void 0 ? void 0 : _b.enabled) {
715
- views.push(new sdkMetrics.View({ meterName: "@azure/opentelemetry-instrumentation-http" }));
714
+ this._views.push(new sdkMetrics.View({ meterName: "@azure/opentelemetry-instrumentation-http" }));
716
715
  }
717
716
  if ((_c = config.instrumentationOptions.mongoDb) === null || _c === void 0 ? void 0 : _c.enabled) {
718
- views.push(new sdkMetrics.View({ meterName: "@azure/opentelemetry-instrumentation-mongodb" }));
717
+ this._views.push(new sdkMetrics.View({ meterName: "@azure/opentelemetry-instrumentation-mongodb" }));
719
718
  }
720
719
  if ((_d = config.instrumentationOptions.mySql) === null || _d === void 0 ? void 0 : _d.enabled) {
721
- views.push(new sdkMetrics.View({ meterName: "@opentelemetry/instrumentation-mysql" }));
720
+ this._views.push(new sdkMetrics.View({ meterName: "@opentelemetry/instrumentation-mysql" }));
722
721
  }
723
722
  if ((_e = config.instrumentationOptions.postgreSql) === null || _e === void 0 ? void 0 : _e.enabled) {
724
- views.push(new sdkMetrics.View({ meterName: "@opentelemetry/instrumentation-pg" }));
723
+ this._views.push(new sdkMetrics.View({ meterName: "@opentelemetry/instrumentation-pg" }));
725
724
  }
726
725
  if ((_f = config.instrumentationOptions.redis4) === null || _f === void 0 ? void 0 : _f.enabled) {
727
- views.push(new sdkMetrics.View({ meterName: "@opentelemetry/instrumentation-redis-4" }));
726
+ this._views.push(new sdkMetrics.View({ meterName: "@opentelemetry/instrumentation-redis-4" }));
728
727
  }
729
728
  if ((_g = config.instrumentationOptions.redis) === null || _g === void 0 ? void 0 : _g.enabled) {
730
- views.push(new sdkMetrics.View({ meterName: "@azure/opentelemetry-instrumentation-redis" }));
729
+ this._views.push(new sdkMetrics.View({ meterName: "@azure/opentelemetry-instrumentation-redis" }));
731
730
  }
732
- const meterProviderConfig = {
733
- resource: this._config.resource,
734
- views: views,
735
- };
736
- this._meterProvider = new sdkMetrics.MeterProvider(meterProviderConfig);
737
731
  this._azureExporter = new monitorOpentelemetryExporter.AzureMonitorMetricExporter(this._config.azureMonitorExporterOptions);
738
732
  let metricReaderOptions = {
739
733
  exporter: this._azureExporter,
740
734
  exportIntervalMillis: (options === null || options === void 0 ? void 0 : options.collectionInterval) || this._collectionInterval,
741
735
  };
742
736
  this._metricReader = new sdkMetrics.PeriodicExportingMetricReader(metricReaderOptions);
743
- this._meterProvider.addMetricReader(this._metricReader);
744
- api.metrics.setGlobalMeterProvider(this._meterProvider);
737
+ if (!process.env[APPLICATION_INSIGHTS_NO_STANDARD_METRICS]) {
738
+ this._standardMetrics = new StandardMetrics(this._config);
739
+ }
740
+ }
741
+ getMetricReader() {
742
+ return this._metricReader;
743
+ }
744
+ getViews() {
745
+ return this._views;
745
746
  }
746
747
  markSpanAsProcessed(span) {
747
748
  var _a;
@@ -756,21 +757,12 @@ class MetricHandler {
756
757
  (_a = this._standardMetrics) === null || _a === void 0 ? void 0 : _a.recordLog(logRecord);
757
758
  }
758
759
  /**
759
- * Shutdown handler, all Meter providers will return no-op Meters
760
+ * Shutdown handler
760
761
  */
761
762
  async shutdown() {
762
763
  var _a;
763
- this._meterProvider.shutdown();
764
764
  (_a = this._standardMetrics) === null || _a === void 0 ? void 0 : _a.shutdown();
765
765
  }
766
- /**
767
- * Force flush all Meter Providers
768
- */
769
- async flush() {
770
- var _a;
771
- await this._meterProvider.forceFlush();
772
- await ((_a = this._standardMetrics) === null || _a === void 0 ? void 0 : _a.flush());
773
- }
774
766
  }
775
767
 
776
768
  // Copyright (c) Microsoft Corporation.
@@ -936,13 +928,7 @@ class TraceHandler {
936
928
  this._config = config;
937
929
  this._metricHandler = metricHandler;
938
930
  this._instrumentations = [];
939
- const aiSampler = new ApplicationInsightsSampler(this._config.samplingRatio);
940
- const tracerConfig = {
941
- sampler: aiSampler,
942
- resource: this._config.resource,
943
- forceFlushTimeoutMillis: 30000,
944
- };
945
- this._tracerProvider = new sdkTraceNode.NodeTracerProvider(tracerConfig);
931
+ this._aiSampler = new ApplicationInsightsSampler(this._config.samplingRatio);
946
932
  this._azureExporter = new monitorOpentelemetryExporter.AzureMonitorTraceExporter(this._config.azureMonitorExporterOptions);
947
933
  const bufferConfig = {
948
934
  maxExportBatchSize: 512,
@@ -951,33 +937,30 @@ class TraceHandler {
951
937
  maxQueueSize: 2048,
952
938
  };
953
939
  this._spanProcessor = new sdkTraceBase.BatchSpanProcessor(this._azureExporter, bufferConfig);
954
- this._tracerProvider.addSpanProcessor(this._spanProcessor);
955
- this._tracerProvider.register();
956
- const azureSpanProcessor = new AzureMonitorSpanProcessor(this._metricHandler);
957
- this._tracerProvider.addSpanProcessor(azureSpanProcessor);
958
940
  this._azureFunctionsHook = new AzureFunctionsHook();
959
941
  this._initializeInstrumentations();
960
942
  }
961
- /**
962
- * Shutdown handler, all Tracer providers will return no-op Tracers
963
- */
964
- async shutdown() {
965
- await this._tracerProvider.shutdown();
966
- this._azureFunctionsHook.shutdown();
943
+ start() {
944
+ try {
945
+ const azureSpanProcessor = new AzureMonitorSpanProcessor(this._metricHandler);
946
+ api.trace.getTracerProvider().getDelegate().addSpanProcessor(azureSpanProcessor);
947
+ }
948
+ catch (error) { }
967
949
  }
968
- /**
969
- * Force flush Tracer Provider
970
- */
971
- async flush() {
972
- return this._tracerProvider.forceFlush();
950
+ getSampler() {
951
+ return this._aiSampler;
952
+ }
953
+ getSpanProcessor() {
954
+ return this._spanProcessor;
955
+ }
956
+ getInstrumentations() {
957
+ return this._instrumentations;
973
958
  }
974
959
  /**
975
- * Disable all OpenTelemetry Instrumentations
960
+ * Shutdown handler
976
961
  */
977
- disableInstrumentations() {
978
- this._instrumentations.forEach((instrumentation) => {
979
- instrumentation.disable();
980
- });
962
+ async shutdown() {
963
+ this._azureFunctionsHook.shutdown();
981
964
  }
982
965
  /**
983
966
  * Start auto collection of telemetry
@@ -1020,13 +1003,6 @@ class TraceHandler {
1020
1003
  if ((_g = this._config.instrumentationOptions.redis4) === null || _g === void 0 ? void 0 : _g.enabled) {
1021
1004
  this._instrumentations.push(new instrumentationRedis4.RedisInstrumentation(this._config.instrumentationOptions.redis4));
1022
1005
  }
1023
- this._instrumentations.forEach((instrumentation) => {
1024
- instrumentation.setTracerProvider(this._tracerProvider);
1025
- instrumentation.setMeterProvider(api.metrics.getMeterProvider());
1026
- if (instrumentation.getConfig().enabled) {
1027
- instrumentation.enable();
1028
- }
1029
- });
1030
1006
  }
1031
1007
  }
1032
1008
 
@@ -1063,38 +1039,25 @@ class LogHandler {
1063
1039
  * @param _metricHandler - MetricHandler.
1064
1040
  */
1065
1041
  constructor(config, metricHandler) {
1066
- this._config = config;
1067
1042
  this._metricHandler = metricHandler;
1068
- const loggerProviderConfig = {
1069
- resource: this._config.resource,
1070
- };
1071
- this._loggerProvider = new sdkLogs.LoggerProvider(loggerProviderConfig);
1072
- this._azureExporter = new monitorOpentelemetryExporter.AzureMonitorLogExporter(this._config.azureMonitorExporterOptions);
1073
- // Log Processor could be configured through env variables
1074
- // https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/#batch-logrecord-processor
1043
+ this._azureExporter = new monitorOpentelemetryExporter.AzureMonitorLogExporter(config.azureMonitorExporterOptions);
1075
1044
  this._logRecordProcessor = new sdkLogs.BatchLogRecordProcessor(this._azureExporter);
1076
- this._loggerProvider.addLogRecordProcessor(this._logRecordProcessor);
1077
- this._azureLogProccessor = new AzureLogRecordProcessor(this._metricHandler);
1078
- this._loggerProvider.addLogRecordProcessor(this._azureLogProccessor);
1079
- apiLogs.logs.setGlobalLoggerProvider(this._loggerProvider);
1080
1045
  }
1081
- /**
1082
- * Shutdown handler, all Logger providers will return no-op Loggers
1083
- */
1084
- async shutdown() {
1085
- await this._loggerProvider.shutdown();
1046
+ start() {
1047
+ try {
1048
+ const azureLogProccessor = new AzureLogRecordProcessor(this._metricHandler);
1049
+ apiLogs.logs.getLoggerProvider().addLogRecordProcessor(azureLogProccessor);
1050
+ }
1051
+ catch (error) { }
1086
1052
  }
1087
- /**
1088
- * Force flush Logger Provider
1089
- */
1090
- async flush() {
1091
- return this._loggerProvider.forceFlush();
1053
+ getLogRecordProcessor() {
1054
+ return this._logRecordProcessor;
1092
1055
  }
1093
1056
  }
1094
1057
 
1095
1058
  // Copyright (c) Microsoft Corporation.
1096
1059
  // Licensed under the MIT license.
1097
- const AZURE_MONITOR_OPENTELEMETRY_VERSION = "1.1.0";
1060
+ const AZURE_MONITOR_OPENTELEMETRY_VERSION = "1.1.1";
1098
1061
  const AZURE_MONITOR_STATSBEAT_FEATURES = "AZURE_MONITOR_STATSBEAT_FEATURES";
1099
1062
  var StatsbeatFeature;
1100
1063
  (function (StatsbeatFeature) {
@@ -1117,9 +1080,7 @@ var StatsbeatInstrumentation;
1117
1080
  // Copyright (c) Microsoft Corporation.
1118
1081
  // Licensed under the MIT license.
1119
1082
  process.env["AZURE_MONITOR_DISTRO_VERSION"] = AZURE_MONITOR_OPENTELEMETRY_VERSION;
1120
- let metricHandler;
1121
- let traceHandler;
1122
- let logHandler;
1083
+ let sdk;
1123
1084
  /**
1124
1085
  * Initialize Azure Monitor Distro
1125
1086
  * @param options Azure Monitor OpenTelemetry Options
@@ -1132,17 +1093,31 @@ function useAzureMonitor(options) {
1132
1093
  api.trace.disable();
1133
1094
  apiLogs.logs.disable();
1134
1095
  // Create internal handlers
1135
- metricHandler = new MetricHandler(config);
1136
- traceHandler = new TraceHandler(config, metricHandler);
1137
- logHandler = new LogHandler(config, metricHandler);
1096
+ const metricHandler = new MetricHandler(config);
1097
+ const traceHandler = new TraceHandler(config, metricHandler);
1098
+ const logHandler = new LogHandler(config, metricHandler);
1099
+ // Initialize OpenTelemetry SDK
1100
+ const sdkConfig = {
1101
+ autoDetectResources: true,
1102
+ logRecordProcessor: logHandler.getLogRecordProcessor(),
1103
+ metricReader: metricHandler.getMetricReader(),
1104
+ views: metricHandler.getViews(),
1105
+ instrumentations: traceHandler.getInstrumentations(),
1106
+ resource: config.resource,
1107
+ sampler: traceHandler.getSampler(),
1108
+ spanProcessor: traceHandler.getSpanProcessor(),
1109
+ };
1110
+ sdk = new sdkNode.NodeSDK(sdkConfig);
1111
+ sdk.start();
1112
+ // Add extra SpanProcessors, MetricReaders and LogRecordProcessors
1113
+ traceHandler.start();
1114
+ logHandler.start();
1138
1115
  }
1139
1116
  /**
1140
1117
  * Shutdown Azure Monitor Distro
1141
1118
  */
1142
1119
  function shutdownAzureMonitor() {
1143
- metricHandler.shutdown();
1144
- traceHandler.shutdown();
1145
- logHandler.shutdown();
1120
+ sdk === null || sdk === void 0 ? void 0 : sdk.shutdown();
1146
1121
  }
1147
1122
  function _setStatsbeatFeatures(config) {
1148
1123
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
@@ -2,6 +2,7 @@
2
2
  // Licensed under the MIT license.
3
3
  import { metrics, trace } from "@opentelemetry/api";
4
4
  import { logs } from "@opentelemetry/api-logs";
5
+ import { NodeSDK } from "@opentelemetry/sdk-node";
5
6
  import { InternalConfig } from "./shared/config";
6
7
  import { MetricHandler } from "./metrics";
7
8
  import { TraceHandler } from "./traces/handler";
@@ -9,9 +10,7 @@ import { Logger as InternalLogger } from "./shared/logging";
9
10
  import { LogHandler } from "./logs";
10
11
  import { AZURE_MONITOR_OPENTELEMETRY_VERSION, AZURE_MONITOR_STATSBEAT_FEATURES, StatsbeatFeature, StatsbeatInstrumentation, } from "./types";
11
12
  process.env["AZURE_MONITOR_DISTRO_VERSION"] = AZURE_MONITOR_OPENTELEMETRY_VERSION;
12
- let metricHandler;
13
- let traceHandler;
14
- let logHandler;
13
+ let sdk;
15
14
  /**
16
15
  * Initialize Azure Monitor Distro
17
16
  * @param options Azure Monitor OpenTelemetry Options
@@ -24,17 +23,31 @@ export function useAzureMonitor(options) {
24
23
  trace.disable();
25
24
  logs.disable();
26
25
  // Create internal handlers
27
- metricHandler = new MetricHandler(config);
28
- traceHandler = new TraceHandler(config, metricHandler);
29
- logHandler = new LogHandler(config, metricHandler);
26
+ const metricHandler = new MetricHandler(config);
27
+ const traceHandler = new TraceHandler(config, metricHandler);
28
+ const logHandler = new LogHandler(config, metricHandler);
29
+ // Initialize OpenTelemetry SDK
30
+ const sdkConfig = {
31
+ autoDetectResources: true,
32
+ logRecordProcessor: logHandler.getLogRecordProcessor(),
33
+ metricReader: metricHandler.getMetricReader(),
34
+ views: metricHandler.getViews(),
35
+ instrumentations: traceHandler.getInstrumentations(),
36
+ resource: config.resource,
37
+ sampler: traceHandler.getSampler(),
38
+ spanProcessor: traceHandler.getSpanProcessor(),
39
+ };
40
+ sdk = new NodeSDK(sdkConfig);
41
+ sdk.start();
42
+ // Add extra SpanProcessors, MetricReaders and LogRecordProcessors
43
+ traceHandler.start();
44
+ logHandler.start();
30
45
  }
31
46
  /**
32
47
  * Shutdown Azure Monitor Distro
33
48
  */
34
49
  export function shutdownAzureMonitor() {
35
- metricHandler.shutdown();
36
- traceHandler.shutdown();
37
- logHandler.shutdown();
50
+ sdk === null || sdk === void 0 ? void 0 : sdk.shutdown();
38
51
  }
39
52
  function _setStatsbeatFeatures(config) {
40
53
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
@@ -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,m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MAAA,MAAA,MAAM,CAAC,sBAAsB,0CAAE,UAAU,0CAAE,OAAO,EAAE;QACtD,qBAAqB,IAAI,wBAAwB,CAAC,QAAQ,CAAC;KAC5D;IACD,IAAI,MAAA,MAAA,MAAM,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"]}
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,OAAO,EAAwB,MAAM,yBAAyB,CAAC;AACxE,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,GAAY,CAAC;AAEjB;;;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;IAEf,2BAA2B;IAC3B,MAAM,aAAa,GAAG,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC;IAChD,MAAM,YAAY,GAAG,IAAI,YAAY,CAA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AAqB,IAAI,wBAAwB,CAAC,KAAK,CAAC;KACzD;IACD,IAAI,MAAA,MAAA,MAAM,CAAC,sBAAsB,0CAAE,UAAU,0CAAE,OAAO,EAAE;QACtD,qBAAqB,IAAI,wBAAwB,CAAC,QAAQ,CAAC;KAC5D;IACD,IAAI,MAAA,MAAA,MAAM,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 { NodeSDK, NodeSDKConfiguration } from \"@opentelemetry/sdk-node\";\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 sdk: NodeSDK;\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\n // Create internal handlers\n const metricHandler = new MetricHandler(config);\n const traceHandler = new TraceHandler(config, metricHandler);\n const logHandler = new LogHandler(config, metricHandler);\n\n // Initialize OpenTelemetry SDK\n const sdkConfig: Partial<NodeSDKConfiguration> = {\n autoDetectResources: true,\n logRecordProcessor: logHandler.getLogRecordProcessor(),\n metricReader: metricHandler.getMetricReader(),\n views: metricHandler.getViews(),\n instrumentations: traceHandler.getInstrumentations(),\n resource: config.resource,\n sampler: traceHandler.getSampler(),\n spanProcessor: traceHandler.getSpanProcessor(),\n };\n sdk = new NodeSDK(sdkConfig);\n sdk.start();\n // Add extra SpanProcessors, MetricReaders and LogRecordProcessors\n traceHandler.start();\n logHandler.start();\n}\n\n/**\n * Shutdown Azure Monitor Distro\n */\nexport function shutdownAzureMonitor() {\n sdk?.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 { AzureMonitorLogExporter } from "@azure/monitor-opentelemetry-exporter";
4
4
  import { logs } from "@opentelemetry/api-logs";
5
- import { LoggerProvider, BatchLogRecordProcessor } from "@opentelemetry/sdk-logs";
5
+ import { BatchLogRecordProcessor } from "@opentelemetry/sdk-logs";
6
6
  import { AzureLogRecordProcessor } from "./logRecordProcessor";
7
7
  /**
8
8
  * Azure Monitor OpenTelemetry Log Handler
@@ -14,32 +14,19 @@ export class LogHandler {
14
14
  * @param _metricHandler - MetricHandler.
15
15
  */
16
16
  constructor(config, metricHandler) {
17
- this._config = config;
18
17
  this._metricHandler = metricHandler;
19
- const loggerProviderConfig = {
20
- resource: this._config.resource,
21
- };
22
- this._loggerProvider = new LoggerProvider(loggerProviderConfig);
23
- this._azureExporter = new AzureMonitorLogExporter(this._config.azureMonitorExporterOptions);
24
- // Log Processor could be configured through env variables
25
- // https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/#batch-logrecord-processor
18
+ this._azureExporter = new AzureMonitorLogExporter(config.azureMonitorExporterOptions);
26
19
  this._logRecordProcessor = new BatchLogRecordProcessor(this._azureExporter);
27
- this._loggerProvider.addLogRecordProcessor(this._logRecordProcessor);
28
- this._azureLogProccessor = new AzureLogRecordProcessor(this._metricHandler);
29
- this._loggerProvider.addLogRecordProcessor(this._azureLogProccessor);
30
- logs.setGlobalLoggerProvider(this._loggerProvider);
31
20
  }
32
- /**
33
- * Shutdown handler, all Logger providers will return no-op Loggers
34
- */
35
- async shutdown() {
36
- await this._loggerProvider.shutdown();
21
+ start() {
22
+ try {
23
+ const azureLogProccessor = new AzureLogRecordProcessor(this._metricHandler);
24
+ logs.getLoggerProvider().addLogRecordProcessor(azureLogProccessor);
25
+ }
26
+ catch (error) { }
37
27
  }
38
- /**
39
- * Force flush Logger Provider
40
- */
41
- async flush() {
42
- return this._loggerProvider.forceFlush();
28
+ getLogRecordProcessor() {
29
+ return this._logRecordProcessor;
43
30
  }
44
31
  }
45
32
  //# sourceMappingURL=handler.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"handler.js","sourceRoot":"","sources":["../../../src/logs/handler.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAChF,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAIlF,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAE/D;;GAEG;AACH,MAAM,OAAO,UAAU;IAQrB;;;;OAIG;IACH,YAAY,MAAsB,EAAE,aAA4B;QAC9D,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;QACpC,MAAM,oBAAoB,GAAyB;YACjD,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ;SAChC,CAAC;QACF,IAAI,CAAC,eAAe,GAAG,IAAI,cAAc,CAAC,oBAAoB,CAAC,CAAC;QAChE,IAAI,CAAC,cAAc,GAAG,IAAI,uBAAuB,CAAC,IAAI,CAAC,OAAO,CAAC,2BAA2B,CAAC,CAAC;QAC5F,0DAA0D;QAC1D,8GAA8G;QAC9G,IAAI,CAAC,mBAAmB,GAAG,IAAI,uBAAuB,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAC5E,IAAI,CAAC,eAAe,CAAC,qBAAqB,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QACrE,IAAI,CAAC,mBAAmB,GAAG,IAAI,uBAAuB,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAC5E,IAAI,CAAC,eAAe,CAAC,qBAAqB,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QACrE,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IACrD,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,QAAQ;QACnB,MAAM,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE,CAAC;IACxC,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,KAAK;QAChB,OAAO,IAAI,CAAC,eAAe,CAAC,UAAU,EAAE,CAAC;IAC3C,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AzureMonitorLogExporter } from \"@azure/monitor-opentelemetry-exporter\";\nimport { logs } from \"@opentelemetry/api-logs\";\nimport { LoggerProvider, BatchLogRecordProcessor } from \"@opentelemetry/sdk-logs\";\nimport { LoggerProviderConfig } from \"@opentelemetry/sdk-logs/build/src/types\";\nimport { InternalConfig } from \"../shared/config\";\nimport { MetricHandler } from \"../metrics/handler\";\nimport { AzureLogRecordProcessor } from \"./logRecordProcessor\";\n\n/**\n * Azure Monitor OpenTelemetry Log Handler\n */\nexport class LogHandler {\n private _loggerProvider: LoggerProvider;\n private _azureExporter: AzureMonitorLogExporter;\n private _logRecordProcessor: BatchLogRecordProcessor;\n private _config: InternalConfig;\n private _metricHandler?: MetricHandler;\n private _azureLogProccessor: AzureLogRecordProcessor;\n\n /**\n * Initializes a new instance of the TraceHandler class.\n * @param _config - Distro configuration.\n * @param _metricHandler - MetricHandler.\n */\n constructor(config: InternalConfig, metricHandler: MetricHandler) {\n this._config = config;\n this._metricHandler = metricHandler;\n const loggerProviderConfig: LoggerProviderConfig = {\n resource: this._config.resource,\n };\n this._loggerProvider = new LoggerProvider(loggerProviderConfig);\n this._azureExporter = new AzureMonitorLogExporter(this._config.azureMonitorExporterOptions);\n // Log Processor could be configured through env variables\n // https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/#batch-logrecord-processor\n this._logRecordProcessor = new BatchLogRecordProcessor(this._azureExporter);\n this._loggerProvider.addLogRecordProcessor(this._logRecordProcessor);\n this._azureLogProccessor = new AzureLogRecordProcessor(this._metricHandler);\n this._loggerProvider.addLogRecordProcessor(this._azureLogProccessor);\n logs.setGlobalLoggerProvider(this._loggerProvider);\n }\n\n /**\n * Shutdown handler, all Logger providers will return no-op Loggers\n */\n public async shutdown(): Promise<void> {\n await this._loggerProvider.shutdown();\n }\n\n /**\n * Force flush Logger Provider\n */\n public async flush(): Promise<void> {\n return this._loggerProvider.forceFlush();\n }\n}\n"]}
1
+ {"version":3,"file":"handler.js","sourceRoot":"","sources":["../../../src/logs/handler.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAChF,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EAAE,uBAAuB,EAAkB,MAAM,yBAAyB,CAAC;AAGlF,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAE/D;;GAEG;AACH,MAAM,OAAO,UAAU;IAKrB;;;;OAIG;IACH,YAAY,MAAsB,EAAE,aAA4B;QAC9D,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;QACpC,IAAI,CAAC,cAAc,GAAG,IAAI,uBAAuB,CAAC,MAAM,CAAC,2BAA2B,CAAC,CAAC;QACtF,IAAI,CAAC,mBAAmB,GAAG,IAAI,uBAAuB,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IAC9E,CAAC;IAEM,KAAK;QACV,IAAI;YACF,MAAM,kBAAkB,GAAG,IAAI,uBAAuB,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;YAC3E,IAAI,CAAC,iBAAiB,EAAqB,CAAC,qBAAqB,CAAC,kBAAkB,CAAC,CAAC;SACxF;QAAC,OAAO,KAAK,EAAE,GAAE;IACpB,CAAC;IAEM,qBAAqB;QAC1B,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AzureMonitorLogExporter } from \"@azure/monitor-opentelemetry-exporter\";\nimport { logs } from \"@opentelemetry/api-logs\";\nimport { BatchLogRecordProcessor, LoggerProvider } from \"@opentelemetry/sdk-logs\";\nimport { InternalConfig } from \"../shared/config\";\nimport { MetricHandler } from \"../metrics/handler\";\nimport { AzureLogRecordProcessor } from \"./logRecordProcessor\";\n\n/**\n * Azure Monitor OpenTelemetry Log Handler\n */\nexport class LogHandler {\n private _azureExporter: AzureMonitorLogExporter;\n private _logRecordProcessor: BatchLogRecordProcessor;\n private _metricHandler: MetricHandler;\n\n /**\n * Initializes a new instance of the TraceHandler class.\n * @param _config - Distro configuration.\n * @param _metricHandler - MetricHandler.\n */\n constructor(config: InternalConfig, metricHandler: MetricHandler) {\n this._metricHandler = metricHandler;\n this._azureExporter = new AzureMonitorLogExporter(config.azureMonitorExporterOptions);\n this._logRecordProcessor = new BatchLogRecordProcessor(this._azureExporter);\n }\n\n public start(): void {\n try {\n const azureLogProccessor = new AzureLogRecordProcessor(this._metricHandler);\n (logs.getLoggerProvider() as LoggerProvider).addLogRecordProcessor(azureLogProccessor);\n } catch (error) {}\n }\n\n public getLogRecordProcessor(): BatchLogRecordProcessor {\n return this._logRecordProcessor;\n }\n}\n"]}
@@ -1,8 +1,7 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT license.
3
3
  import { AzureMonitorMetricExporter } from "@azure/monitor-opentelemetry-exporter";
4
- import { metrics } from "@opentelemetry/api";
5
- import { MeterProvider, PeriodicExportingMetricReader, View, } from "@opentelemetry/sdk-metrics";
4
+ import { PeriodicExportingMetricReader, View, } from "@opentelemetry/sdk-metrics";
6
5
  import { StandardMetrics } from "./standardMetrics";
7
6
  import { APPLICATION_INSIGHTS_NO_STANDARD_METRICS } from "./types";
8
7
  /**
@@ -18,45 +17,44 @@ export class MetricHandler {
18
17
  var _a, _b, _c, _d, _e, _f, _g;
19
18
  this._collectionInterval = 60000; // 60 seconds
20
19
  this._config = config;
21
- if (!process.env[APPLICATION_INSIGHTS_NO_STANDARD_METRICS]) {
22
- this._standardMetrics = new StandardMetrics(this._config);
23
- }
24
20
  // 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 = [];
21
+ this._views = [];
26
22
  if ((_a = config.instrumentationOptions.azureSdk) === null || _a === void 0 ? void 0 : _a.enabled) {
27
- views.push(new View({ meterName: "@azure/opentelemetry-instrumentation-azure-sdk" }));
23
+ this._views.push(new View({ meterName: "@azure/opentelemetry-instrumentation-azure-sdk" }));
28
24
  }
29
25
  if ((_b = config.instrumentationOptions.http) === null || _b === void 0 ? void 0 : _b.enabled) {
30
- views.push(new View({ meterName: "@azure/opentelemetry-instrumentation-http" }));
26
+ this._views.push(new View({ meterName: "@azure/opentelemetry-instrumentation-http" }));
31
27
  }
32
28
  if ((_c = config.instrumentationOptions.mongoDb) === null || _c === void 0 ? void 0 : _c.enabled) {
33
- views.push(new View({ meterName: "@azure/opentelemetry-instrumentation-mongodb" }));
29
+ this._views.push(new View({ meterName: "@azure/opentelemetry-instrumentation-mongodb" }));
34
30
  }
35
31
  if ((_d = config.instrumentationOptions.mySql) === null || _d === void 0 ? void 0 : _d.enabled) {
36
- views.push(new View({ meterName: "@opentelemetry/instrumentation-mysql" }));
32
+ this._views.push(new View({ meterName: "@opentelemetry/instrumentation-mysql" }));
37
33
  }
38
34
  if ((_e = config.instrumentationOptions.postgreSql) === null || _e === void 0 ? void 0 : _e.enabled) {
39
- views.push(new View({ meterName: "@opentelemetry/instrumentation-pg" }));
35
+ this._views.push(new View({ meterName: "@opentelemetry/instrumentation-pg" }));
40
36
  }
41
37
  if ((_f = config.instrumentationOptions.redis4) === null || _f === void 0 ? void 0 : _f.enabled) {
42
- views.push(new View({ meterName: "@opentelemetry/instrumentation-redis-4" }));
38
+ this._views.push(new View({ meterName: "@opentelemetry/instrumentation-redis-4" }));
43
39
  }
44
40
  if ((_g = config.instrumentationOptions.redis) === null || _g === void 0 ? void 0 : _g.enabled) {
45
- views.push(new View({ meterName: "@azure/opentelemetry-instrumentation-redis" }));
41
+ this._views.push(new View({ meterName: "@azure/opentelemetry-instrumentation-redis" }));
46
42
  }
47
- const meterProviderConfig = {
48
- resource: this._config.resource,
49
- views: views,
50
- };
51
- this._meterProvider = new MeterProvider(meterProviderConfig);
52
43
  this._azureExporter = new AzureMonitorMetricExporter(this._config.azureMonitorExporterOptions);
53
44
  let metricReaderOptions = {
54
45
  exporter: this._azureExporter,
55
46
  exportIntervalMillis: (options === null || options === void 0 ? void 0 : options.collectionInterval) || this._collectionInterval,
56
47
  };
57
48
  this._metricReader = new PeriodicExportingMetricReader(metricReaderOptions);
58
- this._meterProvider.addMetricReader(this._metricReader);
59
- metrics.setGlobalMeterProvider(this._meterProvider);
49
+ if (!process.env[APPLICATION_INSIGHTS_NO_STANDARD_METRICS]) {
50
+ this._standardMetrics = new StandardMetrics(this._config);
51
+ }
52
+ }
53
+ getMetricReader() {
54
+ return this._metricReader;
55
+ }
56
+ getViews() {
57
+ return this._views;
60
58
  }
61
59
  markSpanAsProcessed(span) {
62
60
  var _a;
@@ -71,20 +69,11 @@ export class MetricHandler {
71
69
  (_a = this._standardMetrics) === null || _a === void 0 ? void 0 : _a.recordLog(logRecord);
72
70
  }
73
71
  /**
74
- * Shutdown handler, all Meter providers will return no-op Meters
72
+ * Shutdown handler
75
73
  */
76
74
  async shutdown() {
77
75
  var _a;
78
- this._meterProvider.shutdown();
79
76
  (_a = this._standardMetrics) === null || _a === void 0 ? void 0 : _a.shutdown();
80
77
  }
81
- /**
82
- * Force flush all Meter Providers
83
- */
84
- async flush() {
85
- var _a;
86
- await this._meterProvider.forceFlush();
87
- await ((_a = this._standardMetrics) === null || _a === void 0 ? void 0 : _a.flush());
88
- }
89
78
  }
90
79
  //# sourceMappingURL=handler.js.map
@@ -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,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;YACn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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"]}
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,EACL,6BAA6B,EAE7B,IAAI,GACL,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;A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ACnC,MAAA,IAAI,CAAC,gBAAgB,0CAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC9C,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,QAAQ;;QACnB,MAAA,IAAI,CAAC,gBAAgB,0CAAE,QAAQ,EAAE,CAAC;IACpC,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AzureMonitorMetricExporter } from \"@azure/monitor-opentelemetry-exporter\";\nimport {\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 _azureExporter: AzureMonitorMetricExporter;\n private _metricReader: PeriodicExportingMetricReader;\n private _standardMetrics?: StandardMetrics;\n private _config: InternalConfig;\n private _views: View[];\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 // 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 this._views = [];\n if (config.instrumentationOptions.azureSdk?.enabled) {\n this._views.push(new View({ meterName: \"@azure/opentelemetry-instrumentation-azure-sdk\" }));\n }\n if (config.instrumentationOptions.http?.enabled) {\n this._views.push(new View({ meterName: \"@azure/opentelemetry-instrumentation-http\" }));\n }\n if (config.instrumentationOptions.mongoDb?.enabled) {\n this._views.push(new View({ meterName: \"@azure/opentelemetry-instrumentation-mongodb\" }));\n }\n if (config.instrumentationOptions.mySql?.enabled) {\n this._views.push(new View({ meterName: \"@opentelemetry/instrumentation-mysql\" }));\n }\n if (config.instrumentationOptions.postgreSql?.enabled) {\n this._views.push(new View({ meterName: \"@opentelemetry/instrumentation-pg\" }));\n }\n if (config.instrumentationOptions.redis4?.enabled) {\n this._views.push(new View({ meterName: \"@opentelemetry/instrumentation-redis-4\" }));\n }\n if (config.instrumentationOptions.redis?.enabled) {\n this._views.push(new View({ meterName: \"@azure/opentelemetry-instrumentation-redis\" }));\n }\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\n if (!process.env[APPLICATION_INSIGHTS_NO_STANDARD_METRICS]) {\n this._standardMetrics = new StandardMetrics(this._config);\n }\n }\n\n public getMetricReader(): PeriodicExportingMetricReader {\n return this._metricReader;\n }\n\n public getViews(): View[] {\n return this._views;\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\n */\n public async shutdown(): Promise<void> {\n this._standardMetrics?.shutdown();\n }\n}\n"]}
@@ -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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AC,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
+ {"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;IAc9B;QAbQ,SAAI,GAAG,iBAAiB,CAAC;QACzB,oBAAe,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,cAAc;QAChD,sBAAiB,GAA0B,IAAI,CAAC;QAKhD,eAAU,GAAG,KAAK,CAAC;QACnB,kBAAa,GAAG,IAAI,CAAC;QAM3B,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC,0DAA0D;QAClI,IAAI,IAAI,CAAC,eAAe,KAAK,cAAc,EAAE;YAC3C,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;SACxB;QACD,IAAI,IAAI,CAAC,eAAe,KAAK,MAAM,EAAE;YACnC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;YACvB,IAAI,CAAC,aAAa,GAAG,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AAC,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.Timeout | 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"]}
@@ -2,7 +2,6 @@
2
2
  // Licensed under the MIT license.
3
3
  import { createAzureSdkInstrumentation } from "@azure/opentelemetry-instrumentation-azure-sdk";
4
4
  import { AzureMonitorTraceExporter } from "@azure/monitor-opentelemetry-exporter";
5
- import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
6
5
  import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-base";
7
6
  import { HttpInstrumentation, } from "@opentelemetry/instrumentation-http";
8
7
  import { MongoDBInstrumentation } from "@opentelemetry/instrumentation-mongodb";
@@ -13,8 +12,8 @@ import { RedisInstrumentation as Redis4Instrumentation } from "@opentelemetry/in
13
12
  import { ignoreOutgoingRequestHook } from "../utils/common";
14
13
  import { AzureMonitorSpanProcessor } from "./spanProcessor";
15
14
  import { AzureFunctionsHook } from "./azureFnHook";
16
- import { metrics } from "@opentelemetry/api";
17
15
  import { ApplicationInsightsSampler } from "./sampler";
16
+ import { trace } from "@opentelemetry/api";
18
17
  /**
19
18
  * Azure Monitor OpenTelemetry Trace Handler
20
19
  */
@@ -28,13 +27,7 @@ export class TraceHandler {
28
27
  this._config = config;
29
28
  this._metricHandler = metricHandler;
30
29
  this._instrumentations = [];
31
- const aiSampler = new ApplicationInsightsSampler(this._config.samplingRatio);
32
- const tracerConfig = {
33
- sampler: aiSampler,
34
- resource: this._config.resource,
35
- forceFlushTimeoutMillis: 30000,
36
- };
37
- this._tracerProvider = new NodeTracerProvider(tracerConfig);
30
+ this._aiSampler = new ApplicationInsightsSampler(this._config.samplingRatio);
38
31
  this._azureExporter = new AzureMonitorTraceExporter(this._config.azureMonitorExporterOptions);
39
32
  const bufferConfig = {
40
33
  maxExportBatchSize: 512,
@@ -43,33 +36,30 @@ export class TraceHandler {
43
36
  maxQueueSize: 2048,
44
37
  };
45
38
  this._spanProcessor = new BatchSpanProcessor(this._azureExporter, bufferConfig);
46
- this._tracerProvider.addSpanProcessor(this._spanProcessor);
47
- this._tracerProvider.register();
48
- const azureSpanProcessor = new AzureMonitorSpanProcessor(this._metricHandler);
49
- this._tracerProvider.addSpanProcessor(azureSpanProcessor);
50
39
  this._azureFunctionsHook = new AzureFunctionsHook();
51
40
  this._initializeInstrumentations();
52
41
  }
53
- /**
54
- * Shutdown handler, all Tracer providers will return no-op Tracers
55
- */
56
- async shutdown() {
57
- await this._tracerProvider.shutdown();
58
- this._azureFunctionsHook.shutdown();
42
+ start() {
43
+ try {
44
+ const azureSpanProcessor = new AzureMonitorSpanProcessor(this._metricHandler);
45
+ trace.getTracerProvider().getDelegate().addSpanProcessor(azureSpanProcessor);
46
+ }
47
+ catch (error) { }
59
48
  }
60
- /**
61
- * Force flush Tracer Provider
62
- */
63
- async flush() {
64
- return this._tracerProvider.forceFlush();
49
+ getSampler() {
50
+ return this._aiSampler;
51
+ }
52
+ getSpanProcessor() {
53
+ return this._spanProcessor;
54
+ }
55
+ getInstrumentations() {
56
+ return this._instrumentations;
65
57
  }
66
58
  /**
67
- * Disable all OpenTelemetry Instrumentations
59
+ * Shutdown handler
68
60
  */
69
- disableInstrumentations() {
70
- this._instrumentations.forEach((instrumentation) => {
71
- instrumentation.disable();
72
- });
61
+ async shutdown() {
62
+ this._azureFunctionsHook.shutdown();
73
63
  }
74
64
  /**
75
65
  * Start auto collection of telemetry
@@ -112,13 +102,6 @@ export class TraceHandler {
112
102
  if ((_g = this._config.instrumentationOptions.redis4) === null || _g === void 0 ? void 0 : _g.enabled) {
113
103
  this._instrumentations.push(new Redis4Instrumentation(this._config.instrumentationOptions.redis4));
114
104
  }
115
- this._instrumentations.forEach((instrumentation) => {
116
- instrumentation.setTracerProvider(this._tracerProvider);
117
- instrumentation.setMeterProvider(metrics.getMeterProvider());
118
- if (instrumentation.getConfig().enabled) {
119
- instrumentation.enable();
120
- }
121
- });
122
105
  }
123
106
  }
124
107
  //# sourceMappingURL=handler.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"handler.js","sourceRoot":"","sources":["../../../src/traces/handler.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,6BAA6B,EAAE,MAAM,gDAAgD,CAAC;AAC/F,OAAO,EAAE,yBAAyB,EAAE,MAAM,uCAAuC,CAAC;AAClF,OAAO,EAAE,kBAAkB,EAAoB,MAAM,+BAA+B,CAAC;AACrF,OAAO,EAAE,kBAAkB,EAAgB,MAAM,+BAA+B,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3D,IAAI,CAAC,iBAAiB,CAAC,IAAI,CACzB,IAAI,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,UAAU,CAAC,CACtE,CAAC;SACH;QACD,IAAI,MAAA,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,KAAK,0CAAE,OAAO,EAAE;YACtD,IAAI,CAAC,iBAAiB,CAAC,IAAI,CACzB,IAAI,oBAAoB,CAAC,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,KAAK,CAAC,CACpE,CAAC;SACH;QACD,IAAI,MAAA,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,MAAM,0CAAE,OAAO,EAAE;YACvD,IAAI,CAAC,iBAAiB,CAAC,IAAI,CACzB,IAAI,qBAAqB,CAAC,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,MAAM,CAAC,CACtE,CAAC;SACH;QACD,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC,eAAe,EAAE,EAAE;YACjD,eAAe,CAAC,iBAAiB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;YACxD,eAAe,CAAC,gBAAgB,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC;YAC7D,IAAI,eAAe,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE;gBACvC,eAAe,CAAC,MAAM,EAAE,CAAC;aAC1B;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { RequestOptions } from \"http\";\nimport { createAzureSdkInstrumentation } from \"@azure/opentelemetry-instrumentation-azure-sdk\";\nimport { AzureMonitorTraceExporter } from \"@azure/monitor-opentelemetry-exporter\";\nimport { NodeTracerProvider, NodeTracerConfig } from \"@opentelemetry/sdk-trace-node\";\nimport { BatchSpanProcessor, BufferConfig } from \"@opentelemetry/sdk-trace-base\";\nimport {\n HttpInstrumentation,\n HttpInstrumentationConfig,\n IgnoreOutgoingRequestFunction,\n} from \"@opentelemetry/instrumentation-http\";\nimport { MongoDBInstrumentation } from \"@opentelemetry/instrumentation-mongodb\";\nimport { MySQLInstrumentation } from \"@opentelemetry/instrumentation-mysql\";\nimport { PgInstrumentation } from \"@opentelemetry/instrumentation-pg\";\nimport { RedisInstrumentation } from \"@opentelemetry/instrumentation-redis\";\nimport { RedisInstrumentation as Redis4Instrumentation } from \"@opentelemetry/instrumentation-redis-4\";\n\nimport { InternalConfig } from \"../shared/config\";\nimport { MetricHandler } from \"../metrics/handler\";\nimport { ignoreOutgoingRequestHook } from \"../utils/common\";\nimport { AzureMonitorSpanProcessor } from \"./spanProcessor\";\nimport { AzureFunctionsHook } from \"./azureFnHook\";\nimport { metrics } from \"@opentelemetry/api\";\nimport { Instrumentation } from \"@opentelemetry/instrumentation\";\nimport { ApplicationInsightsSampler } from \"./sampler\";\n\n/**\n * Azure Monitor OpenTelemetry Trace Handler\n */\nexport class TraceHandler {\n private _spanProcessor: BatchSpanProcessor;\n private _tracerProvider: NodeTracerProvider;\n private _azureExporter: AzureMonitorTraceExporter;\n private _instrumentations: Instrumentation[];\n private _config: InternalConfig;\n private _metricHandler: MetricHandler;\n private _azureFunctionsHook: AzureFunctionsHook;\n\n /**\n * Initializes a new instance of the TraceHandler class.\n * @param _config - Configuration.\n * @param _metricHandler - MetricHandler.\n */\n constructor(config: InternalConfig, metricHandler: MetricHandler) {\n this._config = config;\n this._metricHandler = metricHandler;\n this._instrumentations = [];\n const aiSampler = new ApplicationInsightsSampler(this._config.samplingRatio);\n const tracerConfig: NodeTracerConfig = {\n sampler: aiSampler,\n resource: this._config.resource,\n forceFlushTimeoutMillis: 30000,\n };\n this._tracerProvider = new NodeTracerProvider(tracerConfig);\n this._azureExporter = new AzureMonitorTraceExporter(this._config.azureMonitorExporterOptions);\n const bufferConfig: BufferConfig = {\n maxExportBatchSize: 512,\n scheduledDelayMillis: 5000,\n exportTimeoutMillis: 30000,\n maxQueueSize: 2048,\n };\n this._spanProcessor = new BatchSpanProcessor(this._azureExporter, bufferConfig);\n this._tracerProvider.addSpanProcessor(this._spanProcessor);\n this._tracerProvider.register();\n const azureSpanProcessor = new AzureMonitorSpanProcessor(this._metricHandler);\n this._tracerProvider.addSpanProcessor(azureSpanProcessor);\n this._azureFunctionsHook = new AzureFunctionsHook();\n this._initializeInstrumentations();\n }\n\n /**\n * Shutdown handler, all Tracer providers will return no-op Tracers\n */\n public async shutdown(): Promise<void> {\n await this._tracerProvider.shutdown();\n this._azureFunctionsHook.shutdown();\n }\n\n /**\n * Force flush Tracer Provider\n */\n public async flush(): Promise<void> {\n return this._tracerProvider.forceFlush();\n }\n\n /**\n * Disable all OpenTelemetry Instrumentations\n */\n public disableInstrumentations() {\n this._instrumentations.forEach((instrumentation) => {\n instrumentation.disable();\n });\n }\n\n /**\n * Start auto collection of telemetry\n */\n private _initializeInstrumentations() {\n if (this._config.instrumentationOptions.http?.enabled) {\n const httpinstrumentationOptions = this._config.instrumentationOptions\n .http as HttpInstrumentationConfig;\n const providedIgnoreOutgoingRequestHook =\n httpinstrumentationOptions.ignoreOutgoingRequestHook;\n const mergedIgnoreOutgoingRequestHook: IgnoreOutgoingRequestFunction = (\n request: RequestOptions\n ) => {\n const result = ignoreOutgoingRequestHook(request);\n if (!result) {\n // Not internal call\n if (providedIgnoreOutgoingRequestHook) {\n // Provided hook in config\n return providedIgnoreOutgoingRequestHook(request);\n }\n }\n return result;\n };\n httpinstrumentationOptions.ignoreOutgoingRequestHook = mergedIgnoreOutgoingRequestHook;\n this._instrumentations.push(\n new HttpInstrumentation(this._config.instrumentationOptions.http)\n );\n }\n if (this._config.instrumentationOptions.azureSdk?.enabled) {\n this._instrumentations.push(\n createAzureSdkInstrumentation(this._config.instrumentationOptions.azureSdk)\n );\n }\n if (this._config.instrumentationOptions.mongoDb?.enabled) {\n this._instrumentations.push(\n new MongoDBInstrumentation(this._config.instrumentationOptions.mongoDb)\n );\n }\n if (this._config.instrumentationOptions.mySql?.enabled) {\n this._instrumentations.push(\n new MySQLInstrumentation(this._config.instrumentationOptions.mySql)\n );\n }\n if (this._config.instrumentationOptions.postgreSql?.enabled) {\n this._instrumentations.push(\n new PgInstrumentation(this._config.instrumentationOptions.postgreSql)\n );\n }\n if (this._config.instrumentationOptions.redis?.enabled) {\n this._instrumentations.push(\n new RedisInstrumentation(this._config.instrumentationOptions.redis)\n );\n }\n if (this._config.instrumentationOptions.redis4?.enabled) {\n this._instrumentations.push(\n new Redis4Instrumentation(this._config.instrumentationOptions.redis4)\n );\n }\n this._instrumentations.forEach((instrumentation) => {\n instrumentation.setTracerProvider(this._tracerProvider);\n instrumentation.setMeterProvider(metrics.getMeterProvider());\n if (instrumentation.getConfig().enabled) {\n instrumentation.enable();\n }\n });\n }\n}\n"]}
1
+ {"version":3,"file":"handler.js","sourceRoot":"","sources":["../../../src/traces/handler.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,6BAA6B,EAAE,MAAM,gDAAgD,CAAC;AAC/F,OAAO,EAAE,yBAAyB,EAAE,MAAM,uCAAuC,CAAC;AAElF,OAAO,EAAE,kBAAkB,EAAgB,MAAM,+BAA+B,CAAC;AACjF,OAAO,EACL,mBAAmB,GAGpB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAC5E,OAAO,EAAE,oBAAoB,IAAI,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAIvG,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,C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AC,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,OAAO,CAAC,CACxE,CAAC;SACH;QACD,IAAI,MAAA,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,KAAK,0CAAE,OAAO,EAAE;YACtD,IAAI,CAAC,iBAAiB,CAAC,IAAI,CACzB,IAAI,oBAAoB,CAAC,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,KAAK,CAAC,CACpE,CAAC;SACH;QACD,IAAI,MAAA,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,UAAU,0CAAE,OAAO,EAAE;YAC3D,IAAI,CAAC,iBAAiB,CAAC,IAAI,CACzB,IAAI,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,UAAU,CAAC,CACtE,CAAC;SACH;QACD,IAAI,MAAA,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,KAAK,0CAAE,OAAO,EAAE;YACtD,IAAI,CAAC,iBAAiB,CAAC,IAAI,CACzB,IAAI,oBAAoB,CAAC,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,KAAK,CAAC,CACpE,CAAC;SACH;QACD,IAAI,MAAA,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,MAAM,0CAAE,OAAO,EAAE;YACvD,IAAI,CAAC,iBAAiB,CAAC,IAAI,CACzB,IAAI,qBAAqB,CAAC,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,MAAM,CAAC,CACtE,CAAC;SACH;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { RequestOptions } from \"http\";\nimport { createAzureSdkInstrumentation } from \"@azure/opentelemetry-instrumentation-azure-sdk\";\nimport { AzureMonitorTraceExporter } from \"@azure/monitor-opentelemetry-exporter\";\nimport { NodeTracerProvider } from \"@opentelemetry/sdk-trace-node\";\nimport { BatchSpanProcessor, BufferConfig } from \"@opentelemetry/sdk-trace-base\";\nimport {\n HttpInstrumentation,\n HttpInstrumentationConfig,\n IgnoreOutgoingRequestFunction,\n} from \"@opentelemetry/instrumentation-http\";\nimport { MongoDBInstrumentation } from \"@opentelemetry/instrumentation-mongodb\";\nimport { MySQLInstrumentation } from \"@opentelemetry/instrumentation-mysql\";\nimport { PgInstrumentation } from \"@opentelemetry/instrumentation-pg\";\nimport { RedisInstrumentation } from \"@opentelemetry/instrumentation-redis\";\nimport { RedisInstrumentation as Redis4Instrumentation } from \"@opentelemetry/instrumentation-redis-4\";\n\nimport { InternalConfig } from \"../shared/config\";\nimport { MetricHandler } from \"../metrics/handler\";\nimport { ignoreOutgoingRequestHook } from \"../utils/common\";\nimport { AzureMonitorSpanProcessor } from \"./spanProcessor\";\nimport { AzureFunctionsHook } from \"./azureFnHook\";\nimport { Instrumentation } from \"@opentelemetry/instrumentation\";\nimport { ApplicationInsightsSampler } from \"./sampler\";\nimport { ProxyTracerProvider, trace } from \"@opentelemetry/api\";\n\n/**\n * Azure Monitor OpenTelemetry Trace Handler\n */\nexport class TraceHandler {\n private _spanProcessor: BatchSpanProcessor;\n private _azureExporter: AzureMonitorTraceExporter;\n private _instrumentations: Instrumentation[];\n private _config: InternalConfig;\n private _metricHandler: MetricHandler;\n private _azureFunctionsHook: AzureFunctionsHook;\n private _aiSampler: ApplicationInsightsSampler;\n\n /**\n * Initializes a new instance of the TraceHandler class.\n * @param _config - Configuration.\n * @param _metricHandler - MetricHandler.\n */\n constructor(config: InternalConfig, metricHandler: MetricHandler) {\n this._config = config;\n this._metricHandler = metricHandler;\n this._instrumentations = [];\n this._aiSampler = new ApplicationInsightsSampler(this._config.samplingRatio);\n this._azureExporter = new AzureMonitorTraceExporter(this._config.azureMonitorExporterOptions);\n const bufferConfig: BufferConfig = {\n maxExportBatchSize: 512,\n scheduledDelayMillis: 5000,\n exportTimeoutMillis: 30000,\n maxQueueSize: 2048,\n };\n this._spanProcessor = new BatchSpanProcessor(this._azureExporter, bufferConfig);\n this._azureFunctionsHook = new AzureFunctionsHook();\n this._initializeInstrumentations();\n }\n\n public start(): void {\n try {\n const azureSpanProcessor = new AzureMonitorSpanProcessor(this._metricHandler);\n (\n (trace.getTracerProvider() as ProxyTracerProvider).getDelegate() as NodeTracerProvider\n ).addSpanProcessor(azureSpanProcessor);\n } catch (error) {}\n }\n\n public getSampler(): ApplicationInsightsSampler {\n return this._aiSampler;\n }\n\n public getSpanProcessor(): BatchSpanProcessor {\n return this._spanProcessor;\n }\n\n public getInstrumentations(): Instrumentation[] {\n return this._instrumentations;\n }\n\n /**\n * Shutdown handler\n */\n public async shutdown(): Promise<void> {\n this._azureFunctionsHook.shutdown();\n }\n\n /**\n * Start auto collection of telemetry\n */\n private _initializeInstrumentations() {\n if (this._config.instrumentationOptions.http?.enabled) {\n const httpinstrumentationOptions = this._config.instrumentationOptions\n .http as HttpInstrumentationConfig;\n const providedIgnoreOutgoingRequestHook =\n httpinstrumentationOptions.ignoreOutgoingRequestHook;\n const mergedIgnoreOutgoingRequestHook: IgnoreOutgoingRequestFunction = (\n request: RequestOptions\n ) => {\n const result = ignoreOutgoingRequestHook(request);\n if (!result) {\n // Not internal call\n if (providedIgnoreOutgoingRequestHook) {\n // Provided hook in config\n return providedIgnoreOutgoingRequestHook(request);\n }\n }\n return result;\n };\n httpinstrumentationOptions.ignoreOutgoingRequestHook = mergedIgnoreOutgoingRequestHook;\n this._instrumentations.push(\n new HttpInstrumentation(this._config.instrumentationOptions.http)\n );\n }\n if (this._config.instrumentationOptions.azureSdk?.enabled) {\n this._instrumentations.push(\n createAzureSdkInstrumentation(this._config.instrumentationOptions.azureSdk)\n );\n }\n if (this._config.instrumentationOptions.mongoDb?.enabled) {\n this._instrumentations.push(\n new MongoDBInstrumentation(this._config.instrumentationOptions.mongoDb)\n );\n }\n if (this._config.instrumentationOptions.mySql?.enabled) {\n this._instrumentations.push(\n new MySQLInstrumentation(this._config.instrumentationOptions.mySql)\n );\n }\n if (this._config.instrumentationOptions.postgreSql?.enabled) {\n this._instrumentations.push(\n new PgInstrumentation(this._config.instrumentationOptions.postgreSql)\n );\n }\n if (this._config.instrumentationOptions.redis?.enabled) {\n this._instrumentations.push(\n new RedisInstrumentation(this._config.instrumentationOptions.redis)\n );\n }\n if (this._config.instrumentationOptions.redis4?.enabled) {\n this._instrumentations.push(\n new Redis4Instrumentation(this._config.instrumentationOptions.redis4)\n );\n }\n }\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT license.
3
- export const AZURE_MONITOR_OPENTELEMETRY_VERSION = "1.1.0";
3
+ export const AZURE_MONITOR_OPENTELEMETRY_VERSION = "1.1.1";
4
4
  export const AZURE_MONITOR_STATSBEAT_FEATURES = "AZURE_MONITOR_STATSBEAT_FEATURES";
5
5
  export var StatsbeatFeature;
6
6
  (function (StatsbeatFeature) {
@@ -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,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"]}
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.1\";\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.1.0",
5
+ "version": "1.1.1",
6
6
  "description": "Azure Monitor OpenTelemetry (Node.js)",
7
7
  "main": "dist/index.js",
8
8
  "module": "dist-esm/src/index.js",
@@ -38,7 +38,7 @@
38
38
  "pack": "npm pack 2>&1"
39
39
  },
40
40
  "engines": {
41
- "node": ">=16.0.0"
41
+ "node": ">=18.0.0"
42
42
  },
43
43
  "files": [
44
44
  "dist-esm/src/",
@@ -70,41 +70,42 @@
70
70
  "@azure/eslint-plugin-azure-sdk": "^3.0.0",
71
71
  "@microsoft/api-extractor": "^7.31.1",
72
72
  "@types/mocha": "^10.0.0",
73
- "@types/node": "^16.0.0",
73
+ "@types/node": "^18.0.0",
74
74
  "@types/sinon": "^10.0.0",
75
75
  "dotenv": "^16.0.0",
76
76
  "eslint": "^8.0.0",
77
77
  "eslint-plugin-node": "^11.1.0",
78
78
  "mocha": "^10.0.0",
79
79
  "nock": "^12.0.3",
80
- "nyc": "^15.0.0",
80
+ "c8": "^8.0.0",
81
81
  "prettier": "^2.5.1",
82
82
  "rimraf": "^3.0.0",
83
- "sinon": "^15.0.0",
83
+ "sinon": "^17.0.0",
84
84
  "ts-node": "^10.0.0",
85
- "typescript": "~5.0.0",
85
+ "typescript": "~5.2.0",
86
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.17",
90
+ "@azure/monitor-opentelemetry-exporter": "1.0.0-beta.18",
91
91
  "@azure/opentelemetry-instrumentation-azure-sdk": "^1.0.0-beta.5",
92
- "@opentelemetry/api": "^1.6.0",
93
- "@opentelemetry/api-logs": "^0.43.0",
94
- "@opentelemetry/core": "^1.17.0",
95
- "@opentelemetry/instrumentation": "^0.43.0",
96
- "@opentelemetry/instrumentation-http": "^0.43.0",
97
- "@opentelemetry/instrumentation-mongodb": "^0.37.0",
98
- "@opentelemetry/instrumentation-mysql": "^0.34.1",
99
- "@opentelemetry/instrumentation-pg": "^0.36.1",
100
- "@opentelemetry/instrumentation-redis": "^0.35.1",
101
- "@opentelemetry/instrumentation-redis-4": "^0.35.1",
102
- "@opentelemetry/resources": "^1.17.0",
103
- "@opentelemetry/sdk-logs": "^0.43.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",
92
+ "@opentelemetry/api": "^1.7.0",
93
+ "@opentelemetry/api-logs": "^0.45.0",
94
+ "@opentelemetry/core": "^1.18.0",
95
+ "@opentelemetry/instrumentation": "^0.45.0",
96
+ "@opentelemetry/instrumentation-http": "^0.45.0",
97
+ "@opentelemetry/instrumentation-mongodb": "^0.37.1",
98
+ "@opentelemetry/instrumentation-mysql": "^0.34.2",
99
+ "@opentelemetry/instrumentation-pg": "^0.36.2",
100
+ "@opentelemetry/instrumentation-redis": "^0.35.2",
101
+ "@opentelemetry/instrumentation-redis-4": "^0.35.2",
102
+ "@opentelemetry/resources": "^1.18.0",
103
+ "@opentelemetry/sdk-logs": "^0.45.0",
104
+ "@opentelemetry/sdk-metrics": "^1.18.0",
105
+ "@opentelemetry/sdk-node": "^0.45.0",
106
+ "@opentelemetry/sdk-trace-base": "^1.18.0",
107
+ "@opentelemetry/sdk-trace-node": "^1.18.0",
108
+ "@opentelemetry/semantic-conventions": "^1.18.0",
108
109
  "tslib": "^2.2.0"
109
110
  },
110
111
  "sideEffects": false,