@azure/monitor-opentelemetry-exporter 1.0.0-beta.18 → 1.0.0-beta.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/index.js +389 -378
- package/dist-esm/src/export/base.js.map +1 -1
- package/dist-esm/src/export/log.js.map +1 -1
- package/dist-esm/src/export/metric.js.map +1 -1
- package/dist-esm/src/export/statsbeat/longIntervalStatsbeatMetrics.js +4 -4
- package/dist-esm/src/export/statsbeat/longIntervalStatsbeatMetrics.js.map +1 -1
- package/dist-esm/src/export/statsbeat/networkStatsbeatMetrics.js +3 -3
- package/dist-esm/src/export/statsbeat/networkStatsbeatMetrics.js.map +1 -1
- package/dist-esm/src/export/statsbeat/statsbeatExporter.js +2 -2
- package/dist-esm/src/export/statsbeat/statsbeatExporter.js.map +1 -1
- package/dist-esm/src/export/statsbeat/statsbeatMetrics.js +1 -1
- package/dist-esm/src/export/statsbeat/statsbeatMetrics.js.map +1 -1
- package/dist-esm/src/export/trace.js.map +1 -1
- package/dist-esm/src/generated/applicationInsightsClient.js +13 -30
- package/dist-esm/src/generated/applicationInsightsClient.js.map +1 -1
- package/dist-esm/src/generated/models/index.js.map +1 -1
- package/dist-esm/src/generated/models/mappers.js +276 -276
- package/dist-esm/src/generated/models/mappers.js.map +1 -1
- package/dist-esm/src/generated/models/parameters.js +14 -14
- package/dist-esm/src/generated/models/parameters.js.map +1 -1
- package/dist-esm/src/platform/nodejs/baseSender.js +27 -8
- package/dist-esm/src/platform/nodejs/baseSender.js.map +1 -1
- package/dist-esm/src/platform/nodejs/context/context.js +2 -4
- package/dist-esm/src/platform/nodejs/context/context.js.map +1 -1
- package/dist-esm/src/platform/nodejs/httpSender.js.map +1 -1
- package/dist-esm/src/platform/nodejs/persist/fileAccessControl.js +2 -2
- package/dist-esm/src/platform/nodejs/persist/fileAccessControl.js.map +1 -1
- package/dist-esm/src/platform/nodejs/persist/fileSystemHelpers.js +15 -8
- package/dist-esm/src/platform/nodejs/persist/fileSystemHelpers.js.map +1 -1
- package/dist-esm/src/platform/nodejs/persist/fileSystemPersist.js.map +1 -1
- package/dist-esm/src/sampling.js.map +1 -1
- package/dist-esm/src/utils/breezeUtils.js +12 -16
- package/dist-esm/src/utils/breezeUtils.js.map +1 -1
- package/dist-esm/src/utils/common.js +5 -1
- package/dist-esm/src/utils/common.js.map +1 -1
- package/dist-esm/src/utils/connectionStringParser.js.map +1 -1
- package/dist-esm/src/utils/constants/applicationinsights.js +2 -1
- package/dist-esm/src/utils/constants/applicationinsights.js.map +1 -1
- package/dist-esm/src/utils/eventhub.js.map +1 -1
- package/dist-esm/src/utils/logUtils.js +2 -3
- package/dist-esm/src/utils/logUtils.js.map +1 -1
- package/dist-esm/src/utils/metricUtils.js +1 -1
- package/dist-esm/src/utils/metricUtils.js.map +1 -1
- package/dist-esm/src/utils/spanUtils.js +14 -9
- package/dist-esm/src/utils/spanUtils.js.map +1 -1
- package/package.json +17 -18
- package/types/monitor-opentelemetry-exporter.d.ts +3 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileSystemPersist.js","sourceRoot":"","sources":["../../../../../src/platform/nodejs/persist/fileSystemPersist.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAChF,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAGjC,MAAM,SAAS,GAAG,SAAS,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;AACrC,MAAM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"fs\";\nimport * as os from \"os\";\nimport * as path from \"path\";\nimport { diag } from \"@opentelemetry/api\";\nimport { PersistentStorage } from \"../../../types\";\nimport { FileAccessControl } from \"./fileAccessControl\";\nimport { confirmDirExists, getShallowDirectorySize } from \"./fileSystemHelpers\";\nimport { promisify } from \"util\";\nimport { AzureMonitorExporterOptions } from \"../../../config\";\n\nconst statAsync = promisify(fs.stat);\nconst readdirAsync = promisify(fs.readdir);\nconst readFileAsync = promisify(fs.readFile);\nconst unlinkAsync = promisify(fs.unlink);\nconst writeFileAsync = promisify(fs.writeFile);\n\n/**\n * File system persist class.\n * @internal\n */\nexport class FileSystemPersist implements PersistentStorage {\n static TEMPDIR_PREFIX = \"ot-azure-exporter-\";\n static FILENAME_SUFFIX = \".ai.json\";\n\n fileRetemptionPeriod = 2 * 24 * 60 * 60 * 1000; // 2 days\n cleanupTimeOut = 60 * 60 * 1000; // 1 hour\n maxBytesOnDisk: number = 50_000_000; // ~50MB\n\n private _enabled: boolean;\n private _tempDirectory: string = \"\";\n private _fileCleanupTimer: NodeJS.Timeout | null = null;\n private _instrumentationKey: string;\n\n constructor(instrumentationKey: string, private _options?: AzureMonitorExporterOptions) {\n this._instrumentationKey = instrumentationKey;\n if (this._options?.disableOfflineStorage) {\n this._enabled = false;\n return;\n }\n this._enabled = true;\n FileAccessControl.checkFileProtection();\n\n if (!FileAccessControl.OS_PROVIDES_FILE_PROTECTION) {\n this._enabled = false;\n diag.error(\n \"Sufficient file protection capabilities were not detected. Files will not be persisted\"\n );\n }\n\n if (!this._instrumentationKey) {\n this._enabled = false;\n diag.error(\n `No instrumentation key was provided to FileSystemPersister. Files will not be persisted`\n );\n }\n if (this._enabled) {\n this._tempDirectory = path.join(\n this._options?.storageDirectory || os.tmpdir(),\n \"Microsoft\",\n \"AzureMonitor\",\n FileSystemPersist.TEMPDIR_PREFIX + this._instrumentationKey\n );\n\n // Starts file cleanup task\n if (!this._fileCleanupTimer) {\n this._fileCleanupTimer = setTimeout(() => {\n this._fileCleanupTask();\n }, this.cleanupTimeOut);\n this._fileCleanupTimer.unref();\n }\n }\n }\n\n push(value: unknown[]): Promise<boolean> {\n if (this._enabled) {\n diag.debug(\"Pushing value to persistent storage\", value.toString());\n return this._storeToDisk(JSON.stringify(value));\n }\n return new Promise((resolve) => {\n resolve(false);\n });\n }\n\n async shift(): Promise<unknown> {\n if (this._enabled) {\n diag.debug(\"Searching for filesystem persisted files\");\n try {\n const buffer = await this._getFirstFileOnDisk();\n if (buffer) {\n return JSON.parse(buffer.toString(\"utf8\"));\n }\n } catch (e: any) {\n diag.debug(\"Failed to read persisted file\", e);\n }\n return null;\n }\n return new Promise((resolve) => {\n resolve(null);\n });\n }\n\n /**\n * Check for temp telemetry files\n * reads the first file if exist, deletes it and tries to send its load\n */\n private async _getFirstFileOnDisk(): Promise<Buffer | null> {\n try {\n const stats = await statAsync(this._tempDirectory);\n if (stats.isDirectory()) {\n const origFiles = await readdirAsync(this._tempDirectory);\n const files = origFiles.filter((f) =>\n path.basename(f).includes(FileSystemPersist.FILENAME_SUFFIX)\n );\n if (files.length === 0) {\n return null;\n } else {\n const firstFile = files[0];\n const filePath = path.join(this._tempDirectory, firstFile);\n const payload = await readFileAsync(filePath);\n // delete the file first to prevent double sending\n await unlinkAsync(filePath);\n return payload;\n }\n }\n return null;\n } catch (e: any) {\n if (e.code === \"ENOENT\") {\n // File does not exist -- return null instead of throwing\n return null;\n } else {\n throw e;\n }\n }\n }\n\n private async _storeToDisk(payload: string): Promise<boolean> {\n try {\n await confirmDirExists(this._tempDirectory);\n } catch (error: any) {\n diag.warn(`Error while checking/creating directory: `, error && error.message);\n return false;\n }\n\n try {\n const size = await getShallowDirectorySize(this._tempDirectory);\n if (size > this.maxBytesOnDisk) {\n diag.warn(\n `Not saving data due to max size limit being met. Directory size in bytes is: ${size}`\n );\n return false;\n }\n } catch (error: any) {\n diag.warn(`Error while checking size of persistence directory: `, error && error.message);\n return false;\n }\n\n const fileName = `${new Date().getTime()}${FileSystemPersist.FILENAME_SUFFIX}`;\n const fileFullPath = path.join(this._tempDirectory, fileName);\n\n // Mode 600 is w/r for creator and no read access for others\n diag.info(`saving data to disk at: ${fileFullPath}`);\n try {\n await writeFileAsync(fileFullPath, payload, { mode: 0o600 });\n } catch (writeError: any) {\n diag.warn(`Error writing file to persistent file storage`, writeError);\n return false;\n }\n return true;\n }\n\n private async _fileCleanupTask(): Promise<boolean> {\n try {\n const stats = await statAsync(this._tempDirectory);\n if (stats.isDirectory()) {\n const origFiles = await readdirAsync(this._tempDirectory);\n const files = origFiles.filter((f) =>\n path.basename(f).includes(FileSystemPersist.FILENAME_SUFFIX)\n );\n if (files.length === 0) {\n return false;\n } else {\n files.forEach(async (file) => {\n // Check expiration\n const fileCreationDate: Date = new Date(\n parseInt(file.split(FileSystemPersist.FILENAME_SUFFIX)[0])\n );\n const expired = new Date(+new Date() - this.fileRetemptionPeriod) > fileCreationDate;\n if (expired) {\n const filePath = path.join(this._tempDirectory, file);\n await unlinkAsync(filePath);\n }\n });\n return true;\n }\n }\n return false;\n } catch (error: any) {\n diag.info(`Failed cleanup of persistent file storage expired files`, error);\n return false;\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"fileSystemPersist.js","sourceRoot":"","sources":["../../../../../src/platform/nodejs/persist/fileSystemPersist.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAChF,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAGjC,MAAM,SAAS,GAAG,SAAS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,CAAC,CAAC;wBAC9B,CAAC;oBACH,CAAC,CAAC,CAAC;oBACH,OAAO,IAAI,CAAC;gBACd,CAAC;YACH,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,IAAI,CAAC,IAAI,CAAC,yDAAyD,EAAE,KAAK,CAAC,CAAC;YAC5E,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;;AAtLM,gCAAc,GAAG,oBAAoB,AAAvB,CAAwB;AACtC,iCAAe,GAAG,UAAU,AAAb,CAAc","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport * as fs from \"fs\";\nimport * as os from \"os\";\nimport * as path from \"path\";\nimport { diag } from \"@opentelemetry/api\";\nimport { PersistentStorage } from \"../../../types\";\nimport { FileAccessControl } from \"./fileAccessControl\";\nimport { confirmDirExists, getShallowDirectorySize } from \"./fileSystemHelpers\";\nimport { promisify } from \"util\";\nimport { AzureMonitorExporterOptions } from \"../../../config\";\n\nconst statAsync = promisify(fs.stat);\nconst readdirAsync = promisify(fs.readdir);\nconst readFileAsync = promisify(fs.readFile);\nconst unlinkAsync = promisify(fs.unlink);\nconst writeFileAsync = promisify(fs.writeFile);\n\n/**\n * File system persist class.\n * @internal\n */\nexport class FileSystemPersist implements PersistentStorage {\n static TEMPDIR_PREFIX = \"ot-azure-exporter-\";\n static FILENAME_SUFFIX = \".ai.json\";\n\n fileRetemptionPeriod = 2 * 24 * 60 * 60 * 1000; // 2 days\n cleanupTimeOut = 60 * 60 * 1000; // 1 hour\n maxBytesOnDisk: number = 50_000_000; // ~50MB\n\n private _enabled: boolean;\n private _tempDirectory: string = \"\";\n private _fileCleanupTimer: NodeJS.Timeout | null = null;\n private _instrumentationKey: string;\n\n constructor(\n instrumentationKey: string,\n private _options?: AzureMonitorExporterOptions,\n ) {\n this._instrumentationKey = instrumentationKey;\n if (this._options?.disableOfflineStorage) {\n this._enabled = false;\n return;\n }\n this._enabled = true;\n FileAccessControl.checkFileProtection();\n\n if (!FileAccessControl.OS_PROVIDES_FILE_PROTECTION) {\n this._enabled = false;\n diag.error(\n \"Sufficient file protection capabilities were not detected. Files will not be persisted\",\n );\n }\n\n if (!this._instrumentationKey) {\n this._enabled = false;\n diag.error(\n `No instrumentation key was provided to FileSystemPersister. Files will not be persisted`,\n );\n }\n if (this._enabled) {\n this._tempDirectory = path.join(\n this._options?.storageDirectory || os.tmpdir(),\n \"Microsoft\",\n \"AzureMonitor\",\n FileSystemPersist.TEMPDIR_PREFIX + this._instrumentationKey,\n );\n\n // Starts file cleanup task\n if (!this._fileCleanupTimer) {\n this._fileCleanupTimer = setTimeout(() => {\n this._fileCleanupTask();\n }, this.cleanupTimeOut);\n this._fileCleanupTimer.unref();\n }\n }\n }\n\n push(value: unknown[]): Promise<boolean> {\n if (this._enabled) {\n diag.debug(\"Pushing value to persistent storage\", value.toString());\n return this._storeToDisk(JSON.stringify(value));\n }\n return new Promise((resolve) => {\n resolve(false);\n });\n }\n\n async shift(): Promise<unknown> {\n if (this._enabled) {\n diag.debug(\"Searching for filesystem persisted files\");\n try {\n const buffer = await this._getFirstFileOnDisk();\n if (buffer) {\n return JSON.parse(buffer.toString(\"utf8\"));\n }\n } catch (e: any) {\n diag.debug(\"Failed to read persisted file\", e);\n }\n return null;\n }\n return new Promise((resolve) => {\n resolve(null);\n });\n }\n\n /**\n * Check for temp telemetry files\n * reads the first file if exist, deletes it and tries to send its load\n */\n private async _getFirstFileOnDisk(): Promise<Buffer | null> {\n try {\n const stats = await statAsync(this._tempDirectory);\n if (stats.isDirectory()) {\n const origFiles = await readdirAsync(this._tempDirectory);\n const files = origFiles.filter((f) =>\n path.basename(f).includes(FileSystemPersist.FILENAME_SUFFIX),\n );\n if (files.length === 0) {\n return null;\n } else {\n const firstFile = files[0];\n const filePath = path.join(this._tempDirectory, firstFile);\n const payload = await readFileAsync(filePath);\n // delete the file first to prevent double sending\n await unlinkAsync(filePath);\n return payload;\n }\n }\n return null;\n } catch (e: any) {\n if (e.code === \"ENOENT\") {\n // File does not exist -- return null instead of throwing\n return null;\n } else {\n throw e;\n }\n }\n }\n\n private async _storeToDisk(payload: string): Promise<boolean> {\n try {\n await confirmDirExists(this._tempDirectory);\n } catch (error: any) {\n diag.warn(`Error while checking/creating directory: `, error && error.message);\n return false;\n }\n\n try {\n const size = await getShallowDirectorySize(this._tempDirectory);\n if (size > this.maxBytesOnDisk) {\n diag.warn(\n `Not saving data due to max size limit being met. Directory size in bytes is: ${size}`,\n );\n return false;\n }\n } catch (error: any) {\n diag.warn(`Error while checking size of persistence directory: `, error && error.message);\n return false;\n }\n\n const fileName = `${new Date().getTime()}${FileSystemPersist.FILENAME_SUFFIX}`;\n const fileFullPath = path.join(this._tempDirectory, fileName);\n\n // Mode 600 is w/r for creator and no read access for others\n diag.info(`saving data to disk at: ${fileFullPath}`);\n try {\n await writeFileAsync(fileFullPath, payload, { mode: 0o600 });\n } catch (writeError: any) {\n diag.warn(`Error writing file to persistent file storage`, writeError);\n return false;\n }\n return true;\n }\n\n private async _fileCleanupTask(): Promise<boolean> {\n try {\n const stats = await statAsync(this._tempDirectory);\n if (stats.isDirectory()) {\n const origFiles = await readdirAsync(this._tempDirectory);\n const files = origFiles.filter((f) =>\n path.basename(f).includes(FileSystemPersist.FILENAME_SUFFIX),\n );\n if (files.length === 0) {\n return false;\n } else {\n files.forEach(async (file) => {\n // Check expiration\n const fileCreationDate: Date = new Date(\n parseInt(file.split(FileSystemPersist.FILENAME_SUFFIX)[0]),\n );\n const expired = new Date(+new Date() - this.fileRetemptionPeriod) > fileCreationDate;\n if (expired) {\n const filePath = path.join(this._tempDirectory, file);\n await unlinkAsync(filePath);\n }\n });\n return true;\n }\n }\n return false;\n } catch (error: any) {\n diag.info(`Failed cleanup of persistent file storage expired files`, error);\n return false;\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sampling.js","sourceRoot":"","sources":["../../src/sampling.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CAAC,IAAI,CAAC,CAAC;QACtD,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC,GAAG,GAAG,CAAC;IAClC,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nimport { Link, Attributes, SpanKind, Context } from \"@opentelemetry/api\";\nimport { Sampler, SamplingDecision, SamplingResult } from \"@opentelemetry/sdk-trace-base\";\nimport { AzureMonitorSampleRate } from \"./utils/constants/applicationinsights\";\n\n/**\n * ApplicationInsightsSampler is responsible for the following:\n * Implements same trace id hashing algorithm so that traces are sampled the same across multiple nodes\n * Adds item count to span attribute if span is sampled (needed for ingestion service)\n * @param samplingRatio - 0 to 1 value.\n */\nexport class ApplicationInsightsSampler implements Sampler {\n private readonly _sampleRate: number;\n private readonly samplingRatio: number;\n\n /**\n * Initializes a new instance of the ApplicationInsightsSampler class.\n * @param samplingRatio - Value in the range [0,1], 1 meaning all data will sampled and 0 all Tracing data will be sampled out.\n */\n constructor(samplingRatio: number = 1) {\n this.samplingRatio = samplingRatio;\n if (this.samplingRatio > 1) {\n throw new Error(\"Wrong sampling rate, data will not be sampled out\");\n }\n this._sampleRate = Math.round(this.samplingRatio * 100);\n }\n\n /**\n * Checks whether span needs to be created and tracked.\n *\n * @param context - Parent Context which may contain a span.\n * @param traceId - traceif of the span to be created. It can be different from the\n * traceId in the {@link SpanContext}. Typically in situations when the\n * span to be created starts a new trace.\n * @param spanName - Name of the span to be created.\n * @param spanKind - Kind of the span to be created.\n * @param attributes - Initial set of SpanAttributes for the Span being constructed.\n * @param links - Collection of links that will be associated with the Span to\n * be created. Typically useful for batch operations.\n * @returns a {@link SamplingResult}.\n */\n public shouldSample(\n // @ts-ignore\n context: Context,\n traceId: string,\n // @ts-ignore\n spanName: string,\n // @ts-ignore\n spanKind: SpanKind,\n attributes: Attributes,\n // @ts-ignore\n links: Link[],\n ): SamplingResult {\n let isSampledIn = false;\n if (this._sampleRate === 100) {\n isSampledIn = true;\n } else if (this._sampleRate === 0) {\n isSampledIn = false;\n } else {\n isSampledIn = this._getSamplingHashCode(traceId) < this._sampleRate;\n }\n // Add sample rate as span attribute\n attributes = attributes || {};\n attributes[AzureMonitorSampleRate] = this._sampleRate;\n return isSampledIn\n ? { decision: SamplingDecision.RECORD_AND_SAMPLED, attributes: attributes }\n : { decision: SamplingDecision.NOT_RECORD, attributes: attributes };\n }\n\n /**\n * Return Sampler description\n */\n public toString(): string {\n return `ApplicationInsightsSampler{${this.samplingRatio}}`;\n }\n\n private _getSamplingHashCode(input: string): number {\n const csharpMin = -2147483648;\n const csharpMax = 2147483647;\n let hash = 5381;\n\n if (!input) {\n return 0;\n }\n\n while (input.length < 8) {\n input = input + input;\n }\n\n for (let i = 0; i < input.length; i++) {\n // JS doesn't respond to integer overflow by wrapping around. Simulate it with bitwise operators ( | 0)\n hash = ((((hash << 5) + hash) | 0) + input.charCodeAt(i)) | 0;\n }\n\n hash = hash <= csharpMin ? csharpMax : Math.abs(hash);\n return (hash / csharpMax) * 100;\n }\n}\n"]}
|
|
@@ -17,23 +17,19 @@ export function isRetriable(statusCode) {
|
|
|
17
17
|
statusCode === 504 // Gateway Timeout
|
|
18
18
|
);
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
*/
|
|
24
|
-
export function msToTimeSpan(ms) {
|
|
25
|
-
let totalms = ms;
|
|
26
|
-
if (Number.isNaN(totalms) || totalms < 0 || !Number.isFinite(ms)) {
|
|
20
|
+
// Convert ms to c# time span format DD.HH:MM:SS.MMMMMM
|
|
21
|
+
export function msToTimeSpan(totalms) {
|
|
22
|
+
if (isNaN(totalms) || totalms < 0) {
|
|
27
23
|
totalms = 0;
|
|
28
24
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
sec = sec.indexOf(".") < 2 ?
|
|
34
|
-
min = min.length < 2 ?
|
|
35
|
-
hour = hour.length < 2 ?
|
|
36
|
-
|
|
37
|
-
return
|
|
25
|
+
var sec = ((totalms / 1000) % 60).toFixed(7).replace(/0{0,4}$/, "");
|
|
26
|
+
var min = "" + (Math.floor(totalms / (1000 * 60)) % 60);
|
|
27
|
+
var hour = "" + (Math.floor(totalms / (1000 * 60 * 60)) % 24);
|
|
28
|
+
var days = Math.floor(totalms / (1000 * 60 * 60 * 24));
|
|
29
|
+
sec = sec.indexOf(".") < 2 ? "0" + sec : sec;
|
|
30
|
+
min = min.length < 2 ? "0" + min : min;
|
|
31
|
+
hour = hour.length < 2 ? "0" + hour : hour;
|
|
32
|
+
var daysText = days > 0 ? days + "." : "";
|
|
33
|
+
return daysText + hour + ":" + min + ":" + sec;
|
|
38
34
|
}
|
|
39
35
|
//# sourceMappingURL=breezeUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"breezeUtils.js","sourceRoot":"","sources":["../../../src/utils/breezeUtils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAsBlC;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,UAAkB;IAC5C,OAAO,CACL,UAAU,KAAK,GAAG,IAAI,iBAAiB;QACvC,UAAU,KAAK,GAAG,IAAI,eAAe;QACrC,UAAU,KAAK,GAAG,IAAI,YAAY;QAClC,UAAU,KAAK,GAAG,IAAI,UAAU;QAChC,UAAU,KAAK,GAAG,IAAI,oBAAoB;QAC1C,UAAU,KAAK,GAAG,IAAI,gCAAgC;QACtD,UAAU,KAAK,GAAG,IAAI,eAAe;QACrC,UAAU,KAAK,GAAG,IAAI,cAAc;QACpC,UAAU,KAAK,GAAG,IAAI,qBAAqB;QAC3C,UAAU,KAAK,GAAG,CAAC,kBAAkB;KACtC,CAAC;AACJ,CAAC;AAED
|
|
1
|
+
{"version":3,"file":"breezeUtils.js","sourceRoot":"","sources":["../../../src/utils/breezeUtils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAsBlC;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,U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CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;IAC7C,GAAG,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;IACvC,IAAI,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;IAC3C,IAAI,QAAQ,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IAC1C,OAAO,QAAQ,GAAG,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AACjD,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/**\n * Breeze errors.\n * @internal\n */\nexport interface BreezeError {\n index: number;\n statusCode: number;\n message: string;\n}\n\n/**\n * Breeze response definition.\n * @internal\n */\nexport interface BreezeResponse {\n itemsReceived: number;\n itemsAccepted: number;\n errors: BreezeError[];\n}\n\n/**\n * Breeze retriable status codes.\n * @internal\n */\nexport function isRetriable(statusCode: number): boolean {\n return (\n statusCode === 206 || // Partial Accept\n statusCode === 401 || // Unauthorized\n statusCode === 403 || // Forbidden\n statusCode === 408 || // Timeout\n statusCode === 429 || // Too many requests\n statusCode === 439 || // Daily quota exceeded (legacy)\n statusCode === 500 || // Server Error\n statusCode === 502 || // Bad Gateway\n statusCode === 503 || // Server Unavailable\n statusCode === 504 // Gateway Timeout\n );\n}\n\n// Convert ms to c# time span format DD.HH:MM:SS.MMMMMM\nexport function msToTimeSpan(totalms: number): string {\n if (isNaN(totalms) || totalms < 0) {\n totalms = 0;\n }\n var sec = ((totalms / 1000) % 60).toFixed(7).replace(/0{0,4}$/, \"\");\n var min = \"\" + (Math.floor(totalms / (1000 * 60)) % 60);\n var hour = \"\" + (Math.floor(totalms / (1000 * 60 * 60)) % 24);\n var days = Math.floor(totalms / (1000 * 60 * 60 * 24));\n\n sec = sec.indexOf(\".\") < 2 ? \"0\" + sec : sec;\n min = min.length < 2 ? \"0\" + min : min;\n hour = hour.length < 2 ? \"0\" + hour : hour;\n var daysText = days > 0 ? days + \".\" : \"\";\n return daysText + hour + \":\" + min + \":\" + sec;\n}\n"]}
|
|
@@ -4,6 +4,10 @@ import os from "os";
|
|
|
4
4
|
import { SemanticResourceAttributes, SemanticAttributes, DbSystemValues, } from "@opentelemetry/semantic-conventions";
|
|
5
5
|
import { getInstance } from "../platform";
|
|
6
6
|
import { KnownContextTagKeys } from "../generated";
|
|
7
|
+
import { hrTimeToNanoseconds } from "@opentelemetry/core";
|
|
8
|
+
export function hrTimeToDate(hrTime) {
|
|
9
|
+
return new Date(hrTimeToNanoseconds(hrTime) / 1000000);
|
|
10
|
+
}
|
|
7
11
|
export function createTagsFromResource(resource) {
|
|
8
12
|
const context = getInstance();
|
|
9
13
|
const tags = Object.assign({}, context.tags);
|
|
@@ -181,7 +185,7 @@ export function createResourceMetricEnvelope(resource, instrumentationKey) {
|
|
|
181
185
|
const envelope = {
|
|
182
186
|
name: "Microsoft.ApplicationInsights.Metric",
|
|
183
187
|
time: new Date(),
|
|
184
|
-
sampleRate: 100,
|
|
188
|
+
sampleRate: 100, // Metrics are never sampled
|
|
185
189
|
instrumentationKey: instrumentationKey,
|
|
186
190
|
version: 1,
|
|
187
191
|
data: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/utils/common.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EACL,0BAA0B,EAC1B,kBAAkB,EAClB,cAAc,GACf,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAA0C,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,IAAI,EAAE,sCAAsC;gBAC5C,IAAI,EAAE,IAAI,IAAI,EAAE;gBAChB,UAAU,EAAE,GAAG;gBACf,kBAAkB,EAAE,kBAAkB;gBACtC,OAAO,EAAE,CAAC;gBACV,IAAI,EAAE;oBACJ,QAAQ,EAAE,YAAY;oBACtB,QAAQ,EAAE,QAAQ;iBACnB;gBACD,IAAI,EAAE,IAAI;aACX,CAAC;YACF,OAAO,QAAQ,CAAC;SACjB;KACF;IACD,OAAO;AACT,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport os from \"os\";\nimport {\n SemanticResourceAttributes,\n SemanticAttributes,\n DbSystemValues,\n} from \"@opentelemetry/semantic-conventions\";\nimport { Tags } from \"../types\";\nimport { getInstance } from \"../platform\";\nimport { KnownContextTagKeys, TelemetryItem as Envelope, MetricsData } from \"../generated\";\nimport { Resource } from \"@opentelemetry/resources\";\nimport { Attributes } from \"@opentelemetry/api\";\n\nexport function createTagsFromResource(resource: Resource): Tags {\n const context = getInstance();\n const tags: Tags = { ...context.tags };\n if (resource && resource.attributes) {\n tags[KnownContextTagKeys.AiCloudRole] = getCloudRole(resource);\n tags[KnownContextTagKeys.AiCloudRoleInstance] = getCloudRoleInstance(resource);\n const endUserId = resource.attributes[SemanticAttributes.ENDUSER_ID];\n if (endUserId) {\n tags[KnownContextTagKeys.AiUserId] = String(endUserId);\n }\n }\n return tags;\n}\n\nfunction getCloudRole(resource: Resource): string {\n let cloudRole = \"\";\n // Service attributes\n const serviceName = resource.attributes[SemanticResourceAttributes.SERVICE_NAME];\n const serviceNamespace = resource.attributes[SemanticResourceAttributes.SERVICE_NAMESPACE];\n if (serviceName) {\n // Custom Service name provided by customer is highest precedence\n if (!String(serviceName).startsWith(\"unknown_service\")) {\n if (serviceNamespace) {\n return `${serviceNamespace}.${serviceName}`;\n } else {\n return String(serviceName);\n }\n } else {\n // Service attributes will be only used if K8S attributes are not present\n if (serviceNamespace) {\n cloudRole = `${serviceNamespace}.${serviceName}`;\n } else {\n cloudRole = String(serviceName);\n }\n }\n }\n // Kubernetes attributes should take precedence\n const kubernetesDeploymentName =\n resource.attributes[SemanticResourceAttributes.K8S_DEPLOYMENT_NAME];\n if (kubernetesDeploymentName) {\n return String(kubernetesDeploymentName);\n }\n const kuberneteReplicasetName =\n resource.attributes[SemanticResourceAttributes.K8S_REPLICASET_NAME];\n if (kuberneteReplicasetName) {\n return String(kuberneteReplicasetName);\n }\n const kubernetesStatefulSetName =\n resource.attributes[SemanticResourceAttributes.K8S_STATEFULSET_NAME];\n if (kubernetesStatefulSetName) {\n return String(kubernetesStatefulSetName);\n }\n const kubernetesJobName = resource.attributes[SemanticResourceAttributes.K8S_JOB_NAME];\n if (kubernetesJobName) {\n return String(kubernetesJobName);\n }\n const kubernetesCronjobName = resource.attributes[SemanticResourceAttributes.K8S_CRONJOB_NAME];\n if (kubernetesCronjobName) {\n return String(kubernetesCronjobName);\n }\n const kubernetesDaemonsetName =\n resource.attributes[SemanticResourceAttributes.K8S_DAEMONSET_NAME];\n if (kubernetesDaemonsetName) {\n return String(kubernetesDaemonsetName);\n }\n return cloudRole;\n}\n\nfunction getCloudRoleInstance(resource: Resource): string {\n // Kubernetes attributes should take precedence\n const kubernetesPodName = resource.attributes[SemanticResourceAttributes.K8S_POD_NAME];\n if (kubernetesPodName) {\n return String(kubernetesPodName);\n }\n // Service attributes\n const serviceInstanceId = resource.attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID];\n if (serviceInstanceId) {\n return String(serviceInstanceId);\n }\n // Default\n return os && os.hostname();\n}\n\nexport function isSqlDB(dbSystem: string) {\n return (\n dbSystem === DbSystemValues.DB2 ||\n dbSystem === DbSystemValues.DERBY ||\n dbSystem === DbSystemValues.MARIADB ||\n dbSystem === DbSystemValues.MSSQL ||\n dbSystem === DbSystemValues.ORACLE ||\n dbSystem === DbSystemValues.SQLITE ||\n dbSystem === DbSystemValues.OTHER_SQL ||\n dbSystem === DbSystemValues.HSQLDB ||\n dbSystem === DbSystemValues.H2\n );\n}\n\nexport function getUrl(attributes: Attributes): string {\n if (!attributes) {\n return \"\";\n }\n const httpMethod = attributes[SemanticAttributes.HTTP_METHOD];\n if (httpMethod) {\n const httpUrl = attributes[SemanticAttributes.HTTP_URL];\n if (httpUrl) {\n return String(httpUrl);\n } else {\n const httpScheme = attributes[SemanticAttributes.HTTP_SCHEME];\n const httpTarget = attributes[SemanticAttributes.HTTP_TARGET];\n if (httpScheme && httpTarget) {\n const httpHost = attributes[SemanticAttributes.HTTP_HOST];\n if (httpHost) {\n return `${httpScheme}://${httpHost}${httpTarget}`;\n } else {\n const netPeerPort = attributes[SemanticAttributes.NET_PEER_PORT];\n if (netPeerPort) {\n const netPeerName = attributes[SemanticAttributes.NET_PEER_NAME];\n if (netPeerName) {\n return `${httpScheme}://${netPeerName}:${netPeerPort}${httpTarget}`;\n } else {\n const netPeerIp = attributes[SemanticAttributes.NET_PEER_IP];\n if (netPeerIp) {\n return `${httpScheme}://${netPeerIp}:${netPeerPort}${httpTarget}`;\n }\n }\n }\n }\n }\n }\n }\n return \"\";\n}\n\nexport function getDependencyTarget(attributes: Attributes): string {\n if (!attributes) {\n return \"\";\n }\n const peerService = attributes[SemanticAttributes.PEER_SERVICE];\n const httpHost = attributes[SemanticAttributes.HTTP_HOST];\n const httpUrl = attributes[SemanticAttributes.HTTP_URL];\n const netPeerName = attributes[SemanticAttributes.NET_PEER_NAME];\n const netPeerIp = attributes[SemanticAttributes.NET_PEER_IP];\n if (peerService) {\n return String(peerService);\n } else if (httpHost) {\n return String(httpHost);\n } else if (httpUrl) {\n return String(httpUrl);\n } else if (netPeerName) {\n return String(netPeerName);\n } else if (netPeerIp) {\n return String(netPeerIp);\n }\n return \"\";\n}\n\nexport function createResourceMetricEnvelope(\n resource: Resource,\n instrumentationKey: string\n): Envelope | undefined {\n if (resource && resource.attributes) {\n const tags = createTagsFromResource(resource);\n const resourceAttributes: { [propertyName: string]: string } = {};\n for (const key of Object.keys(resource.attributes)) {\n // Avoid duplication ignoring fields already mapped.\n if (\n !(\n key.startsWith(\"_MS.\") ||\n key === SemanticResourceAttributes.TELEMETRY_SDK_VERSION ||\n key === SemanticResourceAttributes.TELEMETRY_SDK_LANGUAGE ||\n key === SemanticResourceAttributes.TELEMETRY_SDK_NAME\n )\n ) {\n resourceAttributes[key] = resource.attributes[key] as string;\n }\n }\n // Only send event when resource attributes are available\n if (Object.keys(resourceAttributes).length > 0) {\n const baseData: MetricsData = {\n version: 2,\n metrics: [{ name: \"_OTELRESOURCE_\", value: 1 }],\n properties: resourceAttributes,\n };\n const envelope: Envelope = {\n name: \"Microsoft.ApplicationInsights.Metric\",\n time: new Date(),\n sampleRate: 100, // Metrics are never sampled\n instrumentationKey: instrumentationKey,\n version: 1,\n data: {\n baseType: \"MetricData\",\n baseData: baseData,\n },\n tags: tags,\n };\n return envelope;\n }\n }\n return;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/utils/common.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EACL,0BAA0B,EAC1B,kBAAkB,EAClB,cAAc,GACf,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAA0C,MAAM,cAAc,CAAC;AAG3F,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1D,MAAM,UAAU,YAAY,CAAC,MAAc;IACzC,OAAO,IAAI,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC;AACzD,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,QAAkB;IACvD,MAAM,OAAO,GAAG,WAAW,EAAE,CAAC;IAC9B,MAAM,IAAI,qBAAc,OAAO,CAAC,IAAI,CAAE,CAAC;IACvC,IAAI,QAAQ,IAAI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,IAAI,CAAC,kBAAkB,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC/C,MAAM,QAAQ,GAAgB;gBAC5B,OAAO,EAAE,CAAC;gBACV,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,gBAAgB,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;gBAC/C,UAAU,EAAE,kBAAkB;aAC/B,CAAC;YACF,MAAM,QAAQ,GAAa;gBACzB,IAAI,EAAE,sCAAsC;gBAC5C,IAAI,EAAE,IAAI,IAAI,EAAE;gBAChB,UAAU,EAAE,GAAG,EAAE,4BAA4B;gBAC7C,kBAAkB,EAAE,kBAAkB;gBACtC,OAAO,EAAE,CAAC;gBACV,IAAI,EAAE;oBACJ,QAAQ,EAAE,YAAY;oBACtB,QAAQ,EAAE,QAAQ;iBACnB;gBACD,IAAI,EAAE,IAAI;aACX,CAAC;YACF,OAAO,QAAQ,CAAC;QAClB,CAAC;IACH,CAAC;IACD,OAAO;AACT,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport os from \"os\";\nimport {\n SemanticResourceAttributes,\n SemanticAttributes,\n DbSystemValues,\n} from \"@opentelemetry/semantic-conventions\";\nimport { Tags } from \"../types\";\nimport { getInstance } from \"../platform\";\nimport { KnownContextTagKeys, TelemetryItem as Envelope, MetricsData } from \"../generated\";\nimport { Resource } from \"@opentelemetry/resources\";\nimport { Attributes, HrTime } from \"@opentelemetry/api\";\nimport { hrTimeToNanoseconds } from \"@opentelemetry/core\";\n\nexport function hrTimeToDate(hrTime: HrTime): Date {\n return new Date(hrTimeToNanoseconds(hrTime) / 1000000);\n}\n\nexport function createTagsFromResource(resource: Resource): Tags {\n const context = getInstance();\n const tags: Tags = { ...context.tags };\n if (resource && resource.attributes) {\n tags[KnownContextTagKeys.AiCloudRole] = getCloudRole(resource);\n tags[KnownContextTagKeys.AiCloudRoleInstance] = getCloudRoleInstance(resource);\n const endUserId = resource.attributes[SemanticAttributes.ENDUSER_ID];\n if (endUserId) {\n tags[KnownContextTagKeys.AiUserId] = String(endUserId);\n }\n }\n return tags;\n}\n\nfunction getCloudRole(resource: Resource): string {\n let cloudRole = \"\";\n // Service attributes\n const serviceName = resource.attributes[SemanticResourceAttributes.SERVICE_NAME];\n const serviceNamespace = resource.attributes[SemanticResourceAttributes.SERVICE_NAMESPACE];\n if (serviceName) {\n // Custom Service name provided by customer is highest precedence\n if (!String(serviceName).startsWith(\"unknown_service\")) {\n if (serviceNamespace) {\n return `${serviceNamespace}.${serviceName}`;\n } else {\n return String(serviceName);\n }\n } else {\n // Service attributes will be only used if K8S attributes are not present\n if (serviceNamespace) {\n cloudRole = `${serviceNamespace}.${serviceName}`;\n } else {\n cloudRole = String(serviceName);\n }\n }\n }\n // Kubernetes attributes should take precedence\n const kubernetesDeploymentName =\n resource.attributes[SemanticResourceAttributes.K8S_DEPLOYMENT_NAME];\n if (kubernetesDeploymentName) {\n return String(kubernetesDeploymentName);\n }\n const kuberneteReplicasetName =\n resource.attributes[SemanticResourceAttributes.K8S_REPLICASET_NAME];\n if (kuberneteReplicasetName) {\n return String(kuberneteReplicasetName);\n }\n const kubernetesStatefulSetName =\n resource.attributes[SemanticResourceAttributes.K8S_STATEFULSET_NAME];\n if (kubernetesStatefulSetName) {\n return String(kubernetesStatefulSetName);\n }\n const kubernetesJobName = resource.attributes[SemanticResourceAttributes.K8S_JOB_NAME];\n if (kubernetesJobName) {\n return String(kubernetesJobName);\n }\n const kubernetesCronjobName = resource.attributes[SemanticResourceAttributes.K8S_CRONJOB_NAME];\n if (kubernetesCronjobName) {\n return String(kubernetesCronjobName);\n }\n const kubernetesDaemonsetName =\n resource.attributes[SemanticResourceAttributes.K8S_DAEMONSET_NAME];\n if (kubernetesDaemonsetName) {\n return String(kubernetesDaemonsetName);\n }\n return cloudRole;\n}\n\nfunction getCloudRoleInstance(resource: Resource): string {\n // Kubernetes attributes should take precedence\n const kubernetesPodName = resource.attributes[SemanticResourceAttributes.K8S_POD_NAME];\n if (kubernetesPodName) {\n return String(kubernetesPodName);\n }\n // Service attributes\n const serviceInstanceId = resource.attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID];\n if (serviceInstanceId) {\n return String(serviceInstanceId);\n }\n // Default\n return os && os.hostname();\n}\n\nexport function isSqlDB(dbSystem: string) {\n return (\n dbSystem === DbSystemValues.DB2 ||\n dbSystem === DbSystemValues.DERBY ||\n dbSystem === DbSystemValues.MARIADB ||\n dbSystem === DbSystemValues.MSSQL ||\n dbSystem === DbSystemValues.ORACLE ||\n dbSystem === DbSystemValues.SQLITE ||\n dbSystem === DbSystemValues.OTHER_SQL ||\n dbSystem === DbSystemValues.HSQLDB ||\n dbSystem === DbSystemValues.H2\n );\n}\n\nexport function getUrl(attributes: Attributes): string {\n if (!attributes) {\n return \"\";\n }\n const httpMethod = attributes[SemanticAttributes.HTTP_METHOD];\n if (httpMethod) {\n const httpUrl = attributes[SemanticAttributes.HTTP_URL];\n if (httpUrl) {\n return String(httpUrl);\n } else {\n const httpScheme = attributes[SemanticAttributes.HTTP_SCHEME];\n const httpTarget = attributes[SemanticAttributes.HTTP_TARGET];\n if (httpScheme && httpTarget) {\n const httpHost = attributes[SemanticAttributes.HTTP_HOST];\n if (httpHost) {\n return `${httpScheme}://${httpHost}${httpTarget}`;\n } else {\n const netPeerPort = attributes[SemanticAttributes.NET_PEER_PORT];\n if (netPeerPort) {\n const netPeerName = attributes[SemanticAttributes.NET_PEER_NAME];\n if (netPeerName) {\n return `${httpScheme}://${netPeerName}:${netPeerPort}${httpTarget}`;\n } else {\n const netPeerIp = attributes[SemanticAttributes.NET_PEER_IP];\n if (netPeerIp) {\n return `${httpScheme}://${netPeerIp}:${netPeerPort}${httpTarget}`;\n }\n }\n }\n }\n }\n }\n }\n return \"\";\n}\n\nexport function getDependencyTarget(attributes: Attributes): string {\n if (!attributes) {\n return \"\";\n }\n const peerService = attributes[SemanticAttributes.PEER_SERVICE];\n const httpHost = attributes[SemanticAttributes.HTTP_HOST];\n const httpUrl = attributes[SemanticAttributes.HTTP_URL];\n const netPeerName = attributes[SemanticAttributes.NET_PEER_NAME];\n const netPeerIp = attributes[SemanticAttributes.NET_PEER_IP];\n if (peerService) {\n return String(peerService);\n } else if (httpHost) {\n return String(httpHost);\n } else if (httpUrl) {\n return String(httpUrl);\n } else if (netPeerName) {\n return String(netPeerName);\n } else if (netPeerIp) {\n return String(netPeerIp);\n }\n return \"\";\n}\n\nexport function createResourceMetricEnvelope(\n resource: Resource,\n instrumentationKey: string,\n): Envelope | undefined {\n if (resource && resource.attributes) {\n const tags = createTagsFromResource(resource);\n const resourceAttributes: { [propertyName: string]: string } = {};\n for (const key of Object.keys(resource.attributes)) {\n // Avoid duplication ignoring fields already mapped.\n if (\n !(\n key.startsWith(\"_MS.\") ||\n key === SemanticResourceAttributes.TELEMETRY_SDK_VERSION ||\n key === SemanticResourceAttributes.TELEMETRY_SDK_LANGUAGE ||\n key === SemanticResourceAttributes.TELEMETRY_SDK_NAME\n )\n ) {\n resourceAttributes[key] = resource.attributes[key] as string;\n }\n }\n // Only send event when resource attributes are available\n if (Object.keys(resourceAttributes).length > 0) {\n const baseData: MetricsData = {\n version: 2,\n metrics: [{ name: \"_OTELRESOURCE_\", value: 1 }],\n properties: resourceAttributes,\n };\n const envelope: Envelope = {\n name: \"Microsoft.ApplicationInsights.Metric\",\n time: new Date(),\n sampleRate: 100, // Metrics are never sampled\n instrumentationKey: instrumentationKey,\n version: 1,\n data: {\n baseType: \"MetricData\",\n baseData: baseData,\n },\n tags: tags,\n };\n return envelope;\n }\n }\n return;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connectionStringParser.js","sourceRoot":"","sources":["../../../src/utils/connectionStringParser.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAG1C,OAAO,KAAK,SAAS,MAAM,2BAA2B,CAAC;AA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,GAAW;QACnC,IAAI,MAAM,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;QACxB,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YACnC,8BAA8B;YAC9B,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;QACjD,CAAC;QACD,gCAAgC;QAChC,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;YACtC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC/B,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAEM,MAAM,CAAC,0BAA0B,CAAC,IAAY;QACnD,IAAI,IAAI,CAAC,UAAU,CAAC,qBAAqB,CAAC,EAAE,CAAC;YAC3C,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,GAAG,qBAAqB,CAAC,MAAM,CAAC;YACtF,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;YAC/C,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;QAC9C,CAAC;QACD,MAAM,UAAU,GAAG,gEAAgE,CAAC;QACpF,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,UAAU,CAAC,CAAC;QACtC,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;;AArFuB,uCAAgB,GAAG,GAAG,CAAC;AAEvB,gDAAyB,GAAG,GAAG,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { diag } from \"@opentelemetry/api\";\nimport { ConnectionString, ConnectionStringKey } from \"../Declarations/Contracts\";\n\nimport * as Constants from \"../Declarations/Constants\";\n\n/**\n * ConnectionString parser.\n * @internal\n */\nexport class ConnectionStringParser {\n private static readonly FIELDS_SEPARATOR = \";\";\n\n private static readonly FIELD_KEY_VALUE_SEPARATOR = \"=\";\n\n public static parse(connectionString?: string): ConnectionString {\n if (!connectionString) {\n return {};\n }\n\n const kvPairs = connectionString.split(ConnectionStringParser.FIELDS_SEPARATOR);\n let isValid = true;\n\n const result: ConnectionString = kvPairs.reduce((fields: ConnectionString, kv: string) => {\n const kvParts = kv.split(ConnectionStringParser.FIELD_KEY_VALUE_SEPARATOR);\n\n if (kvParts.length === 2) {\n // only save fields with valid formats\n const key = kvParts[0].toLowerCase() as ConnectionStringKey;\n const value = kvParts[1];\n return { ...fields, [key]: value };\n }\n diag.error(\n `Connection string key-value pair is invalid: ${kv}`,\n `Entire connection string will be discarded`,\n connectionString,\n );\n isValid = false;\n return fields;\n }, {});\n\n if (isValid && Object.keys(result).length > 0) {\n // this is a valid connection string, so parse the results\n\n if (result.endpointsuffix) {\n // use endpoint suffix where overrides are not provided\n const locationPrefix = result.location ? `${result.location}.` : \"\";\n result.ingestionendpoint =\n result.ingestionendpoint || `https://${locationPrefix}dc.${result.endpointsuffix}`;\n result.liveendpoint =\n result.liveendpoint || `https://${locationPrefix}live.${result.endpointsuffix}`;\n }\n\n result.ingestionendpoint = result.ingestionendpoint\n ? ConnectionStringParser.sanitizeUrl(result.ingestionendpoint)\n : Constants.DEFAULT_BREEZE_ENDPOINT;\n result.liveendpoint = result.liveendpoint\n ? ConnectionStringParser.sanitizeUrl(result.liveendpoint)\n : Constants.DEFAULT_LIVEMETRICS_ENDPOINT;\n if (result.authorization && result.authorization.toLowerCase() !== \"ikey\") {\n diag.warn(\n `Connection String contains an unsupported 'Authorization' value: ${result.authorization!}. Defaulting to 'Authorization=ikey'. Instrumentation Key ${result.instrumentationkey!}`,\n );\n }\n } else {\n diag.error(\n \"An invalid connection string was passed in. There may be telemetry loss\",\n connectionString,\n );\n }\n\n return result;\n }\n\n public static sanitizeUrl(url: string) {\n let newUrl = url.trim();\n if (newUrl.indexOf(\"https://\") < 0) {\n // Try to update http to https\n newUrl = newUrl.replace(\"http://\", \"https://\");\n }\n // Remove final slash if present\n if (newUrl[newUrl.length - 1] === \"/\") {\n newUrl = newUrl.slice(0, -1);\n }\n return newUrl;\n }\n\n public static validateInstrumentationKey(iKey: string): boolean {\n if (iKey.startsWith(\"InstrumentationKey=\")) {\n const startIndex = iKey.indexOf(\"InstrumentationKey=\") + \"InstrumentationKey=\".length;\n const endIndex = iKey.indexOf(\";\", startIndex);\n iKey = iKey.substring(startIndex, endIndex);\n }\n const UUID_Regex = \"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$\";\n const regexp = new RegExp(UUID_Regex);\n return regexp.test(iKey);\n }\n}\n"]}
|
|
@@ -19,7 +19,7 @@ export const TIME_SINCE_ENQUEUED = "timeSinceEnqueued";
|
|
|
19
19
|
* AzureMonitorTraceExporter version.
|
|
20
20
|
* @internal
|
|
21
21
|
*/
|
|
22
|
-
export const packageVersion = "1.0.0-beta.
|
|
22
|
+
export const packageVersion = "1.0.0-beta.20";
|
|
23
23
|
export var DependencyTypes;
|
|
24
24
|
(function (DependencyTypes) {
|
|
25
25
|
DependencyTypes["InProc"] = "InProc";
|
|
@@ -27,6 +27,7 @@ export var DependencyTypes;
|
|
|
27
27
|
DependencyTypes["Sql"] = "SQL";
|
|
28
28
|
DependencyTypes["Http"] = "Http";
|
|
29
29
|
DependencyTypes["Grpc"] = "GRPC";
|
|
30
|
+
DependencyTypes["Wcf"] = "WCF Service";
|
|
30
31
|
})(DependencyTypes || (DependencyTypes = {}));
|
|
31
32
|
export const AzureMonitorSampleRate = "_MS.sampleRate";
|
|
32
33
|
export const ApplicationInsightsBaseType = "_MS.baseType";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applicationinsights.js","sourceRoot":"","sources":["../../../../src/utils/constants/applicationinsights.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,WAAW,CAAC;AACpC;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,cAAc,CAAC;AAC5C;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,mBAAmB,CAAC;AACvD;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,eAAe,CAAC;AAE9C,MAAM,CAAN,IAAY,
|
|
1
|
+
{"version":3,"file":"applicationinsights.js","sourceRoot":"","sources":["../../../../src/utils/constants/applicationinsights.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,WAAW,CAAC;AACpC;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,cAAc,CAAC;AAC5C;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,mBAAmB,CAAC;AACvD;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,eAAe,CAAC;AAE9C,MAAM,CAAN,IAAY,eAOX;AAPD,WAAY,eAAe;IACzB,oCAAiB,CAAA;IACjB,iDAA8B,CAAA;IAC9B,8BAAW,CAAA;IACX,gCAAa,CAAA;IACb,gCAAa,CAAA;IACb,sCAAmB,CAAA;AACrB,CAAC,EAPW,eAAe,KAAf,eAAe,QAO1B;AAED,MAAM,CAAC,MAAM,sBAAsB,GAAG,gBAAgB,CAAC;AACvD,MAAM,CAAC,MAAM,2BAA2B,GAAG,cAAc,CAAC;AAE1D,MAAM,CAAC,MAAM,8BAA8B,GAAG,uCAAuC,CAAC;AACtF,MAAM,CAAC,MAAM,gCAAgC,GAAG,yCAAyC,CAAC;AAC1F,MAAM,CAAC,MAAM,+BAA+B,GAAG,wCAAwC,CAAC;AACxF,MAAM,CAAC,MAAM,mCAAmC,GAAG,4CAA4C,CAAC;AAChG,MAAM,CAAC,MAAM,4BAA4B,GAAG,qCAAqC,CAAC;AAElF,MAAM,CAAC,MAAM,kCAAkC,GAAG,aAAa,CAAC;AAChE,MAAM,CAAC,MAAM,oCAAoC,GAAG,eAAe,CAAC;AACpE,MAAM,CAAC,MAAM,mCAAmC,GAAG,cAAc,CAAC;AAClE,MAAM,CAAC,MAAM,uCAAuC,GAAG,kBAAkB,CAAC;AAC1E,MAAM,CAAC,MAAM,gCAAgC,GAAG,WAAW,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/**\n * AI MS Links.\n * @internal\n */\nexport const MS_LINKS = \"_MS.links\";\n/**\n * AI enqueued time attribute.\n * @internal\n */\nexport const ENQUEUED_TIME = \"enqueuedTime\";\n/**\n * AI time since enqueued attribute.\n * @internal\n */\nexport const TIME_SINCE_ENQUEUED = \"timeSinceEnqueued\";\n/**\n * AzureMonitorTraceExporter version.\n * @internal\n */\nexport const packageVersion = \"1.0.0-beta.20\";\n\nexport enum DependencyTypes {\n InProc = \"InProc\",\n QueueMessage = \"Queue Message\",\n Sql = \"SQL\",\n Http = \"Http\",\n Grpc = \"GRPC\",\n Wcf = \"WCF Service\",\n}\n\nexport const AzureMonitorSampleRate = \"_MS.sampleRate\";\nexport const ApplicationInsightsBaseType = \"_MS.baseType\";\n\nexport const ApplicationInsightsMessageName = \"Microsoft.ApplicationInsights.Message\";\nexport const ApplicationInsightsExceptionName = \"Microsoft.ApplicationInsights.Exception\";\nexport const ApplicationInsightsPageViewName = \"Microsoft.ApplicationInsights.PageView\";\nexport const ApplicationInsightsAvailabilityName = \"Microsoft.ApplicationInsights.Availability\";\nexport const ApplicationInsightsEventName = \"Microsoft.ApplicationInsights.Event\";\n\nexport const ApplicationInsightsMessageBaseType = \"MessageData\";\nexport const ApplicationInsightsExceptionBaseType = \"ExceptionData\";\nexport const ApplicationInsightsPageViewBaseType = \"PageViewData\";\nexport const ApplicationInsightsAvailabilityBaseType = \"AvailabilityData\";\nexport const ApplicationInsightsEventBaseType = \"EventData\";\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eventhub.js","sourceRoot":"","sources":["../../../src/utils/eventhub.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AAGzE,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AACrF,OAAO,EACL,WAAW,EACX,qBAAqB,GAEtB,MAAM,+BAA+B,CAAC;AAEvC;;GAEG;AACH,MAAM,oBAAoB,GAAG,CAAC,IAAkB,EAAE,EAAE;IAClD,IAAI,iBAAiB,GAAG,CAAC,CAAC;IAC1B,IAAI,eAAe,GAAG,CAAC,CAAC;IACxB,MAAM,WAAW,GAAG,oBAAoB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAEzD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE;QACpC,MAAM,YAAY,GAAG,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAG,aAAa,CAAoB,CAAC;QACpE,IAAI,YAAY,EAAE;
|
|
1
|
+
{"version":3,"file":"eventhub.js","sourceRoot":"","sources":["../../../src/utils/eventhub.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AAGzE,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AACrF,OAAO,EACL,WAAW,EACX,qBAAqB,GAEtB,MAAM,+BAA+B,CAAC;AAEvC;;GA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,CAAC,IAAI,GAAG,SAAS,CAAC;YAC1B,QAAQ,CAAC,MAAM,GAAG,GAAG,WAAW,IAAI,qBAAqB,EAAE,CAAC;YAC5D,MAAM;QACR,KAAK,QAAQ,CAAC,QAAQ;YACpB,QAAQ,CAAC,IAAI,GAAG,mBAAmB,SAAS,EAAE,CAAC;YAC/C,QAAQ,CAAC,MAAM,GAAG,GAAG,WAAW,IAAI,qBAAqB,EAAE,CAAC;YAC5D,MAAM;QACR,KAAK,QAAQ,CAAC,QAAQ;YACpB,QAAQ,CAAC,IAAI,GAAG,mBAAmB,SAAS,EAAE,CAAC;YAC9C,QAAgB,CAAC,MAAM,GAAG,GAAG,WAAW,IAAI,qBAAqB,EAAE,CAAC;YACrE,QAAQ,CAAC,YAAY,mCAChB,QAAQ,CAAC,YAAY,KACxB,CAAC,mBAAmB,CAAC,EAAE,oBAAoB,CAAC,IAAI,CAAC,GAClD,CAAC;YACF,MAAM;QACR,QAAQ,CAAC,QAAQ;IACnB,CAAC;AACH,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { SpanKind } from \"@opentelemetry/api\";\nimport { hrTimeToMilliseconds } from \"@opentelemetry/core\";\nimport { SemanticAttributes } from \"@opentelemetry/semantic-conventions\";\nimport { ReadableSpan } from \"@opentelemetry/sdk-trace-base\";\nimport { RemoteDependencyData, RequestData } from \"../generated\";\nimport { TIME_SINCE_ENQUEUED, ENQUEUED_TIME } from \"./constants/applicationinsights\";\nimport {\n AzNamespace,\n MessageBusDestination,\n MicrosoftEventHub,\n} from \"./constants/span/azAttributes\";\n\n/**\n * Average span.links[].attributes.enqueuedTime\n */\nconst getTimeSinceEnqueued = (span: ReadableSpan) => {\n let countEnqueueDiffs = 0;\n let sumEnqueueDiffs = 0;\n const startTimeMs = hrTimeToMilliseconds(span.startTime);\n\n span.links.forEach(({ attributes }) => {\n const enqueuedTime = attributes?.[ENQUEUED_TIME] as string | number;\n if (enqueuedTime) {\n countEnqueueDiffs += 1;\n sumEnqueueDiffs += startTimeMs - (parseFloat(enqueuedTime.toString()) || 0);\n }\n });\n\n return Math.max(sumEnqueueDiffs / (countEnqueueDiffs || 1), 0);\n};\n\n/**\n * Implementation of Mapping to Azure Monitor\n *\n * https://gist.github.com/lmolkova/e4215c0f44a49ef824983382762e6b92#mapping-to-azure-monitor-application-insights-telemetry\n * @internal\n */\nexport const parseEventHubSpan = (\n span: ReadableSpan,\n baseData: RequestData | RemoteDependencyData,\n): void => {\n const namespace = span.attributes[AzNamespace] as typeof MicrosoftEventHub;\n const peerAddress = (\n (span.attributes[SemanticAttributes.NET_PEER_NAME] ||\n span.attributes[\"peer.address\"] ||\n \"unknown\") as string\n ).replace(/\\/$/g, \"\"); // remove trailing \"/\"\n const messageBusDestination = (span.attributes[MessageBusDestination] || \"unknown\") as string;\n\n switch (span.kind) {\n case SpanKind.CLIENT:\n baseData.type = namespace;\n baseData.target = `${peerAddress}/${messageBusDestination}`;\n break;\n case SpanKind.PRODUCER:\n baseData.type = `Queue Message | ${namespace}`;\n baseData.target = `${peerAddress}/${messageBusDestination}`;\n break;\n case SpanKind.CONSUMER:\n baseData.type = `Queue Message | ${namespace}`;\n (baseData as any).source = `${peerAddress}/${messageBusDestination}`;\n baseData.measurements = {\n ...baseData.measurements,\n [TIME_SINCE_ENQUEUED]: getTimeSinceEnqueued(span),\n };\n break;\n default: // no op\n }\n};\n"]}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT license.
|
|
3
3
|
import { KnownContextTagKeys, KnownSeverityLevel, } from "../generated";
|
|
4
|
-
import { createTagsFromResource } from "./common";
|
|
4
|
+
import { createTagsFromResource, hrTimeToDate } from "./common";
|
|
5
5
|
import { SemanticAttributes } from "@opentelemetry/semantic-conventions";
|
|
6
|
-
import { hrTimeToMilliseconds } from "@opentelemetry/core";
|
|
7
6
|
import { diag } from "@opentelemetry/api";
|
|
8
7
|
import { ApplicationInsightsAvailabilityBaseType, ApplicationInsightsAvailabilityName, ApplicationInsightsBaseType, ApplicationInsightsEventBaseType, ApplicationInsightsEventName, ApplicationInsightsExceptionBaseType, ApplicationInsightsExceptionName, ApplicationInsightsMessageBaseType, ApplicationInsightsMessageName, ApplicationInsightsPageViewBaseType, ApplicationInsightsPageViewName, } from "./constants/applicationinsights";
|
|
9
8
|
/**
|
|
@@ -11,7 +10,7 @@ import { ApplicationInsightsAvailabilityBaseType, ApplicationInsightsAvailabilit
|
|
|
11
10
|
* @internal
|
|
12
11
|
*/
|
|
13
12
|
export function logToEnvelope(log, ikey) {
|
|
14
|
-
const time =
|
|
13
|
+
const time = hrTimeToDate(log.hrTime);
|
|
15
14
|
const sampleRate = 100;
|
|
16
15
|
const instrumentationKey = ikey;
|
|
17
16
|
const tags = createTagsFromLog(log);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logUtils.js","sourceRoot":"","sources":["../../../src/utils/logUtils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAGL,mBAAmB,EACnB,kBAAkB,GAOnB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAElD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AAEzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EACL,uCAAuC,EACvC,mCAAmC,EACnC,2BAA2B,EAC3B,gCAAgC,EAChC,4BAA4B,EAC5B,oCAAoC,EACpC,gCAAgC,EAChC,kCAAkC,EAClC,8BAA8B,EAC9B,mCAAmC,EACnC,+BAA+B,GAChC,MAAM,iCAAiC,CAAC;AAEzC;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,GAAsB,EAAE,IAAY;IAChE,MAAM,IAAI,GAAG,GAA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,CAAC,GAAG,CAAC,IAAI,CAAuB,CAAC;oBACtD,MAAM;aACT;YACD,IAAI,OAAO,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,OAAO,CAAA,KAAK,QAAQ,EAAE;gBACzC,QAAQ,CAAC,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;aACrD;SACF;QAAC,OAAO,GAAG,EAAE;YACZ,IAAI,CAAC,KAAK,CAAC,wEAAwE,CAAC,CAAC;SACtF;KACF;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n AvailabilityData,\n TelemetryItem as Envelope,\n KnownContextTagKeys,\n KnownSeverityLevel,\n MessageData,\n MonitorDomain,\n PageViewData,\n TelemetryEventData,\n TelemetryExceptionData,\n TelemetryExceptionDetails,\n} from \"../generated\";\nimport { createTagsFromResource } from \"./common\";\nimport { ReadableLogRecord } from \"@opentelemetry/sdk-logs\";\nimport { SemanticAttributes } from \"@opentelemetry/semantic-conventions\";\nimport { Measurements, Properties, Tags } from \"../types\";\nimport { hrTimeToMilliseconds } from \"@opentelemetry/core\";\nimport { diag } from \"@opentelemetry/api\";\nimport {\n ApplicationInsightsAvailabilityBaseType,\n ApplicationInsightsAvailabilityName,\n ApplicationInsightsBaseType,\n ApplicationInsightsEventBaseType,\n ApplicationInsightsEventName,\n ApplicationInsightsExceptionBaseType,\n ApplicationInsightsExceptionName,\n ApplicationInsightsMessageBaseType,\n ApplicationInsightsMessageName,\n ApplicationInsightsPageViewBaseType,\n ApplicationInsightsPageViewName,\n} from \"./constants/applicationinsights\";\n\n/**\n * Log to Azure envelope parsing.\n * @internal\n */\nexport function logToEnvelope(log: ReadableLogRecord, ikey: string): Envelope | undefined {\n const time = log.hrTime ? new Date(hrTimeToMilliseconds(log.hrTime)) : new Date();\n const sampleRate = 100;\n const instrumentationKey = ikey;\n const tags = createTagsFromLog(log);\n const [properties, measurements] = createPropertiesFromLog(log);\n let name: string;\n let baseType: string;\n let baseData: MonitorDomain;\n\n if (!log.attributes[ApplicationInsightsBaseType]) {\n // Get Exception attributes if available\n const exceptionType = log.attributes[SemanticAttributes.EXCEPTION_TYPE];\n if (exceptionType) {\n const exceptionMessage = log.attributes[SemanticAttributes.EXCEPTION_MESSAGE];\n const exceptionStacktrace = log.attributes[SemanticAttributes.EXCEPTION_STACKTRACE];\n name = ApplicationInsightsExceptionName;\n baseType = ApplicationInsightsExceptionBaseType;\n const exceptionDetails: TelemetryExceptionDetails = {\n typeName: String(exceptionType),\n message: String(exceptionMessage),\n hasFullStack: exceptionStacktrace ? true : false,\n stack: String(exceptionStacktrace),\n };\n const exceptionData: TelemetryExceptionData = {\n exceptions: [exceptionDetails],\n severityLevel: String(getSeverity(log.severityNumber)),\n version: 2,\n };\n baseData = exceptionData;\n } else {\n name = ApplicationInsightsMessageName;\n baseType = ApplicationInsightsMessageBaseType;\n const messageData: MessageData = {\n message: String(log.body),\n severityLevel: String(getSeverity(log.severityNumber)),\n version: 2,\n };\n baseData = messageData;\n }\n } else {\n // If Legacy Application Insights Log\n baseType = String(log.attributes[ApplicationInsightsBaseType]);\n name = getLegacyApplicationInsightsName(log);\n baseData = getLegacyApplicationInsightsBaseData(log);\n if (!baseData) {\n // Failed to parse log\n return;\n }\n }\n return {\n name,\n sampleRate,\n time,\n instrumentationKey,\n tags,\n version: 1,\n data: {\n baseType,\n baseData: {\n ...baseData,\n properties,\n measurements,\n },\n },\n };\n}\n\nfunction createTagsFromLog(log: ReadableLogRecord): Tags {\n const tags: Tags = createTagsFromResource(log.resource);\n if (log.spanContext?.traceId) {\n tags[KnownContextTagKeys.AiOperationId] = log.spanContext.traceId;\n }\n if (log.spanContext?.spanId) {\n tags[KnownContextTagKeys.AiOperationParentId] = log.spanContext.spanId;\n }\n return tags;\n}\n\nfunction createPropertiesFromLog(log: ReadableLogRecord): [Properties, Measurements] {\n const measurements: Measurements = {};\n const properties: { [propertyName: string]: string } = {};\n if (log.attributes) {\n for (const key of Object.keys(log.attributes)) {\n // Avoid duplication ignoring fields already mapped.\n if (\n !(\n key.startsWith(\"_MS.\") ||\n key === SemanticAttributes.EXCEPTION_TYPE ||\n key === SemanticAttributes.EXCEPTION_MESSAGE ||\n key === SemanticAttributes.EXCEPTION_STACKTRACE\n )\n ) {\n properties[key] = log.attributes[key] as string;\n }\n }\n }\n return [properties, measurements];\n}\n\n// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/data-model.md#field-severitynumber\nfunction getSeverity(severityNumber: number | undefined): KnownSeverityLevel | undefined {\n if (severityNumber) {\n if (severityNumber > 0 && severityNumber < 9) {\n return KnownSeverityLevel.Verbose;\n } else if (severityNumber >= 9 && severityNumber < 13) {\n return KnownSeverityLevel.Information;\n } else if (severityNumber >= 13 && severityNumber < 17) {\n return KnownSeverityLevel.Warning;\n } else if (severityNumber >= 17 && severityNumber < 21) {\n return KnownSeverityLevel.Error;\n } else if (severityNumber >= 21 && severityNumber < 25) {\n return KnownSeverityLevel.Critical;\n }\n }\n return;\n}\n\nfunction getLegacyApplicationInsightsName(log: ReadableLogRecord): string {\n let name = \"\";\n switch (log.attributes[ApplicationInsightsBaseType]) {\n case ApplicationInsightsAvailabilityBaseType:\n name = ApplicationInsightsAvailabilityName;\n break;\n case ApplicationInsightsExceptionBaseType:\n name = ApplicationInsightsExceptionName;\n break;\n case ApplicationInsightsMessageBaseType:\n name = ApplicationInsightsMessageName;\n break;\n case ApplicationInsightsPageViewBaseType:\n name = ApplicationInsightsPageViewName;\n break;\n case ApplicationInsightsEventBaseType:\n name = ApplicationInsightsEventName;\n break;\n }\n return name;\n}\n\nfunction getLegacyApplicationInsightsBaseData(log: ReadableLogRecord): MonitorDomain {\n let baseData: MonitorDomain = {\n version: 2,\n };\n if (log.body) {\n try {\n switch (log.attributes[ApplicationInsightsBaseType]) {\n case ApplicationInsightsAvailabilityBaseType:\n baseData = JSON.parse(log.body) as AvailabilityData;\n break;\n case ApplicationInsightsExceptionBaseType:\n baseData = JSON.parse(log.body) as TelemetryExceptionData;\n break;\n case ApplicationInsightsMessageBaseType:\n baseData = JSON.parse(log.body) as MessageData;\n break;\n case ApplicationInsightsPageViewBaseType:\n baseData = JSON.parse(log.body) as PageViewData;\n break;\n case ApplicationInsightsEventBaseType:\n baseData = JSON.parse(log.body) as TelemetryEventData;\n break;\n }\n if (typeof baseData?.message === \"object\") {\n baseData.message = JSON.stringify(baseData.message);\n }\n } catch (err) {\n diag.error(\"AzureMonitorLogExporter failed to parse Application Insights Telemetry\");\n }\n }\n return baseData;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"logUtils.js","sourceRoot":"","sources":["../../../src/utils/logUtils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAGL,mBAAmB,EACnB,kBAAkB,GAOnB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAEhE,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AAEzE,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EACL,uCAAuC,EACvC,mCAAmC,EACnC,2BAA2B,EAC3B,gCAAgC,EAChC,4BAA4B,EAC5B,oCAAoC,EACpC,gCAAgC,EAChC,kCAAkC,EAClC,8BAA8B,EAC9B,mCAAmC,EACnC,+BAA+B,GAChC,MAAM,iCAAiC,CAAC;AAEzC;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,GAAsB,EAAE,IAAY;IAChE,MAAM,IAAI,GAAG,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACtC,MAAM,UAAU,GAAG,GAAG,CAAC;IACvB,MAAM,kBAAkB,GAAG,IAAI,CAAC;IAChC,MAAM,IAAI,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC;IACpC,MAAM,CAAC,UAAU,EA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OAAO,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,OAAO,CAAA,KAAK,QAAQ,EAAE,CAAC;gBAC1C,QAAQ,CAAC,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YACtD,CAAC;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,CAAC,KAAK,CAAC,wEAAwE,CAAC,CAAC;QACvF,CAAC;IACH,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n AvailabilityData,\n TelemetryItem as Envelope,\n KnownContextTagKeys,\n KnownSeverityLevel,\n MessageData,\n MonitorDomain,\n PageViewData,\n TelemetryEventData,\n TelemetryExceptionData,\n TelemetryExceptionDetails,\n} from \"../generated\";\nimport { createTagsFromResource, hrTimeToDate } from \"./common\";\nimport { ReadableLogRecord } from \"@opentelemetry/sdk-logs\";\nimport { SemanticAttributes } from \"@opentelemetry/semantic-conventions\";\nimport { Measurements, Properties, Tags } from \"../types\";\nimport { diag } from \"@opentelemetry/api\";\nimport {\n ApplicationInsightsAvailabilityBaseType,\n ApplicationInsightsAvailabilityName,\n ApplicationInsightsBaseType,\n ApplicationInsightsEventBaseType,\n ApplicationInsightsEventName,\n ApplicationInsightsExceptionBaseType,\n ApplicationInsightsExceptionName,\n ApplicationInsightsMessageBaseType,\n ApplicationInsightsMessageName,\n ApplicationInsightsPageViewBaseType,\n ApplicationInsightsPageViewName,\n} from \"./constants/applicationinsights\";\n\n/**\n * Log to Azure envelope parsing.\n * @internal\n */\nexport function logToEnvelope(log: ReadableLogRecord, ikey: string): Envelope | undefined {\n const time = hrTimeToDate(log.hrTime);\n const sampleRate = 100;\n const instrumentationKey = ikey;\n const tags = createTagsFromLog(log);\n const [properties, measurements] = createPropertiesFromLog(log);\n let name: string;\n let baseType: string;\n let baseData: MonitorDomain;\n\n if (!log.attributes[ApplicationInsightsBaseType]) {\n // Get Exception attributes if available\n const exceptionType = log.attributes[SemanticAttributes.EXCEPTION_TYPE];\n if (exceptionType) {\n const exceptionMessage = log.attributes[SemanticAttributes.EXCEPTION_MESSAGE];\n const exceptionStacktrace = log.attributes[SemanticAttributes.EXCEPTION_STACKTRACE];\n name = ApplicationInsightsExceptionName;\n baseType = ApplicationInsightsExceptionBaseType;\n const exceptionDetails: TelemetryExceptionDetails = {\n typeName: String(exceptionType),\n message: String(exceptionMessage),\n hasFullStack: exceptionStacktrace ? true : false,\n stack: String(exceptionStacktrace),\n };\n const exceptionData: TelemetryExceptionData = {\n exceptions: [exceptionDetails],\n severityLevel: String(getSeverity(log.severityNumber)),\n version: 2,\n };\n baseData = exceptionData;\n } else {\n name = ApplicationInsightsMessageName;\n baseType = ApplicationInsightsMessageBaseType;\n const messageData: MessageData = {\n message: String(log.body),\n severityLevel: String(getSeverity(log.severityNumber)),\n version: 2,\n };\n baseData = messageData;\n }\n } else {\n // If Legacy Application Insights Log\n baseType = String(log.attributes[ApplicationInsightsBaseType]);\n name = getLegacyApplicationInsightsName(log);\n baseData = getLegacyApplicationInsightsBaseData(log);\n if (!baseData) {\n // Failed to parse log\n return;\n }\n }\n return {\n name,\n sampleRate,\n time,\n instrumentationKey,\n tags,\n version: 1,\n data: {\n baseType,\n baseData: {\n ...baseData,\n properties,\n measurements,\n },\n },\n };\n}\n\nfunction createTagsFromLog(log: ReadableLogRecord): Tags {\n const tags: Tags = createTagsFromResource(log.resource);\n if (log.spanContext?.traceId) {\n tags[KnownContextTagKeys.AiOperationId] = log.spanContext.traceId;\n }\n if (log.spanContext?.spanId) {\n tags[KnownContextTagKeys.AiOperationParentId] = log.spanContext.spanId;\n }\n return tags;\n}\n\nfunction createPropertiesFromLog(log: ReadableLogRecord): [Properties, Measurements] {\n const measurements: Measurements = {};\n const properties: { [propertyName: string]: string } = {};\n if (log.attributes) {\n for (const key of Object.keys(log.attributes)) {\n // Avoid duplication ignoring fields already mapped.\n if (\n !(\n key.startsWith(\"_MS.\") ||\n key === SemanticAttributes.EXCEPTION_TYPE ||\n key === SemanticAttributes.EXCEPTION_MESSAGE ||\n key === SemanticAttributes.EXCEPTION_STACKTRACE\n )\n ) {\n properties[key] = log.attributes[key] as string;\n }\n }\n }\n return [properties, measurements];\n}\n\n// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/data-model.md#field-severitynumber\nfunction getSeverity(severityNumber: number | undefined): KnownSeverityLevel | undefined {\n if (severityNumber) {\n if (severityNumber > 0 && severityNumber < 9) {\n return KnownSeverityLevel.Verbose;\n } else if (severityNumber >= 9 && severityNumber < 13) {\n return KnownSeverityLevel.Information;\n } else if (severityNumber >= 13 && severityNumber < 17) {\n return KnownSeverityLevel.Warning;\n } else if (severityNumber >= 17 && severityNumber < 21) {\n return KnownSeverityLevel.Error;\n } else if (severityNumber >= 21 && severityNumber < 25) {\n return KnownSeverityLevel.Critical;\n }\n }\n return;\n}\n\nfunction getLegacyApplicationInsightsName(log: ReadableLogRecord): string {\n let name = \"\";\n switch (log.attributes[ApplicationInsightsBaseType]) {\n case ApplicationInsightsAvailabilityBaseType:\n name = ApplicationInsightsAvailabilityName;\n break;\n case ApplicationInsightsExceptionBaseType:\n name = ApplicationInsightsExceptionName;\n break;\n case ApplicationInsightsMessageBaseType:\n name = ApplicationInsightsMessageName;\n break;\n case ApplicationInsightsPageViewBaseType:\n name = ApplicationInsightsPageViewName;\n break;\n case ApplicationInsightsEventBaseType:\n name = ApplicationInsightsEventName;\n break;\n }\n return name;\n}\n\nfunction getLegacyApplicationInsightsBaseData(log: ReadableLogRecord): MonitorDomain {\n let baseData: MonitorDomain = {\n version: 2,\n };\n if (log.body) {\n try {\n switch (log.attributes[ApplicationInsightsBaseType]) {\n case ApplicationInsightsAvailabilityBaseType:\n baseData = JSON.parse(log.body) as AvailabilityData;\n break;\n case ApplicationInsightsExceptionBaseType:\n baseData = JSON.parse(log.body) as TelemetryExceptionData;\n break;\n case ApplicationInsightsMessageBaseType:\n baseData = JSON.parse(log.body) as MessageData;\n break;\n case ApplicationInsightsPageViewBaseType:\n baseData = JSON.parse(log.body) as PageViewData;\n break;\n case ApplicationInsightsEventBaseType:\n baseData = JSON.parse(log.body) as TelemetryEventData;\n break;\n }\n if (typeof baseData?.message === \"object\") {\n baseData.message = JSON.stringify(baseData.message);\n }\n } catch (err) {\n diag.error(\"AzureMonitorLogExporter failed to parse Application Insights Telemetry\");\n }\n }\n return baseData;\n}\n"]}
|
|
@@ -56,7 +56,7 @@ export function resourceMetricsToEnvelope(metrics, ikey, isStatsbeat) {
|
|
|
56
56
|
const envelope = {
|
|
57
57
|
name: envelopeName,
|
|
58
58
|
time: time,
|
|
59
|
-
sampleRate: 100,
|
|
59
|
+
sampleRate: 100, // Metrics are never sampled
|
|
60
60
|
instrumentationKey: instrumentationKey,
|
|
61
61
|
tags: tags,
|
|
62
62
|
version: 1,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metricUtils.js","sourceRoot":"","sources":["../../../src/utils/metricUtils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,aAAa,EAA8B,MAAM,4BAA4B,CAAC;AAEvF,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAElD,SAAS,oCAAoC,CAAC,UAAuB;IAGnE,MAAM,UAAU,GAAuC,EAAE,CAAC;IAC1D,IAAI,UAAU,EAAE;
|
|
1
|
+
{"version":3,"file":"metricUtils.js","sourceRoot":"","sources":["../../../src/utils/metricUtils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,aAAa,EAA8B,MAAM,4BAA4B,CAAC;AAEvF,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAElD,SAAS,oCAAoC,CAAC,UAAuB;IAGnE,MAAM,UAAU,GAAuC,EAAE,CAAC;IAC1D,IAAI,UAAU,EAAE,CAAC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C,aAAa,KAAK,aAAa,CAAC,KAAK,EAC5C,CAAC;oBACD,eAAe,CAAC,KAAK,GAAG,SAAS,CAAC,KAAe,CAAC;oBAClD,eAAe,CAAC,KAAK,GAAG,CAAC,CAAC;gBAC5B,CAAC;qBAAM,CAAC;oBACN,eAAe,CAAC,KAAK,GAAI,SAAS,CAAC,KAAmB,CAAC,GAAG,IAAI,CAAC,CAAC;oBAChE,eAAe,CAAC,KAAK,GAAI,SAAS,CAAC,KAAmB,CAAC,KAAK,CAAC;oBAC7D,eAAe,CAAC,GAAG,GAAI,SAAS,CAAC,KAAmB,CAAC,GAAG,CAAC;oBACzD,eAAe,CAAC,GAAG,GAAI,SAAS,CAAC,KAAmB,CAAC,GAAG,CAAC;gBAC3D,CAAC;gBACD,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;gBACvC,MAAM,QAAQ,GAAa;oBACzB,IAAI,EAAE,YAAY;oBAClB,IAAI,EAAE,IAAI;oBACV,UAAU,EAAE,GAAG,EAAE,4BAA4B;oBAC7C,kBAAkB,EAAE,kBAAkB;oBACtC,IAAI,EAAE,IAAI;oBACV,OAAO,EAAE,CAAC;oBACV,IAAI,EAAE;wBACJ,QAAQ,EAAE,YAAY;wBACtB,QAAQ,oBACH,QAAQ,CACZ;qBACF;iBACF,CAAC;gBACF,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC3B,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { Attributes } from \"@opentelemetry/api\";\nimport { DataPointType, Histogram, ResourceMetrics } from \"@opentelemetry/sdk-metrics\";\nimport { TelemetryItem as Envelope, MetricsData, MetricDataPoint } from \"../generated\";\nimport { createTagsFromResource } from \"./common\";\n\nfunction createPropertiesFromMetricAttributes(attributes?: Attributes): {\n [propertyName: string]: string;\n} {\n const properties: { [propertyName: string]: string } = {};\n if (attributes) {\n for (const key of Object.keys(attributes)) {\n properties[key] = attributes[key] as string;\n }\n }\n return properties;\n}\n\n/**\n * Metric to Azure envelope parsing.\n * @internal\n */\nexport function resourceMetricsToEnvelope(\n metrics: ResourceMetrics,\n ikey: string,\n isStatsbeat?: boolean,\n): Envelope[] {\n const envelopes: Envelope[] = [];\n const time = new Date();\n const instrumentationKey = ikey;\n const tags = createTagsFromResource(metrics.resource);\n let envelopeName: string;\n\n if (isStatsbeat) {\n envelopeName = \"Microsoft.ApplicationInsights.Statsbeat\";\n } else {\n envelopeName = \"Microsoft.ApplicationInsights.Metric\";\n }\n\n metrics.scopeMetrics.forEach((scopeMetric) => {\n scopeMetric.metrics.forEach((metric) => {\n metric.dataPoints.forEach((dataPoint) => {\n const baseData: MetricsData = {\n metrics: [],\n version: 2,\n properties: {},\n };\n baseData.properties = createPropertiesFromMetricAttributes(dataPoint.attributes);\n const metricDataPoint: MetricDataPoint = {\n name: metric.descriptor.name,\n value: 0,\n dataPointType: \"Aggregation\",\n };\n if (\n metric.dataPointType === DataPointType.SUM ||\n metric.dataPointType === DataPointType.GAUGE\n ) {\n metricDataPoint.value = dataPoint.value as number;\n metricDataPoint.count = 1;\n } else {\n metricDataPoint.value = (dataPoint.value as Histogram).sum || 0;\n metricDataPoint.count = (dataPoint.value as Histogram).count;\n metricDataPoint.max = (dataPoint.value as Histogram).max;\n metricDataPoint.min = (dataPoint.value as Histogram).min;\n }\n baseData.metrics.push(metricDataPoint);\n const envelope: Envelope = {\n name: envelopeName,\n time: time,\n sampleRate: 100, // Metrics are never sampled\n instrumentationKey: instrumentationKey,\n tags: tags,\n version: 1,\n data: {\n baseType: \"MetricData\",\n baseData: {\n ...baseData,\n },\n },\n };\n envelopes.push(envelope);\n });\n });\n });\n\n return envelopes;\n}\n"]}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT license.
|
|
3
3
|
import { URL } from "url";
|
|
4
|
-
import { hrTimeToMilliseconds } from "@opentelemetry/core";
|
|
4
|
+
import { addHrTimes, hrTime, hrTimeToMilliseconds } from "@opentelemetry/core";
|
|
5
5
|
import { diag, SpanKind, SpanStatusCode } from "@opentelemetry/api";
|
|
6
6
|
import { SemanticAttributes, DbSystemValues } from "@opentelemetry/semantic-conventions";
|
|
7
|
-
import { createTagsFromResource, getDependencyTarget, getUrl, isSqlDB } from "./common";
|
|
8
|
-
import { msToTimeSpan } from "./breezeUtils";
|
|
7
|
+
import { createTagsFromResource, getDependencyTarget, getUrl, hrTimeToDate, isSqlDB, } from "./common";
|
|
9
8
|
import { parseEventHubSpan } from "./eventhub";
|
|
10
9
|
import { AzureMonitorSampleRate, DependencyTypes, MS_LINKS } from "./constants/applicationinsights";
|
|
11
10
|
import { AzNamespace, MicrosoftEventHub } from "./constants/span/azAttributes";
|
|
12
11
|
import { KnownContextTagKeys, } from "../generated";
|
|
12
|
+
import { msToTimeSpan } from "./breezeUtils";
|
|
13
13
|
function createTagsFromSpan(span) {
|
|
14
14
|
const tags = createTagsFromResource(span.resource);
|
|
15
15
|
tags[KnownContextTagKeys.AiOperationId] = span.spanContext().traceId;
|
|
@@ -97,12 +97,12 @@ function createPropertiesFromSpan(span) {
|
|
|
97
97
|
}
|
|
98
98
|
function createDependencyData(span) {
|
|
99
99
|
const remoteDependencyData = {
|
|
100
|
-
name: span.name,
|
|
100
|
+
name: span.name, // Default
|
|
101
101
|
id: `${span.spanContext().spanId}`,
|
|
102
102
|
success: span.status.code !== SpanStatusCode.ERROR,
|
|
103
103
|
resultCode: "0",
|
|
104
104
|
type: "Dependency",
|
|
105
|
-
duration: msToTimeSpan(hrTimeToMilliseconds(span.duration)),
|
|
105
|
+
duration: msToTimeSpan(hrTimeToMilliseconds(addHrTimes(span.duration, hrTime()))),
|
|
106
106
|
version: 2,
|
|
107
107
|
};
|
|
108
108
|
if (span.kind === SpanKind.PRODUCER) {
|
|
@@ -190,7 +190,12 @@ function createDependencyData(span) {
|
|
|
190
190
|
}
|
|
191
191
|
// grpc Dependency
|
|
192
192
|
else if (rpcSystem) {
|
|
193
|
-
|
|
193
|
+
if (rpcSystem == DependencyTypes.Wcf) {
|
|
194
|
+
remoteDependencyData.type = DependencyTypes.Wcf;
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
remoteDependencyData.type = DependencyTypes.Grpc;
|
|
198
|
+
}
|
|
194
199
|
const grpcStatusCode = span.attributes[SemanticAttributes.RPC_GRPC_STATUS_CODE];
|
|
195
200
|
if (grpcStatusCode) {
|
|
196
201
|
remoteDependencyData.resultCode = String(grpcStatusCode);
|
|
@@ -210,7 +215,7 @@ function createRequestData(span) {
|
|
|
210
215
|
id: `${span.spanContext().spanId}`,
|
|
211
216
|
success: span.status.code !== SpanStatusCode.ERROR,
|
|
212
217
|
responseCode: "0",
|
|
213
|
-
duration: msToTimeSpan(hrTimeToMilliseconds(span.duration)),
|
|
218
|
+
duration: msToTimeSpan(hrTimeToMilliseconds(addHrTimes(span.duration, hrTime()))),
|
|
214
219
|
version: 2,
|
|
215
220
|
source: undefined,
|
|
216
221
|
};
|
|
@@ -236,7 +241,7 @@ export function readableSpanToEnvelope(span, ikey) {
|
|
|
236
241
|
let name;
|
|
237
242
|
let baseType;
|
|
238
243
|
let baseData;
|
|
239
|
-
const time =
|
|
244
|
+
const time = hrTimeToDate(span.startTime);
|
|
240
245
|
const instrumentationKey = ikey;
|
|
241
246
|
const tags = createTagsFromSpan(span);
|
|
242
247
|
const [properties, measurements] = createPropertiesFromSpan(span);
|
|
@@ -297,7 +302,7 @@ export function spanEventsToEnvelopes(span, ikey) {
|
|
|
297
302
|
span.events.forEach((event) => {
|
|
298
303
|
var _a;
|
|
299
304
|
let baseType;
|
|
300
|
-
const time =
|
|
305
|
+
const time = hrTimeToDate(event.time);
|
|
301
306
|
let name = "";
|
|
302
307
|
let baseData;
|
|
303
308
|
const properties = createPropertiesFromSpanAttributes(event.attributes);
|