@azure/monitor-opentelemetry 1.7.0 → 1.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/README.md +1 -1
  2. package/dist/index.js +44 -47
  3. package/dist-esm/src/browserSdkLoader/browserSdkLoader.js +5 -5
  4. package/dist-esm/src/browserSdkLoader/browserSdkLoader.js.map +1 -1
  5. package/dist-esm/src/browserSdkLoader/browserSdkLoaderHelper.js +5 -5
  6. package/dist-esm/src/browserSdkLoader/browserSdkLoaderHelper.js.map +1 -1
  7. package/dist-esm/src/index.js +1 -1
  8. package/dist-esm/src/index.js.map +1 -1
  9. package/dist-esm/src/logs/batchLogRecordProcessor.js +1 -7
  10. package/dist-esm/src/logs/batchLogRecordProcessor.js.map +1 -1
  11. package/dist-esm/src/logs/handler.js +1 -1
  12. package/dist-esm/src/logs/handler.js.map +1 -1
  13. package/dist-esm/src/logs/index.js +1 -1
  14. package/dist-esm/src/logs/index.js.map +1 -1
  15. package/dist-esm/src/logs/logRecordProcessor.js +1 -1
  16. package/dist-esm/src/logs/logRecordProcessor.js.map +1 -1
  17. package/dist-esm/src/metrics/handler.js +1 -1
  18. package/dist-esm/src/metrics/handler.js.map +1 -1
  19. package/dist-esm/src/metrics/index.js +1 -1
  20. package/dist-esm/src/metrics/index.js.map +1 -1
  21. package/dist-esm/src/metrics/quickpulse/export/exporter.js +2 -1
  22. package/dist-esm/src/metrics/quickpulse/export/exporter.js.map +1 -1
  23. package/dist-esm/src/metrics/quickpulse/export/sender.js +1 -1
  24. package/dist-esm/src/metrics/quickpulse/export/sender.js.map +1 -1
  25. package/dist-esm/src/metrics/quickpulse/liveMetrics.js +4 -2
  26. package/dist-esm/src/metrics/quickpulse/liveMetrics.js.map +1 -1
  27. package/dist-esm/src/metrics/quickpulse/types.js +1 -1
  28. package/dist-esm/src/metrics/quickpulse/types.js.map +1 -1
  29. package/dist-esm/src/metrics/quickpulse/utils.js +1 -1
  30. package/dist-esm/src/metrics/quickpulse/utils.js.map +1 -1
  31. package/dist-esm/src/metrics/standardMetrics.js +1 -1
  32. package/dist-esm/src/metrics/standardMetrics.js.map +1 -1
  33. package/dist-esm/src/metrics/types.js +1 -1
  34. package/dist-esm/src/metrics/types.js.map +1 -1
  35. package/dist-esm/src/metrics/utils.js +1 -1
  36. package/dist-esm/src/metrics/utils.js.map +1 -1
  37. package/dist-esm/src/shared/config.js +2 -2
  38. package/dist-esm/src/shared/config.js.map +1 -1
  39. package/dist-esm/src/shared/index.js +1 -1
  40. package/dist-esm/src/shared/index.js.map +1 -1
  41. package/dist-esm/src/shared/jsonConfig.js +1 -1
  42. package/dist-esm/src/shared/jsonConfig.js.map +1 -1
  43. package/dist-esm/src/shared/logging/diagFileConsoleLogger.js +1 -1
  44. package/dist-esm/src/shared/logging/diagFileConsoleLogger.js.map +1 -1
  45. package/dist-esm/src/shared/logging/index.js +1 -1
  46. package/dist-esm/src/shared/logging/index.js.map +1 -1
  47. package/dist-esm/src/shared/logging/logger.js +1 -1
  48. package/dist-esm/src/shared/logging/logger.js.map +1 -1
  49. package/dist-esm/src/traces/azureFnHook.js +1 -1
  50. package/dist-esm/src/traces/azureFnHook.js.map +1 -1
  51. package/dist-esm/src/traces/handler.js +1 -1
  52. package/dist-esm/src/traces/handler.js.map +1 -1
  53. package/dist-esm/src/traces/index.js +1 -1
  54. package/dist-esm/src/traces/index.js.map +1 -1
  55. package/dist-esm/src/traces/sampler.js +1 -1
  56. package/dist-esm/src/traces/sampler.js.map +1 -1
  57. package/dist-esm/src/traces/spanProcessor.js +1 -1
  58. package/dist-esm/src/traces/spanProcessor.js.map +1 -1
  59. package/dist-esm/src/types.js +3 -3
  60. package/dist-esm/src/types.js.map +1 -1
  61. package/dist-esm/src/utils/common.js.map +1 -1
  62. package/dist-esm/src/utils/connectionStringParser.js +1 -1
  63. package/dist-esm/src/utils/connectionStringParser.js.map +1 -1
  64. package/dist-esm/src/utils/fileSystem.js +1 -1
  65. package/dist-esm/src/utils/fileSystem.js.map +1 -1
  66. package/dist-esm/src/utils/index.js +1 -1
  67. package/dist-esm/src/utils/index.js.map +1 -1
  68. package/dist-esm/src/utils/logUtils.js +1 -1
  69. package/dist-esm/src/utils/logUtils.js.map +1 -1
  70. package/dist-esm/src/utils/opentelemetryInstrumentationPatcher.js +3 -3
  71. package/dist-esm/src/utils/opentelemetryInstrumentationPatcher.js.map +1 -1
  72. package/dist-esm/src/utils/statsbeat.js +1 -1
  73. package/dist-esm/src/utils/statsbeat.js.map +1 -1
  74. package/dist-esm/src/utils/types.js +1 -1
  75. package/dist-esm/src/utils/types.js.map +1 -1
  76. package/package.json +25 -25
package/README.md CHANGED
@@ -101,7 +101,7 @@ useAzureMonitor(options);
101
101
  | enableStandardMetrics | Enable/Disable Standard Metrics. |true|
102
102
  | logRecordProcessors | Array of log record processors to register to the global logger provider. ||
103
103
  | spanProcessors | Array of span processors to register to the global tracer provider. ||
104
- <!--- TODO: Enable when feature is released | enableTraceBasedSamplingForLogs | Enable log sampling based on trace. |true|-->
104
+ | enableTraceBasedSamplingForLogs | Enable log sampling based on trace. |false|
105
105
 
106
106
  Options could be set using configuration file `applicationinsights.json` located under root folder of @azure/monitor-opentelemetry package installation folder, Ex: `node_modules/@azure/monitor-opentelemetry`. These configuration values will be applied to all AzureMonitorOpenTelemetryClient instances.
107
107
 
package/dist/index.js CHANGED
@@ -59,7 +59,7 @@ var zlib__namespace = /*#__PURE__*/_interopNamespaceDefault(zlib);
59
59
  var coreClient__namespace = /*#__PURE__*/_interopNamespaceDefault(coreClient);
60
60
 
61
61
  // Copyright (c) Microsoft Corporation.
62
- // Licensed under the MIT license.
62
+ // Licensed under the MIT License.
63
63
  const statAsync = util.promisify(fs__namespace.stat);
64
64
  const lstatAsync = util.promisify(fs__namespace.lstat);
65
65
  const mkdirAsync = util.promisify(fs__namespace.mkdir);
@@ -210,7 +210,7 @@ function parseResourceDetectorsFromEnvVar() {
210
210
  }
211
211
 
212
212
  // Copyright (c) Microsoft Corporation.
