@azure/monitor-opentelemetry 1.0.0-beta.3 → 1.0.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/dist/index.js CHANGED
@@ -374,7 +374,7 @@ class JsonConfig {
374
374
  }
375
375
  try {
376
376
  const jsonConfig = JSON.parse(jsonString);
377
- this.azureMonitorExporterConfig = jsonConfig.azureMonitorExporterConfig;
377
+ this.azureMonitorExporterOptions = jsonConfig.azureMonitorExporterOptions;
378
378
  this.samplingRatio = jsonConfig.samplingRatio;
379
379
  this.instrumentationOptions = jsonConfig.instrumentationOptions;
380
380
  }
@@ -403,7 +403,7 @@ class InternalConfig {
403
403
  */
404
404
  constructor(options) {
405
405
  // Default values
406
- this.azureMonitorExporterConfig = {};
406
+ this.azureMonitorExporterOptions = {};
407
407
  this.samplingRatio = 1;
408
408
  this.instrumentationOptions = {
409
409
  http: { enabled: true },
@@ -421,7 +421,7 @@ class InternalConfig {
421
421
  // This will take precedence over other settings
422
422
  if (options) {
423
423
  // Merge default with provided options
424
- this.azureMonitorExporterConfig = Object.assign(this.azureMonitorExporterConfig, options.azureMonitorExporterConfig);
424
+ this.azureMonitorExporterOptions = Object.assign(this.azureMonitorExporterOptions, options.azureMonitorExporterOptions);
425
425
  this.instrumentationOptions = Object.assign(this.instrumentationOptions, options.instrumentationOptions);
426
426
  this.resource = Object.assign(this.resource, options.resource);
427
427
  this.samplingRatio = options.samplingRatio || this.samplingRatio;
@@ -432,7 +432,7 @@ class InternalConfig {
432
432
  const jsonConfig = JsonConfig.getInstance();
433
433
  this.samplingRatio =
434
434
  jsonConfig.samplingRatio !== undefined ? jsonConfig.samplingRatio : this.samplingRatio;
435
- this.azureMonitorExporterConfig = Object.assign(this.azureMonitorExporterConfig, jsonConfig.azureMonitorExporterConfig);
435
+ this.azureMonitorExporterOptions = Object.assign(this.azureMonitorExporterOptions, jsonConfig.azureMonitorExporterOptions);
436
436
  this.instrumentationOptions = Object.assign(this.instrumentationOptions, jsonConfig.instrumentationOptions);
437
437
  }
438
438
  catch (error) {
@@ -469,7 +469,7 @@ class StandardMetrics {
469
469
  resource: this._config.resource,
470
470
  };
471
471
  this._meterProvider = new sdkMetrics.MeterProvider(meterProviderConfig);
472
- this._azureExporter = new monitorOpentelemetryExporter.AzureMonitorMetricExporter(this._config.azureMonitorExporterConfig);
472
+ this._azureExporter = new monitorOpentelemetryExporter.AzureMonitorMetricExporter(this._config.azureMonitorExporterOptions);
473
473
  const metricReaderOptions = {
474
474
  exporter: this._azureExporter,
475
475
  exportIntervalMillis: (options === null || options === void 0 ? void 0 : options.collectionInterval) || this._collectionInterval,
@@ -707,7 +707,7 @@ class MetricHandler {
707
707
  resource: this._config.resource,
708
708
  };
709
709
  this._meterProvider = new sdkMetrics.MeterProvider(meterProviderConfig);
710
- this._azureExporter = new monitorOpentelemetryExporter.AzureMonitorMetricExporter(this._config.azureMonitorExporterConfig);
710
+ this._azureExporter = new monitorOpentelemetryExporter.AzureMonitorMetricExporter(this._config.azureMonitorExporterOptions);
711
711
  let metricReaderOptions = {
712
712
  exporter: this._azureExporter,
713
713
  exportIntervalMillis: (options === null || options === void 0 ? void 0 : options.collectionInterval) || this._collectionInterval,
@@ -776,15 +776,7 @@ class AzureFunctionsHook {
776
776
  try {
777
777
  // TODO: Add types files when publicly available
778
778
  this._functionsCoreModule = require("@azure/functions-core");
779
- // Only v3 of Azure Functions library is supported right now. See matrix of versions here:
780
- // https://github.com/Azure/azure-functions-nodejs-library
781
- const funcProgModel = this._functionsCoreModule.getProgrammingModel();
782
- if (funcProgModel.name === "@azure/functions" && funcProgModel.version.startsWith("3.")) {
783
- this._addPreInvocationHook();
784
- }
785
- else {
786
- Logger.getInstance().debug(`AzureFunctionsHook does not support model "${funcProgModel.name}" version "${funcProgModel.version}"`);
787
- }
779
+ this._addPreInvocationHook();
788
780
  }
789
781
  catch (error) {
790
782
  Logger.getInstance().debug("@azure/functions-core failed to load, not running in Azure Functions");
@@ -818,6 +810,89 @@ class AzureFunctionsHook {
818
810
  }
819
811
  }
820
812
 
813
+ /**
814
+ * ApplicationInsightsSampler is responsible for the following:
815
+ * Implements same trace id hashing algorithm so that traces are sampled the same across multiple nodes
816
+ * Adds item count to span attribute if span is sampled (needed for ingestion service)
817
+ * @param samplingRatio - 0 to 1 value.
818
+ */
819
+ class ApplicationInsightsSampler {
820
+ /**
821
+ * Initializes a new instance of the ApplicationInsightsSampler class.
822
+ * @param samplingRatio Value in the range [0,1], 1 meaning all data will sampled and 0 all Tracing data will be sampled out.
823
+ */
824
+ constructor(samplingRatio = 1) {
825
+ this._samplingRatio = samplingRatio;
826
+ if (this._samplingRatio > 1) {
827
+ throw new Error("Invalid sampling rate, sampling rate must be a value in the range [0,1].");
828
+ }
829
+ this._sampleRate = Math.round(this._samplingRatio * 100);
830
+ }
831
+ /**
832
+ * Checks whether span needs to be created and tracked.
833
+ *
834
+ * @param context Parent Context which may contain a span.
835
+ * @param traceId of the span to be created. It can be different from the
836
+ * traceId in the {@link SpanContext}. Typically in situations when the
837
+ * span to be created starts a new trace.
838
+ * @param spanName of the span to be created.
839
+ * @param spanKind of the span to be created.
840
+ * @param attributes Initial set of SpanAttributes for the Span being constructed.
841
+ * @param links Collection of links that will be associated with the Span to
842
+ * be created. Typically useful for batch operations.
843
+ * @returns a {@link SamplingResult}.
844
+ */
845
+ shouldSample(
846
+ // @ts-ignore
847
+ context, traceId,
848
+ // @ts-ignore
849
+ spanName,
850
+ // @ts-ignore
851
+ spanKind, attributes,
852
+ // @ts-ignore
853
+ links) {
854
+ let isSampledIn = false;
855
+ if (this._sampleRate == 100) {
856
+ isSampledIn = true;
857
+ }
858
+ else if (this._sampleRate == 0) {
859
+ isSampledIn = false;
860
+ }
861
+ else {
862
+ isSampledIn = this._getSamplingHashCode(traceId) < this._sampleRate;
863
+ }
864
+ // Add sample rate as span attribute
865
+ attributes = attributes || {};
866
+ attributes["_MS.sampleRate"] = this._sampleRate;
867
+ return isSampledIn
868
+ ? { decision: sdkTraceBase.SamplingDecision.RECORD_AND_SAMPLED, attributes: attributes }
869
+ : { decision: sdkTraceBase.SamplingDecision.RECORD, attributes: attributes };
870
+ }
871
+ /**
872
+ * Return Sampler description
873
+ */
874
+ toString() {
875
+ return `ApplicationInsightsSampler{${this._samplingRatio}}`;
876
+ }
877
+ _getSamplingHashCode(input) {
878
+ var csharpMin = -2147483648;
879
+ var csharpMax = 2147483647;
880
+ var hash = 5381;
881
+ if (!input) {
882
+ return 0;
883
+ }
884
+ while (input.length < 8) {
885
+ input = input + input;
886
+ }
887
+ for (var i = 0; i < input.length; i++) {
888
+ // JS doesn't respond to integer overflow by wrapping around. Simulate it with bitwise operators ( | 0)
889
+ hash = ((((hash << 5) + hash) | 0) + input.charCodeAt(i)) | 0;
890
+ }
891
+ hash = hash <= csharpMin ? csharpMax : Math.abs(hash);
892
+ return (hash / csharpMax) * 100;
893
+ }
894
+ }
895
+
821
896
  // Copyright (c) Microsoft Corporation.
822
897
  /**
823
898
  * Azure Monitor OpenTelemetry Trace Handler
@@ -832,14 +907,14 @@ class TraceHandler {
832
907
  this._config = config;
833
908
  this._metricHandler = metricHandler;
834
909
  this._instrumentations = [];
835
- const aiSampler = new monitorOpentelemetryExporter.ApplicationInsightsSampler(this._config.samplingRatio);
910
+ const aiSampler = new ApplicationInsightsSampler(this._config.samplingRatio);
836
911
  const tracerConfig = {
837
912
  sampler: aiSampler,
838
913
  resource: this._config.resource,
839
914
  forceFlushTimeoutMillis: 30000,
840
915
  };
841
916
  this._tracerProvider = new sdkTraceNode.NodeTracerProvider(tracerConfig);
842
- this._azureExporter = new monitorOpentelemetryExporter.AzureMonitorTraceExporter(this._config.azureMonitorExporterConfig);
917
+ this._azureExporter = new monitorOpentelemetryExporter.AzureMonitorTraceExporter(this._config.azureMonitorExporterOptions);
843
918
  const bufferConfig = {
844
919
  maxExportBatchSize: 512,
845
920
  scheduledDelayMillis: 5000,
@@ -964,7 +1039,7 @@ class LogHandler {
964
1039
  resource: this._config.resource,
965
1040
  };
966
1041
  this._loggerProvider = new sdkLogs.LoggerProvider(loggerProviderConfig);
967
- this._azureExporter = new monitorOpentelemetryExporter.AzureMonitorLogExporter(this._config.azureMonitorExporterConfig);
1042
+ this._azureExporter = new monitorOpentelemetryExporter.AzureMonitorLogExporter(this._config.azureMonitorExporterOptions);
968
1043
  // Log Processor could be configured through env variables
969
1044
  // https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/#batch-logrecord-processor
970
1045
  this._logRecordProcessor = new sdkLogs.BatchLogRecordProcessor(this._azureExporter);
@@ -989,6 +1064,7 @@ class LogHandler {
989
1064
 
990
1065
  // Copyright (c) Microsoft Corporation.
991
1066
  // Licensed under the MIT license.
1067
+ const AZURE_MONITOR_OPENTELEMETRY_VERSION = "1.0.0";
992
1068
  const AZURE_MONITOR_STATSBEAT_FEATURES = "AZURE_MONITOR_STATSBEAT_FEATURES";
993
1069
  var StatsbeatFeature;
994
1070
  (function (StatsbeatFeature) {
@@ -1007,6 +1083,7 @@ var StatsbeatInstrumentation;
1007
1083
  })(StatsbeatInstrumentation || (StatsbeatInstrumentation = {}));
1008
1084
 
1009
1085
  // Copyright (c) Microsoft Corporation.
1086
+ process.env["AZURE_MONITOR_DISTRO_VERSION"] = AZURE_MONITOR_OPENTELEMETRY_VERSION;
1010
1087
  let metricHandler;
1011
1088
  let traceHandler;
1012
1089
  let logHandler;
@@ -7,7 +7,8 @@ import { MetricHandler } from "./metrics";
7
7
  import { TraceHandler } from "./traces/handler";
8
8
  import { Logger as InternalLogger } from "./shared/logging";
9
9
  import { LogHandler } from "./logs";
10
- import { AZURE_MONITOR_STATSBEAT_FEATURES, StatsbeatFeature, StatsbeatInstrumentation, } from "./types";
10
+ import { AZURE_MONITOR_OPENTELEMETRY_VERSION, AZURE_MONITOR_STATSBEAT_FEATURES, StatsbeatFeature, StatsbeatInstrumentation, } from "./types";
11
+ process.env["AZURE_MONITOR_DISTRO_VERSION"] = AZURE_MONITOR_OPENTELEMETRY_VERSION;
11
12
  let metricHandler;
12
13
  let traceHandler;
13
14
  let logHandler;
@@ -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,gCAAgC,EAChC,gBAAgB,EAChB,wBAAwB,GACzB,MAAM,SAAS,CAAC;AAIjB,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,EAAE,aAAa,CAAC,CAAC;AACrD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB;IAClC,a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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_STATSBEAT_FEATURES,\n StatsbeatFeature,\n StatsbeatInstrumentation,\n} from \"./types\";\n\nexport { AzureMonitorOpenTelemetryOptions, InstrumentationOptions } from \"./shared/types\";\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;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,IA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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 = 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"]}
@@ -20,7 +20,7 @@ export class LogHandler {
20
20
  resource: this._config.resource,
21
21
  };
22
22
  this._loggerProvider = new LoggerProvider(loggerProviderConfig);
23
- this._azureExporter = new AzureMonitorLogExporter(this._config.azureMonitorExporterConfig);
23
+ this._azureExporter = new AzureMonitorLogExporter(this._config.azureMonitorExporterOptions);
24
24
  // Log Processor could be configured through env variables
25
25
  // https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/#batch-logrecord-processor
26
26
  this._logRecordProcessor = new BatchLogRecordProcessor(this._azureExporter);
@@ -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;AA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\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.azureMonitorExporterConfig);\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":"","s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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"]}
@@ -24,7 +24,7 @@ export class MetricHandler {
24
24
  resource: this._config.resource,
25
25
  };
26
26
  this._meterProvider = new MeterProvider(meterProviderConfig);
27
- this._azureExporter = new AzureMonitorMetricExporter(this._config.azureMonitorExporterConfig);
27
+ this._azureExporter = new AzureMonitorMetricExporter(this._config.azureMonitorExporterOptions);
28
28
  let metricReaderOptions = {
29
29
  exporter: this._azureExporter,
30
30
  exportIntervalMillis: (options === null || options === void 0 ? void 0 : options.collectionInterval) || this._collectionInterval,
@@ -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;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vC,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} 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.azureMonitorExporterConfig);\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,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,mBAAmB,CAAC,CAAC;QAC7D,IAAI,CAAC,cAAc,GAAG,IAAI,0BAA0B,CAAC,IAAI,CAAC,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} 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"]}
@@ -21,7 +21,7 @@ export class StandardMetrics {
21
21
  resource: this._config.resource,
22
22
  };
23
23
  this._meterProvider = new MeterProvider(meterProviderConfig);
24
- this._azureExporter = new AzureMonitorMetricExporter(this._config.azureMonitorExporterConfig);
24
+ this._azureExporter = new AzureMonitorMetricExporter(this._config.azureMonitorExporterOptions);
25
25
  const metricReaderOptions = {
26
26
  exporter: this._azureExporter,
27
27
  exportIntervalMillis: (options === null || options === void 0 ? void 0 : options.collectionInterval) || this._collectionInterval,
@@ -1 +1 @@
1
- {"version":3,"file":"standardMetrics.js","sourceRoot":"","sources":["../../../src/metrics/standardMetrics.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EACL,aAAa,EAEb,6BAA6B,GAE9B,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,0BAA0B,EAAE,MAAM,uCAAuC,CAAC;AACnF,OAAO,EAAyC,QAAQ,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEhG,OAAO,EACL,kBAAkB,EAClB,0BAA0B,GAC3B,MAAM,qCAAqC,CAAC;AAS7C;;;GAGG;AACH,MAAM,OAAO,eAAe;IAY1B;;;;OAIG;IACH,YAAY,MAAsB,EAAE,OAAwC;QAfpE,wBAAmB,GAAG,KAAK,CAAC,CAAC,aAAa;QAgBhD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,MAAM,mBAAmB,GAAyB;YAChD,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ;SAChC,CAAC;QACF,IAAI,CAAC,cAAc,GAAG,IAAI,aAAa,CAAC,mBAAmB,CAAC,CAAC;QAC7D,IAAI,CAAC,cAAc,GAAG,IAAI,0BAA0B,CAAC,IAAI,CAAC,O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AS,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;QACtD,sCAAsC;QACtC,IAAI,QAAQ,IAAI,QAAQ,KAAK,eAAe,EAAE;YAC5C,OAAO,IAAI,CAAC;SACb;aAAM,IACL,SAAS,CAAC,UAAU,CAAC,kBAAkB,CAAC,iBAAiB,CAAC;YAC1D,SAAS,CAAC,UAAU,CAAC,kBAAkB,CAAC,cAAc,CAAC,EACvD;YACA,OAAO,IAAI,CAAC;SACb;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAEO,iBAAiB,CAAC,SAAoB;QAC5C,MAAM,QAAQ,GAAG,SAAS,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;QACtD,sCAAsC;QACtC,IAAI,QAAQ,IAAI,QAAQ,KAAK,aAAa,EAAE;YAC1C,OAAO,IAAI,CAAC;SACb;aAAM,IACL,CAAC,SAAS,CAAC,UAAU,CAAC,kBAAkB,CAAC,iBAAiB,CAAC;YAC3D,CAAC,SAAS,CAAC,UAAU,CAAC,kBAAkB,CAAC,cAAc,CAAC,EACxD;YACA,OAAO,IAAI,CAAC;SACb;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n MeterProvider,\n MeterProviderOptions,\n PeriodicExportingMetricReader,\n PeriodicExportingMetricReaderOptions,\n} from \"@opentelemetry/sdk-metrics\";\nimport { InternalConfig } from \"../shared/config\";\nimport { AzureMonitorMetricExporter } from \"@azure/monitor-opentelemetry-exporter\";\nimport { Attributes, Counter, Histogram, Meter, SpanKind, ValueType } from \"@opentelemetry/api\";\nimport { ReadableSpan, Span, TimedEvent } from \"@opentelemetry/sdk-trace-base\";\nimport {\n SemanticAttributes,\n SemanticResourceAttributes,\n} from \"@opentelemetry/semantic-conventions\";\nimport {\n MetricDependencyDimensions,\n MetricRequestDimensions,\n StandardMetricBaseDimensions,\n} from \"./types\";\nimport { LogRecord } from \"@opentelemetry/sdk-logs\";\nimport { Resource } from \"@opentelemetry/resources\";\n\n/**\n * Azure Monitor Standard Metrics\n * @internal\n */\nexport class StandardMetrics {\n private _config: InternalConfig;\n private _collectionInterval = 60000; // 60 seconds\n private _meterProvider: MeterProvider;\n private _azureExporter: AzureMonitorMetricExporter;\n private _metricReader: PeriodicExportingMetricReader;\n private _meter: Meter;\n private _incomingRequestDurationHistogram: Histogram;\n private _outgoingRequestDurationHistogram: Histogram;\n private _exceptionsCounter: Counter;\n private _tracesCounter: Counter;\n\n /**\n * Initializes a new instance of the StandardMetrics class.\n * @param config - Distro configuration.\n * @param options - Standard Metrics options.\n */\n constructor(config: InternalConfig, options?: { collectionInterval: number }) {\n this._config = config;\n const meterProviderConfig: MeterProviderOptions = {\n resource: this._config.resource,\n };\n this._meterProvider = new MeterProvider(meterProviderConfig);\n this._azureExporter = new AzureMonitorMetricExporter(this._config.azureMonitorExporterConfig);\n const 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 this._meter = this._meterProvider.getMeter(\"AzureMonitorStandardMetricsMeter\");\n this._incomingRequestDurationHistogram = this._meter.createHistogram(\n \"azureMonitor.http.requestDuration\",\n {\n valueType: ValueType.DOUBLE,\n }\n );\n this._outgoingRequestDurationHistogram = this._meter.createHistogram(\n \"azureMonitor.http.dependencyDuration\",\n {\n valueType: ValueType.DOUBLE,\n }\n );\n\n this._exceptionsCounter = this._meter.createCounter(\"azureMonitor.exceptionCount\", {\n valueType: ValueType.INT,\n });\n this._tracesCounter = this._meter.createCounter(\"azureMonitor.traceCount\", {\n valueType: ValueType.INT,\n });\n }\n\n /**\n * Shutdown Meter Provider it will return no-op Meters after being called.\n */\n public shutdown() {\n this._meterProvider.shutdown();\n }\n\n /**\n * Force flush Meter Provider.\n */\n public async flush(): Promise<void> {\n await this._meterProvider.forceFlush();\n }\n\n /**\n *Get OpenTelemetry MeterProvider\n */\n public getMeterProvider(): MeterProvider {\n return this._meterProvider;\n }\n\n /**\n * Add extra attributes to Span so Ingestion doesn't aggregate the data again\n * @internal\n */\n public markSpanAsProcessed(span: Span): void {\n if (span.kind === SpanKind.CLIENT) {\n span.setAttributes({\n \"_MS.ProcessedByMetricExtractors\": \"(Name:'Dependencies', Ver:'1.1')\",\n });\n } else if (span.kind === SpanKind.SERVER) {\n span.setAttributes({\n \"_MS.ProcessedByMetricExtractors\": \"(Name:'Requests', Ver:'1.1')\",\n });\n }\n }\n\n /**\n * Record Span metrics\n * @internal\n */\n public recordSpan(span: ReadableSpan): void {\n const durationMs = span.duration[0];\n if (span.kind === SpanKind.SERVER) {\n this._incomingRequestDurationHistogram.record(durationMs, this._getRequestDimensions(span));\n } else {\n this._outgoingRequestDurationHistogram.record(\n durationMs,\n this._getDependencyDimensions(span)\n );\n }\n if (span.events) {\n span.events.forEach((event: TimedEvent) => {\n event.attributes = event.attributes || {};\n if (event.name === \"exception\") {\n event.attributes[\"_MS.ProcessedByMetricExtractors\"] = \"(Name:'Exceptions', Ver:'1.1')\";\n this._exceptionsCounter.add(1, this._getExceptionDimensions(span.resource));\n } else {\n event.attributes[\"_MS.ProcessedByMetricExtractors\"] = \"(Name:'Traces', Ver:'1.1')\";\n this._tracesCounter.add(1, this._getTraceDimensions(span.resource));\n }\n });\n }\n }\n\n /**\n * Record LogRecord metrics, add attribute so data is not aggregated again in ingestion\n * @internal\n */\n public recordLog(logRecord: LogRecord): void {\n if (this._isExceptionTelemetry(logRecord)) {\n logRecord.setAttribute(\"_MS.ProcessedByMetricExtractors\", \"(Name:'Exceptions', Ver:'1.1')\");\n this._exceptionsCounter.add(1, this._getExceptionDimensions(logRecord.resource));\n } else if (this._isTraceTelemetry(logRecord)) {\n logRecord.setAttribute(\"_MS.ProcessedByMetricExtractors\", \"(Name:'Traces', Ver:'1.1')\");\n this._tracesCounter.add(1, this._getTraceDimensions(logRecord.resource));\n }\n }\n\n private _getRequestDimensions(span: ReadableSpan): Attributes {\n const dimensions: MetricRequestDimensions = this._getBaseDimensions(span.resource);\n dimensions.metricId = \"requests/duration\";\n const statusCode = String(span.attributes[\"http.status_code\"]);\n dimensions.requestResultCode = statusCode;\n dimensions.requestSuccess = statusCode === \"200\" ? \"True\" : \"False\";\n return dimensions as Attributes;\n }\n\n private _getDependencyDimensions(span: ReadableSpan): Attributes {\n const dimensions: MetricDependencyDimensions = this._getBaseDimensions(span.resource);\n dimensions.metricId = \"dependencies/duration\";\n const statusCode = String(span.attributes[\"http.status_code\"]);\n dimensions.dependencyTarget = this._getDependencyTarget(span.attributes);\n dimensions.dependencyResultCode = statusCode;\n dimensions.dependencyType = \"http\";\n dimensions.dependencySuccess = statusCode === \"200\" ? \"True\" : \"False\";\n return dimensions as Attributes;\n }\n\n private _getExceptionDimensions(resource: Resource): Attributes {\n const dimensions: StandardMetricBaseDimensions = this._getBaseDimensions(resource);\n dimensions.metricId = \"exceptions/count\";\n return dimensions as Attributes;\n }\n\n private _getTraceDimensions(resource: Resource): Attributes {\n const dimensions: StandardMetricBaseDimensions = this._getBaseDimensions(resource);\n dimensions.metricId = \"traces/count\";\n return dimensions as Attributes;\n }\n\n private _getBaseDimensions(resource: Resource): StandardMetricBaseDimensions {\n const dimensions: StandardMetricBaseDimensions = {};\n dimensions.IsAutocollected = \"True\";\n if (resource) {\n const spanResourceAttributes = resource.attributes;\n const serviceName = spanResourceAttributes[SemanticResourceAttributes.SERVICE_NAME];\n const serviceNamespace = spanResourceAttributes[SemanticResourceAttributes.SERVICE_NAMESPACE];\n if (serviceName) {\n if (serviceNamespace) {\n dimensions.cloudRoleName = `${serviceNamespace}.${serviceName}`;\n } else {\n dimensions.cloudRoleName = String(serviceName);\n }\n }\n const serviceInstanceId =\n spanResourceAttributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID];\n dimensions.cloudRoleInstance = String(serviceInstanceId);\n }\n return dimensions;\n }\n\n private _getDependencyTarget(attributes: Attributes): string {\n if (!attributes) {\n return \"\";\n }\n const peerService = attributes[SemanticAttributes.PEER_SERVICE];\n const httpHost = attributes[SemanticAttributes.HTTP_HOST];\n const httpUrl = attributes[SemanticAttributes.HTTP_URL];\n const netPeerName = attributes[SemanticAttributes.NET_PEER_NAME];\n const netPeerIp = attributes[SemanticAttributes.NET_PEER_IP];\n if (peerService) {\n return String(peerService);\n } else if (httpHost) {\n return String(httpHost);\n } else if (httpUrl) {\n return String(httpUrl);\n } else if (netPeerName) {\n return String(netPeerName);\n } else if (netPeerIp) {\n return String(netPeerIp);\n }\n return \"\";\n }\n\n private _isExceptionTelemetry(logRecord: LogRecord) {\n const baseType = logRecord.attributes[\"_MS.baseType\"];\n // If Application Insights Legacy logs\n if (baseType && baseType === \"ExceptionData\") {\n return true;\n } else if (\n logRecord.attributes[SemanticAttributes.EXCEPTION_MESSAGE] ||\n logRecord.attributes[SemanticAttributes.EXCEPTION_TYPE]\n ) {\n return true;\n }\n return false;\n }\n\n private _isTraceTelemetry(logRecord: LogRecord) {\n const baseType = logRecord.attributes[\"_MS.baseType\"];\n // If Application Insights Legacy logs\n if (baseType && baseType === \"MessageData\") {\n return true;\n } else if (\n !logRecord.attributes[SemanticAttributes.EXCEPTION_MESSAGE] &&\n !logRecord.attributes[SemanticAttributes.EXCEPTION_TYPE]\n ) {\n return true;\n }\n return false;\n }\n}\n"]}
1
+ {"version":3,"file":"standardMetrics.js","sourceRoot":"","sources":["../../../src/metrics/standardMetrics.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EACL,aAAa,EAEb,6BAA6B,GAE9B,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,0BAA0B,EAAE,MAAM,uCAAuC,CAAC;AACnF,OAAO,EAAyC,QAAQ,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEhG,OAAO,EACL,kBAAkB,EAClB,0BAA0B,GAC3B,MAAM,qCAAqC,C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,CAAC,CAAC;SAC5B;aAAM,IAAI,QAAQ,EAAE;YACnB,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC;SACzB;aAAM,IAAI,OAAO,EAAE;YAClB,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC;SACxB;aAAM,IAAI,WAAW,EAAE;YACtB,OAAO,MAAM,CAAC,WAAW,CAAC,CAAC;SAC5B;aAAM,IAAI,SAAS,EAAE;YACpB,OAAO,MAAM,CAAC,SAAS,CAAC,CAAC;SAC1B;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;IAEO,qBAAqB,CAAC,SAAoB;QAChD,MAAM,QAAQ,GAAG,SAAS,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;QACtD,sCAAsC;QACtC,IAAI,QAAQ,IAAI,QAAQ,KAAK,eAAe,EAAE;YAC5C,OAAO,IAAI,CAAC;SACb;aAAM,IACL,SAAS,CAAC,UAAU,CAAC,kBAAkB,CAAC,iBAAiB,CAAC;YAC1D,SAAS,CAAC,UAAU,CAAC,kBAAkB,CAAC,cAAc,CAAC,EACvD;YACA,OAAO,IAAI,CAAC;SACb;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAEO,iBAAiB,CAAC,SAAoB;QAC5C,MAAM,QAAQ,GAAG,SAAS,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;QACtD,sCAAsC;QACtC,IAAI,QAAQ,IAAI,QAAQ,KAAK,aAAa,EAAE;YAC1C,OAAO,IAAI,CAAC;SACb;aAAM,IACL,CAAC,SAAS,CAAC,UAAU,CAAC,kBAAkB,CAAC,iBAAiB,CAAC;YAC3D,CAAC,SAAS,CAAC,UAAU,CAAC,kBAAkB,CAAC,cAAc,CAAC,EACxD;YACA,OAAO,IAAI,CAAC;SACb;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n MeterProvider,\n MeterProviderOptions,\n PeriodicExportingMetricReader,\n PeriodicExportingMetricReaderOptions,\n} from \"@opentelemetry/sdk-metrics\";\nimport { InternalConfig } from \"../shared/config\";\nimport { AzureMonitorMetricExporter } from \"@azure/monitor-opentelemetry-exporter\";\nimport { Attributes, Counter, Histogram, Meter, SpanKind, ValueType } from \"@opentelemetry/api\";\nimport { ReadableSpan, Span, TimedEvent } from \"@opentelemetry/sdk-trace-base\";\nimport {\n SemanticAttributes,\n SemanticResourceAttributes,\n} from \"@opentelemetry/semantic-conventions\";\nimport {\n MetricDependencyDimensions,\n MetricRequestDimensions,\n StandardMetricBaseDimensions,\n} from \"./types\";\nimport { LogRecord } from \"@opentelemetry/sdk-logs\";\nimport { Resource } from \"@opentelemetry/resources\";\n\n/**\n * Azure Monitor Standard Metrics\n * @internal\n */\nexport class StandardMetrics {\n private _config: InternalConfig;\n private _collectionInterval = 60000; // 60 seconds\n private _meterProvider: MeterProvider;\n private _azureExporter: AzureMonitorMetricExporter;\n private _metricReader: PeriodicExportingMetricReader;\n private _meter: Meter;\n private _incomingRequestDurationHistogram: Histogram;\n private _outgoingRequestDurationHistogram: Histogram;\n private _exceptionsCounter: Counter;\n private _tracesCounter: Counter;\n\n /**\n * Initializes a new instance of the StandardMetrics class.\n * @param config - Distro configuration.\n * @param options - Standard Metrics options.\n */\n constructor(config: InternalConfig, options?: { collectionInterval: number }) {\n this._config = config;\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 const 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 this._meter = this._meterProvider.getMeter(\"AzureMonitorStandardMetricsMeter\");\n this._incomingRequestDurationHistogram = this._meter.createHistogram(\n \"azureMonitor.http.requestDuration\",\n {\n valueType: ValueType.DOUBLE,\n }\n );\n this._outgoingRequestDurationHistogram = this._meter.createHistogram(\n \"azureMonitor.http.dependencyDuration\",\n {\n valueType: ValueType.DOUBLE,\n }\n );\n\n this._exceptionsCounter = this._meter.createCounter(\"azureMonitor.exceptionCount\", {\n valueType: ValueType.INT,\n });\n this._tracesCounter = this._meter.createCounter(\"azureMonitor.traceCount\", {\n valueType: ValueType.INT,\n });\n }\n\n /**\n * Shutdown Meter Provider it will return no-op Meters after being called.\n */\n public shutdown() {\n this._meterProvider.shutdown();\n }\n\n /**\n * Force flush Meter Provider.\n */\n public async flush(): Promise<void> {\n await this._meterProvider.forceFlush();\n }\n\n /**\n *Get OpenTelemetry MeterProvider\n */\n public getMeterProvider(): MeterProvider {\n return this._meterProvider;\n }\n\n /**\n * Add extra attributes to Span so Ingestion doesn't aggregate the data again\n * @internal\n */\n public markSpanAsProcessed(span: Span): void {\n if (span.kind === SpanKind.CLIENT) {\n span.setAttributes({\n \"_MS.ProcessedByMetricExtractors\": \"(Name:'Dependencies', Ver:'1.1')\",\n });\n } else if (span.kind === SpanKind.SERVER) {\n span.setAttributes({\n \"_MS.ProcessedByMetricExtractors\": \"(Name:'Requests', Ver:'1.1')\",\n });\n }\n }\n\n /**\n * Record Span metrics\n * @internal\n */\n public recordSpan(span: ReadableSpan): void {\n const durationMs = span.duration[0];\n if (span.kind === SpanKind.SERVER) {\n this._incomingRequestDurationHistogram.record(durationMs, this._getRequestDimensions(span));\n } else {\n this._outgoingRequestDurationHistogram.record(\n durationMs,\n this._getDependencyDimensions(span)\n );\n }\n if (span.events) {\n span.events.forEach((event: TimedEvent) => {\n event.attributes = event.attributes || {};\n if (event.name === \"exception\") {\n event.attributes[\"_MS.ProcessedByMetricExtractors\"] = \"(Name:'Exceptions', Ver:'1.1')\";\n this._exceptionsCounter.add(1, this._getExceptionDimensions(span.resource));\n } else {\n event.attributes[\"_MS.ProcessedByMetricExtractors\"] = \"(Name:'Traces', Ver:'1.1')\";\n this._tracesCounter.add(1, this._getTraceDimensions(span.resource));\n }\n });\n }\n }\n\n /**\n * Record LogRecord metrics, add attribute so data is not aggregated again in ingestion\n * @internal\n */\n public recordLog(logRecord: LogRecord): void {\n if (this._isExceptionTelemetry(logRecord)) {\n logRecord.setAttribute(\"_MS.ProcessedByMetricExtractors\", \"(Name:'Exceptions', Ver:'1.1')\");\n this._exceptionsCounter.add(1, this._getExceptionDimensions(logRecord.resource));\n } else if (this._isTraceTelemetry(logRecord)) {\n logRecord.setAttribute(\"_MS.ProcessedByMetricExtractors\", \"(Name:'Traces', Ver:'1.1')\");\n this._tracesCounter.add(1, this._getTraceDimensions(logRecord.resource));\n }\n }\n\n private _getRequestDimensions(span: ReadableSpan): Attributes {\n const dimensions: MetricRequestDimensions = this._getBaseDimensions(span.resource);\n dimensions.metricId = \"requests/duration\";\n const statusCode = String(span.attributes[\"http.status_code\"]);\n dimensions.requestResultCode = statusCode;\n dimensions.requestSuccess = statusCode === \"200\" ? \"True\" : \"False\";\n return dimensions as Attributes;\n }\n\n private _getDependencyDimensions(span: ReadableSpan): Attributes {\n const dimensions: MetricDependencyDimensions = this._getBaseDimensions(span.resource);\n dimensions.metricId = \"dependencies/duration\";\n const statusCode = String(span.attributes[\"http.status_code\"]);\n dimensions.dependencyTarget = this._getDependencyTarget(span.attributes);\n dimensions.dependencyResultCode = statusCode;\n dimensions.dependencyType = \"http\";\n dimensions.dependencySuccess = statusCode === \"200\" ? \"True\" : \"False\";\n return dimensions as Attributes;\n }\n\n private _getExceptionDimensions(resource: Resource): Attributes {\n const dimensions: StandardMetricBaseDimensions = this._getBaseDimensions(resource);\n dimensions.metricId = \"exceptions/count\";\n return dimensions as Attributes;\n }\n\n private _getTraceDimensions(resource: Resource): Attributes {\n const dimensions: StandardMetricBaseDimensions = this._getBaseDimensions(resource);\n dimensions.metricId = \"traces/count\";\n return dimensions as Attributes;\n }\n\n private _getBaseDimensions(resource: Resource): StandardMetricBaseDimensions {\n const dimensions: StandardMetricBaseDimensions = {};\n dimensions.IsAutocollected = \"True\";\n if (resource) {\n const spanResourceAttributes = resource.attributes;\n const serviceName = spanResourceAttributes[SemanticResourceAttributes.SERVICE_NAME];\n const serviceNamespace = spanResourceAttributes[SemanticResourceAttributes.SERVICE_NAMESPACE];\n if (serviceName) {\n if (serviceNamespace) {\n dimensions.cloudRoleName = `${serviceNamespace}.${serviceName}`;\n } else {\n dimensions.cloudRoleName = String(serviceName);\n }\n }\n const serviceInstanceId =\n spanResourceAttributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID];\n dimensions.cloudRoleInstance = String(serviceInstanceId);\n }\n return dimensions;\n }\n\n private _getDependencyTarget(attributes: Attributes): string {\n if (!attributes) {\n return \"\";\n }\n const peerService = attributes[SemanticAttributes.PEER_SERVICE];\n const httpHost = attributes[SemanticAttributes.HTTP_HOST];\n const httpUrl = attributes[SemanticAttributes.HTTP_URL];\n const netPeerName = attributes[SemanticAttributes.NET_PEER_NAME];\n const netPeerIp = attributes[SemanticAttributes.NET_PEER_IP];\n if (peerService) {\n return String(peerService);\n } else if (httpHost) {\n return String(httpHost);\n } else if (httpUrl) {\n return String(httpUrl);\n } else if (netPeerName) {\n return String(netPeerName);\n } else if (netPeerIp) {\n return String(netPeerIp);\n }\n return \"\";\n }\n\n private _isExceptionTelemetry(logRecord: LogRecord) {\n const baseType = logRecord.attributes[\"_MS.baseType\"];\n // If Application Insights Legacy logs\n if (baseType && baseType === \"ExceptionData\") {\n return true;\n } else if (\n logRecord.attributes[SemanticAttributes.EXCEPTION_MESSAGE] ||\n logRecord.attributes[SemanticAttributes.EXCEPTION_TYPE]\n ) {\n return true;\n }\n return false;\n }\n\n private _isTraceTelemetry(logRecord: LogRecord) {\n const baseType = logRecord.attributes[\"_MS.baseType\"];\n // If Application Insights Legacy logs\n if (baseType && baseType === \"MessageData\") {\n return true;\n } else if (\n !logRecord.attributes[SemanticAttributes.EXCEPTION_MESSAGE] &&\n !logRecord.attributes[SemanticAttributes.EXCEPTION_TYPE]\n ) {\n return true;\n }\n return false;\n }\n}\n"]}
@@ -21,7 +21,7 @@ export class InternalConfig {
21
21
  */
22
22
  constructor(options) {
23
23
  // Default values
24
- this.azureMonitorExporterConfig = {};
24
+ this.azureMonitorExporterOptions = {};
25
25
  this.samplingRatio = 1;
26
26
  this.instrumentationOptions = {
27
27
  http: { enabled: true },
@@ -39,7 +39,7 @@ export class InternalConfig {
39
39
  // This will take precedence over other settings
40
40
  if (options) {
41
41
  // Merge default with provided options
42
- this.azureMonitorExporterConfig = Object.assign(this.azureMonitorExporterConfig, options.azureMonitorExporterConfig);
42
+ this.azureMonitorExporterOptions = Object.assign(this.azureMonitorExporterOptions, options.azureMonitorExporterOptions);
43
43
  this.instrumentationOptions = Object.assign(this.instrumentationOptions, options.instrumentationOptions);
44
44
  this.resource = Object.assign(this.resource, options.resource);
45
45
  this.samplingRatio = options.samplingRatio || this.samplingRatio;
@@ -50,7 +50,7 @@ export class InternalConfig {
50
50
  const jsonConfig = JsonConfig.getInstance();
51
51
  this.samplingRatio =
52
52
  jsonConfig.samplingRatio !== undefined ? jsonConfig.samplingRatio : this.samplingRatio;
53
- this.azureMonitorExporterConfig = Object.assign(this.azureMonitorExporterConfig, jsonConfig.azureMonitorExporterConfig);
53
+ this.azureMonitorExporterOptions = Object.assign(this.azureMonitorExporterOptions, jsonConfig.azureMonitorExporterOptions);
54
54
  this.instrumentationOptions = Object.assign(this.instrumentationOptions, jsonConfig.instrumentationOptions);
55
55
  }
56
56
  catch (error) {
@@ -1 +1 @@
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;;G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CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;YAC/D,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,IAAI,IAAI,CAAC,aAAa,CAAC;SAClE;IACH,CAAC;IAEO,YAAY;QAClB,IAAI;YACF,MAAM,UAAU,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC;YAC5C,IAAI,CAAC,aAAa;gBAChB,UAAU,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC;YAEzF,IAAI,CAAC,0BAA0B,GAAG,MAAM,CAAC,MAAM,CAC7C,IAAI,CAAC,0BAA0B,EAC/B,UAAU,CAAC,0BAA0B,CACtC,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 azureMonitorExporterConfig: 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.azureMonitorExporterConfig = {};\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.azureMonitorExporterConfig = Object.assign(\n this.azureMonitorExporterConfig,\n options.azureMonitorExporterConfig\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.azureMonitorExporterConfig = Object.assign(\n this.azureMonitorExporterConfig,\n jsonConfig.azureMonitorExporterConfig\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,IAAI,CAAC,2BAA2B,GAAG,EAAE,CAAC;QACtC,IAAI,CAAC,aAAa,GAAG,CAAC,CAAC;QACvB,IAAI,CAAC,sBAAsB,GAAG;YAC5B,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;YACvB,QAAQ,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE;YAC5B,OAAO,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE;YAC3B,KAAK,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE;YACzB,U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C,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 // 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"]}
@@ -53,7 +53,7 @@ export class JsonConfig {
53
53
  }
54
54
  try {
55
55
  const jsonConfig = JSON.parse(jsonString);
56
- this.azureMonitorExporterConfig = jsonConfig.azureMonitorExporterConfig;
56
+ this.azureMonitorExporterOptions = jsonConfig.azureMonitorExporterOptions;
57
57
  this.samplingRatio = jsonConfig.samplingRatio;
58
58
  this.instrumentationOptions = jsonConfig.instrumentationOptions;
59
59
  }
@@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AU,CAAC;iBACtB;qBAAM;oBACL,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC,8CAA8C;iBAC1F;aACF;YACD,IAAI;gBACF,UAAU,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;aAC/C;YAAC,OAAO,GAAG,EAAE;gBACZ,MAAM,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC,mCAAmC,EAAE,GAAG,CAAC,CAAC;aACrE;SACF;QACD,IAAI;YACF,MAAM,UAAU,GAAqC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;YAC5E,IAAI,CAAC,0BAA0B,GAAG,UAAU,CAAC,0BAA0B,CAAC;YACxE,IAAI,CAAC,aAAa,GAAG,UAAU,CAAC,aAAa,CAAC;YAC9C,IAAI,CAAC,sBAAsB,GAAG,UAAU,CAAC,sBAAsB,CAAC;SACjE;QAAC,OAAO,GAAG,EAAE;YACZ,MAAM,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC,uCAAuC,EAAE,GAAG,CAAC,CAAC;SACzE;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport * as fs from \"fs\";\nimport * as path from \"path\";\nimport { AzureMonitorOpenTelemetryOptions, InstrumentationOptions } from \"./types\";\nimport { AzureMonitorExporterOptions } from \"@azure/monitor-opentelemetry-exporter\";\nimport { Logger } from \"./logging\";\n\nconst ENV_CONFIGURATION_FILE = \"APPLICATIONINSIGHTS_CONFIGURATION_FILE\";\nconst ENV_CONTENT = \"APPLICATIONINSIGHTS_CONFIGURATION_CONTENT\";\n\n/**\n * Azure Monitor OpenTelemetry Client Configuration through JSON File\n * @internal\n */\nexport class JsonConfig 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 azureMonitorExporterConfig?: 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 static _instance: JsonConfig;\n\n /** Get Singleton instance */\n public static getInstance() {\n if (!JsonConfig._instance) {\n JsonConfig._instance = new JsonConfig();\n }\n return JsonConfig._instance;\n }\n\n /**\n * Initializes a new instance of the JsonConfig class.\n */\n constructor() {\n this._loadJsonFile();\n }\n\n private _loadJsonFile() {\n let jsonString = \"\";\n const contentJsonConfig = process.env[ENV_CONTENT];\n // JSON string added directly in env variable\n if (contentJsonConfig) {\n jsonString = contentJsonConfig;\n }\n // JSON file\n else {\n let configFileName = \"applicationinsights.json\";\n let rootPath = path.join(__dirname, \"../../../\"); // Root of folder (__dirname = ../dist-esm/src)\n let tempDir = path.join(rootPath, configFileName); // default\n let configFile = process.env[ENV_CONFIGURATION_FILE];\n if (configFile) {\n if (path.isAbsolute(configFile)) {\n tempDir = configFile;\n } else {\n tempDir = path.join(rootPath, configFile); // Relative path to applicationinsights folder\n }\n }\n try {\n jsonString = fs.readFileSync(tempDir, \"utf8\");\n } catch (err) {\n Logger.getInstance().info(\"Failed to read JSON config file: \", err);\n }\n }\n try {\n const jsonConfig: AzureMonitorOpenTelemetryOptions = JSON.parse(jsonString);\n this.azureMonitorExporterConfig = jsonConfig.azureMonitorExporterConfig;\n this.samplingRatio = jsonConfig.samplingRatio;\n this.instrumentationOptions = jsonConfig.instrumentationOptions;\n } catch (err) {\n Logger.getInstance().info(\"Missing or invalid JSON config file: \", err);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"jsonConfig.js","sourceRoot":"","sources":["../../../src/shared/jsonConfig.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAG7B,OAAO,EAAE,MAAM,EAAE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EAAE;gBACZ,MAAM,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC,mCAAmC,EAAE,GAAG,CAAC,CAAC;aACrE;SACF;QACD,IAAI;YACF,MAAM,UAAU,GAAqC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;YAC5E,IAAI,CAAC,2BAA2B,GAAG,UAAU,CAAC,2BAA2B,CAAC;YAC1E,IAAI,CAAC,aAAa,GAAG,UAAU,CAAC,aAAa,CAAC;YAC9C,IAAI,CAAC,sBAAsB,GAAG,UAAU,CAAC,sBAAsB,CAAC;SACjE;QAAC,OAAO,GAAG,EAAE;YACZ,MAAM,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC,uCAAuC,EAAE,GAAG,CAAC,CAAC;SACzE;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport * as fs from \"fs\";\nimport * as path from \"path\";\nimport { AzureMonitorOpenTelemetryOptions, InstrumentationOptions } from \"./types\";\nimport { AzureMonitorExporterOptions } from \"@azure/monitor-opentelemetry-exporter\";\nimport { Logger } from \"./logging\";\n\nconst ENV_CONFIGURATION_FILE = \"APPLICATIONINSIGHTS_CONFIGURATION_FILE\";\nconst ENV_CONTENT = \"APPLICATIONINSIGHTS_CONFIGURATION_CONTENT\";\n\n/**\n * Azure Monitor OpenTelemetry Client Configuration through JSON File\n * @internal\n */\nexport class JsonConfig 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 static _instance: JsonConfig;\n\n /** Get Singleton instance */\n public static getInstance() {\n if (!JsonConfig._instance) {\n JsonConfig._instance = new JsonConfig();\n }\n return JsonConfig._instance;\n }\n\n /**\n * Initializes a new instance of the JsonConfig class.\n */\n constructor() {\n this._loadJsonFile();\n }\n\n private _loadJsonFile() {\n let jsonString = \"\";\n const contentJsonConfig = process.env[ENV_CONTENT];\n // JSON string added directly in env variable\n if (contentJsonConfig) {\n jsonString = contentJsonConfig;\n }\n // JSON file\n else {\n let configFileName = \"applicationinsights.json\";\n let rootPath = path.join(__dirname, \"../../../\"); // Root of folder (__dirname = ../dist-esm/src)\n let tempDir = path.join(rootPath, configFileName); // default\n let configFile = process.env[ENV_CONFIGURATION_FILE];\n if (configFile) {\n if (path.isAbsolute(configFile)) {\n tempDir = configFile;\n } else {\n tempDir = path.join(rootPath, configFile); // Relative path to applicationinsights folder\n }\n }\n try {\n jsonString = fs.readFileSync(tempDir, \"utf8\");\n } catch (err) {\n Logger.getInstance().info(\"Failed to read JSON config file: \", err);\n }\n }\n try {\n const jsonConfig: AzureMonitorOpenTelemetryOptions = JSON.parse(jsonString);\n this.azureMonitorExporterOptions = jsonConfig.azureMonitorExporterOptions;\n this.samplingRatio = jsonConfig.samplingRatio;\n this.instrumentationOptions = jsonConfig.instrumentationOptions;\n } catch (err) {\n Logger.getInstance().info(\"Missing or invalid JSON config file: \", err);\n }\n }\n}\n"]}
@@ -1,6 +1,4 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT license.
3
- export const AZURE_MONITOR_OPENTELEMETRY_VERSION = "1.0.0-beta.3";
4
- export const DEFAULT_ROLE_NAME = "Web";
5
- process.env["AZURE_MONITOR_DISTRO_VERSION"] = AZURE_MONITOR_OPENTELEMETRY_VERSION;
3
+ export {};
6
4
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/shared/types.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAMlC,MAAM,CAAC,MAAM,mCAAmC,GAAG,cAAc,CAAC;AAClE,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,CAAC;AACvC,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,GAAG,mCAAmC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AzureMonitorExporterOptions } from \"@azure/monitor-opentelemetry-exporter\";\nimport { InstrumentationConfig } from \"@opentelemetry/instrumentation\";\nimport { Resource } from \"@opentelemetry/resources\";\n\nexport const AZURE_MONITOR_OPENTELEMETRY_VERSION = \"1.0.0-beta.3\";\nexport const DEFAULT_ROLE_NAME = \"Web\";\nprocess.env[\"AZURE_MONITOR_DISTRO_VERSION\"] = AZURE_MONITOR_OPENTELEMETRY_VERSION;\n\n/**\n * Azure Monitor OpenTelemetry Options\n */\nexport interface AzureMonitorOpenTelemetryOptions {\n /** Azure Monitor Exporter Configuration */\n azureMonitorExporterConfig?: AzureMonitorExporterOptions;\n /** OpenTelemetry Resource */\n resource?: Resource;\n /** The rate of telemetry items tracked that should be transmitted (Default 1.0) */\n samplingRatio?: number;\n /**\n * OpenTelemetry Instrumentations options included as part of Azure Monitor (azureSdk, http, mongoDb, mySql, postgreSql, redis, redis4)\n */\n instrumentationOptions?: InstrumentationOptions;\n}\n\n/**\n * OpenTelemetry Instrumentations Configuration interface\n */\nexport interface InstrumentationOptions {\n /** Azure SDK Instrumentation Config */\n azureSdk?: InstrumentationConfig;\n /** HTTP Instrumentation Config */\n http?: InstrumentationConfig;\n /** MongoDB Instrumentation Config */\n mongoDb?: InstrumentationConfig;\n /** MySQL Instrumentation Config */\n mySql?: InstrumentationConfig;\n /** PostgreSql Instrumentation Config */\n postgreSql?: InstrumentationConfig;\n /** Redis Instrumentation Config */\n redis?: InstrumentationConfig;\n /** Redis4 Instrumentation Config */\n redis4?: InstrumentationConfig;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/shared/types.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AzureMonitorExporterOptions } from \"@azure/monitor-opentelemetry-exporter\";\nimport { InstrumentationConfig } from \"@opentelemetry/instrumentation\";\nimport { Resource } from \"@opentelemetry/resources\";\n\n/**\n * Azure Monitor OpenTelemetry Options\n */\nexport interface AzureMonitorOpenTelemetryOptions {\n /** Azure Monitor Exporter Configuration */\n azureMonitorExporterOptions?: AzureMonitorExporterOptions;\n /** OpenTelemetry Resource */\n resource?: Resource;\n /** The rate of telemetry items tracked that should be transmitted (Default 1.0) */\n samplingRatio?: number;\n /**\n * OpenTelemetry Instrumentations options included as part of Azure Monitor (azureSdk, http, mongoDb, mySql, postgreSql, redis, redis4)\n */\n instrumentationOptions?: InstrumentationOptions;\n}\n\n/**\n * OpenTelemetry Instrumentations Configuration interface\n */\nexport interface InstrumentationOptions {\n /** Azure SDK Instrumentation Config */\n azureSdk?: InstrumentationConfig;\n /** HTTP Instrumentation Config */\n http?: InstrumentationConfig;\n /** MongoDB Instrumentation Config */\n mongoDb?: InstrumentationConfig;\n /** MySQL Instrumentation Config */\n mySql?: InstrumentationConfig;\n /** PostgreSql Instrumentation Config */\n postgreSql?: InstrumentationConfig;\n /** Redis Instrumentation Config */\n redis?: InstrumentationConfig;\n /** Redis4 Instrumentation Config */\n redis4?: InstrumentationConfig;\n}\n"]}
@@ -7,15 +7,7 @@ export class AzureFunctionsHook {
7
7
  try {
8
8
  // TODO: Add types files when publicly available
9
9
  this._functionsCoreModule = require("@azure/functions-core");
10
- // Only v3 of Azure Functions library is supported right now. See matrix of versions here:
11
- // https://github.com/Azure/azure-functions-nodejs-library
12
- const funcProgModel = this._functionsCoreModule.getProgrammingModel();
13
- if (funcProgModel.name === "@azure/functions" && funcProgModel.version.startsWith("3.")) {
14
- this._addPreInvocationHook();
15
- }
16
- else {
17
- Logger.getInstance().debug(`AzureFunctionsHook does not support model "${funcProgModel.name}" version "${funcProgModel.version}"`);
18
- }
10
+ this._addPreInvocationHook();
19
11
  }
20
12
  catch (error) {
21
13
  Logger.getInstance().debug("@azure/functions-core failed to load, not running in Azure Functions");
@@ -1 +1 @@
1
- {"version":3,"file":"azureFnHook.js","sourceRoot":"","sources":["../../../src/traces/azureFnHook.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EACL,OAAO,EACP,WAAW,EACX,YAAY,GAEb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,MAAM,OAAO,kBAAkB;IAI7B;QACE,IAAI;YACF,gDAAgD;YAChD,IAAI,CAAC,oBAAoB,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;YAC7D,0FAA0F;YAC1F,0DAA0D;YAC1D,MAAM,aAAa,GAAG,IAAI,CAAC,oBAAoB,CAAC,mBAAmB,EAAE,CAAC;YACtE,IAAI,aAAa,CAAC,IAAI,KAAK,kBAAkB,IAAI,aAAa,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;gBACvF,IAAI,CAAC,qBAAqB,EAAE,CAAC;aAC9B;iBAAM;gBACL,MAAM,CAAC,WAAW,EAAE,CAAC,KAAK,CACxB,8CAA8C,aAAa,CAAC,IAAI,cAAc,aAAa,CAAC,OAAO,GAAG,CACvG,CAAC;aACH;SACF;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,CAAC,WAAW,EAAE,CAAC,KAAK,CACxB,sEAAsE,CACvE,CAAC;SACH;IACH,CAAC;IAEM,QAAQ;QACb,IAAI,IAAI,CAAC,kBAAkB,EAAE;YAC3B,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,CAAC;YAClC,IAAI,CAAC,kBAAkB,GAAG,SAAS,CAAC;SACrC;QACD,IAAI,CAAC,oBAAoB,GAAG,SAAS,CAAC;IACxC,CAAC;IAEO,qBAAqB;QAC3B,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE;YAC5B,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC,oBAAoB,CAAC,YAAY,CAC9D,eAAe,EACf,KAAK,EAAE,oBAAyB,EAAE,EAAE;gBAClC,MAAM,GAAG,GAAmC,oBAAoB,CAAC,iBAAiB,CAAC;gBACnF,4CAA4C;gBAC5C,IAAI,gBAAgB,GAA+B,IAAI,CAAC;gBACxD,IAAI;oBACF,IAAI,GAAG,CAAC,YAAY,EAAE;wBACpB,gBAAgB,GAAG,WAAW,CAAC,OAAO,CAAC,YAAY,EAAE,GAAG,CAAC,YAAY,CAAC,CAAC;qBACxE;oBACD,MAAM,cAAc,GAAG,gBAAgB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;oBAC5D,oBAAoB,CAAC,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAClD,cAAc,EACd,oBAAoB,CAAC,gBAAgB,CACtC,CAAC;iBACH;gBAAC,OAAO,GAAG,EAAE;oBACZ,MAAM,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,gDAAgD,EAAE,GAAG,CAAC,CAAC;iBACnF;YACH,CAAC,CACF,CAAC;SACH;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { Context as AzureFnContext } from \"@azure/functions\";\nimport {\n context,\n propagation,\n ROOT_CONTEXT,\n Context as OpenTelemetryContext,\n} from \"@opentelemetry/api\";\nimport { Logger } from \"../shared/logging\";\n\nexport class AzureFunctionsHook {\n private _functionsCoreModule: any;\n private _preInvocationHook: any;\n\n constructor() {\n try {\n // TODO: Add types files when publicly available\n this._functionsCoreModule = require(\"@azure/functions-core\");\n // Only v3 of Azure Functions library is supported right now. See matrix of versions here:\n // https://github.com/Azure/azure-functions-nodejs-library\n const funcProgModel = this._functionsCoreModule.getProgrammingModel();\n if (funcProgModel.name === \"@azure/functions\" && funcProgModel.version.startsWith(\"3.\")) {\n this._addPreInvocationHook();\n } else {\n Logger.getInstance().debug(\n `AzureFunctionsHook does not support model \"${funcProgModel.name}\" version \"${funcProgModel.version}\"`\n );\n }\n } catch (error) {\n Logger.getInstance().debug(\n \"@azure/functions-core failed to load, not running in Azure Functions\"\n );\n }\n }\n\n public shutdown() {\n if (this._preInvocationHook) {\n this._preInvocationHook.dispose();\n this._preInvocationHook = undefined;\n }\n this._functionsCoreModule = undefined;\n }\n\n private _addPreInvocationHook() {\n if (!this._preInvocationHook) {\n this._preInvocationHook = this._functionsCoreModule.registerHook(\n \"preInvocation\",\n async (preInvocationContext: any) => {\n const ctx: AzureFnContext = <AzureFnContext>preInvocationContext.invocationContext;\n // Update context to use Azure Functions one\n let extractedContext: OpenTelemetryContext | any = null;\n try {\n if (ctx.traceContext) {\n extractedContext = propagation.extract(ROOT_CONTEXT, ctx.traceContext);\n }\n const currentContext = extractedContext || context.active();\n preInvocationContext.functionCallback = context.bind(\n currentContext,\n preInvocationContext.functionCallback\n );\n } catch (err) {\n Logger.getInstance().error(\"Failed to propagate context in Azure Functions\", err);\n }\n }\n );\n }\n }\n}\n"]}
1
+ {"version":3,"file":"azureFnHook.js","sourceRoot":"","sources":["../../../src/traces/azureFnHook.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EACL,OAAO,EACP,WAAW,EACX,YAAY,GAEb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,MAAM,OAAO,kBAAkB;IAI7B;QACE,IAAI;YACF,gDAAgD;YAChD,IAAI,CAAC,oBAAoB,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;YAC7D,IAAI,CAAC,qBAAqB,EAAE,CAAC;SAC9B;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,CAAC,WAAW,EAAE,CAAC,KAAK,CACxB,sEAAsE,CACvE,CAAC;SACH;IACH,CAAC;IAEM,QAAQ;QACb,IAAI,IAAI,CAAC,kBAAkB,EAAE;YAC3B,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,CAAC;YAClC,IAAI,CAAC,kBAAkB,GAAG,SAAS,CAAC;SACrC;QACD,IAAI,CAAC,oBAAoB,GAAG,SAAS,CAAC;IACxC,CAAC;IAEO,qBAAqB;QAC3B,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE;YAC5B,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC,oBAAoB,CAAC,YAAY,CAC9D,eAAe,EACf,KAAK,EAAE,oBAAyB,EAAE,EAAE;gBAClC,MAAM,GAAG,GAAmC,oBAAoB,CAAC,iBAAiB,CAAC;gBACnF,4CAA4C;gBAC5C,IAAI,gBAAgB,GAA+B,IAAI,CAAC;gBACxD,IAAI;oBACF,IAAI,GAAG,CAAC,YAAY,EAAE;wBACpB,gBAAgB,GAAG,WAAW,CAAC,OAAO,CAAC,YAAY,EAAE,GAAG,CAAC,YAAY,CAAC,CAAC;qBACxE;oBACD,MAAM,cAAc,GAAG,gBAAgB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;oBAC5D,oBAAoB,CAAC,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAClD,cAAc,EACd,oBAAoB,CAAC,gBAAgB,CACtC,CAAC;iBACH;gBAAC,OAAO,GAAG,EAAE;oBACZ,MAAM,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,gDAAgD,EAAE,GAAG,CAAC,CAAC;iBACnF;YACH,CAAC,CACF,CAAC;SACH;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { Context as AzureFnContext } from \"@azure/functions\";\nimport {\n context,\n propagation,\n ROOT_CONTEXT,\n Context as OpenTelemetryContext,\n} from \"@opentelemetry/api\";\nimport { Logger } from \"../shared/logging\";\n\nexport class AzureFunctionsHook {\n private _functionsCoreModule: any;\n private _preInvocationHook: any;\n\n constructor() {\n try {\n // TODO: Add types files when publicly available\n this._functionsCoreModule = require(\"@azure/functions-core\");\n this._addPreInvocationHook();\n } catch (error) {\n Logger.getInstance().debug(\n \"@azure/functions-core failed to load, not running in Azure Functions\"\n );\n }\n }\n\n public shutdown() {\n if (this._preInvocationHook) {\n this._preInvocationHook.dispose();\n this._preInvocationHook = undefined;\n }\n this._functionsCoreModule = undefined;\n }\n\n private _addPreInvocationHook() {\n if (!this._preInvocationHook) {\n this._preInvocationHook = this._functionsCoreModule.registerHook(\n \"preInvocation\",\n async (preInvocationContext: any) => {\n const ctx: AzureFnContext = <AzureFnContext>preInvocationContext.invocationContext;\n // Update context to use Azure Functions one\n let extractedContext: OpenTelemetryContext | any = null;\n try {\n if (ctx.traceContext) {\n extractedContext = propagation.extract(ROOT_CONTEXT, ctx.traceContext);\n }\n const currentContext = extractedContext || context.active();\n preInvocationContext.functionCallback = context.bind(\n currentContext,\n preInvocationContext.functionCallback\n );\n } catch (err) {\n Logger.getInstance().error(\"Failed to propagate context in Azure Functions\", err);\n }\n }\n );\n }\n }\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT license.
3
3
  import { createAzureSdkInstrumentation } from "@azure/opentelemetry-instrumentation-azure-sdk";
4
- import { ApplicationInsightsSampler, AzureMonitorTraceExporter, } from "@azure/monitor-opentelemetry-exporter";
4
+ import { AzureMonitorTraceExporter } from "@azure/monitor-opentelemetry-exporter";
5
5
  import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
6
6
  import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-base";
7
7
  import { HttpInstrumentation, } from "@opentelemetry/instrumentation-http";
@@ -14,6 +14,7 @@ import { ignoreOutgoingRequestHook } from "../utils/common";
14
14
  import { AzureMonitorSpanProcessor } from "./spanProcessor";
15
15
  import { AzureFunctionsHook } from "./azureFnHook";
16
16
  import { metrics } from "@opentelemetry/api";
17
+ import { ApplicationInsightsSampler } from "./sampler";
17
18
  /**
18
19
  * Azure Monitor OpenTelemetry Trace Handler
19
20
  */
@@ -34,7 +35,7 @@ export class TraceHandler {
34
35
  forceFlushTimeoutMillis: 30000,
35
36
  };
36
37
  this._tracerProvider = new NodeTracerProvider(tracerConfig);
37
- this._azureExporter = new AzureMonitorTraceExporter(this._config.azureMonitorExporterConfig);
38
+ this._azureExporter = new AzureMonitorTraceExporter(this._config.azureMonitorExporterOptions);
38
39
  const bufferConfig = {
39
40
  maxExportBatchSize: 512,
40
41
  scheduledDelayMillis: 5000,
@@ -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,EACL,0BAA0B,EAC1B,yBAAyB,GAC1B,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAoB,MAAM,+BAA+B,CAAC;AACrF,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,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAG7C;;GAEG;AACH,MAAM,OAAO,YAAY;IASvB;;;;OAIG;IACH,YAAY,MAAsB,EAAE,aAA4B;QAC9D,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;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BAAgB,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 {\n ApplicationInsightsSampler,\n AzureMonitorTraceExporter,\n} 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\";\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.azureMonitorExporterConfig);\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;AAClF,OAAO,EAAE,kBAAkB,EAAoB,MAAM,+BAA+B,CAAC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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;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"]}
@@ -0,0 +1,84 @@
1
+ import { SamplingDecision } from "@opentelemetry/sdk-trace-base";
2
+ /**
3
+ * ApplicationInsightsSampler is responsible for the following:
4
+ * Implements same trace id hashing algorithm so that traces are sampled the same across multiple nodes
5
+ * Adds item count to span attribute if span is sampled (needed for ingestion service)
6
+ * @param samplingRatio - 0 to 1 value.
7
+ */
8
+ export class ApplicationInsightsSampler {
9
+ /**
10
+ * Initializes a new instance of the ApplicationInsightsSampler class.
11
+ * @param samplingRatio Value in the range [0,1], 1 meaning all data will sampled and 0 all Tracing data will be sampled out.
12
+ */
13
+ constructor(samplingRatio = 1) {
14
+ this._samplingRatio = samplingRatio;
15
+ if (this._samplingRatio > 1) {
16
+ throw new Error("Invalid sampling rate, sampling rate must be a value in the range [0,1].");
17
+ }
18
+ this._sampleRate = Math.round(this._samplingRatio * 100);
19
+ }
20
+ /**
21
+ * Checks whether span needs to be created and tracked.
22
+ *
23
+ * @param context Parent Context which may contain a span.
24
+ * @param traceId of the span to be created. It can be different from the
25
+ * traceId in the {@link SpanContext}. Typically in situations when the
26
+ * span to be created starts a new trace.
27
+ * @param spanName of the span to be created.
28
+ * @param spanKind of the span to be created.
29
+ * @param attributes Initial set of SpanAttributes for the Span being constructed.
30
+ * @param links Collection of links that will be associated with the Span to
31
+ * be created. Typically useful for batch operations.
32
+ * @returns a {@link SamplingResult}.
33
+ */
34
+ shouldSample(
35
+ // @ts-ignore
36
+ context, traceId,
37
+ // @ts-ignore
38
+ spanName,
39
+ // @ts-ignore
40
+ spanKind, attributes,
41
+ // @ts-ignore
42
+ links) {
43
+ let isSampledIn = false;
44
+ if (this._sampleRate == 100) {
45
+ isSampledIn = true;
46
+ }
47
+ else if (this._sampleRate == 0) {
48
+ isSampledIn = false;
49
+ }
50
+ else {
51
+ isSampledIn = this._getSamplingHashCode(traceId) < this._sampleRate;
52
+ }
53
+ // Add sample rate as span attribute
54
+ attributes = attributes || {};
55
+ attributes["_MS.sampleRate"] = this._sampleRate;
56
+ return isSampledIn
57
+ ? { decision: SamplingDecision.RECORD_AND_SAMPLED, attributes: attributes }
58
+ : { decision: SamplingDecision.RECORD, attributes: attributes };
59
+ }
60
+ /**
61
+ * Return Sampler description
62
+ */
63
+ toString() {
64
+ return `ApplicationInsightsSampler{${this._samplingRatio}}`;
65
+ }
66
+ _getSamplingHashCode(input) {
67
+ var csharpMin = -2147483648;
68
+ var csharpMax = 2147483647;
69
+ var hash = 5381;
70
+ if (!input) {
71
+ return 0;
72
+ }
73
+ while (input.length < 8) {
74
+ input = input + input;
75
+ }
76
+ for (var i = 0; i < input.length; i++) {
77
+ // JS doesn't respond to integer overflow by wrapping around. Simulate it with bitwise operators ( | 0)
78
+ hash = ((((hash << 5) + hash) | 0) + input.charCodeAt(i)) | 0;
79
+ }
80
+ hash = hash <= csharpMin ? csharpMax : Math.abs(hash);
81
+ return (hash / csharpMax) * 100;
82
+ }
83
+ }
84
+ //# sourceMappingURL=sampler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sampler.js","sourceRoot":"","sources":["../../../src/traces/sampler.ts"],"names":[],"mappings":"AAGA,OAAO,EAAW,gBAAgB,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AC;IAC9D,CAAC;IAEO,oBAAoB,CAAC,KAAa;QACxC,IAAI,SAAS,GAAG,CAAC,UAAU,CAAC;QAC5B,IAAI,SAAS,GAAG,UAAU,CAAC;QAC3B,IAAI,IAAI,GAAG,IAAI,CAAC;QAEhB,IAAI,CAAC,KAAK,EAAE;YACV,OAAO,CAAC,CAAC;SACV;QAED,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;YACvB,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;SACvB;QAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACrC,uGAAuG;YACvG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;SAC/D;QAED,IAAI,GAAG,IAAI,IAAI,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACtD,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC,GAAG,GAAG,CAAC;IAClC,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nimport { Link, Attributes, SpanKind, Context } from \"@opentelemetry/api\";\nimport { Sampler, SamplingDecision, SamplingResult } from \"@opentelemetry/sdk-trace-base\";\n\n/**\n * ApplicationInsightsSampler is responsible for the following:\n * Implements same trace id hashing algorithm so that traces are sampled the same across multiple nodes\n * Adds item count to span attribute if span is sampled (needed for ingestion service)\n * @param samplingRatio - 0 to 1 value.\n */\nexport class ApplicationInsightsSampler implements Sampler {\n private readonly _sampleRate: number;\n private readonly _samplingRatio: number;\n\n /**\n * Initializes a new instance of the ApplicationInsightsSampler class.\n * @param samplingRatio Value in the range [0,1], 1 meaning all data will sampled and 0 all Tracing data will be sampled out.\n */\n constructor(samplingRatio: number = 1) {\n this._samplingRatio = samplingRatio;\n if (this._samplingRatio > 1) {\n throw new Error(\"Invalid sampling rate, sampling rate must be a value in the range [0,1].\");\n }\n this._sampleRate = Math.round(this._samplingRatio * 100);\n }\n\n /**\n * Checks whether span needs to be created and tracked.\n *\n * @param context Parent Context which may contain a span.\n * @param traceId of the span to be created. It can be different from the\n * traceId in the {@link SpanContext}. Typically in situations when the\n * span to be created starts a new trace.\n * @param spanName of the span to be created.\n * @param spanKind of the span to be created.\n * @param attributes Initial set of SpanAttributes for the Span being constructed.\n * @param links Collection of links that will be associated with the Span to\n * be created. Typically useful for batch operations.\n * @returns a {@link SamplingResult}.\n */\n public shouldSample(\n // @ts-ignore\n context: Context,\n traceId: string,\n // @ts-ignore\n spanName: string,\n // @ts-ignore\n spanKind: SpanKind,\n attributes: Attributes,\n // @ts-ignore\n links: Link[]\n ): SamplingResult {\n let isSampledIn = false;\n if (this._sampleRate == 100) {\n isSampledIn = true;\n } else if (this._sampleRate == 0) {\n isSampledIn = false;\n } else {\n isSampledIn = this._getSamplingHashCode(traceId) < this._sampleRate;\n }\n // Add sample rate as span attribute\n attributes = attributes || {};\n attributes[\"_MS.sampleRate\"] = this._sampleRate;\n return isSampledIn\n ? { decision: SamplingDecision.RECORD_AND_SAMPLED, attributes: attributes }\n : { decision: SamplingDecision.RECORD, attributes: attributes };\n }\n\n /**\n * Return Sampler description\n */\n public toString(): string {\n return `ApplicationInsightsSampler{${this._samplingRatio}}`;\n }\n\n private _getSamplingHashCode(input: string): number {\n var csharpMin = -2147483648;\n var csharpMax = 2147483647;\n var hash = 5381;\n\n if (!input) {\n return 0;\n }\n\n while (input.length < 8) {\n input = input + input;\n }\n\n for (var i = 0; i < input.length; i++) {\n // JS doesn't respond to integer overflow by wrapping around. Simulate it with bitwise operators ( | 0)\n hash = ((((hash << 5) + hash) | 0) + input.charCodeAt(i)) | 0;\n }\n\n hash = hash <= csharpMin ? csharpMax : Math.abs(hash);\n return (hash / csharpMax) * 100;\n }\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT license.
3
+ export const AZURE_MONITOR_OPENTELEMETRY_VERSION = "1.0.0";
3
4
  export const AZURE_MONITOR_STATSBEAT_FEATURES = "AZURE_MONITOR_STATSBEAT_FEATURES";
4
5
  export var StatsbeatFeature;
5
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,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_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,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"]}
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-beta.3",
5
+ "version": "1.0.0",
6
6
  "description": "Azure Monitor OpenTelemetry (Node.js)",
7
7
  "main": "dist/index.js",
8
8
  "module": "dist-esm/src/index.js",
@@ -25,11 +25,11 @@
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": "nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace \"dist-esm/test/internal/**/*.test.js\"",
29
- "unit-test:node:debug": "nyc 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/**/*.test.js\"",
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\"",
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": "nyc 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 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",
@@ -89,22 +89,22 @@
89
89
  "@azure/functions": "^3.2.0",
90
90
  "@azure/monitor-opentelemetry-exporter": "1.0.0-beta.16",
91
91
  "@azure/opentelemetry-instrumentation-azure-sdk": "^1.0.0-beta.3",
92
- "@opentelemetry/api": "^1.4.1",
93
- "@opentelemetry/api-logs": "^0.41.2",
94
- "@opentelemetry/core": "^1.15.2",
95
- "@opentelemetry/instrumentation": "^0.41.2",
96
- "@opentelemetry/instrumentation-http": "^0.41.2",
97
- "@opentelemetry/instrumentation-mongodb": "^0.36.0",
98
- "@opentelemetry/instrumentation-mysql": "^0.34.0",
99
- "@opentelemetry/instrumentation-pg": "^0.36.0",
100
- "@opentelemetry/instrumentation-redis": "^0.35.0",
101
- "@opentelemetry/instrumentation-redis-4": "^0.35.0",
102
- "@opentelemetry/resources": "^1.15.0",
103
- "@opentelemetry/sdk-logs": "^0.41.0",
104
- "@opentelemetry/sdk-metrics": "^1.15.0",
105
- "@opentelemetry/sdk-trace-base": "^1.15.0",
106
- "@opentelemetry/sdk-trace-node": "^1.15.0",
107
- "@opentelemetry/semantic-conventions": "^1.15.0",
92
+ "@opentelemetry/api": "^1.5.0",
93
+ "@opentelemetry/api-logs": "^0.43.0",
94
+ "@opentelemetry/core": "^1.16.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.16.0",
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",
108
108
  "tslib": "^2.2.0"
109
109
  },
110
110
  "sideEffects": false,
@@ -7,7 +7,7 @@ import { Resource } from '@opentelemetry/resources';
7
7
  */
8
8
  export declare interface AzureMonitorOpenTelemetryOptions {
9
9
  /** Azure Monitor Exporter Configuration */
10
- azureMonitorExporterConfig?: AzureMonitorExporterOptions;
10
+ azureMonitorExporterOptions?: AzureMonitorExporterOptions;
11
11
  /** OpenTelemetry Resource */
12
12
  resource?: Resource;
13
13
  /** The rate of telemetry items tracked that should be transmitted (Default 1.0) */