@azure/monitor-opentelemetry-exporter 1.0.0-beta.16 → 1.0.0-beta.18

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 (49) hide show
  1. package/README.md +35 -11
  2. package/dist/index.js +444 -377
  3. package/dist-esm/src/Declarations/Contracts/Constants.js.map +1 -1
  4. package/dist-esm/src/export/base.js +10 -4
  5. package/dist-esm/src/export/base.js.map +1 -1
  6. package/dist-esm/src/export/log.js +10 -4
  7. package/dist-esm/src/export/log.js.map +1 -1
  8. package/dist-esm/src/export/metric.js +11 -5
  9. package/dist-esm/src/export/metric.js.map +1 -1
  10. package/dist-esm/src/export/statsbeat/longIntervalStatsbeatMetrics.js +53 -54
  11. package/dist-esm/src/export/statsbeat/longIntervalStatsbeatMetrics.js.map +1 -1
  12. package/dist-esm/src/export/statsbeat/networkStatsbeatMetrics.js +101 -104
  13. package/dist-esm/src/export/statsbeat/networkStatsbeatMetrics.js.map +1 -1
  14. package/dist-esm/src/export/statsbeat/statsbeatExporter.js +7 -2
  15. package/dist-esm/src/export/statsbeat/statsbeatExporter.js.map +1 -1
  16. package/dist-esm/src/export/statsbeat/statsbeatMetrics.js +33 -21
  17. package/dist-esm/src/export/statsbeat/statsbeatMetrics.js.map +1 -1
  18. package/dist-esm/src/export/statsbeat/types.js +11 -8
  19. package/dist-esm/src/export/statsbeat/types.js.map +1 -1
  20. package/dist-esm/src/export/trace.js +14 -8
  21. package/dist-esm/src/export/trace.js.map +1 -1
  22. package/dist-esm/src/generated/applicationInsightsClient.js +1 -1
  23. package/dist-esm/src/generated/applicationInsightsClient.js.map +1 -1
  24. package/dist-esm/src/platform/nodejs/baseSender.js +52 -52
  25. package/dist-esm/src/platform/nodejs/baseSender.js.map +1 -1
  26. package/dist-esm/src/platform/nodejs/context/context.js +4 -5
  27. package/dist-esm/src/platform/nodejs/context/context.js.map +1 -1
  28. package/dist-esm/src/platform/nodejs/httpSender.js +22 -21
  29. package/dist-esm/src/platform/nodejs/httpSender.js.map +1 -1
  30. package/dist-esm/src/platform/nodejs/persist/fileAccessControl.js +6 -7
  31. package/dist-esm/src/platform/nodejs/persist/fileAccessControl.js.map +1 -1
  32. package/dist-esm/src/platform/nodejs/persist/fileSystemPersist.js +1 -2
  33. package/dist-esm/src/platform/nodejs/persist/fileSystemPersist.js.map +1 -1
  34. package/dist-esm/src/sampling.js +17 -17
  35. package/dist-esm/src/sampling.js.map +1 -1
  36. package/dist-esm/src/utils/common.js +5 -5
  37. package/dist-esm/src/utils/common.js.map +1 -1
  38. package/dist-esm/src/utils/connectionStringParser.js +12 -3
  39. package/dist-esm/src/utils/connectionStringParser.js.map +1 -1
  40. package/dist-esm/src/utils/constants/applicationinsights.js +1 -1
  41. package/dist-esm/src/utils/constants/applicationinsights.js.map +1 -1
  42. package/dist-esm/src/utils/logUtils.js +8 -8
  43. package/dist-esm/src/utils/logUtils.js.map +1 -1
  44. package/dist-esm/src/utils/metricUtils.js +6 -6
  45. package/dist-esm/src/utils/metricUtils.js.map +1 -1
  46. package/dist-esm/src/utils/spanUtils.js +22 -21
  47. package/dist-esm/src/utils/spanUtils.js.map +1 -1
  48. package/package.json +24 -23
  49. package/types/monitor-opentelemetry-exporter.d.ts +16 -12