213
- // Licensed under the MIT license.
213
+ // Licensed under the MIT License.
214
214
  class DiagFileConsoleLogger {
215
215
  constructor() {
216
216
  this._TAG = "DiagFileConsoleLogger:";
@@ -376,7 +376,7 @@ class DiagFileConsoleLogger {
376
376
  }
377
377
 
378
378
  // Copyright (c) Microsoft Corporation.
379
- // Licensed under the MIT license.
379
+ // Licensed under the MIT License.
380
380
  class Logger {
381
381
  static getInstance() {
382
382
  if (!Logger.instance) {
@@ -500,7 +500,7 @@ class Logger {
500
500
  }
501
501
 
502
502
  // Copyright (c) Microsoft Corporation.
503
- // Licensed under the MIT license.
503
+ // Licensed under the MIT License.
504
504
  /* eslint-disable no-underscore-dangle*/
505
505
  const ENV_CONFIGURATION_FILE = "APPLICATIONINSIGHTS_CONFIGURATION_FILE";
506
506
  const ENV_CONTENT = "APPLICATIONINSIGHTS_CONFIGURATION_CONTENT";
@@ -565,7 +565,7 @@ class JsonConfig {
565
565
  }
566
566
 
567
567
  // Copyright (c) Microsoft Corporation.
568
- // Licensed under the MIT license.
568
+ // Licensed under the MIT License.
569
569
  /**
570
570
  * Azure Monitor OpenTelemetry Client Configuration
571
571
  */
@@ -589,7 +589,7 @@ class InternalConfig {
589
589
  this.samplingRatio = 1;
590
590
  this.enableLiveMetrics = true;
591
591
  this.enableStandardMetrics = true;
592
- this.enableTraceBasedSamplingForLogs = true;
592
+ this.enableTraceBasedSamplingForLogs = false;
593
593
  this.instrumentationOptions = {
594
594
  http: { enabled: true },
595
595
  azureSdk: { enabled: false },
@@ -680,7 +680,7 @@ class InternalConfig {
680
680
  }
681
681
 
682
682
  // Copyright (c) Microsoft Corporation.
683
- // Licensed under the MIT license.
683
+ // Licensed under the MIT License.
684
684
  /**
685
685
  * Disable Standard Metrics environment variable name.
686
686
  */
@@ -717,7 +717,7 @@ var StandardMetricIds;
717
717
  })(StandardMetricIds || (StandardMetricIds = {}));
718
718
 
719
719
  // Copyright (c) Microsoft Corporation.
720
- // Licensed under the MIT license.
720
+ // Licensed under the MIT License.
721
721
  function getRequestDimensions(span) {
722
722
  const dimensions = getBaseDimensions(span.resource);
723
723
  dimensions.metricId = StandardMetricIds.REQUEST_DURATION;
@@ -830,7 +830,7 @@ function convertDimensions(dimensions) {
830
830
  }
831
831
 
832
832
  // Copyright (c) Microsoft Corporation.
833
- // Licensed under the MIT license.
833
+ // Licensed under the MIT License.
834
834
  /**
835
835
  * Azure Monitor Standard Metrics
836
836
  * @internal
@@ -2124,9 +2124,9 @@ const publishOperationSpec = {
2124
2124
  };
2125
2125
 
2126
2126
  // Copyright (c) Microsoft Corporation.
2127
- // Licensed under the MIT license.
2127
+ // Licensed under the MIT License.
2128
2128
  // Copyright (c) Microsoft Corporation.
2129
- // Licensed under the MIT license.
2129
+ // Licensed under the MIT License.
2130
2130
  /**
2131
2131
  * Statsbeat Features Mapping
2132
2132
  * @internal
@@ -2139,7 +2139,7 @@ const StatsbeatFeaturesMap = new Map([
2139
2139
  ["liveMetrics", 16],
2140
2140
  ["shim", 32],
2141
2141
  ]);
2142
- const AZURE_MONITOR_OPENTELEMETRY_VERSION = "1.7.0";
2142
+ const AZURE_MONITOR_OPENTELEMETRY_VERSION = "1.7.1";
2143
2143
  const AZURE_MONITOR_STATSBEAT_FEATURES = "AZURE_MONITOR_STATSBEAT_FEATURES";
2144
2144
  const AZURE_MONITOR_PREFIX = "AZURE_MONITOR_PREFIX";
2145
2145
  const AZURE_MONITOR_AUTO_ATTACH = "AZURE_MONITOR_AUTO_ATTACH";
@@ -2255,7 +2255,7 @@ const StatsbeatInstrumentationMap = new Map([
2255
2255
  ]);
2256
2256
 
2257
2257
  // Copyright (c) Microsoft Corporation.
2258
- // Licensed under the MIT license.
2258
+ // Licensed under the MIT License.
2259
2259
  var QuickPulseOpenTelemetryMetricNames;
2260
2260
  (function (QuickPulseOpenTelemetryMetricNames) {
2261
2261
  QuickPulseOpenTelemetryMetricNames["COMMITTED_BYTES"] = "azureMonitor.memoryCommittedBytes";
@@ -2287,7 +2287,7 @@ var QuickPulseMetricNames;
2287
2287
  })(QuickPulseMetricNames || (QuickPulseMetricNames = {}));
2288
2288
 
2289
2289
  // Copyright (c) Microsoft Corporation.
2290
- // Licensed under the MIT license.
2290
+ // Licensed under the MIT License.
2291
2291
  /* eslint-disable @typescript-eslint/no-unsafe-enum-comparison */
2292
2292
  /** Get the internal SDK version */
2293
2293
  function getSdkVersion() {
@@ -2572,7 +2572,7 @@ function getTransmissionTime() {
2572
2572
  }
2573
2573
 
2574
2574
  // Copyright (c) Microsoft Corporation.
2575
- // Licensed under the MIT license.
2575
+ // Licensed under the MIT License.
2576
2576
  const applicationInsightsResource = "https://monitor.azure.com//.default";
2577
2577
  /**
2578
2578
  * Quickpulse sender class
@@ -2642,7 +2642,7 @@ class QuickpulseSender {
2642
2642
  }
2643
2643
 
2644
2644
  // Copyright (c) Microsoft Corporation.
2645
- // Licensed under the MIT license.
2645
+ // Licensed under the MIT License.
2646
2646
  /**
2647
2647
  * Quickpulse Metric Exporter.
2648
2648
  */
@@ -2668,6 +2668,7 @@ class QuickpulseMetricExporter {
2668
2668
  * @param metrics - Resource metrics to export.
2669
2669
  * @param resultCallback - Result callback.
2670
2670
  */
2671
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
2671
2672
  async export(metrics, resultCallback) {
2672
2673
  api.diag.info(`Exporting Live metrics(s). Converting to envelopes...`);
2673
2674
  const optionalParams = {
@@ -2719,7 +2720,7 @@ class QuickpulseMetricExporter {
2719
2720
  }
2720
2721
 
2721
2722
  // Copyright (c) Microsoft Corporation.
2722
- // Licensed under the MIT license.
2723
+ // Licensed under the MIT License.
2723
2724
  /**
2724
2725
  * ConnectionString parser.
2725
2726
  * @internal
@@ -2795,7 +2796,7 @@ ConnectionStringParser.FIELDS_SEPARATOR = ";";
2795
2796
  ConnectionStringParser.FIELD_KEY_VALUE_SEPARATOR = "=";
2796
2797
 
2797
2798
  // Copyright (c) Microsoft Corporation.
2798
- // Licensed under the MIT license.
2799
+ // Licensed under the MIT License.
2799
2800
  let instance;
2800
2801
  class StatsbeatConfiguration {
2801
2802
  constructor() {
@@ -2884,7 +2885,7 @@ function getInstance() {
2884
2885
  }
2885
2886
 
2886
2887
  // Copyright (c) Microsoft Corporation.
2887
- // Licensed under the MIT license.
2888
+ // Licensed under the MIT License.
2888
2889
  const POST_INTERVAL = 1000;
2889
2890
  const MAX_POST_WAIT_TIME = 20000;
2890
2891
  const PING_INTERVAL = 5000;
@@ -3136,7 +3137,9 @@ class LiveMetrics {
3136
3137
  return this.meterProvider;
3137
3138
  }
3138
3139
  getDocuments() {
3139
- return this.documents;
3140
+ const result = this.documents;
3141
+ this.documents = [];
3142
+ return result;
3140
3143
  }
3141
3144
  addDocument(document) {
3142
3145
  if (document) {
@@ -3355,7 +3358,7 @@ class LiveMetrics {
3355
3358
  }
3356
3359
 
3357
3360
  // Copyright (c) Microsoft Corporation.
3358
- // Licensed under the MIT license.
3361
+ // Licensed under the MIT License.
3359
3362
  /**
3360
3363
  * Azure Monitor OpenTelemetry Metric Handler
3361
3364
  */
@@ -3438,7 +3441,7 @@ class MetricHandler {
3438
3441
  }
3439
3442
 
3440
3443
  // Copyright (c) Microsoft Corporation.
3441
- // Licensed under the MIT license.
3444
+ // Licensed under the MIT License.
3442
3445
  /**
3443
3446
  * Azure Monitor Span Processor.
3444
3447
  * @internal
@@ -3462,7 +3465,7 @@ class AzureMonitorSpanProcessor {
3462
3465
  }
3463
3466
 
3464
3467
  // Copyright (c) Microsoft Corporation.
3465
- // Licensed under the MIT license.
3468
+ // Licensed under the MIT License.
3466
3469
  class AzureFunctionsHook {
3467
3470
  constructor() {
3468
3471
  try {
@@ -3510,7 +3513,7 @@ class AzureFunctionsHook {
3510
3513
  }
3511
3514
 
3512
3515
  // Copyright (c) Microsoft Corporation.
3513
- // Licensed under the MIT license.
3516
+ // Licensed under the MIT License.
3514
3517
  /**
3515
3518
  * TODO: Remove this sampler in favor of the implementation in the AzMon Exporter once we support M2M approach for standard metrics.
3516
3519
  * This sampler specifically marks spans as sampled out and records them instead of dropping the span altogether.
@@ -3603,7 +3606,7 @@ class ApplicationInsightsSampler {
3603
3606
  }
3604
3607
 
3605
3608
  // Copyright (c) Microsoft Corporation.
3606
- // Licensed under the MIT license.
3609
+ // Licensed under the MIT License.
3607
3610
  /**
3608
3611
  * Azure Monitor OpenTelemetry Trace Handler
3609
3612
  */
@@ -3694,7 +3697,7 @@ class TraceHandler {
3694
3697
  }
3695
3698
 
3696
3699
  // Copyright (c) Microsoft Corporation.
3697
- // Licensed under the MIT license.
3700
+ // Licensed under the MIT License.
3698
3701
  /**
3699
3702
  * Azure Monitor LogRecord Processor.
3700
3703
  * @internal
@@ -3715,7 +3718,7 @@ class AzureLogRecordProcessor {
3715
3718
  }
3716
3719
 
3717
3720
  // Copyright (c) Microsoft Corporation.
3718
- // Licensed under the MIT license.
3721
+ // Licensed under the MIT License.
3719
3722
  /**
3720
3723
  * Azure Monitor BatchLogRecord Processor.
3721
3724
  * @internal
@@ -3736,18 +3739,12 @@ class AzureBatchLogRecordProcessor extends sdkLogs.BatchLogRecordProcessor {
3736
3739
  }
3737
3740
  }
3738
3741
  }
3739
- // Ensure nested log attributes are serialized
3740
- for (const [key, value] of Object.entries(logRecord.attributes)) {
3741
- if (typeof value === "object") {
3742
- logRecord.attributes[key] = JSON.stringify(value);
3743
- }
3744
- }
3745
3742
  super.onEmit(logRecord);
3746
3743
  }
3747
3744
  }
3748
3745
 
3749
3746
  // Copyright (c) Microsoft Corporation.
3750
- // Licensed under the MIT license.
3747
+ // Licensed under the MIT License.
3751
3748
  /**
3752
3749
  * Convert log level to severity number.
3753
3750
  * @internal
@@ -3778,7 +3775,7 @@ function logLevelToSeverityNumber(logLevel) {
3778
3775
  }
3779
3776
 
3780
3777
  // Copyright (c) Microsoft Corporation.
3781
- // Licensed under the MIT license.
3778
+ // Licensed under the MIT License.
3782
3779
  /**
3783
3780
  * Azure Monitor OpenTelemetry Log Handler
3784
3781
  */
@@ -3824,7 +3821,7 @@ class LogHandler {
3824
3821
  }
3825
3822
 
3826
3823
  // Copyright (c) Microsoft Corporation.
3827
- // Licensed under the MIT license.
3824
+ // Licensed under the MIT License.
3828
3825
  /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
3829
3826
  // currently support the following encoding types
3830
3827
  var contentEncodingMethod;
@@ -3842,7 +3839,7 @@ util.promisify(zlib__namespace.gzip);
3842
3839
  util.promisify(zlib__namespace.gunzip);
3843
3840
  util.promisify(zlib__namespace.deflate);
3844
3841
  util.promisify(zlib__namespace.inflate);
3845
- // eslint-disable-next-line @typescript-eslint/ban-types
3842
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
3846
3843
  const getBrotliCompressSync = (zlibObject) => {
3847
3844
  const isMajorVer = isBrotliSupported();
3848
3845
  if (isMajorVer && typeof zlibObject.brotliCompressSync === "function") {
@@ -3851,7 +3848,7 @@ const getBrotliCompressSync = (zlibObject) => {
3851
3848
  }
3852
3849
  return null;
3853
3850
  };
3854
- // eslint-disable-next-line @typescript-eslint/ban-types
3851
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
3855
3852
  const getBrotliDecompressSync = (zlibObject) => {
3856
3853
  const isMajorVer = isBrotliSupported();
3857
3854
  if (isMajorVer && typeof zlibObject.brotliDecompressSync === "function") {
@@ -3923,7 +3920,7 @@ const isContentTypeHeaderHtml = (response) => {
3923
3920
  };
3924
3921
 
3925
3922
  // Copyright (c) Microsoft Corporation.
3926
- // Licensed under the MIT license.
3923
+ // Licensed under the MIT License.
3927
3924
  /* eslint-disable no-underscore-dangle*/
3928
3925
  class BrowserSdkLoader {
3929
3926
  constructor(config) {
@@ -3997,7 +3994,7 @@ class BrowserSdkLoader {
3997
3994
  // eslint-disable-next-line @typescript-eslint/unbound-method
3998
3995
  const originalResponseWrite = response.write;
3999
3996
  const isGetRequest = request.method === "GET";
4000
- // eslint-disable-next-line @typescript-eslint/ban-types
3997
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
4001
3998
  response.write = function wrap(a, b) {
4002
3999
  var _a, _b;
4003
4000
  // only patch GET request
@@ -4030,7 +4027,7 @@ class BrowserSdkLoader {
4030
4027
  // Patch response end method for cases when HTML is added there
4031
4028
  // eslint-disable-next-line @typescript-eslint/unbound-method
4032
4029
  const originalResponseEnd = response.end;
4033
- // eslint-disable-next-line @typescript-eslint/ban-types, @typescript-eslint/no-redundant-type-constituents
4030
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type, @typescript-eslint/no-redundant-type-constituents
4034
4031
  response.end = function wrap(a, b) {
4035
4032
  var _a, _b;
4036
4033
  if (isGetRequest) {
@@ -4073,7 +4070,7 @@ class BrowserSdkLoader {
4073
4070
  const isGetHttpsRequest = req.method === "GET";
4074
4071
  const originalHttpsResponseWrite = res.write;
4075
4072
  const originalHttpsResponseEnd = res.end;
4076
- // eslint-disable-next-line @typescript-eslint/ban-types, @typescript-eslint/no-redundant-type-constituents
4073
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type, @typescript-eslint/no-redundant-type-constituents
4077
4074
  res.write = function wrap(a, b) {
4078
4075
  var _a, _b;
4079
4076
  try {
@@ -4102,7 +4099,7 @@ class BrowserSdkLoader {
4102
4099
  // eslint-disable-next-line prefer-rest-params, @typescript-eslint/no-unsafe-return
4103
4100
  return originalHttpsResponseWrite.apply(res, arguments);
4104
4101
  };
4105
- // eslint-disable-next-line @typescript-eslint/ban-types, @typescript-eslint/no-redundant-type-constituents
4102
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type, @typescript-eslint/no-redundant-type-constituents
4106
4103
  res.end = function wrap(a, b) {
4107
4104
  var _a, _b;
4108
4105
  try {
@@ -4255,7 +4252,7 @@ class BrowserSdkLoader {
4255
4252
  }
4256
4253
 
4257
4254
  // Copyright (c) Microsoft Corporation.
4258
- // Licensed under the MIT license.
4255
+ // Licensed under the MIT License.
4259
4256
  /**
4260
4257
  * Patch OpenTelemetry Instrumentation enablement to update the statsbeat environment variable with the enabled instrumentations
4261
4258
  * @internal
@@ -4263,9 +4260,9 @@ class BrowserSdkLoader {
4263
4260
  function patchOpenTelemetryInstrumentationEnable() {
4264
4261
  const emptyStatsbeatConfig = JSON.stringify({ instrumentation: 0, feature: 0 });
4265
4262
  try {
4266
- require.resolve("../../../@opentelemetry/instrumentation");
4263
+ require.resolve("@opentelemetry/instrumentation");
4267
4264
  // eslint-disable-next-line @typescript-eslint/no-require-imports
4268
- const autoLoaderUtils = require("../../../@opentelemetry/instrumentation/build/src/autoLoaderUtils");
4265
+ const autoLoaderUtils = require("@opentelemetry/instrumentation/build/src/autoLoaderUtils");
4269
4266
  const originalModuleDefinition = autoLoaderUtils.enableInstrumentations;
4270
4267
  // Parses the enabled instrumentations and then ammends the statsbeat instrumentation environment variable
4271
4268
  autoLoaderUtils.enableInstrumentations = function (instrumentations) {
@@ -4294,7 +4291,7 @@ function patchOpenTelemetryInstrumentationEnable() {
4294
4291
  }
4295
4292
 
4296
4293
  // Copyright (c) Microsoft Corporation.
4297
- // Licensed under the MIT license.
4294
+ // Licensed under the MIT License.
4298
4295
  process.env["AZURE_MONITOR_DISTRO_VERSION"] = AZURE_MONITOR_OPENTELEMETRY_VERSION;
4299
4296
  let sdk;
4300
4297
  let browserSdkLoader;
@@ -1,5 +1,5 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT license.
2
+ // Licensed under the MIT License.
3
3
  /* eslint-disable no-underscore-dangle*/
4
4
  import http from "http";
5
5
  import https from "https";
@@ -83,7 +83,7 @@ export class BrowserSdkLoader {
83
83
  // eslint-disable-next-line @typescript-eslint/unbound-method
84
84
  const originalResponseWrite = response.write;
85
85
  const isGetRequest = request.method === "GET";
86
- // eslint-disable-next-line @typescript-eslint/ban-types
86
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
87
87
  response.write = function wrap(a, b) {
88
88
  var _a, _b;
89
89
  // only patch GET request
@@ -116,7 +116,7 @@ export class BrowserSdkLoader {
116
116
  // Patch response end method for cases when HTML is added there
117
117
  // eslint-disable-next-line @typescript-eslint/unbound-method
118
118
  const originalResponseEnd = response.end;
119
- // eslint-disable-next-line @typescript-eslint/ban-types, @typescript-eslint/no-redundant-type-constituents
119
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type, @typescript-eslint/no-redundant-type-constituents
120
120
  response.end = function wrap(a, b) {
121
121
  var _a, _b;
122
122
  if (isGetRequest) {
@@ -159,7 +159,7 @@ export class BrowserSdkLoader {
159
159
  const isGetHttpsRequest = req.method === "GET";
160
160
  const originalHttpsResponseWrite = res.write;
161
161
  const originalHttpsResponseEnd = res.end;
162
- // eslint-disable-next-line @typescript-eslint/ban-types, @typescript-eslint/no-redundant-type-constituents
162
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type, @typescript-eslint/no-redundant-type-constituents
163
163
  res.write = function wrap(a, b) {
164
164
  var _a, _b;
165
165
  try {
@@ -188,7 +188,7 @@ export class BrowserSdkLoader {
188
188
  // eslint-disable-next-line prefer-rest-params, @typescript-eslint/no-unsafe-return
189
189
  return originalHttpsResponseWrite.apply(res, arguments);
190
190
  };
191
- // eslint-disable-next-line @typescript-eslint/ban-types, @typescript-eslint/no-redundant-type-constituents
191
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type, @typescript-eslint/no-redundant-type-constituents
192
192
  res.end = function wrap(a, b) {
193
193
  var _a, _b;
194
194
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"browserSdkLoader.js","sourceRoot":"","sources":["../../../src/browserSdkLoader/browserSdkLoader.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,wCAAwC;AAExC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,UAAU,IAAI,SAAS,EAAE,MAAM,4CAA4C,CAAC;AACrF,OAAO,KAAK,sBAAsB,MAAM,0BAA0B,CAAC;AACnE,OAAO,KAAK,YAAY,MAAM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AAK,CAAC,CAAC;wBACrD,IAAI,IAAI,CAAC,iBAAiB,CAAC,QAAQ,EAAE,gBAAgB,CAAC,EAAE,CAAC;4BACvD,MAAM,wBAAwB,GAAG,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;4BAClF,KAAK,GAAG,kBAAkB,CAAC,wBAAwB,CAAC,CAAC;wBACvD,CAAC;wBACD,MAAM;oBACR,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC,iDAAiD,GAAG,EAAE,CAAC,CAAC;QACpF,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAEM,OAAO;QACZ,gBAAgB,CAAC,SAAS,GAAG,IAAI,CAAC;QAClC,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC;IAC9B,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/* eslint-disable no-underscore-dangle*/\n\nimport http from \"http\";\nimport https from \"https\";\nimport { webSnippet as sdkLoader } from \"@microsoft/applicationinsights-web-snippet\";\nimport * as browserSdkLoaderHelper from \"./browserSdkLoaderHelper\";\nimport * as prefixHelper from \"../utils/common\";\nimport * as zlib from \"zlib\";\nimport { InternalConfig } from \"../shared\";\nimport { ConnectionStringParser } from \"../utils/connectionStringParser\";\nimport { IncomingMessage, ServerResponse } from \"http\";\nimport { Logger } from \"../shared/logging/logger\";\nimport { BROWSER_SDK_LOADER_DEFAULT_SOURCE } from \"../types\";\nimport { diag } from \"@opentelemetry/api\";\n\nexport class BrowserSdkLoader {\n private static _instance: BrowserSdkLoader | null;\n\n private static _sdkLoader: string;\n private static _aiUrl: string;\n private _isIkeyValid: boolean = true;\n private _isInitialized: boolean = false;\n private _browserSdkLoaderIkey?: string;\n\n constructor(config: InternalConfig) {\n if (BrowserSdkLoader._instance) {\n diag.warn(\"Browser SDK Loader should be configured from the applicationInsights object\");\n }\n\n BrowserSdkLoader._instance = this;\n // AI URL used to validate if sdk loader already included\n BrowserSdkLoader._aiUrl = BROWSER_SDK_LOADER_DEFAULT_SOURCE;\n let clientWebIkey;\n if (config.browserSdkLoaderOptions?.connectionString) {\n clientWebIkey = this._getBrowserSdkLoaderIkey(\n config?.browserSdkLoaderOptions?.connectionString,\n );\n }\n this._browserSdkLoaderIkey =\n clientWebIkey ||\n ConnectionStringParser.parse(config.azureMonitorExporterOptions.connectionString)\n .instrumentationkey;\n\n if (this._isIkeyValid) {\n this._initialize();\n }\n }\n\n public isInitialized(): boolean {\n return this._isInitialized;\n }\n\n public static getInstance(): BrowserSdkLoader {\n return BrowserSdkLoader._instance!;\n }\n\n private _getBrowserSdkLoaderIkey(connectionString: string): string | null {\n let iKey = null;\n try {\n const csCode = ConnectionStringParser.parse(connectionString);\n const iKeyCode = csCode.instrumentationkey || \"\";\n if (!ConnectionStringParser.validateInstrumentationKey(iKeyCode)) {\n this._isIkeyValid = false;\n Logger.getInstance().info(\n \"Invalid browser SDK loader connection string, browser SDK loader is not enabled.\",\n );\n } else {\n this._isIkeyValid = true;\n iKey = iKeyCode;\n }\n } catch (err) {\n Logger.getInstance().info(`get browser SDK loader ikey error: ${err}`);\n }\n return iKey;\n }\n\n /**\n * Gets string to inject into the web page\n * @returns The string to inject into the web page\n */\n private _getBrowserSdkLoaderReplacedStr(): string {\n const osStr = prefixHelper.getOsPrefix();\n const rpStr = prefixHelper.getResourceProvider();\n const sdkLoaderReplacedStr = `${this._browserSdkLoaderIkey}\",\\r\\n disableIkeyDeprecationMessage: true,\\r\\n sdkExtension: \"${rpStr}${osStr}d_n_`;\n const replacedSdkLoader = sdkLoader.replace(\"INSTRUMENTATION_KEY\", sdkLoaderReplacedStr);\n return replacedSdkLoader;\n }\n\n private _initialize(): void {\n this._isInitialized = true;\n BrowserSdkLoader._sdkLoader = this._getBrowserSdkLoaderReplacedStr();\n const originalHttpServer = http.createServer;\n const originalHttpsServer = https.createServer;\n\n (http.createServer as any) = (\n requestListener?: (request: IncomingMessage, response: ServerResponse) => void,\n ) => {\n const originalRequestListener = requestListener;\n if (originalRequestListener) {\n requestListener = (request: IncomingMessage, response: ServerResponse) => {\n // Patch response write method\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const originalResponseWrite = response.write;\n const isGetRequest = request.method === \"GET\";\n // eslint-disable-next-line @typescript-eslint/ban-types\n response.write = function wrap(a: Buffer | string, b?: Function | string) {\n // only patch GET request\n try {\n if (isGetRequest) {\n const headers = browserSdkLoaderHelper.getContentEncodingFromHeaders(response);\n let writeBufferType = undefined;\n if (typeof b === \"string\") {\n writeBufferType = b;\n }\n if (headers === null || headers === undefined) {\n if (BrowserSdkLoader._instance?.ValidateInjection(response, a)) {\n // eslint-disable-next-line prefer-rest-params\n arguments[0] = BrowserSdkLoader._instance.InjectSdkLoader(\n response,\n a,\n undefined,\n writeBufferType,\n );\n }\n } else if (headers.length) {\n const encodeType = headers[0];\n // eslint-disable-next-line prefer-rest-params\n arguments[0] = BrowserSdkLoader._instance?.InjectSdkLoader(\n response,\n a,\n encodeType,\n );\n }\n }\n } catch (err) {\n Logger.getInstance().warn(`Inject browser sdk loader error: ${err}`);\n }\n // eslint-disable-next-line prefer-rest-params\n return originalResponseWrite.apply(response, arguments as any);\n };\n\n // Patch response end method for cases when HTML is added there\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const originalResponseEnd = response.end;\n\n // eslint-disable-next-line @typescript-eslint/ban-types, @typescript-eslint/no-redundant-type-constituents\n (response.end as any) = function wrap(a?: Buffer | string | any, b?: Function) {\n if (isGetRequest) {\n try {\n if (isGetRequest) {\n const headers = browserSdkLoaderHelper.getContentEncodingFromHeaders(response);\n let endBufferType = undefined;\n if (typeof b === \"string\") {\n endBufferType = b;\n }\n if (headers === null || headers === undefined) {\n if (BrowserSdkLoader._instance?.ValidateInjection(response, a)) {\n // eslint-disable-next-line prefer-rest-params\n arguments[0] = BrowserSdkLoader._instance.InjectSdkLoader(\n response,\n a,\n undefined,\n endBufferType,\n );\n }\n } else if (headers.length) {\n const encodeType = headers[0];\n // eslint-disable-next-line prefer-rest-params\n arguments[0] = BrowserSdkLoader._instance?.InjectSdkLoader(\n response,\n a,\n encodeType,\n );\n }\n }\n } catch (err) {\n Logger.getInstance().warn(`Inject browser sdk loader error: ${err}`);\n }\n }\n // eslint-disable-next-line prefer-rest-params\n return originalResponseEnd.apply(response, arguments as any);\n };\n\n return originalRequestListener(request, response);\n };\n }\n return originalHttpServer(requestListener);\n };\n\n (https.createServer as any) = function (options: any, httpsRequestListener: any): any {\n const originalHttpsRequestListener = httpsRequestListener;\n if (originalHttpsRequestListener) {\n httpsRequestListener = function (req: any, res: any) {\n const isGetHttpsRequest = req.method === \"GET\";\n const originalHttpsResponseWrite = res.write;\n const originalHttpsResponseEnd = res.end;\n // eslint-disable-next-line @typescript-eslint/ban-types, @typescript-eslint/no-redundant-type-constituents\n res.write = function wrap(a: Buffer | string | any, b?: Function | string) {\n try {\n if (isGetHttpsRequest) {\n const headers = browserSdkLoaderHelper.getContentEncodingFromHeaders(res);\n let writeBufferType = undefined;\n if (typeof b === \"string\") {\n writeBufferType = b;\n }\n if (headers === null || headers === undefined) {\n if (BrowserSdkLoader._instance?.ValidateInjection(res, a)) {\n // eslint-disable-next-line prefer-rest-params\n arguments[0] = this.InjectSdkLoader(res, a, undefined, writeBufferType);\n }\n } else if (headers.length) {\n const encodeType = headers[0];\n // eslint-disable-next-line prefer-rest-params\n arguments[0] = BrowserSdkLoader._instance?.InjectSdkLoader(res, a, encodeType);\n }\n }\n } catch (err) {\n Logger.getInstance().warn(`Inject SDK loader error: ${err}`);\n }\n // eslint-disable-next-line prefer-rest-params, @typescript-eslint/no-unsafe-return\n return originalHttpsResponseWrite.apply(res, arguments);\n };\n\n // eslint-disable-next-line @typescript-eslint/ban-types, @typescript-eslint/no-redundant-type-constituents\n res.end = function wrap(a: Buffer | string | any, b?: Function | string) {\n try {\n if (isGetHttpsRequest) {\n const headers = browserSdkLoaderHelper.getContentEncodingFromHeaders(res);\n let endBufferType = undefined;\n if (typeof b === \"string\") {\n endBufferType = b;\n }\n if (headers === null || headers === undefined) {\n if (BrowserSdkLoader._instance?.ValidateInjection(res, a)) {\n // eslint-disable-next-line prefer-rest-params\n arguments[0] = BrowserSdkLoader._instance.InjectSdkLoader(\n res,\n a,\n undefined,\n endBufferType,\n );\n }\n } else if (headers.length) {\n const encodeType = headers[0];\n // eslint-disable-next-line prefer-rest-params\n arguments[0] = BrowserSdkLoader._instance?.InjectSdkLoader(res, a, encodeType);\n }\n }\n } catch (err) {\n Logger.getInstance().warn(`Inject SDK loader error: ${err}`);\n }\n // eslint-disable-next-line prefer-rest-params, @typescript-eslint/no-unsafe-return\n return originalHttpsResponseEnd.apply(res, arguments);\n };\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return originalHttpsRequestListener(req, res);\n };\n return originalHttpsServer(options, httpsRequestListener);\n }\n };\n }\n\n /**\n * Validate response and try to inject Browser SDK Loader\n */\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\n public ValidateInjection(response: any, input: string | Buffer): boolean {\n try {\n if (!response || !input || response.statusCode !== 200) return false;\n const isContentHtml = browserSdkLoaderHelper.isContentTypeHeaderHtml(response);\n if (!isContentHtml) return false;\n const inputStr = input.slice().toString();\n if (inputStr.indexOf(\"<head>\") >= 0 && inputStr.indexOf(\"</head>\") >= 0) {\n // Check if sdk loader not already present looking for AI Web SDK URL\n if (inputStr.indexOf(BrowserSdkLoader._aiUrl) < 0) {\n return true;\n }\n }\n } catch (err) {\n Logger.getInstance().info(`validate injections error: ${err}`);\n }\n return false;\n }\n\n /**\n * Inject Browser SDK Loader\n */\n public InjectSdkLoader(\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\n response: any,\n input: string | Buffer,\n encodeType?: browserSdkLoaderHelper.contentEncodingMethod,\n bufferEncodeType?: string,\n ): string | Buffer {\n try {\n const isCompressedBuffer = !!encodeType;\n if (!isCompressedBuffer) {\n const html = input.toString();\n const index = html.indexOf(\"</head>\");\n if (index < 0) return input;\n\n const newHtml = browserSdkLoaderHelper.insertBrowserSdkLoaderByIndex(\n index,\n html,\n BrowserSdkLoader._sdkLoader,\n );\n if (typeof input === \"string\") {\n response.removeHeader(\"Content-Length\");\n if (newHtml) {\n input = newHtml;\n }\n response.setHeader(\"Content-Length\", Buffer.byteLength(input));\n } else if (Buffer.isBuffer(input)) {\n const bufferType = bufferEncodeType ? bufferEncodeType : \"utf8\";\n const isValidBufferType = browserSdkLoaderHelper.isBufferType(input, bufferType);\n if (isValidBufferType && newHtml) {\n response.removeHeader(\"Content-Length\");\n const encodedString = Buffer.from(newHtml).toString(bufferType as BufferEncoding);\n input = Buffer.from(encodedString, bufferType as BufferEncoding);\n response.setHeader(\"Content-Length\", input.length);\n }\n }\n } else {\n response.removeHeader(\"Content-Length\");\n input = this._getInjectedCompressBuffer(response, input as Buffer, encodeType);\n response.setHeader(\"Content-Length\", input.length);\n }\n } catch (ex) {\n Logger.getInstance().warn(\n `Failed to inject browser sdk loader and change content-length headers. Exception:${ex}`,\n );\n }\n return input;\n }\n\n //* **********************\n // should NOT use sync functions here. But currently cannot get async functions to work\n // because reponse.write return boolean\n // and also this function do not support partial compression as well\n // need more investigation\n private _getInjectedCompressBuffer(\n response: any,\n input: Buffer,\n encodeType: browserSdkLoaderHelper.contentEncodingMethod,\n ): Buffer {\n try {\n switch (encodeType) {\n case browserSdkLoaderHelper.contentEncodingMethod.GZIP: {\n const gunzipBuffer = zlib.gunzipSync(input);\n if (this.ValidateInjection(response, gunzipBuffer)) {\n const injectedGunzipBuffer = this.InjectSdkLoader(response, gunzipBuffer);\n input = zlib.gzipSync(injectedGunzipBuffer);\n }\n break;\n }\n case browserSdkLoaderHelper.contentEncodingMethod.DEFLATE: {\n const inflateBuffer = zlib.inflateSync(input);\n if (this.ValidateInjection(response, inflateBuffer)) {\n const injectedInflateBuffer = this.InjectSdkLoader(response, inflateBuffer);\n input = zlib.deflateSync(injectedInflateBuffer);\n }\n break;\n }\n case browserSdkLoaderHelper.contentEncodingMethod.BR: {\n const BrotliDecompressSync = browserSdkLoaderHelper.getBrotliDecompressSync(zlib);\n const BrotliCompressSync = browserSdkLoaderHelper.getBrotliCompressSync(zlib);\n if (BrotliDecompressSync && BrotliCompressSync) {\n const decompressBuffer = BrotliDecompressSync(input);\n if (this.ValidateInjection(response, decompressBuffer)) {\n const injectedDecompressBuffer = this.InjectSdkLoader(response, decompressBuffer);\n input = BrotliCompressSync(injectedDecompressBuffer);\n }\n break;\n }\n }\n }\n } catch (err) {\n Logger.getInstance().info(`get browser SDK loader compress buffer error: ${err}`);\n }\n\n return input;\n }\n\n public dispose(): void {\n BrowserSdkLoader._instance = null;\n this._isInitialized = false;\n }\n}\n"]}
1
+ {"version":3,"file":"browserSdkLoader.js","sourceRoot":"","sources":["../../../src/browserSdkLoader/browserSdkLoader.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,wCAAwC;AAExC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,UAAU,IAAI,SAAS,EAAE,MAAM,4CAA4C,CAAC;AACrF,OAAO,KAAK,sBAAsB,MAAM,0BAA0B,CAAC;AACnE,OAAO,KAAK,YAAY,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAEzE,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,iCAAiC,EAAE,MAAM,UAAU,CAAC;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE1C,MAAM,OAAO,gBAAgB;IAS3B,YAAY,MAAsB;;QAJ1B,iBAAY,GAAY,IAAI,CAAC;QAC7B,mBAAc,GAAY,KAAK,C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AC,iDAAiD,GAAG,EAAE,CAAC,CAAC;QACpF,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAEM,OAAO;QACZ,gBAAgB,CAAC,SAAS,GAAG,IAAI,CAAC;QAClC,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC;IAC9B,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/* eslint-disable no-underscore-dangle*/\n\nimport http from \"http\";\nimport https from \"https\";\nimport { webSnippet as sdkLoader } from \"@microsoft/applicationinsights-web-snippet\";\nimport * as browserSdkLoaderHelper from \"./browserSdkLoaderHelper\";\nimport * as prefixHelper from \"../utils/common\";\nimport * as zlib from \"zlib\";\nimport { InternalConfig } from \"../shared\";\nimport { ConnectionStringParser } from \"../utils/connectionStringParser\";\nimport { IncomingMessage, ServerResponse } from \"http\";\nimport { Logger } from \"../shared/logging/logger\";\nimport { BROWSER_SDK_LOADER_DEFAULT_SOURCE } from \"../types\";\nimport { diag } from \"@opentelemetry/api\";\n\nexport class BrowserSdkLoader {\n private static _instance: BrowserSdkLoader | null;\n\n private static _sdkLoader: string;\n private static _aiUrl: string;\n private _isIkeyValid: boolean = true;\n private _isInitialized: boolean = false;\n private _browserSdkLoaderIkey?: string;\n\n constructor(config: InternalConfig) {\n if (BrowserSdkLoader._instance) {\n diag.warn(\"Browser SDK Loader should be configured from the applicationInsights object\");\n }\n\n BrowserSdkLoader._instance = this;\n // AI URL used to validate if sdk loader already included\n BrowserSdkLoader._aiUrl = BROWSER_SDK_LOADER_DEFAULT_SOURCE;\n let clientWebIkey;\n if (config.browserSdkLoaderOptions?.connectionString) {\n clientWebIkey = this._getBrowserSdkLoaderIkey(\n config?.browserSdkLoaderOptions?.connectionString,\n );\n }\n this._browserSdkLoaderIkey =\n clientWebIkey ||\n ConnectionStringParser.parse(config.azureMonitorExporterOptions.connectionString)\n .instrumentationkey;\n\n if (this._isIkeyValid) {\n this._initialize();\n }\n }\n\n public isInitialized(): boolean {\n return this._isInitialized;\n }\n\n public static getInstance(): BrowserSdkLoader {\n return BrowserSdkLoader._instance!;\n }\n\n private _getBrowserSdkLoaderIkey(connectionString: string): string | null {\n let iKey = null;\n try {\n const csCode = ConnectionStringParser.parse(connectionString);\n const iKeyCode = csCode.instrumentationkey || \"\";\n if (!ConnectionStringParser.validateInstrumentationKey(iKeyCode)) {\n this._isIkeyValid = false;\n Logger.getInstance().info(\n \"Invalid browser SDK loader connection string, browser SDK loader is not enabled.\",\n );\n } else {\n this._isIkeyValid = true;\n iKey = iKeyCode;\n }\n } catch (err) {\n Logger.getInstance().info(`get browser SDK loader ikey error: ${err}`);\n }\n return iKey;\n }\n\n /**\n * Gets string to inject into the web page\n * @returns The string to inject into the web page\n */\n private _getBrowserSdkLoaderReplacedStr(): string {\n const osStr = prefixHelper.getOsPrefix();\n const rpStr = prefixHelper.getResourceProvider();\n const sdkLoaderReplacedStr = `${this._browserSdkLoaderIkey}\",\\r\\n disableIkeyDeprecationMessage: true,\\r\\n sdkExtension: \"${rpStr}${osStr}d_n_`;\n const replacedSdkLoader = sdkLoader.replace(\"INSTRUMENTATION_KEY\", sdkLoaderReplacedStr);\n return replacedSdkLoader;\n }\n\n private _initialize(): void {\n this._isInitialized = true;\n BrowserSdkLoader._sdkLoader = this._getBrowserSdkLoaderReplacedStr();\n const originalHttpServer = http.createServer;\n const originalHttpsServer = https.createServer;\n\n (http.createServer as any) = (\n requestListener?: (request: IncomingMessage, response: ServerResponse) => void,\n ) => {\n const originalRequestListener = requestListener;\n if (originalRequestListener) {\n requestListener = (request: IncomingMessage, response: ServerResponse) => {\n // Patch response write method\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const originalResponseWrite = response.write;\n const isGetRequest = request.method === \"GET\";\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n response.write = function wrap(a: Buffer | string, b?: Function | string) {\n // only patch GET request\n try {\n if (isGetRequest) {\n const headers = browserSdkLoaderHelper.getContentEncodingFromHeaders(response);\n let writeBufferType = undefined;\n if (typeof b === \"string\") {\n writeBufferType = b;\n }\n if (headers === null || headers === undefined) {\n if (BrowserSdkLoader._instance?.ValidateInjection(response, a)) {\n // eslint-disable-next-line prefer-rest-params\n arguments[0] = BrowserSdkLoader._instance.InjectSdkLoader(\n response,\n a,\n undefined,\n writeBufferType,\n );\n }\n } else if (headers.length) {\n const encodeType = headers[0];\n // eslint-disable-next-line prefer-rest-params\n arguments[0] = BrowserSdkLoader._instance?.InjectSdkLoader(\n response,\n a,\n encodeType,\n );\n }\n }\n } catch (err) {\n Logger.getInstance().warn(`Inject browser sdk loader error: ${err}`);\n }\n // eslint-disable-next-line prefer-rest-params\n return originalResponseWrite.apply(response, arguments as any);\n };\n\n // Patch response end method for cases when HTML is added there\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const originalResponseEnd = response.end;\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type, @typescript-eslint/no-redundant-type-constituents\n (response.end as any) = function wrap(a?: Buffer | string | any, b?: Function) {\n if (isGetRequest) {\n try {\n if (isGetRequest) {\n const headers = browserSdkLoaderHelper.getContentEncodingFromHeaders(response);\n let endBufferType = undefined;\n if (typeof b === \"string\") {\n endBufferType = b;\n }\n if (headers === null || headers === undefined) {\n if (BrowserSdkLoader._instance?.ValidateInjection(response, a)) {\n // eslint-disable-next-line prefer-rest-params\n arguments[0] = BrowserSdkLoader._instance.InjectSdkLoader(\n response,\n a,\n undefined,\n endBufferType,\n );\n }\n } else if (headers.length) {\n const encodeType = headers[0];\n // eslint-disable-next-line prefer-rest-params\n arguments[0] = BrowserSdkLoader._instance?.InjectSdkLoader(\n response,\n a,\n encodeType,\n );\n }\n }\n } catch (err) {\n Logger.getInstance().warn(`Inject browser sdk loader error: ${err}`);\n }\n }\n // eslint-disable-next-line prefer-rest-params\n return originalResponseEnd.apply(response, arguments as any);\n };\n\n return originalRequestListener(request, response);\n };\n }\n return originalHttpServer(requestListener);\n };\n\n (https.createServer as any) = function (options: any, httpsRequestListener: any): any {\n const originalHttpsRequestListener = httpsRequestListener;\n if (originalHttpsRequestListener) {\n httpsRequestListener = function (req: any, res: any) {\n const isGetHttpsRequest = req.method === \"GET\";\n const originalHttpsResponseWrite = res.write;\n const originalHttpsResponseEnd = res.end;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type, @typescript-eslint/no-redundant-type-constituents\n res.write = function wrap(a: Buffer | string | any, b?: Function | string) {\n try {\n if (isGetHttpsRequest) {\n const headers = browserSdkLoaderHelper.getContentEncodingFromHeaders(res);\n let writeBufferType = undefined;\n if (typeof b === \"string\") {\n writeBufferType = b;\n }\n if (headers === null || headers === undefined) {\n if (BrowserSdkLoader._instance?.ValidateInjection(res, a)) {\n // eslint-disable-next-line prefer-rest-params\n arguments[0] = this.InjectSdkLoader(res, a, undefined, writeBufferType);\n }\n } else if (headers.length) {\n const encodeType = headers[0];\n // eslint-disable-next-line prefer-rest-params\n arguments[0] = BrowserSdkLoader._instance?.InjectSdkLoader(res, a, encodeType);\n }\n }\n } catch (err) {\n Logger.getInstance().warn(`Inject SDK loader error: ${err}`);\n }\n // eslint-disable-next-line prefer-rest-params, @typescript-eslint/no-unsafe-return\n return originalHttpsResponseWrite.apply(res, arguments);\n };\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type, @typescript-eslint/no-redundant-type-constituents\n res.end = function wrap(a: Buffer | string | any, b?: Function | string) {\n try {\n if (isGetHttpsRequest) {\n const headers = browserSdkLoaderHelper.getContentEncodingFromHeaders(res);\n let endBufferType = undefined;\n if (typeof b === \"string\") {\n endBufferType = b;\n }\n if (headers === null || headers === undefined) {\n if (BrowserSdkLoader._instance?.ValidateInjection(res, a)) {\n // eslint-disable-next-line prefer-rest-params\n arguments[0] = BrowserSdkLoader._instance.InjectSdkLoader(\n res,\n a,\n undefined,\n endBufferType,\n );\n }\n } else if (headers.length) {\n const encodeType = headers[0];\n // eslint-disable-next-line prefer-rest-params\n arguments[0] = BrowserSdkLoader._instance?.InjectSdkLoader(res, a, encodeType);\n }\n }\n } catch (err) {\n Logger.getInstance().warn(`Inject SDK loader error: ${err}`);\n }\n // eslint-disable-next-line prefer-rest-params, @typescript-eslint/no-unsafe-return\n return originalHttpsResponseEnd.apply(res, arguments);\n };\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return originalHttpsRequestListener(req, res);\n };\n return originalHttpsServer(options, httpsRequestListener);\n }\n };\n }\n\n /**\n * Validate response and try to inject Browser SDK Loader\n */\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\n public ValidateInjection(response: any, input: string | Buffer): boolean {\n try {\n if (!response || !input || response.statusCode !== 200) return false;\n const isContentHtml = browserSdkLoaderHelper.isContentTypeHeaderHtml(response);\n if (!isContentHtml) return false;\n const inputStr = input.slice().toString();\n if (inputStr.indexOf(\"<head>\") >= 0 && inputStr.indexOf(\"</head>\") >= 0) {\n // Check if sdk loader not already present looking for AI Web SDK URL\n if (inputStr.indexOf(BrowserSdkLoader._aiUrl) < 0) {\n return true;\n }\n }\n } catch (err) {\n Logger.getInstance().info(`validate injections error: ${err}`);\n }\n return false;\n }\n\n /**\n * Inject Browser SDK Loader\n */\n public InjectSdkLoader(\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\n response: any,\n input: string | Buffer,\n encodeType?: browserSdkLoaderHelper.contentEncodingMethod,\n bufferEncodeType?: string,\n ): string | Buffer {\n try {\n const isCompressedBuffer = !!encodeType;\n if (!isCompressedBuffer) {\n const html = input.toString();\n const index = html.indexOf(\"</head>\");\n if (index < 0) return input;\n\n const newHtml = browserSdkLoaderHelper.insertBrowserSdkLoaderByIndex(\n index,\n html,\n BrowserSdkLoader._sdkLoader,\n );\n if (typeof input === \"string\") {\n response.removeHeader(\"Content-Length\");\n if (newHtml) {\n input = newHtml;\n }\n response.setHeader(\"Content-Length\", Buffer.byteLength(input));\n } else if (Buffer.isBuffer(input)) {\n const bufferType = bufferEncodeType ? bufferEncodeType : \"utf8\";\n const isValidBufferType = browserSdkLoaderHelper.isBufferType(input, bufferType);\n if (isValidBufferType && newHtml) {\n response.removeHeader(\"Content-Length\");\n const encodedString = Buffer.from(newHtml).toString(bufferType as BufferEncoding);\n input = Buffer.from(encodedString, bufferType as BufferEncoding);\n response.setHeader(\"Content-Length\", input.length);\n }\n }\n } else {\n response.removeHeader(\"Content-Length\");\n input = this._getInjectedCompressBuffer(response, input as Buffer, encodeType);\n response.setHeader(\"Content-Length\", input.length);\n }\n } catch (ex) {\n Logger.getInstance().warn(\n `Failed to inject browser sdk loader and change content-length headers. Exception:${ex}`,\n );\n }\n return input;\n }\n\n //* **********************\n // should NOT use sync functions here. But currently cannot get async functions to work\n // because reponse.write return boolean\n // and also this function do not support partial compression as well\n // need more investigation\n private _getInjectedCompressBuffer(\n response: any,\n input: Buffer,\n encodeType: browserSdkLoaderHelper.contentEncodingMethod,\n ): Buffer {\n try {\n switch (encodeType) {\n case browserSdkLoaderHelper.contentEncodingMethod.GZIP: {\n const gunzipBuffer = zlib.gunzipSync(input);\n if (this.ValidateInjection(response, gunzipBuffer)) {\n const injectedGunzipBuffer = this.InjectSdkLoader(response, gunzipBuffer);\n input = zlib.gzipSync(injectedGunzipBuffer);\n }\n break;\n }\n case browserSdkLoaderHelper.contentEncodingMethod.DEFLATE: {\n const inflateBuffer = zlib.inflateSync(input);\n if (this.ValidateInjection(response, inflateBuffer)) {\n const injectedInflateBuffer = this.InjectSdkLoader(response, inflateBuffer);\n input = zlib.deflateSync(injectedInflateBuffer);\n }\n break;\n }\n case browserSdkLoaderHelper.contentEncodingMethod.BR: {\n const BrotliDecompressSync = browserSdkLoaderHelper.getBrotliDecompressSync(zlib);\n const BrotliCompressSync = browserSdkLoaderHelper.getBrotliCompressSync(zlib);\n if (BrotliDecompressSync && BrotliCompressSync) {\n const decompressBuffer = BrotliDecompressSync(input);\n if (this.ValidateInjection(response, decompressBuffer)) {\n const injectedDecompressBuffer = this.InjectSdkLoader(response, decompressBuffer);\n input = BrotliCompressSync(injectedDecompressBuffer);\n }\n break;\n }\n }\n }\n } catch (err) {\n Logger.getInstance().info(`get browser SDK loader compress buffer error: ${err}`);\n }\n\n return input;\n }\n\n public dispose(): void {\n BrowserSdkLoader._instance = null;\n this._isInitialized = false;\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT license.
2
+ // Licensed under the MIT License.
3
3
  /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
4
4
  import * as zlib from "zlib";
5
5
  import { promisify } from "util";
@@ -30,7 +30,7 @@ export const gzipAsync = promisify(zlib.gzip);
30
30
  export const gunzipAsync = promisify(zlib.gunzip);
31
31
  export const deflateAsync = promisify(zlib.deflate);
32
32
  export const inflateAsync = promisify(zlib.inflate);
33
- // eslint-disable-next-line @typescript-eslint/ban-types
33
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
34
34
  export const getBrotliCompressAsync = (zlibObject) => {
35
35
  const isMajorVer = isBrotliSupported();
36
36
  if (isMajorVer && typeof zlibObject.brotliCompress === "function") {
@@ -38,7 +38,7 @@ export const getBrotliCompressAsync = (zlibObject) => {
38
38
  }
39
39
  return null;
40
40
  };
41
- // eslint-disable-next-line @typescript-eslint/ban-types
41
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
42
42
  export const getBrotliCompressSync = (zlibObject) => {
43
43
  const isMajorVer = isBrotliSupported();
44
44
  if (isMajorVer && typeof zlibObject.brotliCompressSync === "function") {
@@ -47,7 +47,7 @@ export const getBrotliCompressSync = (zlibObject) => {
47
47
  }
48
48
  return null;
49
49
  };
50
- // eslint-disable-next-line @typescript-eslint/ban-types
50
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
51
51
  export const getBrotliDecompressAsync = (zlibObject) => {
52
52
  const isMajorVer = isBrotliSupported();
53
53
  if (isMajorVer && typeof zlibObject.brotliDecompress === "function") {
@@ -55,7 +55,7 @@ export const getBrotliDecompressAsync = (zlibObject) => {
55
55
  }
56
56
  return null;
57
57
  };
58
- // eslint-disable-next-line @typescript-eslint/ban-types
58
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
59
59
  export const getBrotliDecompressSync = (zlibObject) => {
60
60
  const isMajorVer = isBrotliSupported();
61
61
  if (isMajorVer && typeof zlibObject.brotliDecompressSync === "function") {
@@ -1 +1 @@
1
- {"version":3,"file":"browserSdkLoaderHelper.js","sourceRoot":"","sources":["../../../src/browserSdkLoader/browserSdkLoaderHelper.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,sEAAsE;AAEtE,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAGjC,iDAAiD;AACjD,MAAM,CAAN,IAAY,qBAIX;AAJD,WAAY,qBAAqB;IAC/B,sCAAa,CAAA;IACb,4CAAmB,CAAA;IACnB,kCAAS,CAAA;AACX,CAAC,EAJW,qBAAqB,KAArB,qBAAqB,QAIhC;AAED,mCAAmC;AACnC,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,MAAM;IACN,SAAS;IACT,QAAQ;IACR,QAAQ;IACR,KAAK;IACL,OAAO;IACP,QAAQ;IACR,MAAM;CACP,CAAC;AAEF,kEAAkE;AAClE,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAY,EAAE;IAC7C,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACnD,OAAO,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;AAChC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC9C,MAAM,CAAC,MAAM,WAAW,GAAG,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAClD,MAAM,CAAC,MAAM,YAAY,GAAG,SAAS,CAAC,I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AAI,MAAM,GAAG,KAAK,CAAC;IACnB,MAAM,WAAW,GAAG,QAAQ,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IACvD,IAAI,WAAW,EAAE,CAAC;QAChB,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE,CAAC;YACpC,MAAM,GAAG,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC5C,CAAC;aAAM,CAAC;YACN,MAAM,GAAG,WAAW,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\n\nimport * as zlib from \"zlib\";\nimport { promisify } from \"util\";\nimport * as http from \"http\";\n\n// currently support the following encoding types\nexport enum contentEncodingMethod {\n GZIP = \"gzip\",\n DEFLATE = \"deflate\",\n BR = \"br\",\n}\n\n// current supported encoding types\nexport const bufferEncodingTypes = [\n \"utf8\",\n \"utf16le\",\n \"latin1\",\n \"base64\",\n \"hex\",\n \"ascii\",\n \"binary\",\n \"ucs2\",\n];\n\n// for node version under 10, Brotli compression is not supported.\nexport const isBrotliSupported = (): boolean => {\n const majVer = process.versions.node.split(\".\")[0];\n return parseInt(majVer) >= 10;\n};\n\nexport const gzipAsync = promisify(zlib.gzip);\nexport const gunzipAsync = promisify(zlib.gunzip);\nexport const deflateAsync = promisify(zlib.deflate);\nexport const inflateAsync = promisify(zlib.inflate);\n\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport const getBrotliCompressAsync = (zlibObject: any): Function | null => {\n const isMajorVer = isBrotliSupported();\n if (isMajorVer && typeof zlibObject.brotliCompress === \"function\") {\n return promisify(zlibObject.brotliCompress);\n }\n return null;\n};\n\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport const getBrotliCompressSync = (zlibObject: any): Function | null => {\n const isMajorVer = isBrotliSupported();\n if (isMajorVer && typeof zlibObject.brotliCompressSync === \"function\") {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return zlibObject.brotliCompressSync;\n }\n return null;\n};\n\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport const getBrotliDecompressAsync = (zlibObject: any): Function | null => {\n const isMajorVer = isBrotliSupported();\n if (isMajorVer && typeof zlibObject.brotliDecompress === \"function\") {\n return promisify(zlibObject.brotliDecompress);\n }\n return null;\n};\n\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport const getBrotliDecompressSync = (zlibObject: any): Function | null => {\n const isMajorVer = isBrotliSupported();\n if (isMajorVer && typeof zlibObject.brotliDecompressSync === \"function\") {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return zlibObject.brotliDecompressSync;\n }\n return null;\n};\n\nexport const isBufferType = (buffer: Buffer, type?: string): boolean | null => {\n const encodingType = type ? type : \"utf8\";\n let result = false;\n if (Buffer.isEncoding(encodingType)) {\n const newBuffer = Buffer.from(buffer.toString(encodingType), encodingType);\n result = newBuffer.toJSON().data.toString() === buffer.toJSON().data.toString();\n }\n\n return result;\n};\n\nexport const findBufferEncodingType = (buffer: Buffer): string | null => {\n let bufferType = null;\n for (const type of bufferEncodingTypes) {\n if (Buffer.isEncoding(type) && isBufferType(buffer, type)) {\n bufferType = type;\n break;\n }\n }\n return bufferType;\n};\n\nexport const isSupportedContentEncoding = (\n encodingMethod: string,\n): contentEncodingMethod | null => {\n let encodingType = null;\n switch (encodingMethod) {\n case \"gzip\":\n encodingType = contentEncodingMethod.GZIP;\n break;\n case \"br\":\n encodingType = contentEncodingMethod.BR;\n break;\n case \"deflate\":\n encodingType = contentEncodingMethod.DEFLATE;\n break;\n default:\n }\n return encodingType;\n};\n\n// mutiple content-encoding is not supported\n// for mutiple content-encoding, this method will return any empty array\nexport const getContentEncodingFromHeaders = (\n response: http.ServerResponse,\n): contentEncodingMethod[] | null => {\n const headers: contentEncodingMethod[] = [];\n const contentEncodingHeaders = response.getHeader(\"Content-Encoding\");\n if (!contentEncodingHeaders) return null;\n if (typeof contentEncodingHeaders === \"string\") {\n const supportedContentEncoding = isSupportedContentEncoding(contentEncodingHeaders);\n if (supportedContentEncoding) {\n headers.push(supportedContentEncoding);\n }\n }\n return headers;\n};\n\nexport const insertBrowserSdkLoaderByIndex = (\n index: number,\n html: string,\n snippet: string,\n): string | null => {\n if (index < 0) return null;\n let newHtml = null;\n const subStart = html.substring(0, index);\n const subEnd = html.substring(index);\n newHtml = subStart + '<script type=\"text/javascript\">' + snippet + \"</script>\" + subEnd;\n return newHtml;\n};\n\nexport const isContentTypeHeaderHtml = (response: http.ServerResponse): boolean => {\n let isHtml = false;\n const contentType = response.getHeader(\"Content-Type\");\n if (contentType) {\n if (typeof contentType === \"string\") {\n isHtml = contentType.indexOf(\"html\") >= 0;\n } else {\n isHtml = contentType.toString().indexOf(\"html\") >= 0;\n }\n }\n return isHtml;\n};\n"]}
1
+ {"version":3,"file":"browserSdkLoaderHelper.js","sourceRoot":"","sources":["../../../src/browserSdkLoader/browserSdkLoaderHelper.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,sEAAsE;AAEtE,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAGjC,iDAAiD;AACjD,MAAM,CAAN,IAAY,qBAIX;AAJD,WAAY,qBAAqB;IAC/B,sCAAa,CAAA;IACb,4CAAmB,CAAA;IACnB,kCAAS,CAAA;AACX,CAAC,EAJW,qBAAqB,KAArB,qBAAqB,QAIhC;AAED,mCAAmC;AACnC,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,MAAM;IACN,SAAS;IACT,QAAQ;IACR,QAAQ;IACR,KAAK;IACL,OAAO;IACP,QAAQ;IACR,MAAM;CACP,CAAC;AAEF,kEAAkE;AAClE,MAAM,CAAC,MAAM,iBAA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AG,CAAC;QAAE,OAAO,IAAI,CAAC;IAC3B,IAAI,OAAO,GAAG,IAAI,CAAC;IACnB,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IAC1C,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACrC,OAAO,GAAG,QAAQ,GAAG,iCAAiC,GAAG,OAAO,GAAG,WAAW,GAAG,MAAM,CAAC;IACxF,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,QAA6B,EAAW,EAAE;IAChF,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,MAAM,WAAW,GAAG,QAAQ,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IACvD,IAAI,WAAW,EAAE,CAAC;QAChB,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE,CAAC;YACpC,MAAM,GAAG,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC5C,CAAC;aAAM,CAAC;YACN,MAAM,GAAG,WAAW,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\n\nimport * as zlib from \"zlib\";\nimport { promisify } from \"util\";\nimport * as http from \"http\";\n\n// currently support the following encoding types\nexport enum contentEncodingMethod {\n GZIP = \"gzip\",\n DEFLATE = \"deflate\",\n BR = \"br\",\n}\n\n// current supported encoding types\nexport const bufferEncodingTypes = [\n \"utf8\",\n \"utf16le\",\n \"latin1\",\n \"base64\",\n \"hex\",\n \"ascii\",\n \"binary\",\n \"ucs2\",\n];\n\n// for node version under 10, Brotli compression is not supported.\nexport const isBrotliSupported = (): boolean => {\n const majVer = process.versions.node.split(\".\")[0];\n return parseInt(majVer) >= 10;\n};\n\nexport const gzipAsync = promisify(zlib.gzip);\nexport const gunzipAsync = promisify(zlib.gunzip);\nexport const deflateAsync = promisify(zlib.deflate);\nexport const inflateAsync = promisify(zlib.inflate);\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const getBrotliCompressAsync = (zlibObject: any): Function | null => {\n const isMajorVer = isBrotliSupported();\n if (isMajorVer && typeof zlibObject.brotliCompress === \"function\") {\n return promisify(zlibObject.brotliCompress);\n }\n return null;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const getBrotliCompressSync = (zlibObject: any): Function | null => {\n const isMajorVer = isBrotliSupported();\n if (isMajorVer && typeof zlibObject.brotliCompressSync === \"function\") {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return zlibObject.brotliCompressSync;\n }\n return null;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const getBrotliDecompressAsync = (zlibObject: any): Function | null => {\n const isMajorVer = isBrotliSupported();\n if (isMajorVer && typeof zlibObject.brotliDecompress === \"function\") {\n return promisify(zlibObject.brotliDecompress);\n }\n return null;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const getBrotliDecompressSync = (zlibObject: any): Function | null => {\n const isMajorVer = isBrotliSupported();\n if (isMajorVer && typeof zlibObject.brotliDecompressSync === \"function\") {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return zlibObject.brotliDecompressSync;\n }\n return null;\n};\n\nexport const isBufferType = (buffer: Buffer, type?: string): boolean | null => {\n const encodingType = type ? type : \"utf8\";\n let result = false;\n if (Buffer.isEncoding(encodingType)) {\n const newBuffer = Buffer.from(buffer.toString(encodingType), encodingType);\n result = newBuffer.toJSON().data.toString() === buffer.toJSON().data.toString();\n }\n\n return result;\n};\n\nexport const findBufferEncodingType = (buffer: Buffer): string | null => {\n let bufferType = null;\n for (const type of bufferEncodingTypes) {\n if (Buffer.isEncoding(type) && isBufferType(buffer, type)) {\n bufferType = type;\n break;\n }\n }\n return bufferType;\n};\n\nexport const isSupportedContentEncoding = (\n encodingMethod: string,\n): contentEncodingMethod | null => {\n let encodingType = null;\n switch (encodingMethod) {\n case \"gzip\":\n encodingType = contentEncodingMethod.GZIP;\n break;\n case \"br\":\n encodingType = contentEncodingMethod.BR;\n break;\n case \"deflate\":\n encodingType = contentEncodingMethod.DEFLATE;\n break;\n default:\n }\n return encodingType;\n};\n\n// mutiple content-encoding is not supported\n// for mutiple content-encoding, this method will return any empty array\nexport const getContentEncodingFromHeaders = (\n response: http.ServerResponse,\n): contentEncodingMethod[] | null => {\n const headers: contentEncodingMethod[] = [];\n const contentEncodingHeaders = response.getHeader(\"Content-Encoding\");\n if (!contentEncodingHeaders) return null;\n if (typeof contentEncodingHeaders === \"string\") {\n const supportedContentEncoding = isSupportedContentEncoding(contentEncodingHeaders);\n if (supportedContentEncoding) {\n headers.push(supportedContentEncoding);\n }\n }\n return headers;\n};\n\nexport const insertBrowserSdkLoaderByIndex = (\n index: number,\n html: string,\n snippet: string,\n): string | null => {\n if (index < 0) return null;\n let newHtml = null;\n const subStart = html.substring(0, index);\n const subEnd = html.substring(index);\n newHtml = subStart + '<script type=\"text/javascript\">' + snippet + \"</script>\" + subEnd;\n return newHtml;\n};\n\nexport const isContentTypeHeaderHtml = (response: http.ServerResponse): boolean => {\n let isHtml = false;\n const contentType = response.getHeader(\"Content-Type\");\n if (contentType) {\n if (typeof contentType === \"string\") {\n isHtml = contentType.indexOf(\"html\") >= 0;\n } else {\n isHtml = contentType.toString().indexOf(\"html\") >= 0;\n }\n }\n return isHtml;\n};\n"]}