@azure/monitor-opentelemetry-exporter 1.0.0-beta.17 → 1.0.0-beta.19

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 (41) hide show
  1. package/README.md +36 -12
  2. package/dist/index.js +352 -335
  3. package/dist-esm/src/export/log.js.map +1 -1
  4. package/dist-esm/src/export/metric.js.map +1 -1
  5. package/dist-esm/src/export/statsbeat/longIntervalStatsbeatMetrics.js +1 -1
  6. package/dist-esm/src/export/statsbeat/longIntervalStatsbeatMetrics.js.map +1 -1
  7. package/dist-esm/src/export/statsbeat/networkStatsbeatMetrics.js +1 -1
  8. package/dist-esm/src/export/statsbeat/networkStatsbeatMetrics.js.map +1 -1
  9. package/dist-esm/src/export/statsbeat/statsbeatExporter.js +1 -2
  10. package/dist-esm/src/export/statsbeat/statsbeatExporter.js.map +1 -1
  11. package/dist-esm/src/export/statsbeat/statsbeatMetrics.js +13 -1
  12. package/dist-esm/src/export/statsbeat/statsbeatMetrics.js.map +1 -1
  13. package/dist-esm/src/export/statsbeat/types.js +3 -2
  14. package/dist-esm/src/export/statsbeat/types.js.map +1 -1
  15. package/dist-esm/src/export/trace.js.map +1 -1
  16. package/dist-esm/src/generated/applicationInsightsClient.js +13 -30
  17. package/dist-esm/src/generated/applicationInsightsClient.js.map +1 -1
  18. package/dist-esm/src/generated/models/index.js.map +1 -1
  19. package/dist-esm/src/generated/models/mappers.js +276 -276
  20. package/dist-esm/src/generated/models/mappers.js.map +1 -1
  21. package/dist-esm/src/generated/models/parameters.js +14 -14
  22. package/dist-esm/src/generated/models/parameters.js.map +1 -1
  23. package/dist-esm/src/platform/nodejs/baseSender.js +20 -6
  24. package/dist-esm/src/platform/nodejs/baseSender.js.map +1 -1
  25. package/dist-esm/src/platform/nodejs/context/context.js +1 -2
  26. package/dist-esm/src/platform/nodejs/context/context.js.map +1 -1
  27. package/dist-esm/src/platform/nodejs/persist/fileAccessControl.js +1 -2
  28. package/dist-esm/src/platform/nodejs/persist/fileAccessControl.js.map +1 -1
  29. package/dist-esm/src/platform/nodejs/persist/fileSystemPersist.js +1 -2
  30. package/dist-esm/src/platform/nodejs/persist/fileSystemPersist.js.map +1 -1
  31. package/dist-esm/src/sampling.js.map +1 -1
  32. package/dist-esm/src/utils/common.js.map +1 -1
  33. package/dist-esm/src/utils/connectionStringParser.js +1 -2
  34. package/dist-esm/src/utils/connectionStringParser.js.map +1 -1
  35. package/dist-esm/src/utils/constants/applicationinsights.js +2 -1
  36. package/dist-esm/src/utils/constants/applicationinsights.js.map +1 -1
  37. package/dist-esm/src/utils/eventhub.js.map +1 -1
  38. package/dist-esm/src/utils/metricUtils.js.map +1 -1
  39. package/dist-esm/src/utils/spanUtils.js +6 -1
  40. package/dist-esm/src/utils/spanUtils.js.map +1 -1
  41. package/package.json +22 -23