@@ -1,3 +1,5 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT license.
1
3
  export class NetworkStatsbeat {
2
4
  constructor(endpoint, host) {
3
5
  this.endpoint = endpoint;
@@ -19,18 +21,19 @@ export const STATSBEAT_LANGUAGE = "node";
19
21
  export const MAX_STATSBEAT_FAILURES = 3;
20
22
  export const StatsbeatResourceProvider = {
21
23
  appsvc: "appsvc",
24
+ aks: "aks",
22
25
  functions: "functions",
23
26
  vm: "vm",
24
27
  unknown: "unknown",
25
28
  };
26
29
  export var StatsbeatCounter;
27
30
  (function (StatsbeatCounter) {
28
- StatsbeatCounter["SUCCESS_COUNT"] = "Request Success Count";
29
- StatsbeatCounter["FAILURE_COUNT"] = "Request Failure Count";
30
- StatsbeatCounter["RETRY_COUNT"] = "Retry Count";
31
- StatsbeatCounter["THROTTLE_COUNT"] = "Throttle Count";
32
- StatsbeatCounter["EXCEPTION_COUNT"] = "Exception Count";
33
- StatsbeatCounter["AVERAGE_DURATION"] = "Request Duration";
31
+ StatsbeatCounter["SUCCESS_COUNT"] = "Request_Success_Count";
32
+ StatsbeatCounter["FAILURE_COUNT"] = "Request_Failure_Count";
33
+ StatsbeatCounter["RETRY_COUNT"] = "Retry_Count";
34
+ StatsbeatCounter["THROTTLE_COUNT"] = "Throttle_Count";
35
+ StatsbeatCounter["EXCEPTION_COUNT"] = "Exception_Count";
36
+ StatsbeatCounter["AVERAGE_DURATION"] = "Request_Duration";
34
37
  StatsbeatCounter["ATTACH"] = "Attach";
35
38
  StatsbeatCounter["FEATURE"] = "Feature";
36
39
  })(StatsbeatCounter || (StatsbeatCounter = {}));
@@ -55,7 +58,7 @@ export const EU_ENDPOINTS = [
55
58
  ];
56
59
  export var StatsbeatFeatureType;
57
60
  (function (StatsbeatFeatureType) {
58
- StatsbeatFeatureType["FEATURE"] = "Feature";
59
- StatsbeatFeatureType["INSTRUMENTATION"] = "Instrumentation";
61
+ StatsbeatFeatureType[StatsbeatFeatureType["FEATURE"] = 0] = "FEATURE";
62
+ StatsbeatFeatureType[StatsbeatFeatureType["INSTRUMENTATION"] = 1] = "INSTRUMENTATION";
60
63
  })(StatsbeatFeatureType || (StatsbeatFeatureType = {}));
61
64
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/export/statsbeat/types.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,gBAAgB;IA6B3B,YAAY,QAAgB,EAAE,IAAY;QACxC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,iBAAiB,GAAG,CAAC,CAAC;QAC3B,IAAI,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C;AACpI,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,YAAY;IACZ,aAAa;IACb,eAAe;IACf,aAAa;IACb,oBAAoB;IACpB,YAAY;IACZ,YAAY;IACZ,eAAe;IACf,kBAAkB;IAClB,iBAAiB;IACjB,SAAS;IACT,QAAQ;CACT,CAAC;AAmCF,MAAM,CAAN,IAAY,oBAGX;AAHD,WAAY,oBAAoB;IAC9B,2CAAmB,CAAA;IACnB,2DAAmC,CAAA;AACrC,CAAC,EAHW,oBAAoB,KAApB,oBAAoB,QAG/B","sourcesContent":["export class NetworkStatsbeat {\n public time: number | undefined;\n\n public lastTime: number;\n\n public endpoint: string;\n\n public host: string;\n\n public totalRequestCount: number;\n\n public lastRequestCount: number;\n\n public totalSuccesfulRequestCount: number;\n\n public totalFailedRequestCount: { statusCode: number; count: number }[];\n\n public retryCount: { statusCode: number; count: number }[];\n\n public exceptionCount: { exceptionType: string; count: number }[];\n\n public throttleCount: { statusCode: number; count: number }[];\n\n public intervalRequestExecutionTime: number;\n\n public lastIntervalRequestExecutionTime: number;\n\n public averageRequestExecutionTime: number;\n\n constructor(endpoint: string, host: string) {\n this.endpoint = endpoint;\n this.host = host;\n this.totalRequestCount = 0;\n this.totalSuccesfulRequestCount = 0;\n this.totalFailedRequestCount = [];\n this.retryCount = [];\n this.exceptionCount = [];\n this.throttleCount = [];\n this.intervalRequestExecutionTime = 0;\n this.lastIntervalRequestExecutionTime = 0;\n this.lastTime = +new Date();\n this.lastRequestCount = 0;\n this.averageRequestExecutionTime = 0;\n }\n}\n\nexport const STATSBEAT_LANGUAGE = \"node\";\n\nexport const MAX_STATSBEAT_FAILURES = 3;\n\nexport const StatsbeatResourceProvider = {\n appsvc: \"appsvc\",\n functions: \"functions\",\n vm: \"vm\",\n unknown: \"unknown\",\n};\n\nexport enum StatsbeatCounter {\n SUCCESS_COUNT = \"Request Success Count\",\n FAILURE_COUNT = \"Request Failure Count\",\n RETRY_COUNT = \"Retry Count\",\n THROTTLE_COUNT = \"Throttle Count\",\n EXCEPTION_COUNT = \"Exception Count\",\n AVERAGE_DURATION = \"Request Duration\",\n ATTACH = \"Attach\",\n FEATURE = \"Feature\",\n}\n\nexport const AIMS_URI = \"http://169.254.169.254/metadata/instance/compute\";\nexport const AIMS_API_VERSION = \"api-version=2017-12-01\";\nexport const AIMS_FORMAT = \"format=json\";\nexport const NON_EU_CONNECTION_STRING =\n \"InstrumentationKey=c4a29126-a7cb-47e5-b348-11414998b11e;IngestionEndpoint=https://westus-0.in.applicationinsights.azure.com\";\nexport const EU_CONNECTION_STRING =\n \"InstrumentationKey=7dc56bab-3c0c-4e9f-9ebb-d1acadee8d0f;IngestionEndpoint=https://westeurope-5.in.applicationinsights.azure.com\";\nexport const EU_ENDPOINTS = [\n \"westeurope\",\n \"northeurope\",\n \"francecentral\",\n \"francesouth\",\n \"germanywestcentral\",\n \"norwayeast\",\n \"norwaywest\",\n \"swedencentral\",\n \"switzerlandnorth\",\n \"switzerlandwest\",\n \"uksouth\",\n \"ukwest\",\n];\n\nexport interface CommonStatsbeatProperties {\n os: string;\n rp: string;\n cikey: string;\n runtimeVersion: string;\n language: string;\n version: string;\n attach: string;\n}\n\nexport interface AttachStatsbeatProperties {\n rpId: string;\n}\n\nexport interface NetworkStatsbeatProperties {\n endpoint: string;\n host: string;\n}\n\nexport interface StatsbeatOptions {\n instrumentationKey: string;\n endpointUrl: string;\n networkCollectionInterval?: number;\n longCollectionInterval?: number;\n}\n\nexport interface VirtualMachineInfo {\n isVM?: boolean;\n id?: string;\n subscriptionId?: string;\n osType?: string;\n}\n\nexport enum StatsbeatFeatureType {\n FEATURE = \"Feature\",\n INSTRUMENTATION = \"Instrumentation\",\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/export/statsbeat/types.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,MAAM,OAAO,gBAAgB;IA6B3B,YAAY,QAAgB,EAAE,IAAY;QACxC,IAAI,CA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AACzD,MAAM,CAAC,MAAM,WAAW,GAAG,aAAa,CAAC;AACzC,MAAM,CAAC,MAAM,wBAAwB,GACnC,6HAA6H,CAAC;AAChI,MAAM,CAAC,MAAM,oBAAoB,GAC/B,iIAAiI,CAAC;AACpI,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,YAAY;IACZ,aAAa;IACb,eAAe;IACf,aAAa;IACb,oBAAoB;IACpB,YAAY;IACZ,YAAY;IACZ,eAAe;IACf,kBAAkB;IAClB,iBAAiB;IACjB,SAAS;IACT,QAAQ;CACT,CAAC;AAmCF,MAAM,CAAN,IAAY,oBAGX;AAHD,WAAY,oBAAoB;IAC9B,qEAAW,CAAA;IACX,qFAAmB,CAAA;AACrB,CAAC,EAHW,oBAAoB,KAApB,oBAAoB,QAG/B","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport class NetworkStatsbeat {\n public time: number | undefined;\n\n public lastTime: number;\n\n public endpoint: string;\n\n public host: string;\n\n public totalRequestCount: number;\n\n public lastRequestCount: number;\n\n public totalSuccesfulRequestCount: number;\n\n public totalFailedRequestCount: { statusCode: number; count: number }[];\n\n public retryCount: { statusCode: number; count: number }[];\n\n public exceptionCount: { exceptionType: string; count: number }[];\n\n public throttleCount: { statusCode: number; count: number }[];\n\n public intervalRequestExecutionTime: number;\n\n public lastIntervalRequestExecutionTime: number;\n\n public averageRequestExecutionTime: number;\n\n constructor(endpoint: string, host: string) {\n this.endpoint = endpoint;\n this.host = host;\n this.totalRequestCount = 0;\n this.totalSuccesfulRequestCount = 0;\n this.totalFailedRequestCount = [];\n this.retryCount = [];\n this.exceptionCount = [];\n this.throttleCount = [];\n this.intervalRequestExecutionTime = 0;\n this.lastIntervalRequestExecutionTime = 0;\n this.lastTime = +new Date();\n this.lastRequestCount = 0;\n this.averageRequestExecutionTime = 0;\n }\n}\n\nexport const STATSBEAT_LANGUAGE = \"node\";\n\nexport const MAX_STATSBEAT_FAILURES = 3;\n\nexport const StatsbeatResourceProvider = {\n appsvc: \"appsvc\",\n aks: \"aks\",\n functions: \"functions\",\n vm: \"vm\",\n unknown: \"unknown\",\n};\n\nexport enum StatsbeatCounter {\n SUCCESS_COUNT = \"Request_Success_Count\",\n FAILURE_COUNT = \"Request_Failure_Count\",\n RETRY_COUNT = \"Retry_Count\",\n THROTTLE_COUNT = \"Throttle_Count\",\n EXCEPTION_COUNT = \"Exception_Count\",\n AVERAGE_DURATION = \"Request_Duration\",\n ATTACH = \"Attach\",\n FEATURE = \"Feature\",\n}\n\nexport const AIMS_URI = \"http://169.254.169.254/metadata/instance/compute\";\nexport const AIMS_API_VERSION = \"api-version=2017-12-01\";\nexport const AIMS_FORMAT = \"format=json\";\nexport const NON_EU_CONNECTION_STRING =\n \"InstrumentationKey=c4a29126-a7cb-47e5-b348-11414998b11e;IngestionEndpoint=https://westus-0.in.applicationinsights.azure.com\";\nexport const EU_CONNECTION_STRING =\n \"InstrumentationKey=7dc56bab-3c0c-4e9f-9ebb-d1acadee8d0f;IngestionEndpoint=https://westeurope-5.in.applicationinsights.azure.com\";\nexport const EU_ENDPOINTS = [\n \"westeurope\",\n \"northeurope\",\n \"francecentral\",\n \"francesouth\",\n \"germanywestcentral\",\n \"norwayeast\",\n \"norwaywest\",\n \"swedencentral\",\n \"switzerlandnorth\",\n \"switzerlandwest\",\n \"uksouth\",\n \"ukwest\",\n];\n\nexport interface CommonStatsbeatProperties {\n os: string;\n rp: string;\n cikey: string;\n runtimeVersion: string;\n language: string;\n version: string;\n attach: string;\n}\n\nexport interface AttachStatsbeatProperties {\n rpId: string;\n}\n\nexport interface NetworkStatsbeatProperties {\n endpoint: string;\n host: string;\n}\n\nexport interface StatsbeatOptions {\n instrumentationKey: string;\n endpointUrl: string;\n networkCollectionInterval?: number;\n longCollectionInterval?: number;\n}\n\nexport interface VirtualMachineInfo {\n isVM?: boolean;\n id?: string;\n subscriptionId?: string;\n osType?: string;\n}\n\nexport enum StatsbeatFeatureType {\n FEATURE = 0,\n INSTRUMENTATION = 1,\n}\n"]}
@@ -19,8 +19,14 @@ export class AzureMonitorTraceExporter extends AzureMonitorBaseExporter {
19
19
  /**
20
20
  * Flag to determine if Exporter is shutdown.
21
21
  */
22
- this._isShutdown = false;
23
- this._sender = new HttpSender(this.endpointUrl, this.instrumentationKey, this.trackStatsbeat, options);
22
+ this.isShutdown = false;
23
+ this.sender = new HttpSender({
24
+ endpointUrl: this.endpointUrl,
25
+ instrumentationKey: this.instrumentationKey,
26
+ trackStatsbeat: this.trackStatsbeat,
27
+ exporterOptions: options,
28
+ aadAudience: this.aadAudience,
29
+ });
24
30
  diag.debug("AzureMonitorTraceExporter was successfully setup");
25
31
  }
26
32
  /**
@@ -29,26 +35,26 @@ export class AzureMonitorTraceExporter extends AzureMonitorBaseExporter {
29
35
  * @param resultCallback - Result callback.
30
36
  */
