@azure/monitor-opentelemetry-exporter 1.0.0-beta.7 → 1.0.0-beta.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +416 -181
- package/dist-esm/src/config.js.map +1 -1
- package/dist-esm/src/export/base.js +172 -0
- package/dist-esm/src/export/base.js.map +1 -0
- package/dist-esm/src/export/metric.js +50 -0
- package/dist-esm/src/export/metric.js.map +1 -0
- package/dist-esm/src/export/trace.js +14 -146
- package/dist-esm/src/export/trace.js.map +1 -1
- package/dist-esm/src/index.js +2 -0
- package/dist-esm/src/index.js.map +1 -1
- package/dist-esm/src/platform/nodejs/httpSender.js.map +1 -1
- package/dist-esm/src/platform/nodejs/persist/fileAccessControl.js.map +1 -1
- 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/utils/constants/applicationinsights.js +1 -1
- package/dist-esm/src/utils/constants/applicationinsights.js.map +1 -1
- package/dist-esm/src/utils/metricUtils.js +53 -0
- package/dist-esm/src/utils/metricUtils.js.map +1 -0
- package/dist-esm/src/utils/resourceUtils.js +35 -0
- package/dist-esm/src/utils/resourceUtils.js.map +1 -0
- package/dist-esm/src/utils/spanUtils.js +112 -43
- package/dist-esm/src/utils/spanUtils.js.map +1 -1
- package/package.json +18 -17
- package/types/monitor-opentelemetry-exporter.d.ts +104 -6
- package/CHANGELOG.md +0 -51
|
@@ -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,EA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KM,gCAAc,GAAG,oBAAoB,CAAC;AAEtC,iCAAe,GAAG,UAAU,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 { DEFAULT_EXPORTER_CONFIG, AzureExporterInternalConfig } from \"../../../config\";\nimport { FileAccessControl } from \"./fileAccessControl\";\nimport { confirmDirExists, getShallowDirectorySize } from \"./fileSystemHelpers\";\nimport { promisify } from \"util\";\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\n static FILENAME_SUFFIX = \".ai.json\";\n\n fileRetemptionPeriod = 7 * 24 * 60 * 60 * 1000; // 7 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.Timer | null = null;\n\n private readonly _options: AzureExporterInternalConfig;\n\n constructor(options: Partial<AzureExporterInternalConfig> = {}) {\n this._options = { ...DEFAULT_EXPORTER_CONFIG, ...options };\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._options.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 os.tmpdir(),\n FileSystemPersist.TEMPDIR_PREFIX + this._options.instrumentationKey\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) {\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) {\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) {\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) {\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) {\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) {\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,uBAAuB,EAA+B,MAAM,iBAAiB,CAAC;AACvF,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,gB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E;gBACvB,MAAM,SAAS,GAAG,MAAM,YAAY,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;gBAC1D,MAAM,KAAK,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CACnC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,iBAAiB,CAAC,eAAe,CAAC,CAC7D,CAAC;gBACF,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;oBACtB,OAAO,KAAK,CAAC;iBACd;qBAAM;oBACL,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;wBAC3B,mBAAmB;wBACnB,MAAM,gBAAgB,GAAS,IAAI,IAAI,CACrC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAC3D,CAAC;wBACF,MAAM,OAAO,GAAG,IAAI,IAAI,CAAC,CAAC,IAAI,IAAI,EAAE,GAAG,IAAI,CAAC,oBAAoB,CAAC,GAAG,gBAAgB,CAAC;wBACrF,IAAI,OAAO,EAAE;4BACX,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;4BACtD,MAAM,WAAW,CAAC,QAAQ,CAAC,CAAC;yBAC7B;oBACH,CAAC,CAAC,CAAC;oBACH,OAAO,IAAI,CAAC;iBACb;aACF;YACD,OAAO,KAAK,CAAC;SACd;QAAC,OAAO,KAAU,EAAE;YACnB,IAAI,CAAC,IAAI,CAAC,yDAAyD,EAAE,KAAK,CAAC,CAAC;YAC5E,OAAO,KAAK,CAAC;SACd;IACH,CAAC;;AA9KM,gCAAc,GAAG,oBAAoB,CAAC;AAEtC,iCAAe,GAAG,UAAU,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 { DEFAULT_EXPORTER_CONFIG, AzureExporterInternalConfig } from \"../../../config\";\nimport { FileAccessControl } from \"./fileAccessControl\";\nimport { confirmDirExists, getShallowDirectorySize } from \"./fileSystemHelpers\";\nimport { promisify } from \"util\";\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\n static FILENAME_SUFFIX = \".ai.json\";\n\n fileRetemptionPeriod = 7 * 24 * 60 * 60 * 1000; // 7 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.Timer | null = null;\n\n private readonly _options: AzureExporterInternalConfig;\n\n constructor(options: Partial<AzureExporterInternalConfig> = {}) {\n this._options = { ...DEFAULT_EXPORTER_CONFIG, ...options };\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._options.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 os.tmpdir(),\n FileSystemPersist.TEMPDIR_PREFIX + this._options.instrumentationKey\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"]}
|
|
@@ -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.8";
|
|
23
23
|
export var DependencyTypes;
|
|
24
24
|
(function (DependencyTypes) {
|
|
25
25
|
DependencyTypes["InProc"] = "InProc";
|
|
@@ -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,cAAc,CAAC;AAE7C,MAAM,CAAN,IAAY,eAMX;AAND,WAAY,eAAe;IACzB,oCAAiB,CAAA;IACjB,iDAA8B,CAAA;IAC9B,8BAAW,CAAA;IACX,gCAAa,CAAA;IACb,gCAAa,CAAA;AACf,CAAC,EANW,eAAe,KAAf,eAAe,QAM1B","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.
|
|
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,cAAc,CAAC;AAE7C,MAAM,CAAN,IAAY,eAMX;AAND,WAAY,eAAe;IACzB,oCAAiB,CAAA;IACjB,iDAA8B,CAAA;IAC9B,8BAAW,CAAA;IACX,gCAAa,CAAA;IACb,gCAAa,CAAA;AACf,CAAC,EANW,eAAe,KAAf,eAAe,QAM1B","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.8\";\n\nexport enum DependencyTypes {\n InProc = \"InProc\",\n QueueMessage = \"Queue Message\",\n Sql = \"SQL\",\n Http = \"Http\",\n Grpc = \"GRPC\",\n}\n"]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT license.
|
|
3
|
+
import { DataPointType } from "@opentelemetry/sdk-metrics-base";
|
|
4
|
+
import { createTagsFromResource } from "./resourceUtils";
|
|
5
|
+
/**
|
|
6
|
+
* Metric to Azure envelope parsing.
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export function resourceMetricsToEnvelope(metrics, ikey) {
|
|
10
|
+
let envelopes = [];
|
|
11
|
+
const time = new Date();
|
|
12
|
+
const instrumentationKey = ikey;
|
|
13
|
+
const tags = createTagsFromResource(metrics.resource);
|
|
14
|
+
metrics.scopeMetrics.forEach((scopeMetric) => {
|
|
15
|
+
let baseData = {
|
|
16
|
+
metrics: [],
|
|
17
|
+
version: 2,
|
|
18
|
+
};
|
|
19
|
+
scopeMetric.metrics.forEach((metric) => {
|
|
20
|
+
metric.dataPoints.forEach((dataPoint) => {
|
|
21
|
+
var metricDataPoint = {
|
|
22
|
+
name: metric.descriptor.name,
|
|
23
|
+
value: 0,
|
|
24
|
+
dataPointType: "Aggregation",
|
|
25
|
+
};
|
|
26
|
+
if (metric.dataPointType == DataPointType.SINGULAR) {
|
|
27
|
+
metricDataPoint.value = dataPoint.value;
|
|
28
|
+
metricDataPoint.count = 1;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
metricDataPoint.value = dataPoint.value.sum;
|
|
32
|
+
metricDataPoint.count = dataPoint.value.count;
|
|
33
|
+
}
|
|
34
|
+
baseData.metrics.push(metricDataPoint);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
let envelope = {
|
|
38
|
+
name: "Microsoft.ApplicationInsights.Metric",
|
|
39
|
+
time: time,
|
|
40
|
+
sampleRate: 100,
|
|
41
|
+
instrumentationKey: instrumentationKey,
|
|
42
|
+
tags: tags,
|
|
43
|
+
version: 1,
|
|
44
|
+
data: {
|
|
45
|
+
baseType: "MetricData",
|
|
46
|
+
baseData: Object.assign({}, baseData),
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
envelopes.push(envelope);
|
|
50
|
+
});
|
|
51
|
+
return envelopes;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=metricUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metricUtils.js","sourceRoot":"","sources":["../../../src/utils/metricUtils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,aAAa,EAA8B,MAAM,iCAAiC,CAAC;AAE5F,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAEzD;;;GAGG;AACH,MAAM,UAAU,yBAAyB,CAAC,OAAwB,EAAE,IAAY;IAC9E,IAAI,SAAS,GAAe,EAAE,CAAC;IAC/B,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;IACxB,MAAM,kBAAkB,GAAG,IAAI,CAAC;IAChC,MAAM,IAAI,GAAG,sBAAsB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAEtD,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE;QAC3C,IAAI,QAAQ,GAAgB;YAC1B,OAAO,EAAE,EAAE;YACX,OAAO,EAAE,CAAC;SACX,CAAC;QACF,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;YACrC,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE;gBACtC,IAAI,eAAe,GAAoB;oBACrC,IAAI,EAAE,MAAM,CAAC,UAAU,CAAC,IAAI;oBAC5B,KAAK,EAAE,CAAC;oBACR,aAAa,EAAE,aAAa;iBAC7B,CAAC;gBACF,IAAI,MAAM,CAAC,aAAa,IAAI,aAAa,CAAC,QAAQ,EAAE;oBAClD,eAAe,CAAC,KAAK,GAAG,SAAS,CAAC,KAAe,CAAC;oBAClD,eAAe,CAAC,KAAK,GAAG,CAAC,CAAC;iBAC3B;qBAAM;oBACL,eAAe,CAAC,KAAK,GAAI,SAAS,CAAC,KAAmB,CAAC,GAAG,CAAC;oBAC3D,eAAe,CAAC,KAAK,GAAI,SAAS,CAAC,KAAmB,CAAC,KAAK,CAAC;iBAC9D;gBACD,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;YACzC,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QACH,IAAI,QAAQ,GAAa;YACvB,IAAI,EAAE,sCAAsC;YAC5C,IAAI,EAAE,IAAI;YACV,UAAU,EAAE,GAAG;YACf,kBAAkB,EAAE,kBAAkB;YACtC,IAAI,EAAE,IAAI;YACV,OAAO,EAAE,CAAC;YACV,IAAI,EAAE;gBACJ,QAAQ,EAAE,YAAY;gBACtB,QAAQ,oBACH,QAAQ,CACZ;aACF;SACF,CAAC;QACF,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;IAEH,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { DataPointType, Histogram, ResourceMetrics } from \"@opentelemetry/sdk-metrics-base\";\nimport { TelemetryItem as Envelope, MetricsData, MetricDataPoint } from \"../generated\";\nimport { createTagsFromResource } from \"./resourceUtils\";\n\n/**\n * Metric to Azure envelope parsing.\n * @internal\n */\nexport function resourceMetricsToEnvelope(metrics: ResourceMetrics, ikey: string): Envelope[] {\n let envelopes: Envelope[] = [];\n const time = new Date();\n const instrumentationKey = ikey;\n const tags = createTagsFromResource(metrics.resource);\n\n metrics.scopeMetrics.forEach((scopeMetric) => {\n let baseData: MetricsData = {\n metrics: [],\n version: 2,\n };\n scopeMetric.metrics.forEach((metric) => {\n metric.dataPoints.forEach((dataPoint) => {\n var metricDataPoint: MetricDataPoint = {\n name: metric.descriptor.name,\n value: 0,\n dataPointType: \"Aggregation\",\n };\n if (metric.dataPointType == DataPointType.SINGULAR) {\n metricDataPoint.value = dataPoint.value as number;\n metricDataPoint.count = 1;\n } else {\n metricDataPoint.value = (dataPoint.value as Histogram).sum;\n metricDataPoint.count = (dataPoint.value as Histogram).count;\n }\n baseData.metrics.push(metricDataPoint);\n });\n });\n let envelope: Envelope = {\n name: \"Microsoft.ApplicationInsights.Metric\",\n time: time,\n sampleRate: 100,\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 return envelopes;\n}\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT license.
|
|
3
|
+
import os from "os";
|
|
4
|
+
import { SemanticResourceAttributes, SemanticAttributes, } from "@opentelemetry/semantic-conventions";
|
|
5
|
+
import { getInstance } from "../platform";
|
|
6
|
+
import { KnownContextTagKeys } from "../generated";
|
|
7
|
+
export function createTagsFromResource(resource) {
|
|
8
|
+
const context = getInstance();
|
|
9
|
+
const tags = Object.assign({}, context.tags);
|
|
10
|
+
if (resource && resource.attributes) {
|
|
11
|
+
const serviceName = resource.attributes[SemanticResourceAttributes.SERVICE_NAME];
|
|
12
|
+
const serviceNamespace = resource.attributes[SemanticResourceAttributes.SERVICE_NAMESPACE];
|
|
13
|
+
if (serviceName) {
|
|
14
|
+
if (serviceNamespace) {
|
|
15
|
+
tags[KnownContextTagKeys.AiCloudRole] = `${serviceNamespace}.${serviceName}`;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
tags[KnownContextTagKeys.AiCloudRole] = String(serviceName);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const serviceInstanceId = resource.attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID];
|
|
22
|
+
if (serviceInstanceId) {
|
|
23
|
+
tags[KnownContextTagKeys.AiCloudRoleInstance] = String(serviceInstanceId);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
tags[KnownContextTagKeys.AiCloudRoleInstance] = os && os.hostname();
|
|
27
|
+
}
|
|
28
|
+
const endUserId = resource.attributes[SemanticAttributes.ENDUSER_ID];
|
|
29
|
+
if (endUserId) {
|
|
30
|
+
tags[KnownContextTagKeys.AiUserId] = String(endUserId);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return tags;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=resourceUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resourceUtils.js","sourceRoot":"","sources":["../../../src/utils/resourceUtils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EACL,0BAA0B,EAC1B,kBAAkB,GACnB,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAGnD,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,QAAQ,CAAC,UAAU,EAAE;QACnC,MAAM,WAAW,GAAG,QAAQ,CAAC,UAAU,CAAC,0BAA0B,CAAC,YAAY,CAAC,CAAC;QACjF,MAAM,gBAAgB,GAAG,QAAQ,CAAC,UAAU,CAAC,0BAA0B,CAAC,iBAAiB,CAAC,CAAC;QAC3F,IAAI,WAAW,EAAE;YACf,IAAI,gBAAgB,EAAE;gBACpB,IAAI,CAAC,mBAAmB,CAAC,WAAW,CAAC,GAAG,GAAG,gBAAgB,IAAI,WAAW,EAAE,CAAC;aAC9E;iBAAM;gBACL,IAAI,CAAC,mBAAmB,CAAC,WAAW,CAAC,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;aAC7D;SACF;QACD,MAAM,iBAAiB,GAAG,QAAQ,CAAC,UAAU,CAAC,0BAA0B,CAAC,mBAAmB,CAAC,CAAC;QAC9F,IAAI,iBAAiB,EAAE;YACrB,IAAI,CAAC,mBAAmB,CAAC,mBAAmB,CAAC,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC;SAC3E;aAAM;YACL,IAAI,CAAC,mBAAmB,CAAC,mBAAmB,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,QAAQ,EAAE,CAAC;SACrE;QACD,MAAM,SAAS,GAAG,QAAQ,CAAC,UAAU,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC;QACrE,IAAI,SAAS,EAAE;YACb,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;SACxD;KACF;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport os from \"os\";\nimport {\n SemanticResourceAttributes,\n SemanticAttributes,\n} from \"@opentelemetry/semantic-conventions\";\nimport { Tags } from \"../types\";\nimport { getInstance } from \"../platform\";\nimport { KnownContextTagKeys } from \"../generated\";\nimport { Resource } from \"@opentelemetry/resources\";\n\nexport function createTagsFromResource(resource: Resource): Tags {\n const context = getInstance();\n const tags: Tags = { ...context.tags };\n if (resource && resource.attributes) {\n const serviceName = resource.attributes[SemanticResourceAttributes.SERVICE_NAME];\n const serviceNamespace = resource.attributes[SemanticResourceAttributes.SERVICE_NAMESPACE];\n if (serviceName) {\n if (serviceNamespace) {\n tags[KnownContextTagKeys.AiCloudRole] = `${serviceNamespace}.${serviceName}`;\n } else {\n tags[KnownContextTagKeys.AiCloudRole] = String(serviceName);\n }\n }\n const serviceInstanceId = resource.attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID];\n if (serviceInstanceId) {\n tags[KnownContextTagKeys.AiCloudRoleInstance] = String(serviceInstanceId);\n } else {\n tags[KnownContextTagKeys.AiCloudRoleInstance] = os && os.hostname();\n }\n const endUserId = resource.attributes[SemanticAttributes.ENDUSER_ID];\n if (endUserId) {\n tags[KnownContextTagKeys.AiUserId] = String(endUserId);\n }\n }\n return tags;\n}\n"]}
|
|
@@ -1,46 +1,30 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT license.
|
|
3
|
-
import os from "os";
|
|
4
3
|
import { URL } from "url";
|
|
5
4
|
import { hrTimeToMilliseconds } from "@opentelemetry/core";
|
|
6
5
|
import { diag, SpanKind, SpanStatusCode } from "@opentelemetry/api";
|
|
7
|
-
import {
|
|
6
|
+
import { SemanticAttributes, DbSystemValues } from "@opentelemetry/semantic-conventions";
|
|
7
|
+
import { createTagsFromResource } from "./resourceUtils";
|
|
8
8
|
import { msToTimeSpan } from "./breezeUtils";
|
|
9
|
-
import { getInstance } from "../platform";
|
|
10
9
|
import { parseEventHubSpan } from "./eventhub";
|
|
11
10
|
import { DependencyTypes, MS_LINKS } from "./constants/applicationinsights";
|
|
12
11
|
import { AzNamespace, MicrosoftEventHub } from "./constants/span/azAttributes";
|
|
13
12
|
import { KnownContextTagKeys, } from "../generated";
|
|
14
|
-
function
|
|
15
|
-
const
|
|
16
|
-
const tags = Object.assign({}, context.tags);
|
|
13
|
+
function createGenericTagsFromSpan(span) {
|
|
14
|
+
const tags = createTagsFromResource(span.resource);
|
|
17
15
|
tags[KnownContextTagKeys.AiOperationId] = span.spanContext().traceId;
|
|
18
16
|
if (span.parentSpanId) {
|
|
19
17
|
tags[KnownContextTagKeys.AiOperationParentId] = span.parentSpanId;
|
|
20
18
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (serviceNamespace) {
|
|
26
|
-
tags[KnownContextTagKeys.AiCloudRole] = `${serviceNamespace}.${serviceName}`;
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
tags[KnownContextTagKeys.AiCloudRole] = String(serviceName);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
const serviceInstanceId = span.resource.attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID];
|
|
33
|
-
if (serviceInstanceId) {
|
|
34
|
-
tags[KnownContextTagKeys.AiCloudRoleInstance] = String(serviceInstanceId);
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
tags[KnownContextTagKeys.AiCloudRoleInstance] = os && os.hostname();
|
|
38
|
-
}
|
|
39
|
-
const endUserId = span.resource.attributes[SemanticAttributes.ENDUSER_ID];
|
|
40
|
-
if (endUserId) {
|
|
41
|
-
tags[KnownContextTagKeys.AiUserId] = String(endUserId);
|
|
42
|
-
}
|
|
19
|
+
const httpUserAgent = span.attributes[SemanticAttributes.HTTP_USER_AGENT];
|
|
20
|
+
if (httpUserAgent) {
|
|
21
|
+
// TODO: Not exposed in Swagger, need to update def
|
|
22
|
+
tags["ai.user.userAgent"] = String(httpUserAgent);
|
|
43
23
|
}
|
|
24
|
+
return tags;
|
|
25
|
+
}
|
|
26
|
+
function createTagsFromSpan(span) {
|
|
27
|
+
const tags = createGenericTagsFromSpan(span);
|
|
44
28
|
if (span.kind === SpanKind.SERVER) {
|
|
45
29
|
const httpMethod = span.attributes[SemanticAttributes.HTTP_METHOD];
|
|
46
30
|
const httpClientIp = span.attributes[SemanticAttributes.HTTP_CLIENT_IP];
|
|
@@ -74,25 +58,33 @@ function createTagsFromSpan(span) {
|
|
|
74
58
|
}
|
|
75
59
|
}
|
|
76
60
|
// TODO: Operation Name and Location IP TBD for non server spans
|
|
77
|
-
const httpUserAgent = span.attributes[SemanticAttributes.HTTP_USER_AGENT];
|
|
78
|
-
if (httpUserAgent) {
|
|
79
|
-
// TODO: Not exposed in Swagger, need to update def
|
|
80
|
-
tags["ai.user.userAgent"] = String(httpUserAgent);
|
|
81
|
-
}
|
|
82
61
|
return tags;
|
|
83
62
|
}
|
|
84
|
-
function
|
|
63
|
+
function createPropertiesFromSpanAttributes(attributes) {
|
|
85
64
|
const properties = {};
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
65
|
+
if (attributes) {
|
|
66
|
+
for (const key of Object.keys(attributes)) {
|
|
67
|
+
if (!(key.startsWith("http.") ||
|
|
68
|
+
key.startsWith("rpc.") ||
|
|
69
|
+
key.startsWith("db.") ||
|
|
70
|
+
key.startsWith("peer.") ||
|
|
71
|
+
key.startsWith("message.") ||
|
|
72
|
+
key.startsWith("messaging.") ||
|
|
73
|
+
key.startsWith("enduser.") ||
|
|
74
|
+
key.startsWith("net.") ||
|
|
75
|
+
key.startsWith("exception.") ||
|
|
76
|
+
key.startsWith("thread.") ||
|
|
77
|
+
key.startsWith("faas.") ||
|
|
78
|
+
key.startsWith("code."))) {
|
|
79
|
+
properties[key] = attributes[key];
|
|
80
|
+
}
|
|
94
81
|
}
|
|
95
82
|
}
|
|
83
|
+
return properties;
|
|
84
|
+
}
|
|
85
|
+
function createPropertiesFromSpan(span) {
|
|
86
|
+
const properties = createPropertiesFromSpanAttributes(span.attributes);
|
|
87
|
+
const measurements = {};
|
|
96
88
|
const links = span.links.map((link) => ({
|
|
97
89
|
operation_Id: link.context.traceId,
|
|
98
90
|
id: link.context.spanId,
|
|
@@ -221,7 +213,7 @@ function createDependencyData(span) {
|
|
|
221
213
|
}
|
|
222
214
|
}
|
|
223
215
|
}
|
|
224
|
-
catch (
|
|
216
|
+
catch (ex) { }
|
|
225
217
|
remoteDependencyData.target = `${target}`;
|
|
226
218
|
}
|
|
227
219
|
}
|
|
@@ -359,4 +351,81 @@ export function readableSpanToEnvelope(span, ikey) {
|
|
|
359
351
|
},
|
|
360
352
|
};
|
|
361
353
|
}
|
|
354
|
+
/**
|
|
355
|
+
* Span Events to Azure envelopes parsing.
|
|
356
|
+
* @internal
|
|
357
|
+
*/
|
|
358
|
+
export function spanEventsToEnvelopes(span, ikey) {
|
|
359
|
+
let envelopes = [];
|
|
360
|
+
if (span.events) {
|
|
361
|
+
span.events.forEach((event) => {
|
|
362
|
+
let baseType;
|
|
363
|
+
const sampleRate = 100;
|
|
364
|
+
let time = new Date(hrTimeToMilliseconds(event.time));
|
|
365
|
+
let name = "";
|
|
366
|
+
let baseData;
|
|
367
|
+
const properties = createPropertiesFromSpanAttributes(event.attributes);
|
|
368
|
+
const tags = createGenericTagsFromSpan(span);
|
|
369
|
+
if (event.name == "exception") {
|
|
370
|
+
name = "Microsoft.ApplicationInsights.Exception";
|
|
371
|
+
baseType = "ExceptionData";
|
|
372
|
+
let typeName = "";
|
|
373
|
+
let message = "Exception";
|
|
374
|
+
let stack = "";
|
|
375
|
+
let hasFullStack = false;
|
|
376
|
+
if (event.attributes) {
|
|
377
|
+
typeName = String(event.attributes[SemanticAttributes.EXCEPTION_TYPE]);
|
|
378
|
+
stack = String(event.attributes[SemanticAttributes.EXCEPTION_STACKTRACE]);
|
|
379
|
+
if (stack) {
|
|
380
|
+
hasFullStack = true;
|
|
381
|
+
}
|
|
382
|
+
let exceptionMsg = event.attributes[SemanticAttributes.EXCEPTION_MESSAGE];
|
|
383
|
+
if (exceptionMsg) {
|
|
384
|
+
message = String(exceptionMsg);
|
|
385
|
+
}
|
|
386
|
+
let escaped = event.attributes[SemanticAttributes.EXCEPTION_ESCAPED];
|
|
387
|
+
if (escaped != undefined) {
|
|
388
|
+
properties[SemanticAttributes.EXCEPTION_ESCAPED] = String(escaped);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
let exceptionDetails = {
|
|
392
|
+
typeName: typeName,
|
|
393
|
+
message: message,
|
|
394
|
+
stack: stack,
|
|
395
|
+
hasFullStack: hasFullStack,
|
|
396
|
+
};
|
|
397
|
+
let exceptionData = {
|
|
398
|
+
exceptions: [exceptionDetails],
|
|
399
|
+
version: 2,
|
|
400
|
+
properties: properties,
|
|
401
|
+
};
|
|
402
|
+
baseData = exceptionData;
|
|
403
|
+
}
|
|
404
|
+
else {
|
|
405
|
+
name = "Microsoft.ApplicationInsights.Message";
|
|
406
|
+
baseType = "MessageData";
|
|
407
|
+
let messageData = {
|
|
408
|
+
message: event.name,
|
|
409
|
+
version: 2,
|
|
410
|
+
properties: properties,
|
|
411
|
+
};
|
|
412
|
+
baseData = messageData;
|
|
413
|
+
}
|
|
414
|
+
let env = {
|
|
415
|
+
name: name,
|
|
416
|
+
time: time,
|
|
417
|
+
instrumentationKey: ikey,
|
|
418
|
+
version: 1,
|
|
419
|
+
sampleRate: sampleRate,
|
|
420
|
+
data: {
|
|
421
|
+
baseType: baseType,
|
|
422
|
+
baseData: baseData,
|
|
423
|
+
},
|
|
424
|
+
tags: tags,
|
|
425
|
+
};
|
|
426
|
+
envelopes.push(env);
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
return envelopes;
|
|
430
|
+
}
|
|
362
431
|
//# sourceMappingURL=spanUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spanUtils.js","sourceRoot":"","sources":["../../../src/utils/spanUtils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO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U,CAAC,WAAW,CAAC,EAAE,CAAC;SAC/E;QACD,IAAI,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,KAAK,iBAAiB,EAAE;YACtD,iBAAiB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;SACnC;KACF;IAED,OAAO;QACL,IAAI;QACJ,UAAU;QACV,IAAI;QACJ,kBAAkB;QAClB,IAAI;QACJ,OAAO,EAAE,CAAC;QACV,IAAI,EAAE;YACJ,QAAQ;YACR,QAAQ,kCACH,QAAQ,KACX,UAAU;gBACV,YAAY,GACb;SACF;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport os from \"os\";\nimport { URL } from \"url\";\nimport { ReadableSpan } from \"@opentelemetry/sdk-trace-base\";\nimport { hrTimeToMilliseconds } from \"@opentelemetry/core\";\nimport { diag, SpanKind, SpanStatusCode, Link } from \"@opentelemetry/api\";\nimport {\n SemanticResourceAttributes,\n SemanticAttributes,\n DbSystemValues,\n} from \"@opentelemetry/semantic-conventions\";\n\nimport { Tags, Properties, MSLink, Measurements } from \"../types\";\nimport { msToTimeSpan } from \"./breezeUtils\";\nimport { getInstance } from \"../platform\";\nimport { parseEventHubSpan } from \"./eventhub\";\nimport { DependencyTypes, MS_LINKS } from \"./constants/applicationinsights\";\nimport { AzNamespace, MicrosoftEventHub } from \"./constants/span/azAttributes\";\nimport {\n RemoteDependencyData,\n RequestData,\n TelemetryItem as Envelope,\n KnownContextTagKeys,\n} from \"../generated\";\n\nfunction createTagsFromSpan(span: ReadableSpan): Tags {\n const context = getInstance();\n const tags: Tags = { ...context.tags };\n\n tags[KnownContextTagKeys.AiOperationId] = span.spanContext().traceId;\n if (span.parentSpanId) {\n tags[KnownContextTagKeys.AiOperationParentId] = span.parentSpanId;\n }\n if (span.resource && span.resource.attributes) {\n const serviceName = span.resource.attributes[SemanticResourceAttributes.SERVICE_NAME];\n const serviceNamespace = span.resource.attributes[SemanticResourceAttributes.SERVICE_NAMESPACE];\n if (serviceName) {\n if (serviceNamespace) {\n tags[KnownContextTagKeys.AiCloudRole] = `${serviceNamespace}.${serviceName}`;\n } else {\n tags[KnownContextTagKeys.AiCloudRole] = String(serviceName);\n }\n }\n const serviceInstanceId =\n span.resource.attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID];\n if (serviceInstanceId) {\n tags[KnownContextTagKeys.AiCloudRoleInstance] = String(serviceInstanceId);\n } else {\n tags[KnownContextTagKeys.AiCloudRoleInstance] = os && os.hostname();\n }\n const endUserId = span.resource.attributes[SemanticAttributes.ENDUSER_ID];\n if (endUserId) {\n tags[KnownContextTagKeys.AiUserId] = String(endUserId);\n }\n }\n if (span.kind === SpanKind.SERVER) {\n const httpMethod = span.attributes[SemanticAttributes.HTTP_METHOD];\n const httpClientIp = span.attributes[SemanticAttributes.HTTP_CLIENT_IP];\n const netPeerIp = span.attributes[SemanticAttributes.NET_PEER_IP];\n if (httpMethod) {\n const httpRoute = span.attributes[SemanticAttributes.HTTP_ROUTE];\n const httpUrl = span.attributes[SemanticAttributes.HTTP_URL];\n tags[KnownContextTagKeys.AiOperationName] = span.name; // Default\n if (httpRoute) {\n tags[KnownContextTagKeys.AiOperationName] = `${httpMethod as string} ${\n httpRoute as string\n }`;\n } else if (httpUrl) {\n try {\n let url = new URL(String(httpUrl));\n tags[KnownContextTagKeys.AiOperationName] = `${httpMethod} ${url.pathname}`;\n } catch (ex) {}\n }\n if (httpClientIp) {\n tags[KnownContextTagKeys.AiLocationIp] = String(httpClientIp);\n } else if (netPeerIp) {\n tags[KnownContextTagKeys.AiLocationIp] = String(netPeerIp);\n }\n } else {\n tags[KnownContextTagKeys.AiOperationName] = span.name;\n if (netPeerIp) {\n tags[KnownContextTagKeys.AiLocationIp] = String(netPeerIp);\n }\n }\n }\n // TODO: Operation Name and Location IP TBD for non server spans\n\n const httpUserAgent = span.attributes[SemanticAttributes.HTTP_USER_AGENT];\n if (httpUserAgent) {\n // TODO: Not exposed in Swagger, need to update def\n tags[\"ai.user.userAgent\"] = String(httpUserAgent);\n }\n\n return tags;\n}\n\nfunction createPropertiesFromSpan(span: ReadableSpan): [Properties, Measurements] {\n const properties: Properties = {};\n const measurements: Measurements = {};\n\n for (const key of Object.keys(span.attributes)) {\n if (\n !(\n key.startsWith(\"http.\") ||\n key.startsWith(\"rpc.\") ||\n key.startsWith(\"db.\") ||\n key.startsWith(\"peer.\") ||\n key.startsWith(\"net.\")\n )\n ) {\n properties[key] = span.attributes[key] as string;\n }\n }\n\n const links: MSLink[] = span.links.map((link: Link) => ({\n operation_Id: link.context.traceId,\n id: link.context.spanId,\n }));\n\n if (links.length > 0) {\n properties[MS_LINKS] = JSON.stringify(links);\n }\n\n return [properties, measurements];\n}\n\nfunction 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\nfunction getUrl(span: ReadableSpan): string {\n const httpMethod = span.attributes[SemanticAttributes.HTTP_METHOD];\n if (httpMethod) {\n const httpUrl = span.attributes[SemanticAttributes.HTTP_URL];\n if (httpUrl) {\n return String(httpUrl);\n } else {\n const httpScheme = span.attributes[SemanticAttributes.HTTP_SCHEME];\n const httpTarget = span.attributes[SemanticAttributes.HTTP_TARGET];\n if (httpScheme && httpTarget) {\n const httpHost = span.attributes[SemanticAttributes.HTTP_HOST];\n if (httpHost) {\n return `${httpScheme}://${httpHost}${httpTarget}`;\n } else {\n const netPeerPort = span.attributes[SemanticAttributes.NET_PEER_PORT];\n if (netPeerPort) {\n const netPeerName = span.attributes[SemanticAttributes.NET_PEER_NAME];\n if (netPeerName) {\n return `${httpScheme}://${netPeerName}:${netPeerPort}${httpTarget}`;\n } else {\n const netPeerIp = span.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\nfunction getDependencyTarget(span: ReadableSpan): string {\n const peerService = span.attributes[SemanticAttributes.PEER_SERVICE];\n const httpHost = span.attributes[SemanticAttributes.HTTP_HOST];\n const httpUrl = span.attributes[SemanticAttributes.HTTP_URL];\n const netPeerName = span.attributes[SemanticAttributes.NET_PEER_NAME];\n const netPeerIp = span.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\nfunction createDependencyData(span: ReadableSpan): RemoteDependencyData {\n const remoteDependencyData: RemoteDependencyData = {\n name: span.name, //Default\n id: `${span.spanContext().spanId}`,\n success: span.status.code != SpanStatusCode.ERROR,\n resultCode: \"0\",\n type: \"Dependency\",\n duration: msToTimeSpan(hrTimeToMilliseconds(span.duration)),\n version: 2,\n };\n if (span.kind === SpanKind.PRODUCER) {\n remoteDependencyData.type = DependencyTypes.QueueMessage;\n }\n if (span.kind === SpanKind.INTERNAL && span.parentSpanId) {\n remoteDependencyData.type = DependencyTypes.InProc;\n }\n\n const httpMethod = span.attributes[SemanticAttributes.HTTP_METHOD];\n const dbSystem = span.attributes[SemanticAttributes.DB_SYSTEM];\n const rpcSystem = span.attributes[SemanticAttributes.RPC_SYSTEM];\n // HTTP Dependency\n if (httpMethod) {\n const httpUrl = span.attributes[SemanticAttributes.HTTP_URL];\n if (httpUrl) {\n try {\n let dependencyUrl = new URL(String(httpUrl));\n remoteDependencyData.name = `${httpMethod} ${dependencyUrl.pathname}`;\n } catch (ex) {}\n }\n remoteDependencyData.type = DependencyTypes.Http;\n remoteDependencyData.data = getUrl(span);\n const httpStatusCode = span.attributes[SemanticAttributes.HTTP_STATUS_CODE];\n if (httpStatusCode) {\n remoteDependencyData.resultCode = String(httpStatusCode);\n }\n let target = getDependencyTarget(span);\n if (target) {\n try {\n // Remove default port\n let portRegex = new RegExp(/(https?)(:\\/\\/.*)(:\\d+)(\\S*)/);\n let res = portRegex.exec(target);\n if (res != null) {\n let protocol = res[1];\n let port = res[3];\n if ((protocol == \"https\" && port == \":443\") || (protocol == \"http\" && port == \":80\")) {\n // Drop port\n target = res[1] + res[2] + res[4];\n }\n }\n } catch (error) {}\n remoteDependencyData.target = `${target}`;\n }\n }\n // DB Dependency\n else if (dbSystem) {\n // TODO: Remove special logic when Azure UX supports OpenTelemetry dbSystem\n if (String(dbSystem) === DbSystemValues.MYSQL) {\n remoteDependencyData.type = \"mysql\";\n } else if (String(dbSystem) === DbSystemValues.POSTGRESQL) {\n remoteDependencyData.type = \"postgresql\";\n } else if (String(dbSystem) === DbSystemValues.MONGODB) {\n remoteDependencyData.type = \"mongodb\";\n } else if (String(dbSystem) === DbSystemValues.REDIS) {\n remoteDependencyData.type = \"redis\";\n } else if (isSqlDB(String(dbSystem))) {\n remoteDependencyData.type = \"SQL\";\n } else {\n remoteDependencyData.type = String(dbSystem);\n }\n const dbStatement = span.attributes[SemanticAttributes.DB_STATEMENT];\n const dbOperation = span.attributes[SemanticAttributes.DB_OPERATION];\n if (dbStatement) {\n remoteDependencyData.data = String(dbStatement);\n } else if (dbOperation) {\n remoteDependencyData.data = String(dbOperation);\n }\n let target = getDependencyTarget(span);\n const dbName = span.attributes[SemanticAttributes.DB_NAME];\n if (target) {\n remoteDependencyData.target = dbName ? `${target}|${dbName}` : `${target}`;\n } else {\n remoteDependencyData.target = dbName ? `${dbName}` : `${dbSystem}`;\n }\n }\n // grpc Dependency\n else if (rpcSystem) {\n remoteDependencyData.type = DependencyTypes.Grpc;\n const grpcStatusCode = span.attributes[SemanticAttributes.RPC_GRPC_STATUS_CODE];\n if (grpcStatusCode) {\n remoteDependencyData.resultCode = String(grpcStatusCode);\n }\n let target = getDependencyTarget(span);\n if (target) {\n remoteDependencyData.target = `${target}`;\n } else if (rpcSystem) {\n remoteDependencyData.target = String(rpcSystem);\n }\n }\n return remoteDependencyData;\n}\n\nfunction createRequestData(span: ReadableSpan): RequestData {\n const requestData: RequestData = {\n id: `${span.spanContext().spanId}`,\n success: span.status.code != SpanStatusCode.ERROR,\n responseCode: \"0\",\n duration: msToTimeSpan(hrTimeToMilliseconds(span.duration)),\n version: 2,\n source: undefined,\n };\n const httpMethod = span.attributes[SemanticAttributes.HTTP_METHOD];\n const grpcStatusCode = span.attributes[SemanticAttributes.RPC_GRPC_STATUS_CODE];\n if (httpMethod) {\n requestData.url = getUrl(span);\n const httpStatusCode = span.attributes[SemanticAttributes.HTTP_STATUS_CODE];\n if (httpStatusCode) {\n requestData.responseCode = String(httpStatusCode);\n }\n } else if (grpcStatusCode) {\n requestData.responseCode = String(grpcStatusCode);\n }\n return requestData;\n}\n\n/**\n * Span to Azure envelope parsing.\n * @internal\n */\nexport function readableSpanToEnvelope(span: ReadableSpan, ikey: string): Envelope {\n let name: string;\n let baseType: \"RemoteDependencyData\" | \"RequestData\";\n const sampleRate = 100;\n let baseData: RemoteDependencyData | RequestData;\n\n const time = new Date(hrTimeToMilliseconds(span.startTime));\n const instrumentationKey = ikey;\n const tags = createTagsFromSpan(span);\n const [properties, measurements] = createPropertiesFromSpan(span);\n switch (span.kind) {\n case SpanKind.CLIENT:\n case SpanKind.PRODUCER:\n case SpanKind.INTERNAL:\n name = \"Microsoft.ApplicationInsights.RemoteDependency\";\n baseType = \"RemoteDependencyData\";\n baseData = createDependencyData(span);\n break;\n case SpanKind.SERVER:\n case SpanKind.CONSUMER:\n name = \"Microsoft.ApplicationInsights.Request\";\n baseType = \"RequestData\";\n baseData = createRequestData(span);\n baseData.name = tags[KnownContextTagKeys.AiOperationName];\n break;\n default:\n // never\n diag.error(`Unsupported span kind ${span.kind}`);\n throw new Error(`Unsupported span kind ${span.kind}`);\n }\n\n // Azure SDK\n if (span.attributes[AzNamespace]) {\n if (span.kind === SpanKind.INTERNAL) {\n baseData.type = `${DependencyTypes.InProc} | ${span.attributes[AzNamespace]}`;\n }\n if (span.attributes[AzNamespace] === MicrosoftEventHub) {\n parseEventHubSpan(span, baseData);\n }\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"]}
|
|
1
|
+
{"version":3,"file":"spanUtils.js","sourceRoot":"","sources":["../../../src/utils/spanUtils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc,EAAwB,MAAM,oBAAoB,CAAC;AAC1F,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAEzF,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAC/E,OAAO,EAML,mBAAmB,GAEpB,MAAM,cAAc,CAAC;AAEtB,SAAS,yBAAyB,CAAC,IAAkB;IACnD,MAAM,IAAI,GAAS,sBAAsB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACzD,IAAI,CAAC,mBAAmB,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,OAAO,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AAW,CAAC;aACxB;YACD,IAAI,GAAG,GAAa;gBAClB,IAAI,EAAE,IAAI;gBACV,IAAI,EAAE,IAAI;gBACV,kBAAkB,EAAE,IAAI;gBACxB,OAAO,EAAE,CAAC;gBACV,UAAU,EAAE,UAAU;gBACtB,IAAI,EAAE;oBACJ,QAAQ,EAAE,QAAQ;oBAClB,QAAQ,EAAE,QAAQ;iBACnB;gBACD,IAAI,EAAE,IAAI;aACX,CAAC;YACF,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACtB,CAAC,CAAC,CAAC;KACJ;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { URL } from \"url\";\nimport { ReadableSpan, TimedEvent } from \"@opentelemetry/sdk-trace-base\";\nimport { hrTimeToMilliseconds } from \"@opentelemetry/core\";\nimport { diag, SpanKind, SpanStatusCode, Link, SpanAttributes } from \"@opentelemetry/api\";\nimport { SemanticAttributes, DbSystemValues } from \"@opentelemetry/semantic-conventions\";\n\nimport { createTagsFromResource } from \"./resourceUtils\";\nimport { Tags, Properties, MSLink, Measurements } from \"../types\";\nimport { msToTimeSpan } from \"./breezeUtils\";\nimport { parseEventHubSpan } from \"./eventhub\";\nimport { DependencyTypes, MS_LINKS } from \"./constants/applicationinsights\";\nimport { AzNamespace, MicrosoftEventHub } from \"./constants/span/azAttributes\";\nimport {\n TelemetryExceptionData,\n MessageData,\n RemoteDependencyData,\n RequestData,\n TelemetryItem as Envelope,\n KnownContextTagKeys,\n TelemetryExceptionDetails,\n} from \"../generated\";\n\nfunction createGenericTagsFromSpan(span: ReadableSpan): Tags {\n const tags: Tags = createTagsFromResource(span.resource);\n tags[KnownContextTagKeys.AiOperationId] = span.spanContext().traceId;\n if (span.parentSpanId) {\n tags[KnownContextTagKeys.AiOperationParentId] = span.parentSpanId;\n }\n const httpUserAgent = span.attributes[SemanticAttributes.HTTP_USER_AGENT];\n if (httpUserAgent) {\n // TODO: Not exposed in Swagger, need to update def\n tags[\"ai.user.userAgent\"] = String(httpUserAgent);\n }\n return tags;\n}\n\nfunction createTagsFromSpan(span: ReadableSpan): Tags {\n const tags: Tags = createGenericTagsFromSpan(span);\n if (span.kind === SpanKind.SERVER) {\n const httpMethod = span.attributes[SemanticAttributes.HTTP_METHOD];\n const httpClientIp = span.attributes[SemanticAttributes.HTTP_CLIENT_IP];\n const netPeerIp = span.attributes[SemanticAttributes.NET_PEER_IP];\n if (httpMethod) {\n const httpRoute = span.attributes[SemanticAttributes.HTTP_ROUTE];\n const httpUrl = span.attributes[SemanticAttributes.HTTP_URL];\n tags[KnownContextTagKeys.AiOperationName] = span.name; // Default\n if (httpRoute) {\n tags[KnownContextTagKeys.AiOperationName] = `${httpMethod as string} ${\n httpRoute as string\n }`;\n } else if (httpUrl) {\n try {\n let url = new URL(String(httpUrl));\n tags[KnownContextTagKeys.AiOperationName] = `${httpMethod} ${url.pathname}`;\n } catch (ex: any) {}\n }\n if (httpClientIp) {\n tags[KnownContextTagKeys.AiLocationIp] = String(httpClientIp);\n } else if (netPeerIp) {\n tags[KnownContextTagKeys.AiLocationIp] = String(netPeerIp);\n }\n } else {\n tags[KnownContextTagKeys.AiOperationName] = span.name;\n if (netPeerIp) {\n tags[KnownContextTagKeys.AiLocationIp] = String(netPeerIp);\n }\n }\n }\n // TODO: Operation Name and Location IP TBD for non server spans\n\n return tags;\n}\n\nfunction createPropertiesFromSpanAttributes(attributes?: SpanAttributes): {\n [propertyName: string]: string;\n} {\n const properties: { [propertyName: string]: string } = {};\n if (attributes) {\n for (const key of Object.keys(attributes)) {\n if (\n !(\n key.startsWith(\"http.\") ||\n key.startsWith(\"rpc.\") ||\n key.startsWith(\"db.\") ||\n key.startsWith(\"peer.\") ||\n key.startsWith(\"message.\") ||\n key.startsWith(\"messaging.\") ||\n key.startsWith(\"enduser.\") ||\n key.startsWith(\"net.\") ||\n key.startsWith(\"exception.\") ||\n key.startsWith(\"thread.\") ||\n key.startsWith(\"faas.\") ||\n key.startsWith(\"code.\")\n )\n ) {\n properties[key] = attributes[key] as string;\n }\n }\n }\n return properties;\n}\n\nfunction createPropertiesFromSpan(span: ReadableSpan): [Properties, Measurements] {\n const properties: Properties = createPropertiesFromSpanAttributes(span.attributes);\n const measurements: Measurements = {};\n\n const links: MSLink[] = span.links.map((link: Link) => ({\n operation_Id: link.context.traceId,\n id: link.context.spanId,\n }));\n if (links.length > 0) {\n properties[MS_LINKS] = JSON.stringify(links);\n }\n return [properties, measurements];\n}\n\nfunction 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\nfunction getUrl(span: ReadableSpan): string {\n const httpMethod = span.attributes[SemanticAttributes.HTTP_METHOD];\n if (httpMethod) {\n const httpUrl = span.attributes[SemanticAttributes.HTTP_URL];\n if (httpUrl) {\n return String(httpUrl);\n } else {\n const httpScheme = span.attributes[SemanticAttributes.HTTP_SCHEME];\n const httpTarget = span.attributes[SemanticAttributes.HTTP_TARGET];\n if (httpScheme && httpTarget) {\n const httpHost = span.attributes[SemanticAttributes.HTTP_HOST];\n if (httpHost) {\n return `${httpScheme}://${httpHost}${httpTarget}`;\n } else {\n const netPeerPort = span.attributes[SemanticAttributes.NET_PEER_PORT];\n if (netPeerPort) {\n const netPeerName = span.attributes[SemanticAttributes.NET_PEER_NAME];\n if (netPeerName) {\n return `${httpScheme}://${netPeerName}:${netPeerPort}${httpTarget}`;\n } else {\n const netPeerIp = span.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\nfunction getDependencyTarget(span: ReadableSpan): string {\n const peerService = span.attributes[SemanticAttributes.PEER_SERVICE];\n const httpHost = span.attributes[SemanticAttributes.HTTP_HOST];\n const httpUrl = span.attributes[SemanticAttributes.HTTP_URL];\n const netPeerName = span.attributes[SemanticAttributes.NET_PEER_NAME];\n const netPeerIp = span.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\nfunction createDependencyData(span: ReadableSpan): RemoteDependencyData {\n const remoteDependencyData: RemoteDependencyData = {\n name: span.name, //Default\n id: `${span.spanContext().spanId}`,\n success: span.status.code != SpanStatusCode.ERROR,\n resultCode: \"0\",\n type: \"Dependency\",\n duration: msToTimeSpan(hrTimeToMilliseconds(span.duration)),\n version: 2,\n };\n if (span.kind === SpanKind.PRODUCER) {\n remoteDependencyData.type = DependencyTypes.QueueMessage;\n }\n if (span.kind === SpanKind.INTERNAL && span.parentSpanId) {\n remoteDependencyData.type = DependencyTypes.InProc;\n }\n\n const httpMethod = span.attributes[SemanticAttributes.HTTP_METHOD];\n const dbSystem = span.attributes[SemanticAttributes.DB_SYSTEM];\n const rpcSystem = span.attributes[SemanticAttributes.RPC_SYSTEM];\n // HTTP Dependency\n if (httpMethod) {\n const httpUrl = span.attributes[SemanticAttributes.HTTP_URL];\n if (httpUrl) {\n try {\n let dependencyUrl = new URL(String(httpUrl));\n remoteDependencyData.name = `${httpMethod} ${dependencyUrl.pathname}`;\n } catch (ex: any) {}\n }\n remoteDependencyData.type = DependencyTypes.Http;\n remoteDependencyData.data = getUrl(span);\n const httpStatusCode = span.attributes[SemanticAttributes.HTTP_STATUS_CODE];\n if (httpStatusCode) {\n remoteDependencyData.resultCode = String(httpStatusCode);\n }\n let target = getDependencyTarget(span);\n if (target) {\n try {\n // Remove default port\n let portRegex = new RegExp(/(https?)(:\\/\\/.*)(:\\d+)(\\S*)/);\n let res = portRegex.exec(target);\n if (res != null) {\n let protocol = res[1];\n let port = res[3];\n if ((protocol == \"https\" && port == \":443\") || (protocol == \"http\" && port == \":80\")) {\n // Drop port\n target = res[1] + res[2] + res[4];\n }\n }\n } catch (ex: any) {}\n remoteDependencyData.target = `${target}`;\n }\n }\n // DB Dependency\n else if (dbSystem) {\n // TODO: Remove special logic when Azure UX supports OpenTelemetry dbSystem\n if (String(dbSystem) === DbSystemValues.MYSQL) {\n remoteDependencyData.type = \"mysql\";\n } else if (String(dbSystem) === DbSystemValues.POSTGRESQL) {\n remoteDependencyData.type = \"postgresql\";\n } else if (String(dbSystem) === DbSystemValues.MONGODB) {\n remoteDependencyData.type = \"mongodb\";\n } else if (String(dbSystem) === DbSystemValues.REDIS) {\n remoteDependencyData.type = \"redis\";\n } else if (isSqlDB(String(dbSystem))) {\n remoteDependencyData.type = \"SQL\";\n } else {\n remoteDependencyData.type = String(dbSystem);\n }\n const dbStatement = span.attributes[SemanticAttributes.DB_STATEMENT];\n const dbOperation = span.attributes[SemanticAttributes.DB_OPERATION];\n if (dbStatement) {\n remoteDependencyData.data = String(dbStatement);\n } else if (dbOperation) {\n remoteDependencyData.data = String(dbOperation);\n }\n let target = getDependencyTarget(span);\n const dbName = span.attributes[SemanticAttributes.DB_NAME];\n if (target) {\n remoteDependencyData.target = dbName ? `${target}|${dbName}` : `${target}`;\n } else {\n remoteDependencyData.target = dbName ? `${dbName}` : `${dbSystem}`;\n }\n }\n // grpc Dependency\n else if (rpcSystem) {\n remoteDependencyData.type = DependencyTypes.Grpc;\n const grpcStatusCode = span.attributes[SemanticAttributes.RPC_GRPC_STATUS_CODE];\n if (grpcStatusCode) {\n remoteDependencyData.resultCode = String(grpcStatusCode);\n }\n let target = getDependencyTarget(span);\n if (target) {\n remoteDependencyData.target = `${target}`;\n } else if (rpcSystem) {\n remoteDependencyData.target = String(rpcSystem);\n }\n }\n return remoteDependencyData;\n}\n\nfunction createRequestData(span: ReadableSpan): RequestData {\n const requestData: RequestData = {\n id: `${span.spanContext().spanId}`,\n success: span.status.code != SpanStatusCode.ERROR,\n responseCode: \"0\",\n duration: msToTimeSpan(hrTimeToMilliseconds(span.duration)),\n version: 2,\n source: undefined,\n };\n const httpMethod = span.attributes[SemanticAttributes.HTTP_METHOD];\n const grpcStatusCode = span.attributes[SemanticAttributes.RPC_GRPC_STATUS_CODE];\n if (httpMethod) {\n requestData.url = getUrl(span);\n const httpStatusCode = span.attributes[SemanticAttributes.HTTP_STATUS_CODE];\n if (httpStatusCode) {\n requestData.responseCode = String(httpStatusCode);\n }\n } else if (grpcStatusCode) {\n requestData.responseCode = String(grpcStatusCode);\n }\n return requestData;\n}\n\n/**\n * Span to Azure envelope parsing.\n * @internal\n */\nexport function readableSpanToEnvelope(span: ReadableSpan, ikey: string): Envelope {\n let name: string;\n let baseType: \"RemoteDependencyData\" | \"RequestData\";\n const sampleRate = 100;\n let baseData: RemoteDependencyData | RequestData;\n\n const time = new Date(hrTimeToMilliseconds(span.startTime));\n const instrumentationKey = ikey;\n const tags = createTagsFromSpan(span);\n const [properties, measurements] = createPropertiesFromSpan(span);\n switch (span.kind) {\n case SpanKind.CLIENT:\n case SpanKind.PRODUCER:\n case SpanKind.INTERNAL:\n name = \"Microsoft.ApplicationInsights.RemoteDependency\";\n baseType = \"RemoteDependencyData\";\n baseData = createDependencyData(span);\n break;\n case SpanKind.SERVER:\n case SpanKind.CONSUMER:\n name = \"Microsoft.ApplicationInsights.Request\";\n baseType = \"RequestData\";\n baseData = createRequestData(span);\n baseData.name = tags[KnownContextTagKeys.AiOperationName];\n break;\n default:\n // never\n diag.error(`Unsupported span kind ${span.kind}`);\n throw new Error(`Unsupported span kind ${span.kind}`);\n }\n\n // Azure SDK\n if (span.attributes[AzNamespace]) {\n if (span.kind === SpanKind.INTERNAL) {\n baseData.type = `${DependencyTypes.InProc} | ${span.attributes[AzNamespace]}`;\n }\n if (span.attributes[AzNamespace] === MicrosoftEventHub) {\n parseEventHubSpan(span, baseData);\n }\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\n/**\n * Span Events to Azure envelopes parsing.\n * @internal\n */\nexport function spanEventsToEnvelopes(span: ReadableSpan, ikey: string): Envelope[] {\n let envelopes: Envelope[] = [];\n if (span.events) {\n span.events.forEach((event: TimedEvent) => {\n let baseType: \"ExceptionData\" | \"MessageData\";\n const sampleRate = 100;\n let time = new Date(hrTimeToMilliseconds(event.time));\n let name = \"\";\n let baseData: TelemetryExceptionData | MessageData;\n const properties = createPropertiesFromSpanAttributes(event.attributes);\n const tags: Tags = createGenericTagsFromSpan(span);\n\n if (event.name == \"exception\") {\n name = \"Microsoft.ApplicationInsights.Exception\";\n baseType = \"ExceptionData\";\n let typeName = \"\";\n let message = \"Exception\";\n let stack = \"\";\n let hasFullStack = false;\n if (event.attributes) {\n typeName = String(event.attributes[SemanticAttributes.EXCEPTION_TYPE]);\n stack = String(event.attributes[SemanticAttributes.EXCEPTION_STACKTRACE]);\n if (stack) {\n hasFullStack = true;\n }\n let exceptionMsg = event.attributes[SemanticAttributes.EXCEPTION_MESSAGE];\n if (exceptionMsg) {\n message = String(exceptionMsg);\n }\n let escaped = event.attributes[SemanticAttributes.EXCEPTION_ESCAPED];\n if (escaped != undefined) {\n properties[SemanticAttributes.EXCEPTION_ESCAPED] = String(escaped);\n }\n }\n let exceptionDetails: TelemetryExceptionDetails = {\n typeName: typeName,\n message: message,\n stack: stack,\n hasFullStack: hasFullStack,\n };\n let exceptionData: TelemetryExceptionData = {\n exceptions: [exceptionDetails],\n version: 2,\n properties: properties,\n };\n baseData = exceptionData;\n } else {\n name = \"Microsoft.ApplicationInsights.Message\";\n baseType = \"MessageData\";\n let messageData: MessageData = {\n message: event.name,\n version: 2,\n properties: properties,\n };\n baseData = messageData;\n }\n let env: Envelope = {\n name: name,\n time: time,\n instrumentationKey: ikey,\n version: 1,\n sampleRate: sampleRate,\n data: {\n baseType: baseType,\n baseData: baseData,\n },\n tags: tags,\n };\n envelopes.push(env);\n });\n }\n return envelopes;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@azure/monitor-opentelemetry-exporter",
|
|
3
3
|
"author": "Microsoft Corporation",
|
|
4
4
|
"sdk-type": "client",
|
|
5
|
-
"version": "1.0.0-beta.
|
|
5
|
+
"version": "1.0.0-beta.8",
|
|
6
6
|
"description": "Application Insights exporter for the OpenTelemetry JavaScript (Node.js) SDK",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"module": "dist-esm/src/index.js",
|
|
@@ -12,8 +12,10 @@
|
|
|
12
12
|
"build:browser": "echo skipped",
|
|
13
13
|
"build:test": "echo skipped",
|
|
14
14
|
"build:node": "tsc -p . && dev-tool run bundle --browser-test=false",
|
|
15
|
+
"build:samples": "dev-tool samples publish --force",
|
|
15
16
|
"build": "npm run build:node && npm run build:browser && api-extractor run --local",
|
|
16
17
|
"check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
|
|
18
|
+
"execute:samples": "dev-tool samples run samples-dev",
|
|
17
19
|
"extract-api": "tsc -p . && api-extractor run --local",
|
|
18
20
|
"format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
|
|
19
21
|
"generate:client": "autorest --typescript ./swagger/README.md",
|
|
@@ -34,9 +36,7 @@
|
|
|
34
36
|
"report": "nyc report --reporter=json",
|
|
35
37
|
"test-opentelemetry-versions": "node test-opentelemetry-versions.js 2>&1",
|
|
36
38
|
"prepare": "npm run build",
|
|
37
|
-
"pack": "npm pack 2>&1"
|
|
38
|
-
"build:samples": "echo Obsolete.",
|
|
39
|
-
"execute:samples": "dev-tool samples run samples-dev"
|
|
39
|
+
"pack": "npm pack 2>&1"
|
|
40
40
|
},
|
|
41
41
|
"engines": {
|
|
42
42
|
"node": ">=12.0.0"
|
|
@@ -85,16 +85,15 @@
|
|
|
85
85
|
"devDependencies": {
|
|
86
86
|
"@azure/dev-tool": "^1.0.0",
|
|
87
87
|
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
|
|
88
|
-
"@microsoft/api-extractor": "
|
|
89
|
-
"@opentelemetry/instrumentation": "^0.
|
|
90
|
-
"@opentelemetry/instrumentation-http": "^0.
|
|
91
|
-
"@opentelemetry/sdk-trace-node": "^1.
|
|
88
|
+
"@microsoft/api-extractor": "7.18.11",
|
|
89
|
+
"@opentelemetry/instrumentation": "^0.29.2",
|
|
90
|
+
"@opentelemetry/instrumentation-http": "^0.29.2",
|
|
91
|
+
"@opentelemetry/sdk-trace-node": "^1.3.1",
|
|
92
92
|
"@types/mocha": "^7.0.2",
|
|
93
93
|
"@types/node": "^12.0.0",
|
|
94
94
|
"dotenv": "^8.2.0",
|
|
95
|
-
"eslint": "^
|
|
95
|
+
"eslint": "^8.0.0",
|
|
96
96
|
"eslint-plugin-node": "^11.1.0",
|
|
97
|
-
"execa": "^5.0.0",
|
|
98
97
|
"mocha": "^7.1.1",
|
|
99
98
|
"nock": "^12.0.3",
|
|
100
99
|
"nyc": "^15.0.0",
|
|
@@ -102,17 +101,19 @@
|
|
|
102
101
|
"rimraf": "^3.0.0",
|
|
103
102
|
"sinon": "^9.0.2",
|
|
104
103
|
"ts-node": "^10.0.0",
|
|
105
|
-
"typescript": "~4.
|
|
104
|
+
"typescript": "~4.6.0"
|
|
106
105
|
},
|
|
107
106
|
"dependencies": {
|
|
108
107
|
"@azure/core-client": "^1.0.0",
|
|
109
|
-
"@azure/core-
|
|
108
|
+
"@azure/core-auth": "^1.3.0",
|
|
110
109
|
"@azure/core-rest-pipeline": "^1.1.0",
|
|
111
|
-
"@opentelemetry/api": "
|
|
112
|
-
"@opentelemetry/
|
|
113
|
-
"@opentelemetry/
|
|
114
|
-
"@opentelemetry/
|
|
115
|
-
"@opentelemetry/
|
|
110
|
+
"@opentelemetry/api": "^1.1.0",
|
|
111
|
+
"@opentelemetry/api-metrics": "0.29.2",
|
|
112
|
+
"@opentelemetry/core": "^1.3.1",
|
|
113
|
+
"@opentelemetry/resources": "^1.3.1",
|
|
114
|
+
"@opentelemetry/sdk-metrics-base": "0.29.2",
|
|
115
|
+
"@opentelemetry/sdk-trace-base": "^1.3.1",
|
|
116
|
+
"@opentelemetry/semantic-conventions": "^1.3.1",
|
|
116
117
|
"tslib": "^2.2.0"
|
|
117
118
|
},
|
|
118
119
|
"sideEffects": false,
|