@@ -1 +1 @@
1
- {"version":3,"file":"log.js","sourceRoot":"","sources":["../../../src/export/log.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAgB,gBAAgB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtF,OAAO,EAAE,wBAAwB,EAAE,MAAM,QAAQ,CAAC;AAElD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAIlD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;GAEG;AACH,MAAM,OAAO,uBAAwB,SAAQ,wBAAwB;IAOnE;;;OAGG;IAEH,YAAY,UAAuC,EAAE;QACnD,KAAK,CAAC,OAAO,CAAC,CAAC;QAZjB;;WAEG;QACK,gBAAW,GAAG,KAAK,CAAC;QAU1B,IAAI,CAAC,OAAO,GAAG,IAAI,UAAU,CAAC;YAC5B,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,kBAAkB,EAAE,IAAI,CAAC,kBAAkB;YAC3C,cAAc,EAA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C,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nimport { context, diag } from \"@opentelemetry/api\";\nimport { ExportResult, ExportResultCode, suppressTracing } from \"@opentelemetry/core\";\nimport { AzureMonitorBaseExporter } from \"./base\";\nimport { TelemetryItem as Envelope } from \"../generated\";\nimport { logToEnvelope } from \"../utils/logUtils\";\nimport { AzureMonitorExporterOptions } from \"../config\";\n\nimport type { ReadableLogRecord, LogRecordExporter } from \"@opentelemetry/sdk-logs\";\nimport { HttpSender } from \"../platform\";\n\n/**\n * Azure Monitor OpenTelemetry Log Exporter.\n */\nexport class AzureMonitorLogExporter extends AzureMonitorBaseExporter implements LogRecordExporter {\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 AzureMonitorLogExporter class.\n * @param AzureExporterConfig - Exporter configuration.\n */\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(\"AzureMonitorLogExporter was successfully setup\");\n }\n\n /**\n * Export OpenTelemetry logs.\n * @param logs - Logs to export.\n * @param resultCallback - Result callback.\n */\n public async export(\n logs: ReadableLogRecord[],\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 diag.info(`Exporting ${logs.length} logs(s). Converting to envelopes...`);\n\n const envelopes: Envelope[] = [];\n logs.forEach((log) => {\n const envelope = logToEnvelope(log, this.instrumentationKey);\n if (envelope) {\n envelopes.push(envelope);\n }\n });\n // Supress tracing until OpenTelemetry Logs SDK support it\n await context.with(suppressTracing(context.active()), async () => {\n resultCallback(await this._sender.exportEnvelopes(envelopes));\n });\n }\n\n /**\n * Shutdown AzureMonitorLogExporter.\n */\n public async shutdown(): Promise<void> {\n this._isShutdown = true;\n diag.info(\"AzureMonitorLogExporter shutting down\");\n return this._sender.shutdown();\n }\n}\n"]}
1
+ {"version":3,"file":"log.js","sourceRoot":"","sources":["../../../src/export/log.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAgB,gBAAgB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtF,OAAO,EAAE,wBAAwB,EAAE,MAAM,QAAQ,CAAC;AAElD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAIlD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;GAEG;AACH,MAAM,OAAO,uBAAwB,SAAQ,wBAAwB;IAOnE;;;OAGG;IAEH,YAAY,UAAuC,EAAE;QACnD,KAAK,CAAC,OAAO,CAAC,CAAC;QAZjB;;WAEG;QACK,gBAAW,GAAG,KAAK,CAAC;QAU1B,IAAI,CAAC,OAAO,GAAG,IAAI,UAAU,CAAC;YAC5B,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;QACH,IAAI,CAAC,KAAK,CAAC,gDAAgD,CAAC,CAAC;IAC/D,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,MAAM,CACjB,IAAyB,EACzB,cAA8C;QAE9C,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,IAAI,CAAC,IAAI,CAAC,6CAA6C,CAAC,CAAC;YACzD,UAAU,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;YACvE,OAAO;SACR;QACD,IAAI,CAAC,IAAI,CAAC,aAAa,IAAI,CAAC,MAAM,sCAAsC,CAAC,CAAC;QAE1E,MAAM,SAAS,GAAe,EAAE,CAAC;QACjC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YACnB,MAAM,QAAQ,GAAG,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;YAC7D,IAAI,QAAQ,EAAE;gBACZ,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;aAC1B;QACH,CAAC,CAAC,CAAC;QACH,0DAA0D;QAC1D,MAAM,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,KAAK,IAAI,EAAE;YAC/D,cAAc,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC,CAAC;QAChE,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,QAAQ;QACnB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAC;QACnD,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;IACjC,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nimport { context, diag } from \"@opentelemetry/api\";\nimport { ExportResult, ExportResultCode, suppressTracing } from \"@opentelemetry/core\";\nimport { AzureMonitorBaseExporter } from \"./base\";\nimport { TelemetryItem as Envelope } from \"../generated\";\nimport { logToEnvelope } from \"../utils/logUtils\";\nimport { AzureMonitorExporterOptions } from \"../config\";\n\nimport type { ReadableLogRecord, LogRecordExporter } from \"@opentelemetry/sdk-logs\";\nimport { HttpSender } from \"../platform\";\n\n/**\n * Azure Monitor OpenTelemetry Log Exporter.\n */\nexport class AzureMonitorLogExporter extends AzureMonitorBaseExporter implements LogRecordExporter {\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 AzureMonitorLogExporter class.\n * @param AzureExporterConfig - Exporter configuration.\n */\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(\"AzureMonitorLogExporter was successfully setup\");\n }\n\n /**\n * Export OpenTelemetry logs.\n * @param logs - Logs to export.\n * @param resultCallback - Result callback.\n */\n public async export(\n logs: ReadableLogRecord[],\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 diag.info(`Exporting ${logs.length} logs(s). Converting to envelopes...`);\n\n const envelopes: Envelope[] = [];\n logs.forEach((log) => {\n const envelope = logToEnvelope(log, this.instrumentationKey);\n if (envelope) {\n envelopes.push(envelope);\n }\n });\n // Supress tracing until OpenTelemetry Logs SDK support it\n await context.with(suppressTracing(context.active()), async () => {\n resultCallback(await this._sender.exportEnvelopes(envelopes));\n });\n }\n\n /**\n * Shutdown AzureMonitorLogExporter.\n */\n public async shutdown(): Promise<void> {\n this._isShutdown = true;\n diag.info(\"AzureMonitorLogExporter shutting down\");\n return this._sender.shutdown();\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"metric.js","sourceRoot":"","sources":["../../../src/export/metric.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EACL,sBAAsB,EACtB,cAAc,GAGf,MAAM,4B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AAC,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,KAAK,IAAI,EAAE;YAC/D,cAAc,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC,CAAC;QAChE,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,QAAQ;QACnB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,IAAI,CAAC,0CAA0C,CAAC,CAAC;QACtD,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;IACjC,CAAC;IAED;;OAEG;IACI,4BAA4B,CAAC,cAA8B;QAChE,IACE,cAAc,KAAK,cAAc,CAAC,eAAe;YACjD,cAAc,KAAK,cAAc,CAAC,0BAA0B,EAC5D;YACA,OAAO,sBAAsB,CAAC,UAAU,CAAC;SAC1C;QACD,OAAO,sBAAsB,CAAC,KAAK,CAAC;IACtC,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,UAAU;QACrB,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nimport { context, diag } from \"@opentelemetry/api\";\nimport {\n AggregationTemporality,\n InstrumentType,\n PushMetricExporter,\n ResourceMetrics,\n} from \"@opentelemetry/sdk-metrics\";\nimport { ExportResult, ExportResultCode, suppressTracing } from \"@opentelemetry/core\";\nimport { AzureMonitorBaseExporter } from \"./base\";\nimport { TelemetryItem as Envelope } from \"../generated\";\nimport { resourceMetricsToEnvelope } from \"../utils/metricUtils\";\nimport { AzureMonitorExporterOptions } from \"../config\";\nimport { HttpSender } from \"../platform\";\n\n/**\n * Azure Monitor OpenTelemetry Metric Exporter.\n */\nexport class AzureMonitorMetricExporter\n extends AzureMonitorBaseExporter\n implements PushMetricExporter\n{\n /**\n * Flag to determine if Exporter is shutdown.\n */\n private _isShutdown = false;\n private _sender: HttpSender;\n\n /**\n * Initializes a new instance of the AzureMonitorMetricExporter class.\n * @param AzureExporterConfig - Exporter configuration.\n */\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(\"AzureMonitorMetricExporter was successfully setup\");\n }\n\n /**\n * Export OpenTelemetry resource metrics.\n * @param metrics - Resource metrics to export.\n * @param resultCallback - Result callback.\n */\n async export(\n metrics: ResourceMetrics,\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 diag.info(`Exporting ${metrics.scopeMetrics.length} metrics(s). Converting to envelopes...`);\n\n const envelopes: Envelope[] = resourceMetricsToEnvelope(metrics, this.instrumentationKey);\n // Supress tracing until OpenTelemetry Metrics SDK support it\n await context.with(suppressTracing(context.active()), async () => {\n resultCallback(await this._sender.exportEnvelopes(envelopes));\n });\n }\n\n /**\n * Shutdown AzureMonitorMetricExporter.\n */\n public async shutdown(): Promise<void> {\n this._isShutdown = true;\n diag.info(\"AzureMonitorMetricExporter shutting down\");\n return this._sender.shutdown();\n }\n\n /**\n * Select aggregation temporality\n */\n public selectAggregationTemporality(instrumentType: InstrumentType): AggregationTemporality {\n if (\n instrumentType === InstrumentType.UP_DOWN_COUNTER ||\n instrumentType === InstrumentType.OBSERVABLE_UP_DOWN_COUNTER\n ) {\n return AggregationTemporality.CUMULATIVE;\n }\n return AggregationTemporality.DELTA;\n }\n\n /**\n * Force flush\n */\n public async forceFlush(): Promise<void> {\n return Promise.resolve();\n }\n}\n"]}
1
+ {"version":3,"file":"metric.js","sourceRoot":"","sources":["../../../src/export/metric.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE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AAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;QAC1F,6DAA6D;QAC7D,MAAM,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,KAAK,IAAI,EAAE;YAC/D,cAAc,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC,CAAC;QAChE,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,QAAQ;QACnB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,IAAI,CAAC,0CAA0C,CAAC,CAAC;QACtD,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;IACjC,CAAC;IAED;;OAEG;IACI,4BAA4B,CAAC,cAA8B;QAChE,IACE,cAAc,KAAK,cAAc,CAAC,eAAe;YACjD,cAAc,KAAK,cAAc,CAAC,0BAA0B,EAC5D;YACA,OAAO,sBAAsB,CAAC,UAAU,CAAC;SAC1C;QACD,OAAO,sBAAsB,CAAC,KAAK,CAAC;IACtC,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,UAAU;QACrB,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nimport { context, diag } from \"@opentelemetry/api\";\nimport {\n AggregationTemporality,\n InstrumentType,\n PushMetricExporter,\n ResourceMetrics,\n} from \"@opentelemetry/sdk-metrics\";\nimport { ExportResult, ExportResultCode, suppressTracing } from \"@opentelemetry/core\";\nimport { AzureMonitorBaseExporter } from \"./base\";\nimport { TelemetryItem as Envelope } from \"../generated\";\nimport { resourceMetricsToEnvelope } from \"../utils/metricUtils\";\nimport { AzureMonitorExporterOptions } from \"../config\";\nimport { HttpSender } from \"../platform\";\n\n/**\n * Azure Monitor OpenTelemetry Metric Exporter.\n */\nexport class AzureMonitorMetricExporter\n extends AzureMonitorBaseExporter\n implements PushMetricExporter\n{\n /**\n * Flag to determine if Exporter is shutdown.\n */\n private _isShutdown = false;\n private _sender: HttpSender;\n\n /**\n * Initializes a new instance of the AzureMonitorMetricExporter class.\n * @param AzureExporterConfig - Exporter configuration.\n */\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(\"AzureMonitorMetricExporter was successfully setup\");\n }\n\n /**\n * Export OpenTelemetry resource metrics.\n * @param metrics - Resource metrics to export.\n * @param resultCallback - Result callback.\n */\n async export(\n metrics: ResourceMetrics,\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 diag.info(`Exporting ${metrics.scopeMetrics.length} metrics(s). Converting to envelopes...`);\n\n const envelopes: Envelope[] = resourceMetricsToEnvelope(metrics, this.instrumentationKey);\n // Supress tracing until OpenTelemetry Metrics SDK support it\n await context.with(suppressTracing(context.active()), async () => {\n resultCallback(await this._sender.exportEnvelopes(envelopes));\n });\n }\n\n /**\n * Shutdown AzureMonitorMetricExporter.\n */\n public async shutdown(): Promise<void> {\n this._isShutdown = true;\n diag.info(\"AzureMonitorMetricExporter shutting down\");\n return this._sender.shutdown();\n }\n\n /**\n * Select aggregation temporality\n */\n public selectAggregationTemporality(instrumentType: InstrumentType): AggregationTemporality {\n if (\n instrumentType === InstrumentType.UP_DOWN_COUNTER ||\n instrumentType === InstrumentType.OBSERVABLE_UP_DOWN_COUNTER\n ) {\n return AggregationTemporality.CUMULATIVE;\n }\n return AggregationTemporality.DELTA;\n }\n\n /**\n * Force flush\n */\n public async forceFlush(): Promise<void> {\n return Promise.resolve();\n }\n}\n"]}
@@ -17,7 +17,7 @@ class LongIntervalStatsbeatMetrics extends StatsbeatMetrics {
17
17
  super();
18
18
  this.AZURE_MONITOR_STATSBEAT_FEATURES = process.env.AZURE_MONITOR_STATSBEAT_FEATURES;
19
19
  this.statsCollectionLongInterval = 86400000; // 1 day
20
- this.attach = "sdk";
20
+ this.attach = "Manual";
21
21
  this.feature = 0;
22
22
  this.instrumentation = 0;
23
23
  this.isInitialized = false;
@@ -1 +1 @@
1
- {"version":3,"file":"longIntervalStatsbeatMetrics.js","sourceRoot":"","sources":["../../../../src/export/statsbeat/longIntervalStatsbeatMetrics.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EACL,IAAI,GAKL,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAgB,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EACL,aAAa,EACb,6BAA6B,GAE9B,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,MAAM,2CAA2C,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAGlB,oBAAoB,GAErB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,6BAA6B,EAAE,MAAM,qBAAqB,CAAC;AAEpE,IAAI,QAAQ,GAAwC,IAAI,CAAC;AAEzD;;;GAGG;AACH,MAAM,4BAA6B,SAAQ,gBAAgB;IA8BzD,YAAY,OAAyB;QACnC,KAAK,EAAE,CAAC;QA9BF,qCAAgC,GAAG,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC;QAChF,gCAA2B,GAAW,QAAQ,CAAC,CAAC,QAAQ;QAMxD,WAAM,GAAW,KAAK,CAAC;QAKvB,YAAO,GAAW,CAAC,CAAC;QACpB,oBAAe,GAAW,CAAC,CAAC;QAc7B,kBAAa,GAAY,KAAK,CAAC;QAIpC,IAAI,CAAC,gBAAgB,GAAG,KAAK,CAAC,mBAAmB,CAAC,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B,CAAC,OAAO,CAAC,CAAC;KACtD;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n diag,\n BatchObservableResult,\n ObservableGauge,\n ObservableResult,\n Meter,\n} from \"@opentelemetry/api\";\nimport { ExportResult, ExportResultCode } from \"@opentelemetry/core\";\nimport {\n MeterProvider,\n PeriodicExportingMetricReader,\n PeriodicExportingMetricReaderOptions,\n} from \"@opentelemetry/sdk-metrics\";\nimport { AzureMonitorExporterOptions } from \"../../index\";\nimport * as ai from \"../../utils/constants/applicationinsights\";\nimport { StatsbeatMetrics } from \"./statsbeatMetrics\";\nimport {\n StatsbeatCounter,\n STATSBEAT_LANGUAGE,\n CommonStatsbeatProperties,\n AttachStatsbeatProperties,\n StatsbeatFeatureType,\n StatsbeatOptions,\n} from \"./types\";\nimport { AzureMonitorStatsbeatExporter } from \"./statsbeatExporter\";\n\nlet instance: LongIntervalStatsbeatMetrics | null = null;\n\n/**\n * Long Interval Statsbeat Metrics\n * @internal\n */\nclass LongIntervalStatsbeatMetrics extends StatsbeatMetrics {\n private AZURE_MONITOR_STATSBEAT_FEATURES = process.env.AZURE_MONITOR_STATSBEAT_FEATURES;\n private statsCollectionLongInterval: number = 86400000; // 1 day\n // Custom dimensions\n private cikey: string;\n private runtimeVersion: string;\n private language: string;\n private version: string;\n private attach: string = \"sdk\";\n\n private commonProperties: CommonStatsbeatProperties;\n private attachProperties: AttachStatsbeatProperties;\n\n private feature: number = 0;\n private instrumentation: number = 0;\n\n private longIntervalStatsbeatMeterProvider: MeterProvider;\n private longIntervalAzureExporter: AzureMonitorStatsbeatExporter;\n private longIntervalMetricReader: PeriodicExportingMetricReader;\n private longIntervalStatsbeatMeter: Meter;\n\n // Network Attributes\n private connectionString: string;\n\n // Observable Gauges\n private featureStatsbeatGauge: ObservableGauge;\n private attachStatsbeatGauge: ObservableGauge;\n\n public isInitialized: boolean = false;\n\n constructor(options: StatsbeatOptions) {\n super();\n this.connectionString = super.getConnectionString(options.endpointUrl);\n const exporterConfig: AzureMonitorExporterOptions = {\n connectionString: this.connectionString,\n };\n\n if (this.AZURE_MONITOR_STATSBEAT_FEATURES) {\n try {\n this.feature = JSON.parse(this.AZURE_MONITOR_STATSBEAT_FEATURES).feature;\n this.instrumentation = JSON.parse(this.AZURE_MONITOR_STATSBEAT_FEATURES).instrumentation;\n } catch (error: any) {\n diag.error(\n `LongIntervalStatsbeat: Failed to parse features/instrumentations (error ${error})`\n );\n }\n }\n\n this.longIntervalStatsbeatMeterProvider = new MeterProvider();\n this.longIntervalAzureExporter = new AzureMonitorStatsbeatExporter(exporterConfig);\n\n // Export Long Interval Statsbeats every day\n const longIntervalMetricReaderOptions: PeriodicExportingMetricReaderOptions = {\n exporter: this.longIntervalAzureExporter,\n exportIntervalMillis:\n Number(process.env.LONG_INTERVAL_EXPORT_MILLIS) || this.statsCollectionLongInterval, // 1 day\n };\n\n this.longIntervalMetricReader = new PeriodicExportingMetricReader(\n longIntervalMetricReaderOptions\n );\n this.longIntervalStatsbeatMeterProvider.addMetricReader(this.longIntervalMetricReader);\n this.longIntervalStatsbeatMeter = this.longIntervalStatsbeatMeterProvider.getMeter(\n \"Azure Monitor Long Interval Statsbeat\"\n );\n\n // Assign Common Properties\n this.runtimeVersion = process.version;\n this.language = STATSBEAT_LANGUAGE;\n this.version = ai.packageVersion;\n this.cikey = options.instrumentationKey;\n\n this.featureStatsbeatGauge = this.longIntervalStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.FEATURE\n );\n this.attachStatsbeatGauge = this.longIntervalStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.ATTACH\n );\n\n this.commonProperties = {\n os: super.os,\n rp: super.resourceProvider,\n cikey: this.cikey,\n runtimeVersion: this.runtimeVersion,\n language: this.language,\n version: this.version,\n attach: this.attach,\n };\n\n this.attachProperties = {\n rpId: super.resourceIdentifier,\n };\n\n this.isInitialized = true;\n this.initialize();\n }\n\n private async initialize() {\n try {\n await this.getResourceProvider();\n\n // Add long interval observable callbacks\n this.attachStatsbeatGauge.addCallback(this.attachCallback.bind(this));\n this.longIntervalStatsbeatMeter.addBatchObservableCallback(this.featureCallback.bind(this), [\n this.featureStatsbeatGauge,\n ]);\n\n // Export Feature/Attach Statsbeat once upon app initialization\n this.longIntervalAzureExporter.export(\n (await this.longIntervalMetricReader.collect()).resourceMetrics,\n (result: ExportResult) => {\n if (result.code !== ExportResultCode.SUCCESS) {\n diag.error(`LongIntervalStatsbeat: metrics export failed (error ${result.error})`);\n }\n }\n );\n } catch (error) {\n diag.debug(\"Call to get the resource provider failed.\");\n }\n }\n\n private featureCallback(observableResult: BatchObservableResult) {\n let attributes;\n if (this.instrumentation) {\n attributes = {\n ...this.commonProperties,\n feature: this.instrumentation,\n type: StatsbeatFeatureType.INSTRUMENTATION,\n };\n observableResult.observe(this.featureStatsbeatGauge, 1, { ...attributes });\n }\n\n if (this.feature) {\n attributes = {\n ...this.commonProperties,\n feature: this.feature,\n type: StatsbeatFeatureType.FEATURE,\n };\n observableResult.observe(this.featureStatsbeatGauge, 1, { ...attributes });\n }\n }\n\n private attachCallback(observableResult: ObservableResult) {\n const attributes = { ...this.commonProperties, ...this.attachProperties };\n observableResult.observe(1, attributes);\n }\n\n public shutdown(): Promise<void> {\n return this.longIntervalStatsbeatMeterProvider.shutdown();\n }\n}\n\n/**\n * Singleton LongIntervalStatsbeatMetrics instance.\n * @internal\n */\nexport function getInstance(options: StatsbeatOptions): LongIntervalStatsbeatMetrics {\n if (!instance) {\n instance = new LongIntervalStatsbeatMetrics(options);\n }\n return instance;\n}\n"]}
1
+ {"version":3,"file":"longIntervalStatsbeatMetrics.js","sourceRoot":"","sources":["../../../../src/export/statsbeat/longIntervalStatsbeatMetrics.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EACL,IAAI,GAKL,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAgB,gBAAgB,EAA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F,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,qBAAqB,EAAE,CAAC,oBAAO,UAAU,EAAG,CAAC;SAC5E;QAED,IAAI,IAAI,CAAC,OAAO,EAAE;YAChB,UAAU,mCACL,IAAI,CAAC,gBAAgB,KACxB,OAAO,EAAE,IAAI,CAAC,OAAO,EACrB,IAAI,EAAE,oBAAoB,CAAC,OAAO,GACnC,CAAC;YACF,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,qBAAqB,EAAE,CAAC,oBAAO,UAAU,EAAG,CAAC;SAC5E;IACH,CAAC;IAEO,cAAc,CAAC,gBAAkC;QACvD,MAAM,UAAU,mCAAQ,IAAI,CAAC,gBAAgB,GAAK,IAAI,CAAC,gBAAgB,CAAE,CAAC;QAC1E,gBAAgB,CAAC,OAAO,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;IAC1C,CAAC;IAEM,QAAQ;QACb,OAAO,IAAI,CAAC,kCAAkC,CAAC,QAAQ,EAAE,CAAC;IAC5D,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,OAAyB;IACnD,IAAI,CAAC,QAAQ,EAAE;QACb,QAAQ,GAAG,IAAI,4BAA4B,CAAC,OAAO,CAAC,CAAC;KACtD;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n diag,\n BatchObservableResult,\n ObservableGauge,\n ObservableResult,\n Meter,\n} from \"@opentelemetry/api\";\nimport { ExportResult, ExportResultCode } from \"@opentelemetry/core\";\nimport {\n MeterProvider,\n PeriodicExportingMetricReader,\n PeriodicExportingMetricReaderOptions,\n} from \"@opentelemetry/sdk-metrics\";\nimport { AzureMonitorExporterOptions } from \"../../index\";\nimport * as ai from \"../../utils/constants/applicationinsights\";\nimport { StatsbeatMetrics } from \"./statsbeatMetrics\";\nimport {\n StatsbeatCounter,\n STATSBEAT_LANGUAGE,\n CommonStatsbeatProperties,\n AttachStatsbeatProperties,\n StatsbeatFeatureType,\n StatsbeatOptions,\n} from \"./types\";\nimport { AzureMonitorStatsbeatExporter } from \"./statsbeatExporter\";\n\nlet instance: LongIntervalStatsbeatMetrics | null = null;\n\n/**\n * Long Interval Statsbeat Metrics\n * @internal\n */\nclass LongIntervalStatsbeatMetrics extends StatsbeatMetrics {\n private AZURE_MONITOR_STATSBEAT_FEATURES = process.env.AZURE_MONITOR_STATSBEAT_FEATURES;\n private statsCollectionLongInterval: number = 86400000; // 1 day\n // Custom dimensions\n private cikey: string;\n private runtimeVersion: string;\n private language: string;\n private version: string;\n private attach: string = \"Manual\";\n\n private commonProperties: CommonStatsbeatProperties;\n private attachProperties: AttachStatsbeatProperties;\n\n private feature: number = 0;\n private instrumentation: number = 0;\n\n private longIntervalStatsbeatMeterProvider: MeterProvider;\n private longIntervalAzureExporter: AzureMonitorStatsbeatExporter;\n private longIntervalMetricReader: PeriodicExportingMetricReader;\n private longIntervalStatsbeatMeter: Meter;\n\n // Network Attributes\n private connectionString: string;\n\n // Observable Gauges\n private featureStatsbeatGauge: ObservableGauge;\n private attachStatsbeatGauge: ObservableGauge;\n\n public isInitialized: boolean = false;\n\n constructor(options: StatsbeatOptions) {\n super();\n this.connectionString = super.getConnectionString(options.endpointUrl);\n const exporterConfig: AzureMonitorExporterOptions = {\n connectionString: this.connectionString,\n };\n\n if (this.AZURE_MONITOR_STATSBEAT_FEATURES) {\n try {\n this.feature = JSON.parse(this.AZURE_MONITOR_STATSBEAT_FEATURES).feature;\n this.instrumentation = JSON.parse(this.AZURE_MONITOR_STATSBEAT_FEATURES).instrumentation;\n } catch (error: any) {\n diag.error(\n `LongIntervalStatsbeat: Failed to parse features/instrumentations (error ${error})`,\n );\n }\n }\n\n this.longIntervalStatsbeatMeterProvider = new MeterProvider();\n this.longIntervalAzureExporter = new AzureMonitorStatsbeatExporter(exporterConfig);\n\n // Export Long Interval Statsbeats every day\n const longIntervalMetricReaderOptions: PeriodicExportingMetricReaderOptions = {\n exporter: this.longIntervalAzureExporter,\n exportIntervalMillis:\n Number(process.env.LONG_INTERVAL_EXPORT_MILLIS) || this.statsCollectionLongInterval, // 1 day\n };\n\n this.longIntervalMetricReader = new PeriodicExportingMetricReader(\n longIntervalMetricReaderOptions,\n );\n this.longIntervalStatsbeatMeterProvider.addMetricReader(this.longIntervalMetricReader);\n this.longIntervalStatsbeatMeter = this.longIntervalStatsbeatMeterProvider.getMeter(\n \"Azure Monitor Long Interval Statsbeat\",\n );\n\n // Assign Common Properties\n this.runtimeVersion = process.version;\n this.language = STATSBEAT_LANGUAGE;\n this.version = ai.packageVersion;\n this.cikey = options.instrumentationKey;\n\n this.featureStatsbeatGauge = this.longIntervalStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.FEATURE,\n );\n this.attachStatsbeatGauge = this.longIntervalStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.ATTACH,\n );\n\n this.commonProperties = {\n os: super.os,\n rp: super.resourceProvider,\n cikey: this.cikey,\n runtimeVersion: this.runtimeVersion,\n language: this.language,\n version: this.version,\n attach: this.attach,\n };\n\n this.attachProperties = {\n rpId: super.resourceIdentifier,\n };\n\n this.isInitialized = true;\n this.initialize();\n }\n\n private async initialize() {\n try {\n await this.getResourceProvider();\n\n // Add long interval observable callbacks\n this.attachStatsbeatGauge.addCallback(this.attachCallback.bind(this));\n this.longIntervalStatsbeatMeter.addBatchObservableCallback(this.featureCallback.bind(this), [\n this.featureStatsbeatGauge,\n ]);\n\n // Export Feature/Attach Statsbeat once upon app initialization\n this.longIntervalAzureExporter.export(\n (await this.longIntervalMetricReader.collect()).resourceMetrics,\n (result: ExportResult) => {\n if (result.code !== ExportResultCode.SUCCESS) {\n diag.error(`LongIntervalStatsbeat: metrics export failed (error ${result.error})`);\n }\n },\n );\n } catch (error) {\n diag.debug(\"Call to get the resource provider failed.\");\n }\n }\n\n private featureCallback(observableResult: BatchObservableResult) {\n let attributes;\n if (this.instrumentation) {\n attributes = {\n ...this.commonProperties,\n feature: this.instrumentation,\n type: StatsbeatFeatureType.INSTRUMENTATION,\n };\n observableResult.observe(this.featureStatsbeatGauge, 1, { ...attributes });\n }\n\n if (this.feature) {\n attributes = {\n ...this.commonProperties,\n feature: this.feature,\n type: StatsbeatFeatureType.FEATURE,\n };\n observableResult.observe(this.featureStatsbeatGauge, 1, { ...attributes });\n }\n }\n\n private attachCallback(observableResult: ObservableResult) {\n const attributes = { ...this.commonProperties, ...this.attachProperties };\n observableResult.observe(1, attributes);\n }\n\n public shutdown(): Promise<void> {\n return this.longIntervalStatsbeatMeterProvider.shutdown();\n }\n}\n\n/**\n * Singleton LongIntervalStatsbeatMetrics instance.\n * @internal\n */\nexport function getInstance(options: StatsbeatOptions): LongIntervalStatsbeatMetrics {\n if (!instance) {\n instance = new LongIntervalStatsbeatMetrics(options);\n }\n return instance;\n}\n"]}
@@ -12,7 +12,7 @@ export class NetworkStatsbeatMetrics extends StatsbeatMetrics {
12
12
  this.isInitialized = false;
13
13
  this.statsCollectionShortInterval = 900000; // 15 minutes
14
14
  this.networkStatsbeatCollection = [];
15
- this.attach = "sdk";
15
+ this.attach = "Manual";
16
16
  this.connectionString = super.getConnectionString(options.endpointUrl);
17
17
  this.networkStatsbeatMeterProvider = new MeterProvider();
18
18
  const exporterConfig = {
@@ -1 +1 @@
1
- {"version":3,"file":"networkStatsbeatMetrics.js","sourceRoot":"","sources":["../../../../src/export/statsbeat/networkStatsbeatMetrics.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EACL,IAAI,GAKL,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,aAAa,EACb,6BAA6B,GAE9B,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,MAAM,2CAA2C,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,GAIjB,MAAM,SAAS,CA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M,GAAG,CAAC,EAAE;gBAClC,SAAS,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;aACpB;YACD,SAAS,GAAG,SAAS,CAAC,OAAO,CAAC,mCAAmC,EAAE,EAAE,CAAC,CAAC;SACxE;QAAC,OAAO,KAAK,EAAE;YACd,IAAI,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAC;SAClD;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n diag,\n BatchObservableResult,\n Meter,\n ObservableGauge,\n ObservableResult,\n} from \"@opentelemetry/api\";\nimport {\n MeterProvider,\n PeriodicExportingMetricReader,\n PeriodicExportingMetricReaderOptions,\n} from \"@opentelemetry/sdk-metrics\";\nimport { AzureMonitorExporterOptions } from \"../../index\";\nimport * as ai from \"../../utils/constants/applicationinsights\";\nimport { StatsbeatMetrics } from \"./statsbeatMetrics\";\nimport {\n StatsbeatCounter,\n STATSBEAT_LANGUAGE,\n NetworkStatsbeat,\n CommonStatsbeatProperties,\n NetworkStatsbeatProperties,\n StatsbeatOptions,\n} from \"./types\";\nimport { AzureMonitorStatsbeatExporter } from \"./statsbeatExporter\";\n\nexport class NetworkStatsbeatMetrics extends StatsbeatMetrics {\n private commonProperties: CommonStatsbeatProperties;\n private networkProperties: NetworkStatsbeatProperties;\n private isInitialized: boolean = false;\n private statsCollectionShortInterval: number = 900000; // 15 minutes\n\n private networkStatsbeatCollection: Array<NetworkStatsbeat> = [];\n private networkStatsbeatMeter: Meter;\n private networkStatsbeatMeterProvider: MeterProvider;\n private networkAzureExporter: AzureMonitorStatsbeatExporter;\n private networkMetricReader: PeriodicExportingMetricReader;\n\n // Custom dimensions\n private cikey: string;\n private runtimeVersion: string;\n private language: string;\n private version: string;\n private attach: string = \"sdk\";\n\n // Observable Gauges\n private successCountGauge: ObservableGauge;\n private failureCountGauge: ObservableGauge;\n private retryCountGauge: ObservableGauge;\n private throttleCountGauge: ObservableGauge;\n private exceptionCountGauge: ObservableGauge;\n private averageDurationGauge: ObservableGauge;\n\n // Network attributes\n private connectionString: string;\n private endpointUrl: string;\n private host: string;\n\n constructor(options: StatsbeatOptions) {\n super();\n this.connectionString = super.getConnectionString(options.endpointUrl);\n this.networkStatsbeatMeterProvider = new MeterProvider();\n\n const exporterConfig: AzureMonitorExporterOptions = {\n connectionString: this.connectionString,\n };\n\n this.networkAzureExporter = new AzureMonitorStatsbeatExporter(exporterConfig);\n\n // Exports Network Statsbeat every 15 minutes\n const networkMetricReaderOptions: PeriodicExportingMetricReaderOptions = {\n exporter: this.networkAzureExporter,\n exportIntervalMillis: options.networkCollectionInterval || this.statsCollectionShortInterval, // 15 minutes\n };\n\n this.networkMetricReader = new PeriodicExportingMetricReader(networkMetricReaderOptions);\n this.networkStatsbeatMeterProvider.addMetricReader(this.networkMetricReader);\n this.networkStatsbeatMeter = this.networkStatsbeatMeterProvider.getMeter(\n \"Azure Monitor Network Statsbeat\"\n );\n\n this.endpointUrl = options.endpointUrl;\n this.runtimeVersion = process.version;\n this.language = STATSBEAT_LANGUAGE;\n this.version = ai.packageVersion;\n this.host = this.getShortHost(options.endpointUrl);\n this.cikey = options.instrumentationKey;\n\n this.successCountGauge = this.networkStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.SUCCESS_COUNT\n );\n this.failureCountGauge = this.networkStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.FAILURE_COUNT\n );\n this.retryCountGauge = this.networkStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.RETRY_COUNT\n );\n this.throttleCountGauge = this.networkStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.THROTTLE_COUNT\n );\n this.exceptionCountGauge = this.networkStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.EXCEPTION_COUNT\n );\n this.averageDurationGauge = this.networkStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.AVERAGE_DURATION\n );\n\n this.commonProperties = {\n os: super.os,\n rp: super.resourceProvider,\n cikey: this.cikey,\n runtimeVersion: this.runtimeVersion,\n language: this.language,\n version: this.version,\n attach: this.attach,\n };\n\n this.networkProperties = {\n endpoint: this.endpointUrl,\n host: this.host,\n };\n\n this.isInitialized = true;\n this.initialize();\n }\n\n public shutdown(): Promise<void> {\n return this.networkStatsbeatMeterProvider.shutdown();\n }\n\n private async initialize(): Promise<void> {\n try {\n await super.getResourceProvider();\n\n // Add network observable callbacks\n this.successCountGauge.addCallback(this.successCallback.bind(this));\n this.networkStatsbeatMeter.addBatchObservableCallback(this.failureCallback.bind(this), [\n this.failureCountGauge,\n ]);\n this.networkStatsbeatMeter.addBatchObservableCallback(this.retryCallback.bind(this), [\n this.retryCountGauge,\n ]);\n this.networkStatsbeatMeter.addBatchObservableCallback(this.throttleCallback.bind(this), [\n this.throttleCountGauge,\n ]);\n this.networkStatsbeatMeter.addBatchObservableCallback(this.exceptionCallback.bind(this), [\n this.exceptionCountGauge,\n ]);\n this.averageDurationGauge.addCallback(this.durationCallback.bind(this));\n } catch (error) {\n diag.debug(\"Call to get the resource provider failed.\");\n }\n }\n\n // Observable gauge callbacks\n private successCallback(observableResult: ObservableResult): void {\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n const attributes = { ...this.commonProperties, ...this.networkProperties };\n observableResult.observe(counter.totalSuccesfulRequestCount, attributes);\n counter.totalSuccesfulRequestCount = 0;\n }\n\n private failureCallback(observableResult: BatchObservableResult) {\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n\n /*\n Takes the failureCountGauge, value (of the counter), and attributes\n create a unqiue counter based on statusCode as well\n append statusCode to attributes so the newly created attributes are unique.\n */\n const attributes = { ...this.networkProperties, ...this.commonProperties, statusCode: 0 };\n\n // For each { statusCode -> count } mapping, call observe, passing the count and attributes that include the statusCode\n for (let i = 0; i < counter.totalFailedRequestCount.length; i++) {\n attributes.statusCode = counter.totalFailedRequestCount[i].statusCode;\n observableResult.observe(this.failureCountGauge, counter.totalFailedRequestCount[i].count, {\n ...attributes,\n });\n counter.totalFailedRequestCount[i].count = 0;\n }\n }\n\n private retryCallback(observableResult: BatchObservableResult): void {\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n const attributes = { ...this.networkProperties, ...this.commonProperties, statusCode: 0 };\n\n for (let i = 0; i < counter.retryCount.length; i++) {\n attributes.statusCode = counter.retryCount[i].statusCode;\n observableResult.observe(this.retryCountGauge, counter.retryCount[i].count, {\n ...attributes,\n });\n counter.retryCount[i].count = 0;\n }\n }\n\n private throttleCallback(observableResult: BatchObservableResult): void {\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n const attributes = { ...this.networkProperties, ...this.commonProperties, statusCode: 0 };\n\n for (let i = 0; i < counter.throttleCount.length; i++) {\n attributes.statusCode = counter.throttleCount[i].statusCode;\n observableResult.observe(this.throttleCountGauge, counter.throttleCount[i].count, {\n ...attributes,\n });\n counter.throttleCount[i].count = 0;\n }\n }\n\n private exceptionCallback(observableResult: BatchObservableResult): void {\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n const attributes = { ...this.networkProperties, ...this.commonProperties, exceptionType: \"\" };\n\n for (let i = 0; i < counter.exceptionCount.length; i++) {\n attributes.exceptionType = counter.exceptionCount[i].exceptionType;\n observableResult.observe(this.exceptionCountGauge, counter.exceptionCount[i].count, {\n ...attributes,\n });\n counter.exceptionCount[i].count = 0;\n }\n }\n\n private durationCallback(observableResult: ObservableResult): void {\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n const attributes = { ...this.networkProperties, ...this.commonProperties };\n for (let i = 0; i < this.networkStatsbeatCollection.length; i++) {\n const currentCounter = this.networkStatsbeatCollection[i];\n currentCounter.time = Number(new Date());\n const intervalRequests =\n currentCounter.totalRequestCount - currentCounter.lastRequestCount || 0;\n currentCounter.averageRequestExecutionTime =\n (currentCounter.intervalRequestExecutionTime -\n currentCounter.lastIntervalRequestExecutionTime) /\n intervalRequests || 0;\n currentCounter.lastIntervalRequestExecutionTime = currentCounter.intervalRequestExecutionTime; // reset\n\n currentCounter.lastRequestCount = currentCounter.totalRequestCount;\n currentCounter.lastTime = currentCounter.time;\n }\n observableResult.observe(counter.averageRequestExecutionTime, attributes);\n\n counter.averageRequestExecutionTime = 0;\n }\n\n // Public methods to increase counters\n public countSuccess(duration: number): void {\n if (!this.isInitialized) {\n return;\n }\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n counter.totalRequestCount++;\n counter.totalSuccesfulRequestCount++;\n counter.intervalRequestExecutionTime += duration;\n }\n\n public countFailure(duration: number, statusCode: number) {\n if (!this.isInitialized) {\n return;\n }\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n const currentStatusCounter = counter.totalFailedRequestCount.find(\n (statusCounter) => statusCode === statusCounter.statusCode\n );\n\n if (currentStatusCounter) {\n currentStatusCounter.count++;\n } else {\n counter.totalFailedRequestCount.push({ statusCode: statusCode, count: 1 });\n }\n\n counter.totalRequestCount++;\n counter.intervalRequestExecutionTime += duration;\n }\n\n public countRetry(statusCode: number): void {\n if (!this.isInitialized) {\n return;\n }\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n const currentStatusCounter = counter.retryCount.find(\n (statusCounter) => statusCode === statusCounter.statusCode\n );\n\n if (currentStatusCounter) {\n currentStatusCounter.count++;\n } else {\n counter.retryCount.push({ statusCode: statusCode, count: 1 });\n }\n }\n\n public countThrottle(statusCode: number): void {\n if (!this.isInitialized) {\n return;\n }\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n const currentStatusCounter = counter.throttleCount.find(\n (statusCounter) => statusCode === statusCounter.statusCode\n );\n\n if (currentStatusCounter) {\n currentStatusCounter.count++;\n } else {\n counter.throttleCount.push({ statusCode: statusCode, count: 1 });\n }\n }\n\n public countException(exceptionType: Error): void {\n if (!this.isInitialized) {\n return;\n }\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n const currentErrorCounter = counter.exceptionCount.find(\n (exceptionCounter) => exceptionType.name === exceptionCounter.exceptionType\n );\n if (currentErrorCounter) {\n currentErrorCounter.count++;\n } else {\n counter.exceptionCount.push({ exceptionType: exceptionType.name, count: 1 });\n }\n }\n\n // Gets a networkStatsbeat counter if one exists for the given endpoint\n private getNetworkStatsbeatCounter(endpoint: string, host: string): NetworkStatsbeat {\n // Check if the counter is available\n for (let i = 0; i < this.networkStatsbeatCollection.length; i++) {\n // Same object\n if (\n endpoint === this.networkStatsbeatCollection[i].endpoint &&\n host === this.networkStatsbeatCollection[i].host\n ) {\n return this.networkStatsbeatCollection[i];\n }\n }\n // Create a new counter if not found\n const newCounter = new NetworkStatsbeat(endpoint, host);\n this.networkStatsbeatCollection.push(newCounter);\n return newCounter;\n }\n\n private getShortHost(originalHost: string): string {\n let shortHost = originalHost;\n try {\n const hostRegex = new RegExp(/^https?:\\/\\/(?:www\\.)?([^\\/.-]+)/);\n const res = hostRegex.exec(originalHost);\n if (res !== null && res.length > 1) {\n shortHost = res[1];\n }\n shortHost = shortHost.replace(\".in.applicationinsights.azure.com\", \"\");\n } catch (error) {\n diag.debug(\"Failed to get the short host name.\");\n }\n return shortHost;\n }\n}\n"]}
1
+ {"version":3,"file":"networkStatsbeatMetrics.js","sourceRoot":"","sources":["../../../../src/export/statsbeat/networkStatsbeatMetrics.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EACL,IAAI,GAKL,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,aAAa,EACb,6BAA6B,GAE9B,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,MAAM,2CAA2C,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAA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AAC,IAAI,CAAC,YAAY,CAAC,CAAC;YACzC,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE;gBAClC,SAAS,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;aACpB;YACD,SAAS,GAAG,SAAS,CAAC,OAAO,CAAC,mCAAmC,EAAE,EAAE,CAAC,CAAC;SACxE;QAAC,OAAO,KAAK,EAAE;YACd,IAAI,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAC;SAClD;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n diag,\n BatchObservableResult,\n Meter,\n ObservableGauge,\n ObservableResult,\n} from \"@opentelemetry/api\";\nimport {\n MeterProvider,\n PeriodicExportingMetricReader,\n PeriodicExportingMetricReaderOptions,\n} from \"@opentelemetry/sdk-metrics\";\nimport { AzureMonitorExporterOptions } from \"../../index\";\nimport * as ai from \"../../utils/constants/applicationinsights\";\nimport { StatsbeatMetrics } from \"./statsbeatMetrics\";\nimport {\n StatsbeatCounter,\n STATSBEAT_LANGUAGE,\n NetworkStatsbeat,\n CommonStatsbeatProperties,\n NetworkStatsbeatProperties,\n StatsbeatOptions,\n} from \"./types\";\nimport { AzureMonitorStatsbeatExporter } from \"./statsbeatExporter\";\n\nexport class NetworkStatsbeatMetrics extends StatsbeatMetrics {\n private commonProperties: CommonStatsbeatProperties;\n private networkProperties: NetworkStatsbeatProperties;\n private isInitialized: boolean = false;\n private statsCollectionShortInterval: number = 900000; // 15 minutes\n\n private networkStatsbeatCollection: Array<NetworkStatsbeat> = [];\n private networkStatsbeatMeter: Meter;\n private networkStatsbeatMeterProvider: MeterProvider;\n private networkAzureExporter: AzureMonitorStatsbeatExporter;\n private networkMetricReader: PeriodicExportingMetricReader;\n\n // Custom dimensions\n private cikey: string;\n private runtimeVersion: string;\n private language: string;\n private version: string;\n private attach: string = \"Manual\";\n\n // Observable Gauges\n private successCountGauge: ObservableGauge;\n private failureCountGauge: ObservableGauge;\n private retryCountGauge: ObservableGauge;\n private throttleCountGauge: ObservableGauge;\n private exceptionCountGauge: ObservableGauge;\n private averageDurationGauge: ObservableGauge;\n\n // Network attributes\n private connectionString: string;\n private endpointUrl: string;\n private host: string;\n\n constructor(options: StatsbeatOptions) {\n super();\n this.connectionString = super.getConnectionString(options.endpointUrl);\n this.networkStatsbeatMeterProvider = new MeterProvider();\n\n const exporterConfig: AzureMonitorExporterOptions = {\n connectionString: this.connectionString,\n };\n\n this.networkAzureExporter = new AzureMonitorStatsbeatExporter(exporterConfig);\n\n // Exports Network Statsbeat every 15 minutes\n const networkMetricReaderOptions: PeriodicExportingMetricReaderOptions = {\n exporter: this.networkAzureExporter,\n exportIntervalMillis: options.networkCollectionInterval || this.statsCollectionShortInterval, // 15 minutes\n };\n\n this.networkMetricReader = new PeriodicExportingMetricReader(networkMetricReaderOptions);\n this.networkStatsbeatMeterProvider.addMetricReader(this.networkMetricReader);\n this.networkStatsbeatMeter = this.networkStatsbeatMeterProvider.getMeter(\n \"Azure Monitor Network Statsbeat\",\n );\n\n this.endpointUrl = options.endpointUrl;\n this.runtimeVersion = process.version;\n this.language = STATSBEAT_LANGUAGE;\n this.version = ai.packageVersion;\n this.host = this.getShortHost(options.endpointUrl);\n this.cikey = options.instrumentationKey;\n\n this.successCountGauge = this.networkStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.SUCCESS_COUNT,\n );\n this.failureCountGauge = this.networkStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.FAILURE_COUNT,\n );\n this.retryCountGauge = this.networkStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.RETRY_COUNT,\n );\n this.throttleCountGauge = this.networkStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.THROTTLE_COUNT,\n );\n this.exceptionCountGauge = this.networkStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.EXCEPTION_COUNT,\n );\n this.averageDurationGauge = this.networkStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.AVERAGE_DURATION,\n );\n\n this.commonProperties = {\n os: super.os,\n rp: super.resourceProvider,\n cikey: this.cikey,\n runtimeVersion: this.runtimeVersion,\n language: this.language,\n version: this.version,\n attach: this.attach,\n };\n\n this.networkProperties = {\n endpoint: this.endpointUrl,\n host: this.host,\n };\n\n this.isInitialized = true;\n this.initialize();\n }\n\n public shutdown(): Promise<void> {\n return this.networkStatsbeatMeterProvider.shutdown();\n }\n\n private async initialize(): Promise<void> {\n try {\n await super.getResourceProvider();\n\n // Add network observable callbacks\n this.successCountGauge.addCallback(this.successCallback.bind(this));\n this.networkStatsbeatMeter.addBatchObservableCallback(this.failureCallback.bind(this), [\n this.failureCountGauge,\n ]);\n this.networkStatsbeatMeter.addBatchObservableCallback(this.retryCallback.bind(this), [\n this.retryCountGauge,\n ]);\n this.networkStatsbeatMeter.addBatchObservableCallback(this.throttleCallback.bind(this), [\n this.throttleCountGauge,\n ]);\n this.networkStatsbeatMeter.addBatchObservableCallback(this.exceptionCallback.bind(this), [\n this.exceptionCountGauge,\n ]);\n this.averageDurationGauge.addCallback(this.durationCallback.bind(this));\n } catch (error) {\n diag.debug(\"Call to get the resource provider failed.\");\n }\n }\n\n // Observable gauge callbacks\n private successCallback(observableResult: ObservableResult): void {\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n const attributes = { ...this.commonProperties, ...this.networkProperties };\n observableResult.observe(counter.totalSuccesfulRequestCount, attributes);\n counter.totalSuccesfulRequestCount = 0;\n }\n\n private failureCallback(observableResult: BatchObservableResult) {\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n\n /*\n Takes the failureCountGauge, value (of the counter), and attributes\n create a unqiue counter based on statusCode as well\n append statusCode to attributes so the newly created attributes are unique.\n */\n const attributes = { ...this.networkProperties, ...this.commonProperties, statusCode: 0 };\n\n // For each { statusCode -> count } mapping, call observe, passing the count and attributes that include the statusCode\n for (let i = 0; i < counter.totalFailedRequestCount.length; i++) {\n attributes.statusCode = counter.totalFailedRequestCount[i].statusCode;\n observableResult.observe(this.failureCountGauge, counter.totalFailedRequestCount[i].count, {\n ...attributes,\n });\n counter.totalFailedRequestCount[i].count = 0;\n }\n }\n\n private retryCallback(observableResult: BatchObservableResult): void {\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n const attributes = { ...this.networkProperties, ...this.commonProperties, statusCode: 0 };\n\n for (let i = 0; i < counter.retryCount.length; i++) {\n attributes.statusCode = counter.retryCount[i].statusCode;\n observableResult.observe(this.retryCountGauge, counter.retryCount[i].count, {\n ...attributes,\n });\n counter.retryCount[i].count = 0;\n }\n }\n\n private throttleCallback(observableResult: BatchObservableResult): void {\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n const attributes = { ...this.networkProperties, ...this.commonProperties, statusCode: 0 };\n\n for (let i = 0; i < counter.throttleCount.length; i++) {\n attributes.statusCode = counter.throttleCount[i].statusCode;\n observableResult.observe(this.throttleCountGauge, counter.throttleCount[i].count, {\n ...attributes,\n });\n counter.throttleCount[i].count = 0;\n }\n }\n\n private exceptionCallback(observableResult: BatchObservableResult): void {\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n const attributes = { ...this.networkProperties, ...this.commonProperties, exceptionType: \"\" };\n\n for (let i = 0; i < counter.exceptionCount.length; i++) {\n attributes.exceptionType = counter.exceptionCount[i].exceptionType;\n observableResult.observe(this.exceptionCountGauge, counter.exceptionCount[i].count, {\n ...attributes,\n });\n counter.exceptionCount[i].count = 0;\n }\n }\n\n private durationCallback(observableResult: ObservableResult): void {\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n const attributes = { ...this.networkProperties, ...this.commonProperties };\n for (let i = 0; i < this.networkStatsbeatCollection.length; i++) {\n const currentCounter = this.networkStatsbeatCollection[i];\n currentCounter.time = Number(new Date());\n const intervalRequests =\n currentCounter.totalRequestCount - currentCounter.lastRequestCount || 0;\n currentCounter.averageRequestExecutionTime =\n (currentCounter.intervalRequestExecutionTime -\n currentCounter.lastIntervalRequestExecutionTime) /\n intervalRequests || 0;\n currentCounter.lastIntervalRequestExecutionTime = currentCounter.intervalRequestExecutionTime; // reset\n\n currentCounter.lastRequestCount = currentCounter.totalRequestCount;\n currentCounter.lastTime = currentCounter.time;\n }\n observableResult.observe(counter.averageRequestExecutionTime, attributes);\n\n counter.averageRequestExecutionTime = 0;\n }\n\n // Public methods to increase counters\n public countSuccess(duration: number): void {\n if (!this.isInitialized) {\n return;\n }\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n counter.totalRequestCount++;\n counter.totalSuccesfulRequestCount++;\n counter.intervalRequestExecutionTime += duration;\n }\n\n public countFailure(duration: number, statusCode: number) {\n if (!this.isInitialized) {\n return;\n }\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n const currentStatusCounter = counter.totalFailedRequestCount.find(\n (statusCounter) => statusCode === statusCounter.statusCode,\n );\n\n if (currentStatusCounter) {\n currentStatusCounter.count++;\n } else {\n counter.totalFailedRequestCount.push({ statusCode: statusCode, count: 1 });\n }\n\n counter.totalRequestCount++;\n counter.intervalRequestExecutionTime += duration;\n }\n\n public countRetry(statusCode: number): void {\n if (!this.isInitialized) {\n return;\n }\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n const currentStatusCounter = counter.retryCount.find(\n (statusCounter) => statusCode === statusCounter.statusCode,\n );\n\n if (currentStatusCounter) {\n currentStatusCounter.count++;\n } else {\n counter.retryCount.push({ statusCode: statusCode, count: 1 });\n }\n }\n\n public countThrottle(statusCode: number): void {\n if (!this.isInitialized) {\n return;\n }\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n const currentStatusCounter = counter.throttleCount.find(\n (statusCounter) => statusCode === statusCounter.statusCode,\n );\n\n if (currentStatusCounter) {\n currentStatusCounter.count++;\n } else {\n counter.throttleCount.push({ statusCode: statusCode, count: 1 });\n }\n }\n\n public countException(exceptionType: Error): void {\n if (!this.isInitialized) {\n return;\n }\n const counter: NetworkStatsbeat = this.getNetworkStatsbeatCounter(this.endpointUrl, this.host);\n const currentErrorCounter = counter.exceptionCount.find(\n (exceptionCounter) => exceptionType.name === exceptionCounter.exceptionType,\n );\n if (currentErrorCounter) {\n currentErrorCounter.count++;\n } else {\n counter.exceptionCount.push({ exceptionType: exceptionType.name, count: 1 });\n }\n }\n\n // Gets a networkStatsbeat counter if one exists for the given endpoint\n private getNetworkStatsbeatCounter(endpoint: string, host: string): NetworkStatsbeat {\n // Check if the counter is available\n for (let i = 0; i < this.networkStatsbeatCollection.length; i++) {\n // Same object\n if (\n endpoint === this.networkStatsbeatCollection[i].endpoint &&\n host === this.networkStatsbeatCollection[i].host\n ) {\n return this.networkStatsbeatCollection[i];\n }\n }\n // Create a new counter if not found\n const newCounter = new NetworkStatsbeat(endpoint, host);\n this.networkStatsbeatCollection.push(newCounter);\n return newCounter;\n }\n\n private getShortHost(originalHost: string): string {\n let shortHost = originalHost;\n try {\n const hostRegex = new RegExp(/^https?:\\/\\/(?:www\\.)?([^\\/.-]+)/);\n const res = hostRegex.exec(originalHost);\n if (res !== null && res.length > 1) {\n shortHost = res[1];\n }\n shortHost = shortHost.replace(\".in.applicationinsights.azure.com\", \"\");\n } catch (error) {\n diag.debug(\"Failed to get the short host name.\");\n }\n return shortHost;\n }\n}\n"]}
@@ -34,8 +34,7 @@ export class AzureMonitorStatsbeatExporter extends AzureMonitorBaseExporter {
34
34
  setTimeout(() => resultCallback({ code: ExportResultCode.FAILED }), 0);
35
35
  return;
36
36
  }
37
- const envelopes = resourceMetricsToEnvelope(metrics, this.instrumentationKey, true // isStatsbeat flag passed to create a Statsbeat envelope.
38
- );
37
+ const envelopes = resourceMetricsToEnvelope(metrics, this.instrumentationKey, true);
39
38
  // Supress tracing until OpenTelemetry Metrics SDK support it
40
39
  context.with(suppressTracing(context.active()), async () => {
41
40
  resultCallback(await this._sender.exportEnvelopes(envelopes));
@@ -1 +1 @@
1
- {"version":3,"file":"statsbeatExporter.js","sourceRoot":"","sources":["../../../../src/export/statsbeat/statsbeatExporter.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,OAAO,EAAgB,gBAAgB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAGtF,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;GAEG;AACH,MAAM,OAAO,6BACX,SAAQ,wBAAwB;IAShC;;;OAGG;IACH,YAAY,OAAoC;QAC9C,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAXvB;;WAEG;QACK,gBAAW,GAAG,KAAK,CAAC;QAS1B,IAAI,CAAC,OAAO,GAAG,IAAI,UAAU,CAAC;YAC5B,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,kBAAkB,EAAE,IAAI,CAAC,kBAAkB;YAC3C,cAAc,EAAE,IAAI,CAAC,cAAc;YACnC,eAAe,EAAE,OAAO;SACzB,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAM,CACV,OAAwB,EACxB,cAA8C;QAE9C,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,UAAU,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;YACvE,OAAO;SACR;QAED,MAAM,SAAS,GAAe,yBAAyB,CACrD,OAAO,EACP,IAAI,CAAC,kBAAkB,EACvB,IAAI,CAAC,0DAA0D;SAChE,CAAC;QACF,6DAA6D;QAC7D,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,KAAK,IAAI,EAAE;YACzD,cAAc,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC,CAAC;QAChE,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,QAAQ;QACnB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;IACjC,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,UAAU;QACrB,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nimport { context } from \"@opentelemetry/api\";\nimport { PushMetricExporter, ResourceMetrics } from \"@opentelemetry/sdk-metrics\";\nimport { ExportResult, ExportResultCode, suppressTracing } from \"@opentelemetry/core\";\nimport { AzureMonitorExporterOptions } from \"../../config\";\nimport { TelemetryItem as Envelope } from \"../../generated\";\nimport { resourceMetricsToEnvelope } from \"../../utils/metricUtils\";\nimport { AzureMonitorBaseExporter } from \"../base\";\nimport { HttpSender } from \"../../platform\";\n\n/**\n * Azure Monitor Statsbeat Exporter\n */\nexport class AzureMonitorStatsbeatExporter\n extends AzureMonitorBaseExporter\n implements PushMetricExporter\n{\n /**\n * Flag to determine if the Exporter is shutdown.\n */\n private _isShutdown = false;\n private _sender: HttpSender;\n\n /**\n * Initializes a new instance of the AzureMonitorStatsbeatExporter class.\n * @param options - Exporter configuration\n */\n constructor(options: AzureMonitorExporterOptions) {\n super(options, true);\n this._sender = new HttpSender({\n endpointUrl: this.endpointUrl,\n instrumentationKey: this.instrumentationKey,\n trackStatsbeat: this.trackStatsbeat,\n exporterOptions: options,\n });\n }\n\n /**\n * Export Statsbeat metrics.\n */\n async export(\n metrics: ResourceMetrics,\n resultCallback: (result: ExportResult) => void\n ): Promise<void> {\n if (this._isShutdown) {\n setTimeout(() => resultCallback({ code: ExportResultCode.FAILED }), 0);\n return;\n }\n\n const envelopes: Envelope[] = resourceMetricsToEnvelope(\n metrics,\n this.instrumentationKey,\n true // isStatsbeat flag passed to create a Statsbeat envelope.\n );\n // Supress tracing until OpenTelemetry Metrics SDK support it\n context.with(suppressTracing(context.active()), async () => {\n resultCallback(await this._sender.exportEnvelopes(envelopes));\n });\n }\n\n /**\n * Shutdown AzureMonitorStatsbeatExporter.\n */\n public async shutdown(): Promise<void> {\n this._isShutdown = true;\n return this._sender.shutdown();\n }\n\n /**\n * Force flush.\n */\n public async forceFlush(): Promise<void> {\n return Promise.resolve();\n }\n}\n"]}
1
+ {"version":3,"file":"statsbeatExporter.js","sourceRoot":"","sources":["../../../../src/export/statsbeat/statsbeatExporter.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,OAAO,EAAgB,gBAAgB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAGtF,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;GAEG;AACH,MAAM,OAAO,6BACX,SAAQ,wBAAwB;IAShC;;;OAGG;IACH,YAAY,OAAoC;QAC9C,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAXvB;;WAEG;QACK,gBAAW,GAAG,KAAK,CAAC;QAS1B,IAAI,CAAC,OAAO,GAAG,IAAI,UAAU,CAAC;YAC5B,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,kBAAkB,EAAE,IAAI,CAAC,kBAAkB;YAC3C,cAAc,EAAE,IAAI,CAAC,cAAc;YACnC,eAAe,EAAE,OAAO;SACzB,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAM,CACV,OAAwB,EACxB,cAA8C;QAE9C,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,UAAU,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;YACvE,OAAO;SACR;QAED,MAAM,SAAS,GAAe,yBAAyB,CACrD,OAAO,EACP,IAAI,CAAC,kBAAkB,EACvB,IAAI,CACL,CAAC;QACF,6DAA6D;QAC7D,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,KAAK,IAAI,EAAE;YACzD,cAAc,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC,CAAC;QAChE,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,QAAQ;QACnB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;IACjC,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,UAAU;QACrB,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nimport { context } from \"@opentelemetry/api\";\nimport { PushMetricExporter, ResourceMetrics } from \"@opentelemetry/sdk-metrics\";\nimport { ExportResult, ExportResultCode, suppressTracing } from \"@opentelemetry/core\";\nimport { AzureMonitorExporterOptions } from \"../../config\";\nimport { TelemetryItem as Envelope } from \"../../generated\";\nimport { resourceMetricsToEnvelope } from \"../../utils/metricUtils\";\nimport { AzureMonitorBaseExporter } from \"../base\";\nimport { HttpSender } from \"../../platform\";\n\n/**\n * Azure Monitor Statsbeat Exporter\n */\nexport class AzureMonitorStatsbeatExporter\n extends AzureMonitorBaseExporter\n implements PushMetricExporter\n{\n /**\n * Flag to determine if the Exporter is shutdown.\n */\n private _isShutdown = false;\n private _sender: HttpSender;\n\n /**\n * Initializes a new instance of the AzureMonitorStatsbeatExporter class.\n * @param options - Exporter configuration\n */\n constructor(options: AzureMonitorExporterOptions) {\n super(options, true);\n this._sender = new HttpSender({\n endpointUrl: this.endpointUrl,\n instrumentationKey: this.instrumentationKey,\n trackStatsbeat: this.trackStatsbeat,\n exporterOptions: options,\n });\n }\n\n /**\n * Export Statsbeat metrics.\n */\n async export(\n metrics: ResourceMetrics,\n resultCallback: (result: ExportResult) => void,\n ): Promise<void> {\n if (this._isShutdown) {\n setTimeout(() => resultCallback({ code: ExportResultCode.FAILED }), 0);\n return;\n }\n\n const envelopes: Envelope[] = resourceMetricsToEnvelope(\n metrics,\n this.instrumentationKey,\n true, // isStatsbeat flag passed to create a Statsbeat envelope.\n );\n // Supress tracing until OpenTelemetry Metrics SDK support it\n context.with(suppressTracing(context.active()), async () => {\n resultCallback(await this._sender.exportEnvelopes(envelopes));\n });\n }\n\n /**\n * Shutdown AzureMonitorStatsbeatExporter.\n */\n public async shutdown(): Promise<void> {\n this._isShutdown = true;\n return this._sender.shutdown();\n }\n\n /**\n * Force flush.\n */\n public async forceFlush(): Promise<void> {\n return Promise.resolve();\n }\n}\n"]}
@@ -14,13 +14,25 @@ export class StatsbeatMetrics {
14
14
  async getResourceProvider() {
15
15
  // Check resource provider
16
16
  this.resourceProvider = StatsbeatResourceProvider.unknown;
17
- if (process.env.WEBSITE_SITE_NAME) {
17
+ if (process.env.AKS_ARM_NAMESPACE_ID) {
18
+ // AKS
19
+ this.resourceProvider = StatsbeatResourceProvider.aks;
20
+ this.resourceIdentifier = process.env.AKS_ARM_NAMESPACE_ID;
21
+ }
22
+ else if (process.env.WEBSITE_SITE_NAME) {
18
23
  // Web apps
19
24
  this.resourceProvider = StatsbeatResourceProvider.appsvc;
25
+ this.resourceIdentifier = process.env.WEBSITE_SITE_NAME;
26
+ if (process.env.WEBSITE_HOME_STAMPNAME) {
27
+ this.resourceIdentifier += "/" + process.env.WEBSITE_HOME_STAMPNAME;
28
+ }
20
29
  }
21
30
  else if (process.env.FUNCTIONS_WORKER_RUNTIME) {
22
31
  // Function apps
23
32
  this.resourceProvider = StatsbeatResourceProvider.functions;
33
+ if (process.env.WEBSITE_HOSTNAME) {
34
+ this.resourceIdentifier = process.env.WEBSITE_HOSTNAME;
35
+ }
24
36
  }
25
37
  else if (await this.getAzureComputeMetadata()) {
26
38
  this.resourceProvider = StatsbeatResourceProvider.vm;
@@ -1 +1 @@
1
- {"version":3,"file":"statsbeatMetrics.js","sourceRoot":"","sources":["../../../../src/export/statsbeat/statsbeatMetrics.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EACL,uBAAuB,EACvB,qBAAqB,GAEtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,QAAQ,EACR,oBAAoB,EACpB,YAAY,EACZ,wBAAwB,EACxB,yBAAyB,GAE1B,MAAM,SAAS,CAAC;AAEjB,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEzB,MAAM,OAAO,gBAAgB;IAA7B;QACY,qBAAgB,GAAW,yBAAyB,CAAC,OAAO,CAAC;QAC7D,WAAM,GAAuB,EAAE,CAAC;QAChC,OAAE,GAAW,EAAE,CAAC,IAAI,EAAE,CAAC;QACvB,uBAAkB,GAAG,EAAE,CAAC;IA2EpC,CAAC;IAzEW,KAAK,CAAC,mBAAmB;QACjC,0BAA0B;QAC1B,IAAI,CAAC,gBAAgB,GAAG,yBAAyB,CAAC,OAAO,CAAC;QAC1D,IAAI,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE;YACjC,WAAW;YACX,IAAI,CAAC,g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AC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAS,EAAE,EAAE;oBAC3B,kBAAkB,IAAI,IAAI,CAAC;gBAC7B,CAAC,CAAC,CAAC;gBACH,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;oBACjB,IAAI;wBACF,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;wBAC5C,IAAI,CAAC,MAAM,CAAC,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;wBACpC,IAAI,CAAC,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC,gBAAgB,CAAC,IAAI,EAAE,CAAC;wBAC1D,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;qBAC3C;oBAAC,OAAO,KAAK,EAAE;wBACd,IAAI,CAAC,KAAK,CAAC,wBAAwB,EAAE,KAAK,CAAC,CAAC;qBAC7C;gBACH,CAAC,CAAC,CAAC;gBACH,OAAO,IAAI,CAAC;aACb;iBAAM;gBACL,OAAO,KAAK,CAAC;aACd;QACH,CAAC,CAAC;aACD,KAAK,CAAC,GAAG,EAAE;YACV,OAAO,KAAK,CAAC;QACf,CAAC,CAAC,CAAC;QACL,OAAO,KAAK,CAAC;IACf,CAAC;IAES,mBAAmB,CAAC,WAAmB;QAC/C,MAAM,eAAe,GAAG,WAAW,CAAC;QACpC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAC5C,IAAI,eAAe,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE;gBAC7C,OAAO,oBAAoB,CAAC;aAC7B;SACF;QACD,OAAO,wBAAwB,CAAC;IAClC,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n createDefaultHttpClient,\n createPipelineRequest,\n HttpMethods,\n} from \"@azure/core-rest-pipeline\";\nimport { diag } from \"@opentelemetry/api\";\nimport {\n AIMS_API_VERSION,\n AIMS_FORMAT,\n AIMS_URI,\n EU_CONNECTION_STRING,\n EU_ENDPOINTS,\n NON_EU_CONNECTION_STRING,\n StatsbeatResourceProvider,\n VirtualMachineInfo,\n} from \"./types\";\n\nconst os = require(\"os\");\n\nexport class StatsbeatMetrics {\n protected resourceProvider: string = StatsbeatResourceProvider.unknown;\n protected vmInfo: VirtualMachineInfo = {};\n protected os: string = os.type();\n protected resourceIdentifier = \"\";\n\n protected async getResourceProvider(): Promise<void> {\n // Check resource provider\n this.resourceProvider = StatsbeatResourceProvider.unknown;\n if (process.env.WEBSITE_SITE_NAME) {\n // Web apps\n this.resourceProvider = StatsbeatResourceProvider.appsvc;\n } else if (process.env.FUNCTIONS_WORKER_RUNTIME) {\n // Function apps\n this.resourceProvider = StatsbeatResourceProvider.functions;\n } else if (await this.getAzureComputeMetadata()) {\n this.resourceProvider = StatsbeatResourceProvider.vm;\n this.resourceIdentifier = this.vmInfo.id + \"/\" + this.vmInfo.subscriptionId;\n // Overrride OS as VM info have higher precedence\n if (this.vmInfo.osType) {\n this.os = this.vmInfo.osType;\n }\n } else {\n this.resourceProvider = StatsbeatResourceProvider.unknown;\n }\n }\n\n public async getAzureComputeMetadata(): Promise<boolean> {\n const httpClient = createDefaultHttpClient();\n const method: HttpMethods = \"GET\";\n\n const options = {\n url: `${AIMS_URI}?${AIMS_API_VERSION}&${AIMS_FORMAT}`,\n timeout: 5000, // 5 seconds\n method: method,\n allowInsecureConnection: true,\n };\n const request = createPipelineRequest(options);\n\n await httpClient\n .sendRequest(request)\n .then((res: any) => {\n if (res.status === 200) {\n // Success; VM\n this.vmInfo.isVM = true;\n let virtualMachineData = \"\";\n res.on(\"data\", (data: any) => {\n virtualMachineData += data;\n });\n res.on(\"end\", () => {\n try {\n const data = JSON.parse(virtualMachineData);\n this.vmInfo.id = data[\"vmId\"] || \"\";\n this.vmInfo.subscriptionId = data[\"subscriptionId\"] || \"\";\n this.vmInfo.osType = data[\"osType\"] || \"\";\n } catch (error) {\n diag.debug(\"Failed to parse JSON: \", error);\n }\n });\n return true;\n } else {\n return false;\n }\n })\n .catch(() => {\n return false;\n });\n return false;\n }\n\n protected getConnectionString(endpointUrl: string): string {\n const currentEndpoint = endpointUrl;\n for (let i = 0; i < EU_ENDPOINTS.length; i++) {\n if (currentEndpoint.includes(EU_ENDPOINTS[i])) {\n return EU_CONNECTION_STRING;\n }\n }\n return NON_EU_CONNECTION_STRING;\n }\n}\n"]}
1
+ {"version":3,"file":"statsbeatMetrics.js","sourceRoot":"","sources":["../../../../src/export/statsbeat/statsbeatMetrics.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EACL,uBAAuB,EACvB,qBAAqB,GAEtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,QAAQ,EACR,oBAAoB,EACpB,YAAY,EACZ,wBAAwB,EACxB,yBAAyB,GAE1B,MAAM,SAAS,CAAC;AAEjB,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEzB,MAAM,OAAO,gBAAgB;IAA7B;QACY,qBAAgB,GAAW,yBAAyB,CAAC,OAAO,CAAC;QAC7D,WAAM,GAAuB,EAAE,CAAC;QAChC,OAAE,GAAW,EAAE,CAAC,IAAI,EAAE,CAAC;QACvB,uBAAkB,GAAG,EAAE,CAAC;IAsFpC,CAAC;IApFW,KAAK,CAAC,mBAAmB;QACjC,0BAA0B;QAC1B,IAAI,CAAC,gBAAgB,GAAG,yBAAyB,CAAC,OAAO,CAAC;QAC1D,IAAI,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE;YACpC,MAAM;YACN,IAAI,CAAC,gBAAgB,GAAG,yBAAyB,CAAC,GAAG,CAAC;YACtD,IAA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AAE;YACV,OAAO,KAAK,CAAC;QACf,CAAC,CAAC,CAAC;QACL,OAAO,KAAK,CAAC;IACf,CAAC;IAES,mBAAmB,CAAC,WAAmB;QAC/C,MAAM,eAAe,GAAG,WAAW,CAAC;QACpC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAC5C,IAAI,eAAe,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE;gBAC7C,OAAO,oBAAoB,CAAC;aAC7B;SACF;QACD,OAAO,wBAAwB,CAAC;IAClC,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n createDefaultHttpClient,\n createPipelineRequest,\n HttpMethods,\n} from \"@azure/core-rest-pipeline\";\nimport { diag } from \"@opentelemetry/api\";\nimport {\n AIMS_API_VERSION,\n AIMS_FORMAT,\n AIMS_URI,\n EU_CONNECTION_STRING,\n EU_ENDPOINTS,\n NON_EU_CONNECTION_STRING,\n StatsbeatResourceProvider,\n VirtualMachineInfo,\n} from \"./types\";\n\nconst os = require(\"os\");\n\nexport class StatsbeatMetrics {\n protected resourceProvider: string = StatsbeatResourceProvider.unknown;\n protected vmInfo: VirtualMachineInfo = {};\n protected os: string = os.type();\n protected resourceIdentifier = \"\";\n\n protected async getResourceProvider(): Promise<void> {\n // Check resource provider\n this.resourceProvider = StatsbeatResourceProvider.unknown;\n if (process.env.AKS_ARM_NAMESPACE_ID) {\n // AKS\n this.resourceProvider = StatsbeatResourceProvider.aks;\n this.resourceIdentifier = process.env.AKS_ARM_NAMESPACE_ID;\n } else if (process.env.WEBSITE_SITE_NAME) {\n // Web apps\n this.resourceProvider = StatsbeatResourceProvider.appsvc;\n this.resourceIdentifier = process.env.WEBSITE_SITE_NAME;\n if (process.env.WEBSITE_HOME_STAMPNAME) {\n this.resourceIdentifier += \"/\" + process.env.WEBSITE_HOME_STAMPNAME;\n }\n } else if (process.env.FUNCTIONS_WORKER_RUNTIME) {\n // Function apps\n this.resourceProvider = StatsbeatResourceProvider.functions;\n if (process.env.WEBSITE_HOSTNAME) {\n this.resourceIdentifier = process.env.WEBSITE_HOSTNAME;\n }\n } else if (await this.getAzureComputeMetadata()) {\n this.resourceProvider = StatsbeatResourceProvider.vm;\n this.resourceIdentifier = this.vmInfo.id + \"/\" + this.vmInfo.subscriptionId;\n // Overrride OS as VM info have higher precedence\n if (this.vmInfo.osType) {\n this.os = this.vmInfo.osType;\n }\n } else {\n this.resourceProvider = StatsbeatResourceProvider.unknown;\n }\n }\n\n public async getAzureComputeMetadata(): Promise<boolean> {\n const httpClient = createDefaultHttpClient();\n const method: HttpMethods = \"GET\";\n\n const options = {\n url: `${AIMS_URI}?${AIMS_API_VERSION}&${AIMS_FORMAT}`,\n timeout: 5000, // 5 seconds\n method: method,\n allowInsecureConnection: true,\n };\n const request = createPipelineRequest(options);\n\n await httpClient\n .sendRequest(request)\n .then((res: any) => {\n if (res.status === 200) {\n // Success; VM\n this.vmInfo.isVM = true;\n let virtualMachineData = \"\";\n res.on(\"data\", (data: any) => {\n virtualMachineData += data;\n });\n res.on(\"end\", () => {\n try {\n const data = JSON.parse(virtualMachineData);\n this.vmInfo.id = data[\"vmId\"] || \"\";\n this.vmInfo.subscriptionId = data[\"subscriptionId\"] || \"\";\n this.vmInfo.osType = data[\"osType\"] || \"\";\n } catch (error) {\n diag.debug(\"Failed to parse JSON: \", error);\n }\n });\n return true;\n } else {\n return false;\n }\n })\n .catch(() => {\n return false;\n });\n return false;\n }\n\n protected getConnectionString(endpointUrl: string): string {\n const currentEndpoint = endpointUrl;\n for (let i = 0; i < EU_ENDPOINTS.length; i++) {\n if (currentEndpoint.includes(EU_ENDPOINTS[i])) {\n return EU_CONNECTION_STRING;\n }\n }\n return NON_EU_CONNECTION_STRING;\n }\n}\n"]}
@@ -21,6 +21,7 @@ export const STATSBEAT_LANGUAGE = "node";
21
21
  export const MAX_STATSBEAT_FAILURES = 3;
22
22
  export const StatsbeatResourceProvider = {
23
23
  appsvc: "appsvc",
24
+ aks: "aks",
24
25
  functions: "functions",
25
26
  vm: "vm",
26
27
  unknown: "unknown",
@@ -57,7 +58,7 @@ export const EU_ENDPOINTS = [
57
58
  ];
58
59
  export var StatsbeatFeatureType;
59
60
  (function (StatsbeatFeatureType) {
60
- StatsbeatFeatureType["FEATURE"] = "Feature";
61
- StatsbeatFeatureType["INSTRUMENTATION"] = "Instrumentation";
61
+ StatsbeatFeatureType[StatsbeatFeatureType["FEATURE"] = 0] = "FEATURE";
62
+ StatsbeatFeatureType[StatsbeatFeatureType["INSTRUMENTATION"] = 1] = "INSTRUMENTATION";
62
63
  })(StatsbeatFeatureType || (StatsbeatFeatureType = {}));
63
64
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
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,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,iBAAiB,GAAG,CAAC,CAAC;QAC3B,IAAI,CAAC,0BAA0B,GAAG,CAAC,CAAC;QACpC,IAAI,CAAC,uBAAuB,GAAG,EAAE,CAAC;QAClC,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;QACrB,IAAI,CAAC,cAAc,GAAG,EAAE,CAAC;QACzB,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;QACxB,IAAI,CAAC,4BAA4B,GAAG,CAAC,CAAC;QACtC,IAAI,CAAC,gCAAgC,GAAG,CAAC,CAAC;QAC1C,IAAI,CAAC,QAAQ,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC;QAC5B,IAAI,CAAC,gBAAgB,GAAG,CAAC,CAAC;QAC1B,IAAI,CAAC,2BAA2B,GAAG,CAAC,CAAC;IACvC,CAAC;CACF;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAEzC,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAExC,MAAM,CAAC,MAAM,yBAAyB,GAAG;IACvC,MAAM,EAAE,QAAQ;IAChB,SAAS,EAAE,WAAW;IACtB,EAAE,EAAE,IAAI;IACR,OAAO,EAAE,SAAS;CACnB,CAAC;AAEF,MAAM,CAAN,IAAY,gBASX;AATD,WAAY,gBAAgB;IAC1B,2DAAuC,CAAA;IACvC,2DAAuC,CAAA;IACvC,+CAA2B,CAAA;IAC3B,qDAAiC,CAAA;IACjC,uDAAmC,CAAA;IACnC,yDAAqC,CAAA;IACrC,qCAAiB,CAAA;IACjB,uCAAmB,CAAA;AACrB,CAAC,EATW,gBAAgB,KAAhB,gBAAgB,QAS3B;AAED,MAAM,CAAC,MAAM,QAAQ,GAAG,kDAAkD,CAAC;AAC3E,MAAM,CAAC,MAAM,gBAAgB,GAAG,wBAAwB,CAAC;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,2CAAmB,CAAA;IACnB,2DAAmC,CAAA;AACrC,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 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,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,iBAAiB,GAAG,CAAC,CAAC;QAC3B,IAAI,CAAC,0BAA0B,GAAG,CAAC,CAAC;QACpC,IAAI,CAAC,uBAAuB,GAAG,EAAE,CAAC;QAClC,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;QACrB,IAAI,CAAC,cAAc,GAAG,EAAE,CAAC;QACzB,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;QACxB,IAAI,CAAC,4B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CF,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"]}
@@ -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,oBAA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AC;aACxC;YACD,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;gBACrB,SAAS,CAAC,IAAI,CAAC,sBAAsB,CAAC,IAAI,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC;gBACtE,MAAM,kBAAkB,GAAG,qBAAqB,CAAC,IAAI,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;gBAChF,IAAI,kBAAkB,CAAC,MAAM,GAAG,CAAC,EAAE;oBACjC,SAAS,CAAC,IAAI,CAAC,GAAG,kBAAkB,CAAC,CAAC;iBACvC;YACH,CAAC,CAAC,CAAC;YACH,cAAc,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC,CAAC;SAC9D;QACD,oBAAoB;QACpB,cAAc,CAAC,EAAE,IAAI,EAAE,gBAAgB,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"]}
1
+ {"version":3,"file":"trace.js","sourceRoot":"","sources":["../../../src/export/trace.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kC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,MAAM,SAAS,GAAe,EAAE,CAAC;YACjC,MAAM,sBAAsB,GAAG,4BAA4B,CACzD,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,EACjB,IAAI,CAAC,kBAAkB,CACxB,CAAC;YACF,IAAI,sBAAsB,EAAE;gBAC1B,SAAS,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;aACxC;YACD,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;gBACrB,SAAS,CAAC,IAAI,CAAC,sBAAsB,CAAC,IAAI,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC;gBACtE,MAAM,kBAAkB,GAAG,qBAAqB,CAAC,IAAI,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;gBAChF,IAAI,kBAAkB,CAAC,MAAM,GAAG,CAAC,EAAE;oBACjC,SAAS,CAAC,IAAI,CAAC,GAAG,kBAAkB,CAAC,CAAC;iBACvC;YACH,CAAC,CAAC,CAAC;YACH,cAAc,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC,CAAC;SAC9D;QACD,oBAAoB;QACpB,cAAc,CAAC,EAAE,IAAI,EAAE,gBAAgB,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"]}
@@ -6,7 +6,6 @@
6
6
  * Changes may cause incorrect behavior and will be lost if the code is regenerated.
7
7
  */
8
8
  import * as coreClient from "@azure/core-client";
9
- import * as coreRestPipeline from "@azure/core-rest-pipeline";
10
9
  import * as Parameters from "./models/parameters";
11
10
  import * as Mappers from "./models/mappers";
12
11
  export class ApplicationInsightsClient extends coreClient.ServiceClient {
@@ -21,32 +20,16 @@ export class ApplicationInsightsClient extends coreClient.ServiceClient {
21
20
  options = {};
22
21
  }
23
22
  const defaults = {
24
- requestContentType: "application/json; charset=utf-8"
23
+ requestContentType: "application/json; charset=utf-8",
25
24
  };
26
- const packageDetails = `azsdk-js-monitor-opentelemetry-exporter/1.0.0-beta.17`;
25
+ const packageDetails = `azsdk-js-monitor-opentelemetry-exporter/1.0.0-beta.19`;
27
26
  const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
28
27
  ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
29
28
  : `${packageDetails}`;
30
29
  const optionsWithDefaults = Object.assign(Object.assign(Object.assign({}, defaults), options), { userAgentOptions: {
31
- userAgentPrefix
32
- }, baseUri: (_b = (_a = options.endpoint) !== null && _a !== void 0 ? _a : options.baseUri) !== null && _b !== void 0 ? _b : "{Host}/v2.1" });
30
+ userAgentPrefix,
31
+ }, endpoint: (_b = (_a = options.endpoint) !== null && _a !== void 0 ? _a : options.baseUri) !== null && _b !== void 0 ? _b : "{Host}/v2.1" });
33
32
  super(optionsWithDefaults);
34
- if ((options === null || options === void 0 ? void 0 : options.pipeline) && options.pipeline.getOrderedPolicies().length > 0) {
35
- const pipelinePolicies = options.pipeline.getOrderedPolicies();
36
- const bearerTokenAuthenticationPolicyFound = pipelinePolicies.some((pipelinePolicy) => pipelinePolicy.name ===
37
- coreRestPipeline.bearerTokenAuthenticationPolicyName);
38
- if (!bearerTokenAuthenticationPolicyFound) {
39
- this.pipeline.removePolicy({
40
- name: coreRestPipeline.bearerTokenAuthenticationPolicyName
41
- });
42
- this.pipeline.addPolicy(coreRestPipeline.bearerTokenAuthenticationPolicy({
43
- scopes: `${optionsWithDefaults.baseUri}/.default`,
44
- challengeCallbacks: {
45
- authorizeRequestOnChallenge: coreClient.authorizeRequestOnClaimChallenge
46
- }
47
- }));
48
- }
49
- }
50
33
  // Assigning values to Constant parameters
51
34
  this.host = options.host || "https://dc.services.visualstudio.com";
52
35
  }
@@ -66,36 +49,36 @@ const trackOperationSpec = {
66
49
  httpMethod: "POST",
67
50
  responses: {
68
51
  200: {
69
- bodyMapper: Mappers.TrackResponse
52
+ bodyMapper: Mappers.TrackResponse,
70
53
  },
71
54
  206: {
72
- bodyMapper: Mappers.TrackResponse
55
+ bodyMapper: Mappers.TrackResponse,
73
56
  },
74
57
  400: {
75
58
  bodyMapper: Mappers.TrackResponse,
76
- isError: true
59
+ isError: true,
77
60
  },
78
61
  402: {
79
62
  bodyMapper: Mappers.TrackResponse,
80
- isError: true
63
+ isError: true,
81
64
  },
82
65
  429: {
83
66
  bodyMapper: Mappers.TrackResponse,
84
- isError: true
67
+ isError: true,
85
68
  },
86
69
  500: {
87
70
  bodyMapper: Mappers.TrackResponse,
88
- isError: true
71
+ isError: true,
89
72
  },
90
73
  503: {
91
74
  bodyMapper: Mappers.TrackResponse,
92
- isError: true
93
- }
75
+ isError: true,
76
+ },
94
77
  },
95
78
  requestBody: Parameters.body,
96
79
  urlParameters: [Parameters.host],
97
80
  headerParameters: [Parameters.contentType, Parameters.accept],
98
81
  mediaType: "json",
99
- serializer
82
+ serializer,
100
83
  };
101
84
  //# sourceMappingURL=applicationInsightsClient.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"applicationInsightsClient.js","sourceRoot":"","sources":["../../../src/generated/applicationInsightsClient.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG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,CAAC,aAAa;YACjC,OAAO,EAAE,IAAI;SACd;QACD,GAAG,EAAE;YACH,UAAU,EAAE,OAAO,CAAC,aAAa;YACjC,OAAO,EAAE,IAAI;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.17`;\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/gener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AC,KAAK,CAAC,CAAC;AAE3E,MAAM,kBAAkB,GAA6B;IACnD,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE,MAAM;IAClB,SAAS,EAAE;QACT,GAAG,EAAE;YACH,UAAU,EAAE,OAAO,CAAC,aAAa;SAClC;QACD,GAAG,EAAE;YACH,UAAU,EAAE,OAAO,CAAC,aAAa;SAClC;QACD,GAAG,EAAE;YACH,UAAU,EAAE,OAAO,CAAC,aAAa;YACjC,OAAO,EAAE,IAAI;SACd;QACD,GAAG,EAAE;YACH,UAAU,EAAE,OAAO,CAAC,aAAa;YACjC,OAAO,EAAE,IAAI;SACd;QACD,GAAG,EAAE;YACH,UAAU,EAAE,OAAO,CAAC,aAAa;YACjC,OAAO,EAAE,IAAI;SACd;QACD,GAAG,EAAE;YACH,UAAU,EAAE,OAAO,CAAC,aAAa;YACjC,OAAO,EAAE,IAAI;SACd;QACD,GAAG,EAAE;YACH,UAAU,EAAE,OAAO,CAAC,aAAa;YACjC,OAAO,EAAE,IAAI;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 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.19`;\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 endpoint: options.endpoint ?? options.baseUri ?? \"{Host}/v2.1\",\n };\n super(optionsWithDefaults);\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"]}