31
37
  async export(spans, resultCallback) {
32
- if (this._isShutdown) {
38
+ if (this.isShutdown) {
33
39
  diag.info("Exporter shut down. Failed to export spans.");
34
40
  setTimeout(() => resultCallback({ code: ExportResultCode.FAILED }), 0);
35
41
  return;
36
42
  }
37
43
  diag.info(`Exporting ${spans.length} span(s). Converting to envelopes...`);
38
44
  if (spans.length > 0) {
39
- let envelopes = [];
45
+ const envelopes = [];
40
46
  const resourceMetricEnvelope = createResourceMetricEnvelope(spans[0].resource, this.instrumentationKey);
41
47
  if (resourceMetricEnvelope) {
42
48
  envelopes.push(resourceMetricEnvelope);
43
49
  }
44
50
  spans.forEach((span) => {
45
51
  envelopes.push(readableSpanToEnvelope(span, this.instrumentationKey));
46
- let spanEventEnvelopes = spanEventsToEnvelopes(span, this.instrumentationKey);
52
+ const spanEventEnvelopes = spanEventsToEnvelopes(span, this.instrumentationKey);
47
53
  if (spanEventEnvelopes.length > 0) {
48
54
  envelopes.push(...spanEventEnvelopes);
49
55
  }
50
56
  });
51
- resultCallback(await this._sender.exportEnvelopes(envelopes));
57
+ resultCallback(await this.sender.exportEnvelopes(envelopes));
52
58
  }
53
59
  // No data to export
54
60
  resultCallback({ code: ExportResultCode.SUCCESS });
@@ -57,9 +63,9 @@ export class AzureMonitorTraceExporter extends AzureMonitorBaseExporter {
57
63
  * Shutdown AzureMonitorTraceExporter.
58
64
  */
59
65
  async shutdown() {
60
- this._isShutdown = true;
66
+ this.isShutdown = true;
61
67
  diag.info("AzureMonitorTraceExporter shutting down");
62
- return this._sender.shutdown();
68
+ return this.sender.shutdown();
63
69
  }
64
70
  }
65
71
  //# sourceMappingURL=trace.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"trace.js","sourceRoot":"","sources":["../../../src/export/trace.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAgB,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAErE,OAAO,EAAE,wBAAwB,EAAE,MAAM,QAAQ,CAAC;AAGlD,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AACnF,OAAO,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;GAEG;AACH,MAAM,OAAO,yBAA0B,SAAQ,wBAAwB;IAOrE;;;OAGG;IACH,YAAY,UAAuC,EAAE;QACnD,KAAK,CAAC,OAAO,CAAC,CAAC;QAXjB;;WAEG;QACK,gBAAW,GAAG,KAAK,CAAC;QAS1B,IAAI,CAAC,OAAO,GAAG,IAAI,UAAU,CAC3B,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,kBAAkB,EACvB,IAAI,CAAC,cAAc,EACnB,OAAO,CACR,CAAC;QACF,IAAI,CAAC,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACjE,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,MAAM,CACV,KAAqB,EACrB,cAA8C;QAE9C,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,I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,CAAC;QACrD,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;IACjC,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { diag } from \"@opentelemetry/api\";\nimport { ExportResult, ExportResultCode } from \"@opentelemetry/core\";\nimport { ReadableSpan, SpanExporter } from \"@opentelemetry/sdk-trace-base\";\nimport { AzureMonitorBaseExporter } from \"./base\";\nimport { AzureMonitorExporterOptions } from \"../config\";\nimport { TelemetryItem as Envelope } from \"../generated\";\nimport { readableSpanToEnvelope, spanEventsToEnvelopes } from \"../utils/spanUtils\";\nimport { createResourceMetricEnvelope } from \"../utils/common\";\nimport { HttpSender } from \"../platform\";\n\n/**\n * Azure Monitor OpenTelemetry Trace Exporter.\n */\nexport class AzureMonitorTraceExporter extends AzureMonitorBaseExporter implements SpanExporter {\n /**\n * Flag to determine if Exporter is shutdown.\n */\n private _isShutdown = false;\n private readonly _sender: HttpSender;\n\n /**\n * Initializes a new instance of the AzureMonitorTraceExporter class.\n * @param AzureExporterConfig - Exporter configuration.\n */\n constructor(options: AzureMonitorExporterOptions = {}) {\n super(options);\n this._sender = new HttpSender(\n this.endpointUrl,\n this.instrumentationKey,\n this.trackStatsbeat,\n options\n );\n diag.debug(\"AzureMonitorTraceExporter was successfully setup\");\n }\n\n /**\n * Export OpenTelemetry spans.\n * @param spans - Spans to export.\n * @param resultCallback - Result callback.\n */\n async export(\n spans: ReadableSpan[],\n resultCallback: (result: ExportResult) => void\n ): Promise<void> {\n if (this._isShutdown) {\n diag.info(\"Exporter shut down. Failed to export spans.\");\n setTimeout(() => resultCallback({ code: ExportResultCode.FAILED }), 0);\n return;\n }\n\n diag.info(`Exporting ${spans.length} span(s). Converting to envelopes...`);\n\n if (spans.length > 0) {\n let envelopes: Envelope[] = [];\n const resourceMetricEnvelope = createResourceMetricEnvelope(\n spans[0].resource,\n this.instrumentationKey\n );\n if (resourceMetricEnvelope) {\n envelopes.push(resourceMetricEnvelope);\n }\n spans.forEach((span) => {\n envelopes.push(readableSpanToEnvelope(span, this.instrumentationKey));\n let spanEventEnvelopes = spanEventsToEnvelopes(span, this.instrumentationKey);\n if (spanEventEnvelopes.length > 0) {\n envelopes.push(...spanEventEnvelopes);\n }\n });\n resultCallback(await this._sender.exportEnvelopes(envelopes));\n }\n // No data to export\n resultCallback({ code: ExportResultCode.SUCCESS });\n }\n\n /**\n * Shutdown AzureMonitorTraceExporter.\n */\n async shutdown(): Promise<void> {\n this._isShutdown = true;\n diag.info(\"AzureMonitorTraceExporter shutting down\");\n return this._sender.shutdown();\n }\n}\n"]}
1
+ {"version":3,"file":"trace.js","sourceRoot":"","sources":["../../../src/export/trace.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAgB,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAErE,OAAO,EAAE,wBAAwB,EAAE,MAAM,QAAQ,CAAC;AAGlD,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AACnF,OAAO,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;GAEG;AACH,MAAM,OAAO,yBAA0B,SAAQ,wBAAwB;IAOrE;;;OAGG;IACH,YAAY,UAAuC,EAAE;QACnD,KAAK,CAAC,OAAO,CAAC,CAAC;QAXjB;;WAEG;QACK,eAAU,GAAG,KAAK,CAAC;QASzB,IAAI,CAAC,MAAM,GAAG,IAAI,UAAU,CAAC;YAC3B,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,kBAAkB,EAAE,IAAI,CAAC,kBAAkB;YAC3C,cAAc,EAAE,IAAI,CAAC,cAAc;YACnC,eAAe,EAAE,OAAO;YACxB,WAAW,EAAE,IAAI,CAAC,WAAW;SAC9B,CAAC,CAAC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gB,CAAC,OAAO,EAAE,CAAC,CAAC;IACrD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,QAAQ;QACZ,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACvB,IAAI,CAAC,IAAI,CAAC,yCAAyC,CAAC,CAAC;QACrD,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;IAChC,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { diag } from \"@opentelemetry/api\";\nimport { ExportResult, ExportResultCode } from \"@opentelemetry/core\";\nimport { ReadableSpan, SpanExporter } from \"@opentelemetry/sdk-trace-base\";\nimport { AzureMonitorBaseExporter } from \"./base\";\nimport { AzureMonitorExporterOptions } from \"../config\";\nimport { TelemetryItem as Envelope } from \"../generated\";\nimport { readableSpanToEnvelope, spanEventsToEnvelopes } from \"../utils/spanUtils\";\nimport { createResourceMetricEnvelope } from \"../utils/common\";\nimport { HttpSender } from \"../platform\";\n\n/**\n * Azure Monitor OpenTelemetry Trace Exporter.\n */\nexport class AzureMonitorTraceExporter extends AzureMonitorBaseExporter implements SpanExporter {\n /**\n * Flag to determine if Exporter is shutdown.\n */\n private isShutdown = false;\n private readonly sender: HttpSender;\n\n /**\n * Initializes a new instance of the AzureMonitorTraceExporter class.\n * @param AzureExporterConfig - Exporter configuration.\n */\n constructor(options: AzureMonitorExporterOptions = {}) {\n super(options);\n this.sender = new HttpSender({\n endpointUrl: this.endpointUrl,\n instrumentationKey: this.instrumentationKey,\n trackStatsbeat: this.trackStatsbeat,\n exporterOptions: options,\n aadAudience: this.aadAudience,\n });\n diag.debug(\"AzureMonitorTraceExporter was successfully setup\");\n }\n\n /**\n * Export OpenTelemetry spans.\n * @param spans - Spans to export.\n * @param resultCallback - Result callback.\n */\n async export(\n spans: ReadableSpan[],\n resultCallback: (result: ExportResult) => void\n ): Promise<void> {\n if (this.isShutdown) {\n diag.info(\"Exporter shut down. Failed to export spans.\");\n setTimeout(() => resultCallback({ code: ExportResultCode.FAILED }), 0);\n return;\n }\n\n diag.info(`Exporting ${spans.length} span(s). Converting to envelopes...`);\n\n if (spans.length > 0) {\n const envelopes: Envelope[] = [];\n const resourceMetricEnvelope = createResourceMetricEnvelope(\n spans[0].resource,\n this.instrumentationKey\n );\n if (resourceMetricEnvelope) {\n envelopes.push(resourceMetricEnvelope);\n }\n spans.forEach((span) => {\n envelopes.push(readableSpanToEnvelope(span, this.instrumentationKey));\n const spanEventEnvelopes = spanEventsToEnvelopes(span, this.instrumentationKey);\n if (spanEventEnvelopes.length > 0) {\n envelopes.push(...spanEventEnvelopes);\n }\n });\n resultCallback(await this.sender.exportEnvelopes(envelopes));\n }\n // No data to export\n resultCallback({ code: ExportResultCode.SUCCESS });\n }\n\n /**\n * Shutdown AzureMonitorTraceExporter.\n */\n async shutdown(): Promise<void> {\n this.isShutdown = true;\n diag.info(\"AzureMonitorTraceExporter shutting down\");\n return this.sender.shutdown();\n }\n}\n"]}
@@ -23,7 +23,7 @@ export class ApplicationInsightsClient extends coreClient.ServiceClient {
23
23
  const defaults = {
24
24
  requestContentType: "application/json; charset=utf-8"
25
25
  };
26
- const packageDetails = `azsdk-js-monitor-opentelemetry-exporter/1.0.0-beta.16`;
26
+ const packageDetails = `azsdk-js-monitor-opentelemetry-exporter/1.0.0-beta.18`;
27
27
  const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
28
28
  ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
29
29
  : `${packageDetails}`;
@@ -1 +1 @@
1
- {"version":3,"file":"applicationInsightsClient.js","sourceRoot":"","sources":["../../../src/generated/applicationInsightsClient.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,UAAU,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,gBAAgB,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,UAAU,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,OAAO,MAAM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B,aAAa,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC;IAChC,gBAAgB,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,UAAU,CAAC,MAAM,CAAC;IAC7D,SAAS,EAAE,MAAM;IACjB,UAAU;CACX,CAAC","sourcesContent":["/*\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * Code generated by Microsoft (R) AutoRest Code Generator.\n * Changes may cause incorrect behavior and will be lost if the code is regenerated.\n */\n\nimport * as coreClient from \"@azure/core-client\";\nimport * as coreRestPipeline from \"@azure/core-rest-pipeline\";\nimport * as Parameters from \"./models/parameters\";\nimport * as Mappers from \"./models/mappers\";\nimport {\n ApplicationInsightsClientOptionalParams,\n TelemetryItem,\n TrackOptionalParams,\n TrackOperationResponse\n} from \"./models\";\n\nexport class ApplicationInsightsClient extends coreClient.ServiceClient {\n host: string;\n\n /**\n * Initializes a new instance of the ApplicationInsightsClient class.\n * @param options The parameter options\n */\n constructor(options?: ApplicationInsightsClientOptionalParams) {\n // Initializing default values for options\n if (!options) {\n options = {};\n }\n const defaults: ApplicationInsightsClientOptionalParams = {\n requestContentType: \"application/json; charset=utf-8\"\n };\n\n const packageDetails = `azsdk-js-monitor-opentelemetry-exporter/1.0.0-beta.16`;\n const userAgentPrefix =\n options.userAgentOptions && options.userAgentOptions.userAgentPrefix\n ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`\n : `${packageDetails}`;\n\n const optionsWithDefaults = {\n ...defaults,\n ...options,\n userAgentOptions: {\n userAgentPrefix\n },\n baseUri: options.endpoint ?? options.baseUri ?? \"{Host}/v2.1\"\n };\n super(optionsWithDefaults);\n\n if (options?.pipeline && options.pipeline.getOrderedPolicies().length > 0) {\n const pipelinePolicies: coreRestPipeline.PipelinePolicy[] = options.pipeline.getOrderedPolicies();\n const bearerTokenAuthenticationPolicyFound = pipelinePolicies.some(\n (pipelinePolicy) =>\n pipelinePolicy.name ===\n coreRestPipeline.bearerTokenAuthenticationPolicyName\n );\n if (!bearerTokenAuthenticationPolicyFound) {\n this.pipeline.removePolicy({\n name: coreRestPipeline.bearerTokenAuthenticationPolicyName\n });\n this.pipeline.addPolicy(\n coreRestPipeline.bearerTokenAuthenticationPolicy({\n scopes: `${optionsWithDefaults.baseUri}/.default`,\n challengeCallbacks: {\n authorizeRequestOnChallenge:\n coreClient.authorizeRequestOnClaimChallenge\n }\n })\n );\n }\n }\n\n // Assigning values to Constant parameters\n this.host = options.host || \"https://dc.services.visualstudio.com\";\n }\n\n /**\n * This operation sends a sequence of telemetry events that will be monitored by Azure Monitor.\n * @param body The list of telemetry events to track.\n * @param options The options parameters.\n */\n track(\n body: TelemetryItem[],\n options?: TrackOptionalParams\n ): Promise<TrackOperationResponse> {\n return this.sendOperationRequest({ body, options }, trackOperationSpec);\n }\n}\n// Operation Specifications\nconst serializer = coreClient.createSerializer(Mappers, /* isXml */ false);\n\nconst trackOperationSpec: coreClient.OperationSpec = {\n path: \"/track\",\n httpMethod: \"POST\",\n responses: {\n 200: {\n bodyMapper: Mappers.TrackResponse\n },\n 206: {\n bodyMapper: Mappers.TrackResponse\n },\n 400: {\n bodyMapper: Mappers.TrackResponse,\n isError: true\n },\n 402: {\n bodyMapper: Mappers.TrackResponse,\n isError: true\n },\n 429: {\n bodyMapper: Mappers.TrackResponse,\n isError: true\n },\n 500: {\n bodyMapper: Mappers.TrackResponse,\n isError: true\n },\n 503: {\n bodyMapper: Mappers.TrackResponse,\n isError: true\n }\n },\n requestBody: Parameters.body,\n urlParameters: [Parameters.host],\n headerParameters: [Parameters.contentType, Parameters.accept],\n mediaType: \"json\",\n serializer\n};\n"]}
1
+ {"version":3,"file":"applicationInsightsClient.js","sourceRoot":"","sources":["../../../src/generated/applicationInsightsClient.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,UAAU,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,gBAAgB,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,UAAU,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SACd;KACF;IACD,WAAW,EAAE,UAAU,CAAC,IAAI;IAC5B,aAAa,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC;IAChC,gBAAgB,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,UAAU,CAAC,MAAM,CAAC;IAC7D,SAAS,EAAE,MAAM;IACjB,UAAU;CACX,CAAC","sourcesContent":["/*\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * Code generated by Microsoft (R) AutoRest Code Generator.\n * Changes may cause incorrect behavior and will be lost if the code is regenerated.\n */\n\nimport * as coreClient from \"@azure/core-client\";\nimport * as coreRestPipeline from \"@azure/core-rest-pipeline\";\nimport * as Parameters from \"./models/parameters\";\nimport * as Mappers from \"./models/mappers\";\nimport {\n ApplicationInsightsClientOptionalParams,\n TelemetryItem,\n TrackOptionalParams,\n TrackOperationResponse\n} from \"./models\";\n\nexport class ApplicationInsightsClient extends coreClient.ServiceClient {\n host: string;\n\n /**\n * Initializes a new instance of the ApplicationInsightsClient class.\n * @param options The parameter options\n */\n constructor(options?: ApplicationInsightsClientOptionalParams) {\n // Initializing default values for options\n if (!options) {\n options = {};\n }\n const defaults: ApplicationInsightsClientOptionalParams = {\n requestContentType: \"application/json; charset=utf-8\"\n };\n\n const packageDetails = `azsdk-js-monitor-opentelemetry-exporter/1.0.0-beta.18`;\n const userAgentPrefix =\n options.userAgentOptions && options.userAgentOptions.userAgentPrefix\n ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`\n : `${packageDetails}`;\n\n const optionsWithDefaults = {\n ...defaults,\n ...options,\n userAgentOptions: {\n userAgentPrefix\n },\n baseUri: options.endpoint ?? options.baseUri ?? \"{Host}/v2.1\"\n };\n super(optionsWithDefaults);\n\n if (options?.pipeline && options.pipeline.getOrderedPolicies().length > 0) {\n const pipelinePolicies: coreRestPipeline.PipelinePolicy[] = options.pipeline.getOrderedPolicies();\n const bearerTokenAuthenticationPolicyFound = pipelinePolicies.some(\n (pipelinePolicy) =>\n pipelinePolicy.name ===\n coreRestPipeline.bearerTokenAuthenticationPolicyName\n );\n if (!bearerTokenAuthenticationPolicyFound) {\n this.pipeline.removePolicy({\n name: coreRestPipeline.bearerTokenAuthenticationPolicyName\n });\n this.pipeline.addPolicy(\n coreRestPipeline.bearerTokenAuthenticationPolicy({\n scopes: `${optionsWithDefaults.baseUri}/.default`,\n challengeCallbacks: {\n authorizeRequestOnChallenge:\n coreClient.authorizeRequestOnClaimChallenge\n }\n })\n );\n }\n }\n\n // Assigning values to Constant parameters\n this.host = options.host || \"https://dc.services.visualstudio.com\";\n }\n\n /**\n * This operation sends a sequence of telemetry events that will be monitored by Azure Monitor.\n * @param body The list of telemetry events to track.\n * @param options The options parameters.\n */\n track(\n body: TelemetryItem[],\n options?: TrackOptionalParams\n ): Promise<TrackOperationResponse> {\n return this.sendOperationRequest({ body, options }, trackOperationSpec);\n }\n}\n// Operation Specifications\nconst serializer = coreClient.createSerializer(Mappers, /* isXml */ false);\n\nconst trackOperationSpec: coreClient.OperationSpec = {\n path: \"/track\",\n httpMethod: \"POST\",\n responses: {\n 200: {\n bodyMapper: Mappers.TrackResponse\n },\n 206: {\n bodyMapper: Mappers.TrackResponse\n },\n 400: {\n bodyMapper: Mappers.TrackResponse,\n isError: true\n },\n 402: {\n bodyMapper: Mappers.TrackResponse,\n isError: true\n },\n 429: {\n bodyMapper: Mappers.TrackResponse,\n isError: true\n },\n 500: {\n bodyMapper: Mappers.TrackResponse,\n isError: true\n },\n 503: {\n bodyMapper: Mappers.TrackResponse,\n isError: true\n }\n },\n requestBody: Parameters.body,\n urlParameters: [Parameters.host],\n headerParameters: [Parameters.contentType, Parameters.accept],\n mediaType: \"json\",\n serializer\n};\n"]}
@@ -13,23 +13,23 @@ const DEFAULT_BATCH_SEND_RETRY_INTERVAL_MS = 60000;
13
13
  * @internal
14
14
  */
15
15
  export class BaseSender {
16
- constructor(endpointUrl, instrumentationKey, trackStatsbeat, options = {}) {
17
- this._statsbeatFailureCount = 0;
18
- this._batchSendRetryIntervalMs = DEFAULT_BATCH_SEND_RETRY_INTERVAL_MS;
19
- this._numConsecutiveRedirects = 0;
20
- this._persister = new FileSystemPersist(instrumentationKey, options);
21
- if (trackStatsbeat) {
16
+ constructor(options) {
17
+ this.statsbeatFailureCount = 0;
18
+ this.batchSendRetryIntervalMs = DEFAULT_BATCH_SEND_RETRY_INTERVAL_MS;
19
+ this.numConsecutiveRedirects = 0;
20
+ this.persister = new FileSystemPersist(options.instrumentationKey, options.exporterOptions);
21
+ if (options.trackStatsbeat) {
22
22
  // Initialize statsbeatMetrics
23
- this._networkStatsbeatMetrics = new NetworkStatsbeatMetrics({
24
- instrumentationKey: instrumentationKey,
25
- endpointUrl: endpointUrl,
23
+ this.networkStatsbeatMetrics = new NetworkStatsbeatMetrics({
24
+ instrumentationKey: options.instrumentationKey,
25
+ endpointUrl: options.endpointUrl,
26
26
  });
27
- this._longIntervalStatsbeatMetrics = getInstance({
28
- instrumentationKey: instrumentationKey,
29
- endpointUrl: endpointUrl,
27
+ this.longIntervalStatsbeatMetrics = getInstance({
28
+ instrumentationKey: options.instrumentationKey,
29
+ endpointUrl: options.endpointUrl,
30
30
  });
31
31
  }
32
- this._retryTimer = null;
32
+ this.retryTimer = null;
33
33
  }
34
34
  /**
35
35
  * Export envelopes
@@ -45,24 +45,24 @@ export class BaseSender {
45
45
  const { result, statusCode } = await this.send(envelopes);
46
46
  const endTime = new Date().getTime();
47
47
  const duration = endTime - startTime;
48
- this._numConsecutiveRedirects = 0;
48
+ this.numConsecutiveRedirects = 0;
49
49
  if (statusCode === 200) {
50
50
  // Success -- @todo: start retry timer
51
- if (!this._retryTimer) {
52
- this._retryTimer = setTimeout(() => {
53
- this._retryTimer = null;
54
- this._sendFirstPersistedFile();
55
- }, this._batchSendRetryIntervalMs);
56
- this._retryTimer.unref();
51
+ if (!this.retryTimer) {
52
+ this.retryTimer = setTimeout(() => {
53
+ this.retryTimer = null;
54
+ this.sendFirstPersistedFile();
55
+ }, this.batchSendRetryIntervalMs);
56
+ this.retryTimer.unref();
57
57
  }
58
58
  // If we are not exportings statsbeat and statsbeat is not disabled -- count success
59
- (_a = this._networkStatsbeatMetrics) === null || _a === void 0 ? void 0 : _a.countSuccess(duration);
59
+ (_a = this.networkStatsbeatMetrics) === null || _a === void 0 ? void 0 : _a.countSuccess(duration);
60
60
  return { code: ExportResultCode.SUCCESS };
61
61
  }
62
62
  else if (statusCode && isRetriable(statusCode)) {
63
63
  // Failed -- persist failed data
64
64
  if (statusCode === 429 || statusCode === 439) {
65
- (_b = this._networkStatsbeatMetrics) === null || _b === void 0 ? void 0 : _b.countThrottle(statusCode);
65
+ (_b = this.networkStatsbeatMetrics) === null || _b === void 0 ? void 0 : _b.countThrottle(statusCode);
66
66
  }
67
67
  if (result) {
68
68
  diag.info(result);
@@ -76,31 +76,31 @@ export class BaseSender {
76
76
  });
77
77
  }
78
78
  if (filteredEnvelopes.length > 0) {
79
- (_c = this._networkStatsbeatMetrics) === null || _c === void 0 ? void 0 : _c.countRetry(statusCode);
79
+ (_c = this.networkStatsbeatMetrics) === null || _c === void 0 ? void 0 : _c.countRetry(statusCode);
80
80
  // calls resultCallback(ExportResult) based on result of persister.push
81
- return await this._persist(filteredEnvelopes);
81
+ return await this.persist(filteredEnvelopes);
82
82
  }
83
83
  // Failed -- not retriable
84
- (_d = this._networkStatsbeatMetrics) === null || _d === void 0 ? void 0 : _d.countFailure(duration, statusCode);
84
+ (_d = this.networkStatsbeatMetrics) === null || _d === void 0 ? void 0 : _d.countFailure(duration, statusCode);
85
85
  return {
86
86
  code: ExportResultCode.FAILED,
87
87
  };
88
88
  }
89
89
  else {
90
90
  // calls resultCallback(ExportResult) based on result of persister.push
91
- (_e = this._networkStatsbeatMetrics) === null || _e === void 0 ? void 0 : _e.countRetry(statusCode);
92
- return await this._persist(envelopes);
91
+ (_e = this.networkStatsbeatMetrics) === null || _e === void 0 ? void 0 : _e.countRetry(statusCode);
92
+ return await this.persist(envelopes);
93
93
  }
94
94
  }
95
95
  else {
96
96
  // Failed -- not retriable
97
- if (this._networkStatsbeatMetrics) {
97
+ if (this.networkStatsbeatMetrics) {
98
98
  if (statusCode) {
99
- this._networkStatsbeatMetrics.countFailure(duration, statusCode);
99
+ this.networkStatsbeatMetrics.countFailure(duration, statusCode);
100
100
  }
101
101
  }
102
102
  else {
103
- this._incrementStatsbeatFailure();
103
+ this.incrementStatsbeatFailure();
104
104
  }
105
105
  return {
106
106
  code: ExportResultCode.FAILED,
@@ -113,9 +113,9 @@ export class BaseSender {
113
113
  (restError.statusCode === 307 || // Temporary redirect
114
114
  restError.statusCode === 308)) {
115
115
  // Permanent redirect
116
- this._numConsecutiveRedirects++;
116
+ this.numConsecutiveRedirects++;
117
117
  // To prevent circular redirects
118
- if (this._numConsecutiveRedirects < 10) {
118
+ if (this.numConsecutiveRedirects < 10) {
119
119
  if (restError.response && restError.response.headers) {
120
120
  const location = restError.response.headers.get("location");
121
121
  if (location) {
@@ -127,23 +127,23 @@ export class BaseSender {
127
127
  }
128
128
  }
129
129
  else {
130
- let redirectError = new Error("Circular redirect");
131
- (_f = this._networkStatsbeatMetrics) === null || _f === void 0 ? void 0 : _f.countException(redirectError);
130
+ const redirectError = new Error("Circular redirect");
131
+ (_f = this.networkStatsbeatMetrics) === null || _f === void 0 ? void 0 : _f.countException(redirectError);
132
132
  return { code: ExportResultCode.FAILED, error: redirectError };
133
133
  }
134
134
  }
135
135
  else if (restError.statusCode && isRetriable(restError.statusCode)) {
136
- (_g = this._networkStatsbeatMetrics) === null || _g === void 0 ? void 0 : _g.countRetry(restError.statusCode);
137
- return await this._persist(envelopes);
136
+ (_g = this.networkStatsbeatMetrics) === null || _g === void 0 ? void 0 : _g.countRetry(restError.statusCode);
137
+ return this.persist(envelopes);
138
138
  }
139
- if (this._isNetworkError(restError)) {
139
+ if (this.isNetworkError(restError)) {
140
140
  if (restError.statusCode) {
141
- (_h = this._networkStatsbeatMetrics) === null || _h === void 0 ? void 0 : _h.countRetry(restError.statusCode);
141
+ (_h = this.networkStatsbeatMetrics) === null || _h === void 0 ? void 0 : _h.countRetry(restError.statusCode);
142
142
  }
143
143
  diag.error("Retrying due to transient client side error. Error message:", restError.message);
144
- return await this._persist(envelopes);
144
+ return this.persist(envelopes);
145
145
  }
146
- (_j = this._networkStatsbeatMetrics) === null || _j === void 0 ? void 0 : _j.countException(restError);
146
+ (_j = this.networkStatsbeatMetrics) === null || _j === void 0 ? void 0 : _j.countException(restError);
147
147
  diag.error("Envelopes could not be exported and are not retriable. Error message:", restError.message);
148
148
  return { code: ExportResultCode.FAILED, error: restError };
149
149
  }
@@ -151,9 +151,9 @@ export class BaseSender {
151
151
  /**
152
152
  * Persist envelopes to disk
153
153
  */
154
- async _persist(envelopes) {
154
+ async persist(envelopes) {
155
155
  try {
156
- const success = await this._persister.push(envelopes);
156
+ const success = await this.persister.push(envelopes);
157
157
  return success
158
158
  ? { code: ExportResultCode.SUCCESS }
159
159
  : {
@@ -166,19 +166,19 @@ export class BaseSender {
166
166
  }
167
167
  }
168
168
  // Disable collection of statsbeat metrics after max failures
169
- _incrementStatsbeatFailure() {
169
+ incrementStatsbeatFailure() {
170
170
  var _a, _b;
171
- this._statsbeatFailureCount++;
172
- if (this._statsbeatFailureCount > MAX_STATSBEAT_FAILURES) {
173
- (_a = this._networkStatsbeatMetrics) === null || _a === void 0 ? void 0 : _a.shutdown();
174
- (_b = this._longIntervalStatsbeatMetrics) === null || _b === void 0 ? void 0 : _b.shutdown();
175
- this._networkStatsbeatMetrics = undefined;
176
- this._statsbeatFailureCount = 0;
171
+ this.statsbeatFailureCount++;
172
+ if (this.statsbeatFailureCount > MAX_STATSBEAT_FAILURES) {
173
+ (_a = this.networkStatsbeatMetrics) === null || _a === void 0 ? void 0 : _a.shutdown();
174
+ (_b = this.longIntervalStatsbeatMetrics) === null || _b === void 0 ? void 0 : _b.shutdown();
175
+ this.networkStatsbeatMetrics = undefined;
176
+ this.statsbeatFailureCount = 0;
177
177
  }
178
178
  }
179
- async _sendFirstPersistedFile() {
179
+ async sendFirstPersistedFile() {
180
180
  try {
181
- const envelopes = (await this._persister.shift());
181
+ const envelopes = (await this.persister.shift());
182
182
  if (envelopes) {
183
183
  await this.send(envelopes);
184
184
  }
@@ -187,7 +187,7 @@ export class BaseSender {
187
187
  diag.warn(`Failed to fetch persisted file`, err);
188
188
  }
189
189
  }
190
- _isNetworkError(error) {
190
+ isNetworkError(error) {
191
191
  if (error && error.code && error.code === "REQUEST_SEND_ERROR") {
192
192
  return true;
193
193
  }
@@ -1 +1 @@
1
- {"version":3,"file":"baseSender.js","sourceRoot":"","sources":["../../../../src/platform/nodejs/baseSender.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAG1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAgB,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,gDAAgD,CAAC;AACzF,OAAO,EAAE,WAAW,EAAE,MAAM,qDAAqD,CAAC;AAElF,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAkB,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAGtE,MAAM,oCAAoC,GAAG,KAAM,CAAC;AAEpD;;;GAGG;AACH,MAAM,OAAgB,UAAU;IAS9B,YACE,WAAmB,EACnB,kBAA0B,EAC1B,cAAuB,EACvB,UAAuC,EAAE;QAPnC,2BAAsB,GAAW,CAAC,CAAC;QACnC,8BAAyB,GAAW,oCAAoC,CAAC;QAQ/E,IAAI,CAAC,wBAAwB,GAAG,CAAC,CAAC;QAClC,IAAI,CAAC,UAAU,GAAG,IAAI,iBAAiB,CAAC,kBAAkB,EAAE,OAAO,CAAC,CAAC;QACrE,IAAI,cAAc,EAAE;YAClB,8BAA8B;YAC9B,IAAI,CAAC,wBAAwB,GAA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AI,KAAK,CAAC,qCAAqC,CAAC;iBACxD,CAAC;SACP;QAAC,OAAO,EAAO,EAAE;YAChB,OAAO,EAAE,IAAI,EAAE,gBAAgB,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;SACrD;IACH,CAAC;IAED,6DAA6D;IACrD,0BAA0B;;QAChC,IAAI,CAAC,sBAAsB,EAAE,CAAC;QAC9B,IAAI,IAAI,CAAC,sBAAsB,GAAG,sBAAsB,EAAE;YACxD,MAAA,IAAI,CAAC,wBAAwB,0CAAE,QAAQ,EAAE,CAAC;YAC1C,MAAA,IAAI,CAAC,6BAA6B,0CAAE,QAAQ,EAAE,CAAC;YAC/C,IAAI,CAAC,wBAAwB,GAAG,SAAS,CAAC;YAC1C,IAAI,CAAC,sBAAsB,GAAG,CAAC,CAAC;SACjC;IACH,CAAC;IAEO,KAAK,CAAC,uBAAuB;QACnC,IAAI;YACF,MAAM,SAAS,GAAG,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAsB,CAAC;YACvE,IAAI,SAAS,EAAE;gBACb,MAAM,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;aAC5B;SACF;QAAC,OAAO,GAAQ,EAAE;YACjB,IAAI,CAAC,IAAI,CAAC,gCAAgC,EAAE,GAAG,CAAC,CAAC;SAClD;IACH,CAAC;IAEO,eAAe,CAAC,KAAgB;QACtC,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,KAAK,oBAAoB,EAAE;YAC9D,OAAO,IAAI,CAAC;SACb;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nimport { diag } from \"@opentelemetry/api\";\nimport { PersistentStorage, SenderResult } from \"../../types\";\nimport { AzureMonitorExporterOptions } from \"../../config\";\nimport { FileSystemPersist } from \"./persist\";\nimport { ExportResult, ExportResultCode } from \"@opentelemetry/core\";\nimport { NetworkStatsbeatMetrics } from \"../../export/statsbeat/networkStatsbeatMetrics\";\nimport { getInstance } from \"../../export/statsbeat/longIntervalStatsbeatMetrics\";\nimport { RestError } from \"@azure/core-rest-pipeline\";\nimport { MAX_STATSBEAT_FAILURES } from \"../../export/statsbeat/types\";\nimport { BreezeResponse, isRetriable } from \"../../utils/breezeUtils\";\nimport { TelemetryItem as Envelope } from \"../../generated\";\n\nconst DEFAULT_BATCH_SEND_RETRY_INTERVAL_MS = 60_000;\n\n/**\n * Base sender class\n * @internal\n */\nexport abstract class BaseSender {\n private readonly _persister: PersistentStorage;\n private _numConsecutiveRedirects: number;\n private _retryTimer: NodeJS.Timer | null;\n private _networkStatsbeatMetrics: NetworkStatsbeatMetrics | undefined;\n private _longIntervalStatsbeatMetrics;\n private _statsbeatFailureCount: number = 0;\n private _batchSendRetryIntervalMs: number = DEFAULT_BATCH_SEND_RETRY_INTERVAL_MS;\n\n constructor(\n endpointUrl: string,\n instrumentationKey: string,\n trackStatsbeat: boolean,\n options: AzureMonitorExporterOptions = {}\n ) {\n this._numConsecutiveRedirects = 0;\n this._persister = new FileSystemPersist(instrumentationKey, options);\n if (trackStatsbeat) {\n // Initialize statsbeatMetrics\n this._networkStatsbeatMetrics = new NetworkStatsbeatMetrics({\n instrumentationKey: instrumentationKey,\n endpointUrl: endpointUrl,\n });\n this._longIntervalStatsbeatMetrics = getInstance({\n instrumentationKey: instrumentationKey,\n endpointUrl: endpointUrl,\n });\n }\n this._retryTimer = null;\n }\n\n abstract send(payload: unknown[]): Promise<SenderResult>;\n abstract shutdown(): Promise<void>;\n abstract handlePermanentRedirect(location: string | undefined): void;\n\n /**\n * Export envelopes\n */\n public async exportEnvelopes(envelopes: Envelope[]): Promise<ExportResult> {\n diag.info(`Exporting ${envelopes.length} envelope(s)`);\n\n if (envelopes.length < 1) {\n return { code: ExportResultCode.SUCCESS };\n }\n\n try {\n const startTime = new Date().getTime();\n const { result, statusCode } = await this.send(envelopes);\n const endTime = new Date().getTime();\n const duration = endTime - startTime;\n this._numConsecutiveRedirects = 0;\n\n if (statusCode === 200) {\n // Success -- @todo: start retry timer\n if (!this._retryTimer) {\n this._retryTimer = setTimeout(() => {\n this._retryTimer = null;\n this._sendFirstPersistedFile();\n }, this._batchSendRetryIntervalMs);\n this._retryTimer.unref();\n }\n // If we are not exportings statsbeat and statsbeat is not disabled -- count success\n this._networkStatsbeatMetrics?.countSuccess(duration);\n return { code: ExportResultCode.SUCCESS };\n } else if (statusCode && isRetriable(statusCode)) {\n // Failed -- persist failed data\n if (statusCode === 429 || statusCode === 439) {\n this._networkStatsbeatMetrics?.countThrottle(statusCode);\n }\n if (result) {\n diag.info(result);\n const breezeResponse = JSON.parse(result) as BreezeResponse;\n const filteredEnvelopes: Envelope[] = [];\n if (breezeResponse.errors) {\n breezeResponse.errors.forEach((error) => {\n if (error.statusCode && isRetriable(error.statusCode)) {\n filteredEnvelopes.push(envelopes[error.index]);\n }\n });\n }\n if (filteredEnvelopes.length > 0) {\n this._networkStatsbeatMetrics?.countRetry(statusCode);\n // calls resultCallback(ExportResult) based on result of persister.push\n return await this._persist(filteredEnvelopes);\n }\n // Failed -- not retriable\n this._networkStatsbeatMetrics?.countFailure(duration, statusCode);\n return {\n code: ExportResultCode.FAILED,\n };\n } else {\n // calls resultCallback(ExportResult) based on result of persister.push\n this._networkStatsbeatMetrics?.countRetry(statusCode);\n return await this._persist(envelopes);\n }\n } else {\n // Failed -- not retriable\n if (this._networkStatsbeatMetrics) {\n if (statusCode) {\n this._networkStatsbeatMetrics.countFailure(duration, statusCode);\n }\n } else {\n this._incrementStatsbeatFailure();\n }\n return {\n code: ExportResultCode.FAILED,\n };\n }\n } catch (error: any) {\n const restError = error as RestError;\n if (\n restError.statusCode &&\n (restError.statusCode === 307 || // Temporary redirect\n restError.statusCode === 308)\n ) {\n // Permanent redirect\n this._numConsecutiveRedirects++;\n // To prevent circular redirects\n if (this._numConsecutiveRedirects < 10) {\n if (restError.response && restError.response.headers) {\n const location = restError.response.headers.get(\"location\");\n if (location) {\n // Update sender URL\n this.handlePermanentRedirect(location);\n // Send to redirect endpoint as HTTPs library doesn't handle redirect automatically\n return this.exportEnvelopes(envelopes);\n }\n }\n } else {\n let redirectError = new Error(\"Circular redirect\");\n this._networkStatsbeatMetrics?.countException(redirectError);\n return { code: ExportResultCode.FAILED, error: redirectError };\n }\n } else if (restError.statusCode && isRetriable(restError.statusCode)) {\n this._networkStatsbeatMetrics?.countRetry(restError.statusCode);\n return await this._persist(envelopes);\n }\n if (this._isNetworkError(restError)) {\n if (restError.statusCode) {\n this._networkStatsbeatMetrics?.countRetry(restError.statusCode);\n }\n diag.error(\n \"Retrying due to transient client side error. Error message:\",\n restError.message\n );\n return await this._persist(envelopes);\n }\n this._networkStatsbeatMetrics?.countException(restError);\n diag.error(\n \"Envelopes could not be exported and are not retriable. Error message:\",\n restError.message\n );\n return { code: ExportResultCode.FAILED, error: restError };\n }\n }\n\n /**\n * Persist envelopes to disk\n */\n private async _persist(envelopes: unknown[]): Promise<ExportResult> {\n try {\n const success = await this._persister.push(envelopes);\n return success\n ? { code: ExportResultCode.SUCCESS }\n : {\n code: ExportResultCode.FAILED,\n error: new Error(\"Failed to persist envelope in disk.\"),\n };\n } catch (ex: any) {\n return { code: ExportResultCode.FAILED, error: ex };\n }\n }\n\n // Disable collection of statsbeat metrics after max failures\n private _incrementStatsbeatFailure() {\n this._statsbeatFailureCount++;\n if (this._statsbeatFailureCount > MAX_STATSBEAT_FAILURES) {\n this._networkStatsbeatMetrics?.shutdown();\n this._longIntervalStatsbeatMetrics?.shutdown();\n this._networkStatsbeatMetrics = undefined;\n this._statsbeatFailureCount = 0;\n }\n }\n\n private async _sendFirstPersistedFile(): Promise<void> {\n try {\n const envelopes = (await this._persister.shift()) as Envelope[] | null;\n if (envelopes) {\n await this.send(envelopes);\n }\n } catch (err: any) {\n diag.warn(`Failed to fetch persisted file`, err);\n }\n }\n\n private _isNetworkError(error: RestError): boolean {\n if (error && error.code && error.code === \"REQUEST_SEND_ERROR\") {\n return true;\n }\n return false;\n }\n}\n"]}
1
+ {"version":3,"file":"baseSender.js","sourceRoot":"","sources":["../../../../src/platform/nodejs/baseSender.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAG1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAgB,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,gDAAgD,CAAC;AACzF,OAAO,EAAE,WAAW,EAAE,MAAM,qDAAqD,CAAC;AAElF,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAkB,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAGtE,MAAM,oCAAoC,GAAG,KAAM,CAAC;AAEpD;;;GAGG;AACH,MAAM,OAAgB,UAAU;IAS9B,YAAY,OAMX;QATO,0BAAqB,GAAW,CAAC,CAAC;QAClC,6BAAwB,GAAW,oCAAoC,CAAC;QAS9E,IAAI,CAAC,uBAAuB,GAAG,CAAC,CAAC;QACjC,IAAI,CAAC,SAAS,GAAG,IAAI,iBAAiB,CAAC,OAAO,CAAC,kBAAkB,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;QAC5F,IAAI,OAAO,CAAC,cAAc,EAAE;YAC1B,8BAA8B;YAC9B,IAAI,CAAC,uBAAuB,GAAG,IAAI,uBAAuB,CAAC;gBACzD,kBAAkB,EAAE,OAAO,CAAC,kBAAkB;gBAC9C,WAAW,EAAE,OAAO,CAAC,WAAW;aACjC,CAAC,CAAC;YACH,IAAI,CAAC,4BAA4B,GAAG,WAAW,CAAC;gBAC9C,kBAAkB,EAAE,OAAO,CAAC,kBAAkB;gBAC9C,WAAW,EAAE,OAAO,CAAC,WAAW;aACjC,CAAC,CAAC;SACJ;QACD,IAAI,CAAC,UAAU,GAAG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C,qBAAqB,GAAG,sBAAsB,EAAE;YACvD,MAAA,IAAI,CAAC,uBAAuB,0CAAE,QAAQ,EAAE,CAAC;YACzC,MAAA,IAAI,CAAC,4BAA4B,0CAAE,QAAQ,EAAE,CAAC;YAC9C,IAAI,CAAC,uBAAuB,GAAG,SAAS,CAAC;YACzC,IAAI,CAAC,qBAAqB,GAAG,CAAC,CAAC;SAChC;IACH,CAAC;IAEO,KAAK,CAAC,sBAAsB;QAClC,IAAI;YACF,MAAM,SAAS,GAAG,CAAC,MAAM,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAsB,CAAC;YACtE,IAAI,SAAS,EAAE;gBACb,MAAM,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;aAC5B;SACF;QAAC,OAAO,GAAQ,EAAE;YACjB,IAAI,CAAC,IAAI,CAAC,gCAAgC,EAAE,GAAG,CAAC,CAAC;SAClD;IACH,CAAC;IAEO,cAAc,CAAC,KAAgB;QACrC,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,KAAK,oBAAoB,EAAE;YAC9D,OAAO,IAAI,CAAC;SACb;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nimport { diag } from \"@opentelemetry/api\";\nimport { PersistentStorage, SenderResult } from \"../../types\";\nimport { AzureMonitorExporterOptions } from \"../../config\";\nimport { FileSystemPersist } from \"./persist\";\nimport { ExportResult, ExportResultCode } from \"@opentelemetry/core\";\nimport { NetworkStatsbeatMetrics } from \"../../export/statsbeat/networkStatsbeatMetrics\";\nimport { getInstance } from \"../../export/statsbeat/longIntervalStatsbeatMetrics\";\nimport { RestError } from \"@azure/core-rest-pipeline\";\nimport { MAX_STATSBEAT_FAILURES } from \"../../export/statsbeat/types\";\nimport { BreezeResponse, isRetriable } from \"../../utils/breezeUtils\";\nimport { TelemetryItem as Envelope } from \"../../generated\";\n\nconst DEFAULT_BATCH_SEND_RETRY_INTERVAL_MS = 60_000;\n\n/**\n * Base sender class\n * @internal\n */\nexport abstract class BaseSender {\n private readonly persister: PersistentStorage;\n private numConsecutiveRedirects: number;\n private retryTimer: NodeJS.Timeout | null;\n private networkStatsbeatMetrics: NetworkStatsbeatMetrics | undefined;\n private longIntervalStatsbeatMetrics;\n private statsbeatFailureCount: number = 0;\n private batchSendRetryIntervalMs: number = DEFAULT_BATCH_SEND_RETRY_INTERVAL_MS;\n\n constructor(options: {\n endpointUrl: string;\n instrumentationKey: string;\n trackStatsbeat: boolean;\n exporterOptions: AzureMonitorExporterOptions;\n aadAudience?: string;\n }) {\n this.numConsecutiveRedirects = 0;\n this.persister = new FileSystemPersist(options.instrumentationKey, options.exporterOptions);\n if (options.trackStatsbeat) {\n // Initialize statsbeatMetrics\n this.networkStatsbeatMetrics = new NetworkStatsbeatMetrics({\n instrumentationKey: options.instrumentationKey,\n endpointUrl: options.endpointUrl,\n });\n this.longIntervalStatsbeatMetrics = getInstance({\n instrumentationKey: options.instrumentationKey,\n endpointUrl: options.endpointUrl,\n });\n }\n this.retryTimer = null;\n }\n\n abstract send(payload: unknown[]): Promise<SenderResult>;\n abstract shutdown(): Promise<void>;\n abstract handlePermanentRedirect(location: string | undefined): void;\n\n /**\n * Export envelopes\n */\n public async exportEnvelopes(envelopes: Envelope[]): Promise<ExportResult> {\n diag.info(`Exporting ${envelopes.length} envelope(s)`);\n\n if (envelopes.length < 1) {\n return { code: ExportResultCode.SUCCESS };\n }\n\n try {\n const startTime = new Date().getTime();\n const { result, statusCode } = await this.send(envelopes);\n const endTime = new Date().getTime();\n const duration = endTime - startTime;\n this.numConsecutiveRedirects = 0;\n\n if (statusCode === 200) {\n // Success -- @todo: start retry timer\n if (!this.retryTimer) {\n this.retryTimer = setTimeout(() => {\n this.retryTimer = null;\n this.sendFirstPersistedFile();\n }, this.batchSendRetryIntervalMs);\n this.retryTimer.unref();\n }\n // If we are not exportings statsbeat and statsbeat is not disabled -- count success\n this.networkStatsbeatMetrics?.countSuccess(duration);\n return { code: ExportResultCode.SUCCESS };\n } else if (statusCode && isRetriable(statusCode)) {\n // Failed -- persist failed data\n if (statusCode === 429 || statusCode === 439) {\n this.networkStatsbeatMetrics?.countThrottle(statusCode);\n }\n if (result) {\n diag.info(result);\n const breezeResponse = JSON.parse(result) as BreezeResponse;\n const filteredEnvelopes: Envelope[] = [];\n if (breezeResponse.errors) {\n breezeResponse.errors.forEach((error) => {\n if (error.statusCode && isRetriable(error.statusCode)) {\n filteredEnvelopes.push(envelopes[error.index]);\n }\n });\n }\n if (filteredEnvelopes.length > 0) {\n this.networkStatsbeatMetrics?.countRetry(statusCode);\n // calls resultCallback(ExportResult) based on result of persister.push\n return await this.persist(filteredEnvelopes);\n }\n // Failed -- not retriable\n this.networkStatsbeatMetrics?.countFailure(duration, statusCode);\n return {\n code: ExportResultCode.FAILED,\n };\n } else {\n // calls resultCallback(ExportResult) based on result of persister.push\n this.networkStatsbeatMetrics?.countRetry(statusCode);\n return await this.persist(envelopes);\n }\n } else {\n // Failed -- not retriable\n if (this.networkStatsbeatMetrics) {\n if (statusCode) {\n this.networkStatsbeatMetrics.countFailure(duration, statusCode);\n }\n } else {\n this.incrementStatsbeatFailure();\n }\n return {\n code: ExportResultCode.FAILED,\n };\n }\n } catch (error: any) {\n const restError = error as RestError;\n if (\n restError.statusCode &&\n (restError.statusCode === 307 || // Temporary redirect\n restError.statusCode === 308)\n ) {\n // Permanent redirect\n this.numConsecutiveRedirects++;\n // To prevent circular redirects\n if (this.numConsecutiveRedirects < 10) {\n if (restError.response && restError.response.headers) {\n const location = restError.response.headers.get(\"location\");\n if (location) {\n // Update sender URL\n this.handlePermanentRedirect(location);\n // Send to redirect endpoint as HTTPs library doesn't handle redirect automatically\n return this.exportEnvelopes(envelopes);\n }\n }\n } else {\n const redirectError = new Error(\"Circular redirect\");\n this.networkStatsbeatMetrics?.countException(redirectError);\n return { code: ExportResultCode.FAILED, error: redirectError };\n }\n } else if (restError.statusCode && isRetriable(restError.statusCode)) {\n this.networkStatsbeatMetrics?.countRetry(restError.statusCode);\n return this.persist(envelopes);\n }\n if (this.isNetworkError(restError)) {\n if (restError.statusCode) {\n this.networkStatsbeatMetrics?.countRetry(restError.statusCode);\n }\n diag.error(\n \"Retrying due to transient client side error. Error message:\",\n restError.message\n );\n return this.persist(envelopes);\n }\n this.networkStatsbeatMetrics?.countException(restError);\n diag.error(\n \"Envelopes could not be exported and are not retriable. Error message:\",\n restError.message\n );\n return { code: ExportResultCode.FAILED, error: restError };\n }\n }\n\n /**\n * Persist envelopes to disk\n */\n private async persist(envelopes: unknown[]): Promise<ExportResult> {\n try {\n const success = await this.persister.push(envelopes);\n return success\n ? { code: ExportResultCode.SUCCESS }\n : {\n code: ExportResultCode.FAILED,\n error: new Error(\"Failed to persist envelope in disk.\"),\n };\n } catch (ex: any) {\n return { code: ExportResultCode.FAILED, error: ex };\n }\n }\n\n // Disable collection of statsbeat metrics after max failures\n private incrementStatsbeatFailure() {\n this.statsbeatFailureCount++;\n if (this.statsbeatFailureCount > MAX_STATSBEAT_FAILURES) {\n this.networkStatsbeatMetrics?.shutdown();\n this.longIntervalStatsbeatMetrics?.shutdown();\n this.networkStatsbeatMetrics = undefined;\n this.statsbeatFailureCount = 0;\n }\n }\n\n private async sendFirstPersistedFile(): Promise<void> {\n try {\n const envelopes = (await this.persister.shift()) as Envelope[] | null;\n if (envelopes) {\n await this.send(envelopes);\n }\n } catch (err: any) {\n diag.warn(`Failed to fetch persisted file`, err);\n }\n }\n\n private isNetworkError(error: RestError): boolean {\n if (error && error.code && error.code === \"REQUEST_SEND_ERROR\") {\n return true;\n }\n return false;\n }\n}\n"]}
@@ -10,7 +10,7 @@ let instance = null;
10
10
  * Azure Telemetry context.
11
11
  * @internal
12
12
  */
13
- class Context {
13
+ export class Context {
14
14
  constructor() {
15
15
  this.tags = {};
16
16
  this._loadDeviceContext();
@@ -24,20 +24,19 @@ class Context {
24
24
  [Context.nodeVersion] = node.split(".");
25
25
  Context.opentelemetryVersion = SDK_INFO[SemanticResourceAttributes.TELEMETRY_SDK_VERSION];
26
26
  Context.sdkVersion = ai.packageVersion;
27
- let prefix = process.env["AZURE_MONITOR_AGENT_PREFIX"]
27
+ const prefix = process.env["AZURE_MONITOR_AGENT_PREFIX"]
28
28
  ? process.env["AZURE_MONITOR_AGENT_PREFIX"]
29
29
  : "";
30
- let version = process.env["AZURE_MONITOR_DISTRO_VERSION"]
30
+ const version = process.env["AZURE_MONITOR_DISTRO_VERSION"]
31
31
  ? `dst${process.env["AZURE_MONITOR_DISTRO_VERSION"]}`
32
32
  : `ext${Context.sdkVersion}`;
33
- let internalSdkVersion = `${prefix}node${Context.nodeVersion}:otel${Context.opentelemetryVersion}:${version}`;
33
+ const internalSdkVersion = `${prefix}node${Context.nodeVersion}:otel${Context.opentelemetryVersion}:${version}`;
34
34
  this.tags[KnownContextTagKeys.AiInternalSdkVersion] = internalSdkVersion;
35
35
  }
36
36
  }
37
37
  Context.sdkVersion = null;
38
38
  Context.opentelemetryVersion = null;
39
39
  Context.nodeVersion = "";
40
- export { Context };
41
40
  /**
42
41
  * Singleton Context instance
43
42
  * @internal
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","sourceRoot":"","sources":["../../../../../src/platform/nodejs/context/context.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AAEjF,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,8CAA8C,CAAC;AAGnE,IAAI,QAAQ,GAAmB,IAAI,CAAC;AAEpC;;;GAGG;AACH,MAAa,OAAO;IASlB;QACE,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;QACf,IAAI,CAAC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MAAM,UAAU,WAAW;IACzB,IAAI,CAAC,QAAQ,EAAE;QACb,QAAQ,GAAG,IAAI,OAAO,EAAE,CAAC;KAC1B;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport * as os from \"os\";\nimport { SDK_INFO } from \"@opentelemetry/core\";\nimport { SemanticResourceAttributes } from \"@opentelemetry/semantic-conventions\";\n\nimport { KnownContextTagKeys } from \"../../../generated\";\nimport * as ai from \"../../../utils/constants/applicationinsights\";\nimport { Tags } from \"../../../types\";\n\nlet instance: Context | null = null;\n\n/**\n * Azure Telemetry context.\n * @internal\n */\nexport class Context {\n public tags: Tags;\n\n public static sdkVersion: string | null = null;\n\n public static opentelemetryVersion: string | null = null;\n\n public static nodeVersion: string = \"\";\n\n constructor() {\n this.tags = {};\n this._loadDeviceContext();\n this._loadInternalContext();\n }\n\n private _loadDeviceContext(): void {\n this.tags[KnownContextTagKeys.AiDeviceOsVersion] = os && `${os.type()} ${os.release()}`;\n }\n\n private _loadInternalContext(): void {\n const { node } = process.versions;\n [Context.nodeVersion] = node.split(\".\");\n Context.opentelemetryVersion = SDK_INFO[SemanticResourceAttributes.TELEMETRY_SDK_VERSION];\n Context.sdkVersion = ai.packageVersion;\n\n let prefix = process.env[\"AZURE_MONITOR_AGENT_PREFIX\"]\n ? process.env[\"AZURE_MONITOR_AGENT_PREFIX\"]\n : \"\";\n let version = process.env[\"AZURE_MONITOR_DISTRO_VERSION\"]\n ? `dst${process.env[\"AZURE_MONITOR_DISTRO_VERSION\"]}`\n : `ext${Context.sdkVersion}`;\n let internalSdkVersion = `${prefix}node${Context.nodeVersion}:otel${Context.opentelemetryVersion}:${version}`;\n this.tags[KnownContextTagKeys.AiInternalSdkVersion] = internalSdkVersion;\n }\n}\n\n/**\n * Singleton Context instance\n * @internal\n */\nexport function getInstance(): Context {\n if (!instance) {\n instance = new Context();\n }\n return instance;\n}\n"]}
1
+ {"version":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8BAA8B,CAAC;YACzD,CAAC,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,EAAE;YACrD,CAAC,CAAC,MAAM,OAAO,CAAC,UAAU,EAAE,CAAC;QAC/B,MAAM,kBAAkB,GAAG,GAAG,MAAM,OAAO,OAAO,CAAC,WAAW,QAAQ,OAAO,CAAC,oBAAoB,IAAI,OAAO,EAAE,CAAC;QAChH,IAAI,CAAC,IAAI,CAAC,mBAAmB,CAAC,oBAAoB,CAAC,GAAG,kBAAkB,CAAC;IAC3E,CAAC;;AA9Ba,kBAAU,GAAkB,IAAI,CAAC;AAEjC,4BAAoB,GAAkB,IAAI,CAAC;AAE3C,mBAAW,GAAW,EAAE,CAAC;AA6BzC;;;GAGG;AACH,MAAM,UAAU,WAAW;IACzB,IAAI,CAAC,QAAQ,EAAE;QACb,QAAQ,GAAG,IAAI,OAAO,EAAE,CAAC;KAC1B;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport * as os from \"os\";\nimport { SDK_INFO } from \"@opentelemetry/core\";\nimport { SemanticResourceAttributes } from \"@opentelemetry/semantic-conventions\";\n\nimport { KnownContextTagKeys } from \"../../../generated\";\nimport * as ai from \"../../../utils/constants/applicationinsights\";\nimport { Tags } from \"../../../types\";\n\nlet instance: Context | null = null;\n\n/**\n * Azure Telemetry context.\n * @internal\n */\nexport class Context {\n public tags: Tags;\n\n public static sdkVersion: string | null = null;\n\n public static opentelemetryVersion: string | null = null;\n\n public static nodeVersion: string = \"\";\n\n constructor() {\n this.tags = {};\n this._loadDeviceContext();\n this._loadInternalContext();\n }\n\n private _loadDeviceContext(): void {\n this.tags[KnownContextTagKeys.AiDeviceOsVersion] = os && `${os.type()} ${os.release()}`;\n }\n\n private _loadInternalContext(): void {\n const { node } = process.versions;\n [Context.nodeVersion] = node.split(\".\");\n Context.opentelemetryVersion = SDK_INFO[SemanticResourceAttributes.TELEMETRY_SDK_VERSION];\n Context.sdkVersion = ai.packageVersion;\n\n const prefix = process.env[\"AZURE_MONITOR_AGENT_PREFIX\"]\n ? process.env[\"AZURE_MONITOR_AGENT_PREFIX\"]\n : \"\";\n const version = process.env[\"AZURE_MONITOR_DISTRO_VERSION\"]\n ? `dst${process.env[\"AZURE_MONITOR_DISTRO_VERSION\"]}`\n : `ext${Context.sdkVersion}`;\n const internalSdkVersion = `${prefix}node${Context.nodeVersion}:otel${Context.opentelemetryVersion}:${version}`;\n this.tags[KnownContextTagKeys.AiInternalSdkVersion] = internalSdkVersion;\n }\n}\n\n/**\n * Singleton Context instance\n * @internal\n */\nexport function getInstance(): Context {\n if (!instance) {\n instance = new Context();\n }\n return instance;\n}\n"]}
@@ -11,17 +11,23 @@ const applicationInsightsResource = "https://monitor.azure.com//.default";
11
11
  * @internal
12
12
  */
13
13
  export class HttpSender extends BaseSender {
14
- constructor(endpointUrl, instrumentationKey, trackStatsbeat, options) {
15
- super(endpointUrl, instrumentationKey, trackStatsbeat, options);
14
+ constructor(options) {
15
+ super(options);
16
16
  // Build endpoint using provided configuration or default values
17
- this._appInsightsClientOptions = Object.assign({ host: endpointUrl }, options);
18
- if (options === null || options === void 0 ? void 0 : options.credential) {
17
+ this.appInsightsClientOptions = Object.assign({ host: options.endpointUrl }, options.exporterOptions);
18
+ if (this.appInsightsClientOptions.credential) {
19
19
  // Add credentialScopes
20
- options.credentialScopes = [applicationInsightsResource];
20
+ if (options.aadAudience) {
21
+ this.appInsightsClientOptions.credentialScopes = [options.aadAudience];
22
+ }
23
+ else {
24
+ // Default
25
+ this.appInsightsClientOptions.credentialScopes = [applicationInsightsResource];
26
+ }
21
27
  }
22
- this._appInsightsClient = new ApplicationInsightsClient(this._appInsightsClientOptions);
28
+ this.appInsightsClient = new ApplicationInsightsClient(this.appInsightsClientOptions);
23
29
  // Handle redirects in HTTP Sender
24
- this._appInsightsClient.pipeline.removePolicy({ name: redirectPolicyName });
30
+ this.appInsightsClient.pipeline.removePolicy({ name: redirectPolicyName });
25
31
  }
26
32
  /**
27
33
  * Send Azure envelopes
@@ -29,21 +35,16 @@ export class HttpSender extends BaseSender {
29
35
  */
30
36
  async send(envelopes) {
31
37
  var _a;
32
- let options = {};
33
- try {
34
- let response;
35
- function onResponse(rawResponse, flatResponse) {
36
- response = rawResponse;
37
- if (options.onResponse) {
38
- options.onResponse(rawResponse, flatResponse);
39
- }
38
+ const options = {};
39
+ let response;
40
+ function onResponse(rawResponse, flatResponse) {
41
+ response = rawResponse;
42
+ if (options.onResponse) {
43
+ options.onResponse(rawResponse, flatResponse);
40
44
  }
41
- await this._appInsightsClient.track(envelopes, Object.assign(Object.assign({}, options), { onResponse }));
42
- return { statusCode: response === null || response === void 0 ? void 0 : response.status, result: (_a = response === null || response === void 0 ? void 0 : response.bodyAsText) !== null && _a !== void 0 ? _a : "" };
43
- }
44
- catch (e) {
45
- throw e;
46
45
  }
46
+ await this.appInsightsClient.track(envelopes, Object.assign(Object.assign({}, options), { onResponse }));
47
+ return { statusCode: response === null || response === void 0 ? void 0 : response.status, result: (_a = response === null || response === void 0 ? void 0 : response.bodyAsText) !== null && _a !== void 0 ? _a : "" };
47
48
  }
48
49
  /**
49
50
  * Shutdown sender
@@ -56,7 +57,7 @@ export class HttpSender extends BaseSender {
56
57
  if (location) {
57
58
  const locUrl = new url.URL(location);
58
59
  if (locUrl && locUrl.host) {
59
- this._appInsightsClient.host = "https://" + locUrl.host;
60
+ this.appInsightsClient.host = "https://" + locUrl.host;
60
61
  }
61
62
  }
62
63
  }