@azure/monitor-opentelemetry-exporter 1.0.0-beta.20 → 1.0.0-beta.22
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 +2 -0
- package/dist/index.js +127 -112
- package/dist-esm/src/export/statsbeat/longIntervalStatsbeatMetrics.js +16 -14
- package/dist-esm/src/export/statsbeat/longIntervalStatsbeatMetrics.js.map +1 -1
- package/dist-esm/src/generated/applicationInsightsClient.js +1 -1
- package/dist-esm/src/generated/applicationInsightsClient.js.map +1 -1
- package/dist-esm/src/utils/common.js +44 -39
- package/dist-esm/src/utils/common.js.map +1 -1
- package/dist-esm/src/utils/constants/applicationinsights.js +2 -2
- package/dist-esm/src/utils/constants/applicationinsights.js.map +1 -1
- package/dist-esm/src/utils/eventhub.js +2 -2
- package/dist-esm/src/utils/eventhub.js.map +1 -1
- package/dist-esm/src/utils/logUtils.js +12 -12
- package/dist-esm/src/utils/logUtils.js.map +1 -1
- package/dist-esm/src/utils/spanUtils.js +55 -47
- package/dist-esm/src/utils/spanUtils.js.map +1 -1
- package/package.json +27 -30
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"longIntervalStatsbeatMetrics.js","sourceRoot":"","sources":["../../../../src/export/statsbeat/longIntervalStatsbeatMetrics.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EACL,IAAI,GAKL,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAgB,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EACL,aAAa,EACb,6BAA6B,GAE9B,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,MAAM,2CAA2C,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAGlB,oBAAoB,GAErB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,6BAA6B,E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AO,EACrB,IAAI,EAAE,oBAAoB,CAAC,OAAO,GACnC,CAAC;YACF,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,qBAAqB,EAAE,CAAC,oBAAO,UAAU,EAAG,CAAC;QAC7E,CAAC;IACH,CAAC;IAEO,cAAc,CAAC,gBAAkC;QACvD,MAAM,UAAU,mCAAQ,IAAI,CAAC,gBAAgB,GAAK,IAAI,CAAC,gBAAgB,CAAE,CAAC;QAC1E,gBAAgB,CAAC,OAAO,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;IAC1C,CAAC;IAEM,QAAQ;QACb,OAAO,IAAI,CAAC,kCAAkC,CAAC,QAAQ,EAAE,CAAC;IAC5D,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,OAAyB;IACnD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,QAAQ,GAAG,IAAI,4BAA4B,CAAC,OAAO,CAAC,CAAC;IACvD,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n diag,\n BatchObservableResult,\n ObservableGauge,\n ObservableResult,\n Meter,\n} from \"@opentelemetry/api\";\nimport { ExportResult, ExportResultCode } from \"@opentelemetry/core\";\nimport {\n MeterProvider,\n PeriodicExportingMetricReader,\n PeriodicExportingMetricReaderOptions,\n} from \"@opentelemetry/sdk-metrics\";\nimport { AzureMonitorExporterOptions } from \"../../index\";\nimport * as ai from \"../../utils/constants/applicationinsights\";\nimport { StatsbeatMetrics } from \"./statsbeatMetrics\";\nimport {\n StatsbeatCounter,\n STATSBEAT_LANGUAGE,\n CommonStatsbeatProperties,\n AttachStatsbeatProperties,\n StatsbeatFeatureType,\n StatsbeatOptions,\n} from \"./types\";\nimport { AzureMonitorStatsbeatExporter } from \"./statsbeatExporter\";\n\nlet instance: LongIntervalStatsbeatMetrics | null = null;\n\n/**\n * Long Interval Statsbeat Metrics\n * @internal\n */\nclass LongIntervalStatsbeatMetrics extends StatsbeatMetrics {\n private AZURE_MONITOR_STATSBEAT_FEATURES = process.env.AZURE_MONITOR_STATSBEAT_FEATURES;\n private statsCollectionLongInterval: number = 86400000; // 1 day\n // Custom dimensions\n private cikey: string;\n private runtimeVersion: string;\n private language: string;\n private version: string;\n private attach: string = \"Manual\";\n\n private commonProperties: CommonStatsbeatProperties;\n private attachProperties: AttachStatsbeatProperties;\n\n private feature: number = 0;\n private instrumentation: number = 0;\n\n private longIntervalStatsbeatMeterProvider: MeterProvider;\n private longIntervalAzureExporter: AzureMonitorStatsbeatExporter;\n private longIntervalMetricReader: PeriodicExportingMetricReader;\n private longIntervalStatsbeatMeter: Meter;\n\n // Network Attributes\n private connectionString: string;\n\n // Observable Gauges\n private featureStatsbeatGauge: ObservableGauge;\n private attachStatsbeatGauge: ObservableGauge;\n\n public isInitialized: boolean = false;\n\n constructor(options: StatsbeatOptions) {\n super();\n this.connectionString = super.getConnectionString(options.endpointUrl);\n const exporterConfig: AzureMonitorExporterOptions = {\n connectionString: this.connectionString,\n };\n\n if (this.AZURE_MONITOR_STATSBEAT_FEATURES) {\n try {\n this.feature = JSON.parse(this.AZURE_MONITOR_STATSBEAT_FEATURES).feature;\n this.instrumentation = JSON.parse(this.AZURE_MONITOR_STATSBEAT_FEATURES).instrumentation;\n } catch (error: any) {\n diag.error(\n `LongIntervalStatsbeat: Failed to parse features/instrumentations (error ${error})`,\n );\n }\n }\n\n this.longIntervalStatsbeatMeterProvider = new MeterProvider();\n this.longIntervalAzureExporter = new AzureMonitorStatsbeatExporter(exporterConfig);\n\n // Export Long Interval Statsbeats every day\n const longIntervalMetricReaderOptions: PeriodicExportingMetricReaderOptions = {\n exporter: this.longIntervalAzureExporter,\n exportIntervalMillis:\n Number(process.env.LONG_INTERVAL_EXPORT_MILLIS) || this.statsCollectionLongInterval, // 1 day\n };\n\n this.longIntervalMetricReader = new PeriodicExportingMetricReader(\n longIntervalMetricReaderOptions,\n );\n this.longIntervalStatsbeatMeterProvider.addMetricReader(this.longIntervalMetricReader);\n this.longIntervalStatsbeatMeter = this.longIntervalStatsbeatMeterProvider.getMeter(\n \"Azure Monitor Long Interval Statsbeat\",\n );\n\n // Assign Common Properties\n this.runtimeVersion = process.version;\n this.language = STATSBEAT_LANGUAGE;\n this.version = ai.packageVersion;\n this.cikey = options.instrumentationKey;\n\n this.featureStatsbeatGauge = this.longIntervalStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.FEATURE,\n );\n this.attachStatsbeatGauge = this.longIntervalStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.ATTACH,\n );\n\n this.commonProperties = {\n os: this.os,\n rp: this.resourceProvider,\n cikey: this.cikey,\n runtimeVersion: this.runtimeVersion,\n language: this.language,\n version: this.version,\n attach: this.attach,\n };\n\n this.attachProperties = {\n rpId: this.resourceIdentifier,\n };\n\n this.isInitialized = true;\n this.initialize();\n }\n\n private async initialize() {\n try {\n await this.getResourceProvider();\n\n // Add long interval observable callbacks\n this.attachStatsbeatGauge.addCallback(this.attachCallback.bind(this));\n this.longIntervalStatsbeatMeter.addBatchObservableCallback(this.featureCallback.bind(this), [\n this.featureStatsbeatGauge,\n ]);\n\n // Export Feature/Attach Statsbeat once upon app initialization\n this.longIntervalAzureExporter.export(\n (await this.longIntervalMetricReader.collect()).resourceMetrics,\n (result: ExportResult) => {\n if (result.code !== ExportResultCode.SUCCESS) {\n diag.error(`LongIntervalStatsbeat: metrics export failed (error ${result.error})`);\n }\n },\n );\n } catch (error) {\n diag.debug(\"Call to get the resource provider failed.\");\n }\n }\n\n private featureCallback(observableResult: BatchObservableResult) {\n let attributes;\n if (this.instrumentation) {\n attributes = {\n ...this.commonProperties,\n feature: this.instrumentation,\n type: StatsbeatFeatureType.INSTRUMENTATION,\n };\n observableResult.observe(this.featureStatsbeatGauge, 1, { ...attributes });\n }\n\n if (this.feature) {\n attributes = {\n ...this.commonProperties,\n feature: this.feature,\n type: StatsbeatFeatureType.FEATURE,\n };\n observableResult.observe(this.featureStatsbeatGauge, 1, { ...attributes });\n }\n }\n\n private attachCallback(observableResult: ObservableResult) {\n const attributes = { ...this.commonProperties, ...this.attachProperties };\n observableResult.observe(1, attributes);\n }\n\n public shutdown(): Promise<void> {\n return this.longIntervalStatsbeatMeterProvider.shutdown();\n }\n}\n\n/**\n * Singleton LongIntervalStatsbeatMetrics instance.\n * @internal\n */\nexport function getInstance(options: StatsbeatOptions): LongIntervalStatsbeatMetrics {\n if (!instance) {\n instance = new LongIntervalStatsbeatMetrics(options);\n }\n return instance;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"longIntervalStatsbeatMetrics.js","sourceRoot":"","sources":["../../../../src/export/statsbeat/longIntervalStatsbeatMetrics.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EACL,IAAI,GAKL,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAgB,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EACL,aAAa,EACb,6BAA6B,GAE9B,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,MAAM,2CAA2C,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAGlB,oBAAoB,GAErB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,6BAA6B,EAAE,MAAM,qBAAqB,CAAC;AAEpE,IAAI,QAAQ,GAAwC,IAAI,CAAC;AAEzD;;;GAGG;AACH,MAAM,4BAA6B,SAAQ,gBAAgB;IA6BzD,YAAY,OAAyB;QACnC,KAAK,EAAE,CAAC;QA7BF,gCAA2B,GAAW,QAAQ,CAAC,CAAC,QAAQ;QAMxD,WAAM,GAAW,QAAQ,CAAC;QAK1B,YAAO,GAAW,CAAC,CAAC;QACpB,oBAAe,GAAW,CAAC,CAAC;QAc7B,kBAAa,GAAY,KAAK,CAAC;QAIpC,IAAI,CAAC,gBAA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CAAC,OAAO,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;IAC1C,CAAC;IAEM,QAAQ;QACb,OAAO,IAAI,CAAC,kCAAkC,CAAC,QAAQ,EAAE,CAAC;IAC5D,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,OAAyB;IACnD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,QAAQ,GAAG,IAAI,4BAA4B,CAAC,OAAO,CAAC,CAAC;IACvD,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n diag,\n BatchObservableResult,\n ObservableGauge,\n ObservableResult,\n Meter,\n} from \"@opentelemetry/api\";\nimport { ExportResult, ExportResultCode } from \"@opentelemetry/core\";\nimport {\n MeterProvider,\n PeriodicExportingMetricReader,\n PeriodicExportingMetricReaderOptions,\n} from \"@opentelemetry/sdk-metrics\";\nimport { AzureMonitorExporterOptions } from \"../../index\";\nimport * as ai from \"../../utils/constants/applicationinsights\";\nimport { StatsbeatMetrics } from \"./statsbeatMetrics\";\nimport {\n StatsbeatCounter,\n STATSBEAT_LANGUAGE,\n CommonStatsbeatProperties,\n AttachStatsbeatProperties,\n StatsbeatFeatureType,\n StatsbeatOptions,\n} from \"./types\";\nimport { AzureMonitorStatsbeatExporter } from \"./statsbeatExporter\";\n\nlet instance: LongIntervalStatsbeatMetrics | null = null;\n\n/**\n * Long Interval Statsbeat Metrics\n * @internal\n */\nclass LongIntervalStatsbeatMetrics extends StatsbeatMetrics {\n private statsCollectionLongInterval: number = 86400000; // 1 day\n // Custom dimensions\n private cikey: string;\n private runtimeVersion: string;\n private language: string;\n private version: string;\n private attach: string = \"Manual\";\n\n private commonProperties: CommonStatsbeatProperties;\n private attachProperties: AttachStatsbeatProperties;\n\n private feature: number = 0;\n private instrumentation: number = 0;\n\n private longIntervalStatsbeatMeterProvider: MeterProvider;\n private longIntervalAzureExporter: AzureMonitorStatsbeatExporter;\n private longIntervalMetricReader: PeriodicExportingMetricReader;\n private longIntervalStatsbeatMeter: Meter;\n\n // Network Attributes\n private connectionString: string;\n\n // Observable Gauges\n private featureStatsbeatGauge: ObservableGauge;\n private attachStatsbeatGauge: ObservableGauge;\n\n public isInitialized: boolean = false;\n\n constructor(options: StatsbeatOptions) {\n super();\n this.connectionString = super.getConnectionString(options.endpointUrl);\n const exporterConfig: AzureMonitorExporterOptions = {\n connectionString: this.connectionString,\n };\n\n this.setFeatures();\n\n this.longIntervalStatsbeatMeterProvider = new MeterProvider();\n this.longIntervalAzureExporter = new AzureMonitorStatsbeatExporter(exporterConfig);\n\n // Export Long Interval Statsbeats every day\n const longIntervalMetricReaderOptions: PeriodicExportingMetricReaderOptions = {\n exporter: this.longIntervalAzureExporter,\n exportIntervalMillis:\n Number(process.env.LONG_INTERVAL_EXPORT_MILLIS) || this.statsCollectionLongInterval, // 1 day\n };\n\n this.longIntervalMetricReader = new PeriodicExportingMetricReader(\n longIntervalMetricReaderOptions,\n );\n this.longIntervalStatsbeatMeterProvider.addMetricReader(this.longIntervalMetricReader);\n this.longIntervalStatsbeatMeter = this.longIntervalStatsbeatMeterProvider.getMeter(\n \"Azure Monitor Long Interval Statsbeat\",\n );\n\n // Assign Common Properties\n this.runtimeVersion = process.version;\n this.language = STATSBEAT_LANGUAGE;\n this.version = ai.packageVersion;\n this.cikey = options.instrumentationKey;\n\n this.featureStatsbeatGauge = this.longIntervalStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.FEATURE,\n );\n this.attachStatsbeatGauge = this.longIntervalStatsbeatMeter.createObservableGauge(\n StatsbeatCounter.ATTACH,\n );\n\n this.commonProperties = {\n os: this.os,\n rp: this.resourceProvider,\n cikey: this.cikey,\n runtimeVersion: this.runtimeVersion,\n language: this.language,\n version: this.version,\n attach: this.attach,\n };\n\n this.attachProperties = {\n rpId: this.resourceIdentifier,\n };\n\n this.isInitialized = true;\n this.initialize();\n }\n\n private async initialize() {\n try {\n await this.getResourceProvider();\n\n // Add long interval observable callbacks\n this.attachStatsbeatGauge.addCallback(this.attachCallback.bind(this));\n this.longIntervalStatsbeatMeter.addBatchObservableCallback(\n this.getEnvironmentStatus.bind(this),\n [this.featureStatsbeatGauge],\n );\n\n // Export Feature/Attach Statsbeat once upon app initialization\n this.longIntervalAzureExporter.export(\n (await this.longIntervalMetricReader.collect()).resourceMetrics,\n (result: ExportResult) => {\n if (result.code !== ExportResultCode.SUCCESS) {\n diag.error(`LongIntervalStatsbeat: metrics export failed (error ${result.error})`);\n }\n },\n );\n } catch (error) {\n diag.debug(\"Call to get the resource provider failed.\");\n }\n }\n\n private getEnvironmentStatus(observableResult: BatchObservableResult) {\n this.setFeatures();\n let attributes;\n if (this.instrumentation) {\n attributes = {\n ...this.commonProperties,\n feature: this.instrumentation,\n type: StatsbeatFeatureType.INSTRUMENTATION,\n };\n observableResult.observe(this.featureStatsbeatGauge, 1, { ...attributes });\n }\n\n if (this.feature) {\n attributes = {\n ...this.commonProperties,\n feature: this.feature,\n type: StatsbeatFeatureType.FEATURE,\n };\n observableResult.observe(this.featureStatsbeatGauge, 1, { ...attributes });\n }\n }\n\n private setFeatures() {\n let statsbeatFeatures = process.env.AZURE_MONITOR_STATSBEAT_FEATURES;\n if (statsbeatFeatures) {\n try {\n this.feature = JSON.parse(statsbeatFeatures).feature;\n this.instrumentation = JSON.parse(statsbeatFeatures).instrumentation;\n } catch (error: any) {\n diag.error(\n `LongIntervalStatsbeat: Failed to parse features/instrumentations (error ${error})`,\n );\n }\n }\n }\n\n private attachCallback(observableResult: ObservableResult) {\n const attributes = { ...this.commonProperties, ...this.attachProperties };\n observableResult.observe(1, attributes);\n }\n\n public shutdown(): Promise<void> {\n return this.longIntervalStatsbeatMeterProvider.shutdown();\n }\n}\n\n/**\n * Singleton LongIntervalStatsbeatMetrics instance.\n * @internal\n */\nexport function getInstance(options: StatsbeatOptions): LongIntervalStatsbeatMetrics {\n if (!instance) {\n instance = new LongIntervalStatsbeatMetrics(options);\n }\n return instance;\n}\n"]}
|
|
@@ -22,7 +22,7 @@ export class ApplicationInsightsClient extends coreClient.ServiceClient {
|
|
|
22
22
|
const defaults = {
|
|
23
23
|
requestContentType: "application/json; charset=utf-8",
|
|
24
24
|
};
|
|
25
|
-
const packageDetails = `azsdk-js-monitor-opentelemetry-exporter/1.0.0-beta.
|
|
25
|
+
const packageDetails = `azsdk-js-monitor-opentelemetry-exporter/1.0.0-beta.22`;
|
|
26
26
|
const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
|
|
27
27
|
? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
|
|
28
28
|
: `${packageDetails}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applicationInsightsClient.js","sourceRoot":"","sources":["../../../src/generated/applicationInsightsClient.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,UAAU,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,UAAU,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAC;AAQ5C,MAAM,OAAO,yBAA0B,SAAQ,UAAU,CAAC,aAAa;IAGrE;;;OAGG;IACH,YAAY,OAAiD;;QAC3D,0CAA0C;QAC1C,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,GAAG,EAAE,CAAC;QACf,CAAC;QACD,MAAM,QAAQ,GAA4C;YACxD,kBAAkB,EAAE,iCAAiC;SACtD,CAAC;QAEF,MAAM,cAAc,GAAG,uDAAuD,CAAC;QAC/E,MAAM,eAAe,GACnB,OAAO,CAAC,gBAAgB,IAAI,OAAO,CAAC,gBAAgB,CAAC,eAAe;YAClE,CAAC,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAC,eAAe,IAAI,cAAc,EAAE;YACjE,CAAC,CAAC,GAAG,cAAc,EAAE,CAAC;QAE1B,MAAM,mBAAmB,iDACpB,QAAQ,GACR,OAAO,KACV,gB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AI,CAAC;IAChC,gBAAgB,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,UAAU,CAAC,MAAM,CAAC;IAC7D,SAAS,EAAE,MAAM;IACjB,UAAU;CACX,CAAC","sourcesContent":["/*\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * Code generated by Microsoft (R) AutoRest Code Generator.\n * Changes may cause incorrect behavior and will be lost if the code is regenerated.\n */\n\nimport * as coreClient from \"@azure/core-client\";\nimport * as Parameters from \"./models/parameters\";\nimport * as Mappers from \"./models/mappers\";\nimport {\n ApplicationInsightsClientOptionalParams,\n TelemetryItem,\n TrackOptionalParams,\n TrackOperationResponse,\n} from \"./models\";\n\nexport class ApplicationInsightsClient extends coreClient.ServiceClient {\n host: string;\n\n /**\n * Initializes a new instance of the ApplicationInsightsClient class.\n * @param options The parameter options\n */\n constructor(options?: ApplicationInsightsClientOptionalParams) {\n // Initializing default values for options\n if (!options) {\n options = {};\n }\n const defaults: ApplicationInsightsClientOptionalParams = {\n requestContentType: \"application/json; charset=utf-8\",\n };\n\n const packageDetails = `azsdk-js-monitor-opentelemetry-exporter/1.0.0-beta.
|
|
1
|
+
{"version":3,"file":"applicationInsightsClient.js","sourceRoot":"","sources":["../../../src/generated/applicationInsightsClient.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,UAAU,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,UAAU,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAC;AAQ5C,MAAM,OAAO,yBAA0B,SAAQ,UAAU,CAAC,aAAa;IAGrE;;;OAGG;IACH,YAAY,OAAiD;;QAC3D,0CAA0C;QAC1C,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,GAAG,EAAE,CAAC;QACf,CAAC;QACD,MAAM,QAAQ,GAA4C;YACxD,kBAAkB,EAAE,iCAAiC;SACtD,CAAC;QAEF,MAAM,cAAc,GAAG,uDAAuD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AAO,EAAE,IAAI;SACd;QACD,GAAG,EAAE;YACH,UAAU,EAAE,OAAO,CAAC,aAAa;YACjC,OAAO,EAAE,IAAI;SACd;QACD,GAAG,EAAE;YACH,UAAU,EAAE,OAAO,CAAC,aAAa;YACjC,OAAO,EAAE,IAAI;SACd;KACF;IACD,WAAW,EAAE,UAAU,CAAC,IAAI;IAC5B,aAAa,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC;IAChC,gBAAgB,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,UAAU,CAAC,MAAM,CAAC;IAC7D,SAAS,EAAE,MAAM;IACjB,UAAU;CACX,CAAC","sourcesContent":["/*\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * Code generated by Microsoft (R) AutoRest Code Generator.\n * Changes may cause incorrect behavior and will be lost if the code is regenerated.\n */\n\nimport * as coreClient from \"@azure/core-client\";\nimport * as Parameters from \"./models/parameters\";\nimport * as Mappers from \"./models/mappers\";\nimport {\n ApplicationInsightsClientOptionalParams,\n TelemetryItem,\n TrackOptionalParams,\n TrackOperationResponse,\n} from \"./models\";\n\nexport class ApplicationInsightsClient extends coreClient.ServiceClient {\n host: string;\n\n /**\n * Initializes a new instance of the ApplicationInsightsClient class.\n * @param options The parameter options\n */\n constructor(options?: ApplicationInsightsClientOptionalParams) {\n // Initializing default values for options\n if (!options) {\n options = {};\n }\n const defaults: ApplicationInsightsClientOptionalParams = {\n requestContentType: \"application/json; charset=utf-8\",\n };\n\n const packageDetails = `azsdk-js-monitor-opentelemetry-exporter/1.0.0-beta.22`;\n const userAgentPrefix =\n options.userAgentOptions && options.userAgentOptions.userAgentPrefix\n ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`\n : `${packageDetails}`;\n\n const optionsWithDefaults = {\n ...defaults,\n ...options,\n userAgentOptions: {\n userAgentPrefix,\n },\n endpoint: options.endpoint ?? options.baseUri ?? \"{Host}/v2.1\",\n };\n super(optionsWithDefaults);\n\n // Assigning values to Constant parameters\n this.host = options.host || \"https://dc.services.visualstudio.com\";\n }\n\n /**\n * This operation sends a sequence of telemetry events that will be monitored by Azure Monitor.\n * @param body The list of telemetry events to track.\n * @param options The options parameters.\n */\n track(\n body: TelemetryItem[],\n options?: TrackOptionalParams,\n ): Promise<TrackOperationResponse> {\n return this.sendOperationRequest({ body, options }, trackOperationSpec);\n }\n}\n// Operation Specifications\nconst serializer = coreClient.createSerializer(Mappers, /* isXml */ false);\n\nconst trackOperationSpec: coreClient.OperationSpec = {\n path: \"/track\",\n httpMethod: \"POST\",\n responses: {\n 200: {\n bodyMapper: Mappers.TrackResponse,\n },\n 206: {\n bodyMapper: Mappers.TrackResponse,\n },\n 400: {\n bodyMapper: Mappers.TrackResponse,\n isError: true,\n },\n 402: {\n bodyMapper: Mappers.TrackResponse,\n isError: true,\n },\n 429: {\n bodyMapper: Mappers.TrackResponse,\n isError: true,\n },\n 500: {\n bodyMapper: Mappers.TrackResponse,\n isError: true,\n },\n 503: {\n bodyMapper: Mappers.TrackResponse,\n isError: true,\n },\n },\n requestBody: Parameters.body,\n urlParameters: [Parameters.host],\n headerParameters: [Parameters.contentType, Parameters.accept],\n mediaType: \"json\",\n serializer,\n};\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT license.
|
|
3
3
|
import os from "os";
|
|
4
|
-
import {
|
|
4
|
+
import { SEMRESATTRS_DEVICE_ID, SEMRESATTRS_DEVICE_MODEL_NAME, SEMRESATTRS_SERVICE_VERSION, SEMRESATTRS_K8S_POD_NAME, SEMRESATTRS_SERVICE_INSTANCE_ID, DBSYSTEMVALUES_DB2, DBSYSTEMVALUES_DERBY, DBSYSTEMVALUES_MARIADB, DBSYSTEMVALUES_MSSQL, DBSYSTEMVALUES_ORACLE, DBSYSTEMVALUES_SQLITE, DBSYSTEMVALUES_OTHER_SQL, DBSYSTEMVALUES_HSQLDB, DBSYSTEMVALUES_H2, SEMATTRS_HTTP_METHOD, SEMATTRS_HTTP_URL, SEMATTRS_HTTP_SCHEME, SEMATTRS_HTTP_TARGET, SEMATTRS_HTTP_HOST, SEMATTRS_NET_PEER_PORT, SEMATTRS_NET_PEER_NAME, SEMATTRS_NET_PEER_IP, SEMATTRS_PEER_SERVICE, SEMRESATTRS_SERVICE_NAME, SEMRESATTRS_SERVICE_NAMESPACE, SEMRESATTRS_K8S_DEPLOYMENT_NAME, SEMRESATTRS_K8S_REPLICASET_NAME, SEMRESATTRS_K8S_STATEFULSET_NAME, SEMRESATTRS_K8S_JOB_NAME, SEMRESATTRS_K8S_CRONJOB_NAME, SEMRESATTRS_K8S_DAEMONSET_NAME, SEMRESATTRS_TELEMETRY_SDK_VERSION, SEMRESATTRS_TELEMETRY_SDK_LANGUAGE, SEMRESATTRS_TELEMETRY_SDK_NAME, } from "@opentelemetry/semantic-conventions";
|
|
5
5
|
import { getInstance } from "../platform";
|
|
6
6
|
import { KnownContextTagKeys } from "../generated";
|
|
7
7
|
import { hrTimeToNanoseconds } from "@opentelemetry/core";
|
|
@@ -14,9 +14,14 @@ export function createTagsFromResource(resource) {
|
|
|
14
14
|
if (resource && resource.attributes) {
|
|
15
15
|
tags[KnownContextTagKeys.AiCloudRole] = getCloudRole(resource);
|
|
16
16
|
tags[KnownContextTagKeys.AiCloudRoleInstance] = getCloudRoleInstance(resource);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
if (resource.attributes[SEMRESATTRS_DEVICE_ID]) {
|
|
18
|
+
tags[KnownContextTagKeys.AiDeviceId] = String(resource.attributes[SEMRESATTRS_DEVICE_ID]);
|
|
19
|
+
}
|
|
20
|
+
if (resource.attributes[SEMRESATTRS_DEVICE_MODEL_NAME]) {
|
|
21
|
+
tags[KnownContextTagKeys.AiDeviceModel] = String(resource.attributes[SEMRESATTRS_DEVICE_MODEL_NAME]);
|
|
22
|
+
}
|
|
23
|
+
if (resource.attributes[SEMRESATTRS_SERVICE_VERSION]) {
|
|
24
|
+
tags[KnownContextTagKeys.AiApplicationVer] = String(resource.attributes[SEMRESATTRS_SERVICE_VERSION]);
|
|
20
25
|
}
|
|
21
26
|
}
|
|
22
27
|
return tags;
|
|
@@ -24,8 +29,8 @@ export function createTagsFromResource(resource) {
|
|
|
24
29
|
function getCloudRole(resource) {
|
|
25
30
|
let cloudRole = "";
|
|
26
31
|
// Service attributes
|
|
27
|
-
const serviceName = resource.attributes[
|
|
28
|
-
const serviceNamespace = resource.attributes[
|
|
32
|
+
const serviceName = resource.attributes[SEMRESATTRS_SERVICE_NAME];
|
|
33
|
+
const serviceNamespace = resource.attributes[SEMRESATTRS_SERVICE_NAMESPACE];
|
|
29
34
|
if (serviceName) {
|
|
30
35
|
// Custom Service name provided by customer is highest precedence
|
|
31
36
|
if (!String(serviceName).startsWith("unknown_service")) {
|
|
@@ -47,27 +52,27 @@ function getCloudRole(resource) {
|
|
|
47
52
|
}
|
|
48
53
|
}
|
|
49
54
|
// Kubernetes attributes should take precedence
|
|
50
|
-
const kubernetesDeploymentName = resource.attributes[
|
|
55
|
+
const kubernetesDeploymentName = resource.attributes[SEMRESATTRS_K8S_DEPLOYMENT_NAME];
|
|
51
56
|
if (kubernetesDeploymentName) {
|
|
52
57
|
return String(kubernetesDeploymentName);
|
|
53
58
|
}
|
|
54
|
-
const kuberneteReplicasetName = resource.attributes[
|
|
59
|
+
const kuberneteReplicasetName = resource.attributes[SEMRESATTRS_K8S_REPLICASET_NAME];
|
|
55
60
|
if (kuberneteReplicasetName) {
|
|
56
61
|
return String(kuberneteReplicasetName);
|
|
57
62
|
}
|
|
58
|
-
const kubernetesStatefulSetName = resource.attributes[
|
|
63
|
+
const kubernetesStatefulSetName = resource.attributes[SEMRESATTRS_K8S_STATEFULSET_NAME];
|
|
59
64
|
if (kubernetesStatefulSetName) {
|
|
60
65
|
return String(kubernetesStatefulSetName);
|
|
61
66
|
}
|
|
62
|
-
const kubernetesJobName = resource.attributes[
|
|
67
|
+
const kubernetesJobName = resource.attributes[SEMRESATTRS_K8S_JOB_NAME];
|
|
63
68
|
if (kubernetesJobName) {
|
|
64
69
|
return String(kubernetesJobName);
|
|
65
70
|
}
|
|
66
|
-
const kubernetesCronjobName = resource.attributes[
|
|
71
|
+
const kubernetesCronjobName = resource.attributes[SEMRESATTRS_K8S_CRONJOB_NAME];
|
|
67
72
|
if (kubernetesCronjobName) {
|
|
68
73
|
return String(kubernetesCronjobName);
|
|
69
74
|
}
|
|
70
|
-
const kubernetesDaemonsetName = resource.attributes[
|
|
75
|
+
const kubernetesDaemonsetName = resource.attributes[SEMRESATTRS_K8S_DAEMONSET_NAME];
|
|
71
76
|
if (kubernetesDaemonsetName) {
|
|
72
77
|
return String(kubernetesDaemonsetName);
|
|
73
78
|
}
|
|
@@ -75,12 +80,12 @@ function getCloudRole(resource) {
|
|
|
75
80
|
}
|
|
76
81
|
function getCloudRoleInstance(resource) {
|
|
77
82
|
// Kubernetes attributes should take precedence
|
|
78
|
-
const kubernetesPodName = resource.attributes[
|
|
83
|
+
const kubernetesPodName = resource.attributes[SEMRESATTRS_K8S_POD_NAME];
|
|
79
84
|
if (kubernetesPodName) {
|
|
80
85
|
return String(kubernetesPodName);
|
|
81
86
|
}
|
|
82
87
|
// Service attributes
|
|
83
|
-
const serviceInstanceId = resource.attributes[
|
|
88
|
+
const serviceInstanceId = resource.attributes[SEMRESATTRS_SERVICE_INSTANCE_ID];
|
|
84
89
|
if (serviceInstanceId) {
|
|
85
90
|
return String(serviceInstanceId);
|
|
86
91
|
}
|
|
@@ -88,43 +93,43 @@ function getCloudRoleInstance(resource) {
|
|
|
88
93
|
return os && os.hostname();
|
|
89
94
|
}
|
|
90
95
|
export function isSqlDB(dbSystem) {
|
|
91
|
-
return (dbSystem ===
|
|
92
|
-
dbSystem ===
|
|
93
|
-
dbSystem ===
|
|
94
|
-
dbSystem ===
|
|
95
|
-
dbSystem ===
|
|
96
|
-
dbSystem ===
|
|
97
|
-
dbSystem ===
|
|
98
|
-
dbSystem ===
|
|
99
|
-
dbSystem ===
|
|
96
|
+
return (dbSystem === DBSYSTEMVALUES_DB2 ||
|
|
97
|
+
dbSystem === DBSYSTEMVALUES_DERBY ||
|
|
98
|
+
dbSystem === DBSYSTEMVALUES_MARIADB ||
|
|
99
|
+
dbSystem === DBSYSTEMVALUES_MSSQL ||
|
|
100
|
+
dbSystem === DBSYSTEMVALUES_ORACLE ||
|
|
101
|
+
dbSystem === DBSYSTEMVALUES_SQLITE ||
|
|
102
|
+
dbSystem === DBSYSTEMVALUES_OTHER_SQL ||
|
|
103
|
+
dbSystem === DBSYSTEMVALUES_HSQLDB ||
|
|
104
|
+
dbSystem === DBSYSTEMVALUES_H2);
|
|
100
105
|
}
|
|
101
106
|
export function getUrl(attributes) {
|
|
102
107
|
if (!attributes) {
|
|
103
108
|
return "";
|
|
104
109
|
}
|
|
105
|
-
const httpMethod = attributes[
|
|
110
|
+
const httpMethod = attributes[SEMATTRS_HTTP_METHOD];
|
|
106
111
|
if (httpMethod) {
|
|
107
|
-
const httpUrl = attributes[
|
|
112
|
+
const httpUrl = attributes[SEMATTRS_HTTP_URL];
|
|
108
113
|
if (httpUrl) {
|
|
109
114
|
return String(httpUrl);
|
|
110
115
|
}
|
|
111
116
|
else {
|
|
112
|
-
const httpScheme = attributes[
|
|
113
|
-
const httpTarget = attributes[
|
|
117
|
+
const httpScheme = attributes[SEMATTRS_HTTP_SCHEME];
|
|
118
|
+
const httpTarget = attributes[SEMATTRS_HTTP_TARGET];
|
|
114
119
|
if (httpScheme && httpTarget) {
|
|
115
|
-
const httpHost = attributes[
|
|
120
|
+
const httpHost = attributes[SEMATTRS_HTTP_HOST];
|
|
116
121
|
if (httpHost) {
|
|
117
122
|
return `${httpScheme}://${httpHost}${httpTarget}`;
|
|
118
123
|
}
|
|
119
124
|
else {
|
|
120
|
-
const netPeerPort = attributes[
|
|
125
|
+
const netPeerPort = attributes[SEMATTRS_NET_PEER_PORT];
|
|
121
126
|
if (netPeerPort) {
|
|
122
|
-
const netPeerName = attributes[
|
|
127
|
+
const netPeerName = attributes[SEMATTRS_NET_PEER_NAME];
|
|
123
128
|
if (netPeerName) {
|
|
124
129
|
return `${httpScheme}://${netPeerName}:${netPeerPort}${httpTarget}`;
|
|
125
130
|
}
|
|
126
131
|
else {
|
|
127
|
-
const netPeerIp = attributes[
|
|
132
|
+
const netPeerIp = attributes[SEMATTRS_NET_PEER_IP];
|
|
128
133
|
if (netPeerIp) {
|
|
129
134
|
return `${httpScheme}://${netPeerIp}:${netPeerPort}${httpTarget}`;
|
|
130
135
|
}
|
|
@@ -140,11 +145,11 @@ export function getDependencyTarget(attributes) {
|
|
|
140
145
|
if (!attributes) {
|
|
141
146
|
return "";
|
|
142
147
|
}
|
|
143
|
-
const peerService = attributes[
|
|
144
|
-
const httpHost = attributes[
|
|
145
|
-
const httpUrl = attributes[
|
|
146
|
-
const netPeerName = attributes[
|
|
147
|
-
const netPeerIp = attributes[
|
|
148
|
+
const peerService = attributes[SEMATTRS_PEER_SERVICE];
|
|
149
|
+
const httpHost = attributes[SEMATTRS_HTTP_HOST];
|
|
150
|
+
const httpUrl = attributes[SEMATTRS_HTTP_URL];
|
|
151
|
+
const netPeerName = attributes[SEMATTRS_NET_PEER_NAME];
|
|
152
|
+
const netPeerIp = attributes[SEMATTRS_NET_PEER_IP];
|
|
148
153
|
if (peerService) {
|
|
149
154
|
return String(peerService);
|
|
150
155
|
}
|
|
@@ -169,9 +174,9 @@ export function createResourceMetricEnvelope(resource, instrumentationKey) {
|
|
|
169
174
|
for (const key of Object.keys(resource.attributes)) {
|
|
170
175
|
// Avoid duplication ignoring fields already mapped.
|
|
171
176
|
if (!(key.startsWith("_MS.") ||
|
|
172
|
-
key ===
|
|
173
|
-
key ===
|
|
174
|
-
key ===
|
|
177
|
+
key === SEMRESATTRS_TELEMETRY_SDK_VERSION ||
|
|
178
|
+
key === SEMRESATTRS_TELEMETRY_SDK_LANGUAGE ||
|
|
179
|
+
key === SEMRESATTRS_TELEMETRY_SDK_NAME)) {
|
|
175
180
|
resourceAttributes[key] = resource.attributes[key];
|
|
176
181
|
}
|
|
177
182
|
}
|
|
@@ -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,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,QAAQ,CAAC,UAAU,EAAE,CAAC;QACpC,IAAI,CAAC,mBAAmB,CAAC,WAAW,CAAC,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;QAC/D,IAAI,CAAC,mBAAmB,CAAC,mBAAmB,CAAC,GAAG,oBAAoB,CAAC,QAAQ,CAAC,CAAC;QAC/E,MAAM,SAAS,GAAG,QAAQ,CAAC,UAAU,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC;QACrE,IAAI,SAAS,EAAE,CAAC;YACd,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,YAA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AAE,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
|
+
{"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,qBAAqB,EACrB,6BAA6B,EAC7B,2BAA2B,EAC3B,wBAAwB,EACxB,+BAA+B,EAC/B,kBAAkB,EAClB,oBAAoB,EACpB,sBAAsB,EACtB,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,wBAAwB,EACxB,qBAAqB,EACrB,iBAAiB,EACjB,oBAAoB,EACpB,iBAAiB,EACjB,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,oBAAoB,EACpB,qBAAqB,EACrB,wBAAwB,EACxB,6BAA6B,EAC7B,+BAA+B,EAC/B,+BAA+B,EAC/B,gCAAgC,EAChC,wBAAwB,EACxB,4BAA4B,EAC5B,8BAA8B,EAC9B,iCAAiC,EACjC,kCAAkC,EAClC,8BAA8B,GAC/B,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAAE,WAAW,E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,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;YACnD,oDAAoD;YACpD,IACE,CAAC,CACC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC;gBACtB,GAAG,KAAK,iCAAiC;gBACzC,GAAG,KAAK,kCAAkC;gBAC1C,GAAG,KAAK,8BAA8B,CACvC,EACD,CAAC;gBACD,kBAAkB,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAW,CAAC;YAC/D,CAAC;QACH,CAAC;QACD,yDAAyD;QACzD,IAAI,MAAM,CAAC,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 SEMRESATTRS_DEVICE_ID,\n SEMRESATTRS_DEVICE_MODEL_NAME,\n SEMRESATTRS_SERVICE_VERSION,\n SEMRESATTRS_K8S_POD_NAME,\n SEMRESATTRS_SERVICE_INSTANCE_ID,\n DBSYSTEMVALUES_DB2,\n DBSYSTEMVALUES_DERBY,\n DBSYSTEMVALUES_MARIADB,\n DBSYSTEMVALUES_MSSQL,\n DBSYSTEMVALUES_ORACLE,\n DBSYSTEMVALUES_SQLITE,\n DBSYSTEMVALUES_OTHER_SQL,\n DBSYSTEMVALUES_HSQLDB,\n DBSYSTEMVALUES_H2,\n SEMATTRS_HTTP_METHOD,\n SEMATTRS_HTTP_URL,\n SEMATTRS_HTTP_SCHEME,\n SEMATTRS_HTTP_TARGET,\n SEMATTRS_HTTP_HOST,\n SEMATTRS_NET_PEER_PORT,\n SEMATTRS_NET_PEER_NAME,\n SEMATTRS_NET_PEER_IP,\n SEMATTRS_PEER_SERVICE,\n SEMRESATTRS_SERVICE_NAME,\n SEMRESATTRS_SERVICE_NAMESPACE,\n SEMRESATTRS_K8S_DEPLOYMENT_NAME,\n SEMRESATTRS_K8S_REPLICASET_NAME,\n SEMRESATTRS_K8S_STATEFULSET_NAME,\n SEMRESATTRS_K8S_JOB_NAME,\n SEMRESATTRS_K8S_CRONJOB_NAME,\n SEMRESATTRS_K8S_DAEMONSET_NAME,\n SEMRESATTRS_TELEMETRY_SDK_VERSION,\n SEMRESATTRS_TELEMETRY_SDK_LANGUAGE,\n SEMRESATTRS_TELEMETRY_SDK_NAME,\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 if (resource.attributes[SEMRESATTRS_DEVICE_ID]) {\n tags[KnownContextTagKeys.AiDeviceId] = String(resource.attributes[SEMRESATTRS_DEVICE_ID]);\n }\n if (resource.attributes[SEMRESATTRS_DEVICE_MODEL_NAME]) {\n tags[KnownContextTagKeys.AiDeviceModel] = String(\n resource.attributes[SEMRESATTRS_DEVICE_MODEL_NAME],\n );\n }\n if (resource.attributes[SEMRESATTRS_SERVICE_VERSION]) {\n tags[KnownContextTagKeys.AiApplicationVer] = String(\n resource.attributes[SEMRESATTRS_SERVICE_VERSION],\n );\n }\n }\n return tags;\n}\n\nfunction getCloudRole(resource: Resource): string {\n let cloudRole = \"\";\n // Service attributes\n const serviceName = resource.attributes[SEMRESATTRS_SERVICE_NAME];\n const serviceNamespace = resource.attributes[SEMRESATTRS_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 = resource.attributes[SEMRESATTRS_K8S_DEPLOYMENT_NAME];\n if (kubernetesDeploymentName) {\n return String(kubernetesDeploymentName);\n }\n const kuberneteReplicasetName = resource.attributes[SEMRESATTRS_K8S_REPLICASET_NAME];\n if (kuberneteReplicasetName) {\n return String(kuberneteReplicasetName);\n }\n const kubernetesStatefulSetName = resource.attributes[SEMRESATTRS_K8S_STATEFULSET_NAME];\n if (kubernetesStatefulSetName) {\n return String(kubernetesStatefulSetName);\n }\n const kubernetesJobName = resource.attributes[SEMRESATTRS_K8S_JOB_NAME];\n if (kubernetesJobName) {\n return String(kubernetesJobName);\n }\n const kubernetesCronjobName = resource.attributes[SEMRESATTRS_K8S_CRONJOB_NAME];\n if (kubernetesCronjobName) {\n return String(kubernetesCronjobName);\n }\n const kubernetesDaemonsetName = resource.attributes[SEMRESATTRS_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[SEMRESATTRS_K8S_POD_NAME];\n if (kubernetesPodName) {\n return String(kubernetesPodName);\n }\n // Service attributes\n const serviceInstanceId = resource.attributes[SEMRESATTRS_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[SEMATTRS_HTTP_METHOD];\n if (httpMethod) {\n const httpUrl = attributes[SEMATTRS_HTTP_URL];\n if (httpUrl) {\n return String(httpUrl);\n } else {\n const httpScheme = attributes[SEMATTRS_HTTP_SCHEME];\n const httpTarget = attributes[SEMATTRS_HTTP_TARGET];\n if (httpScheme && httpTarget) {\n const httpHost = attributes[SEMATTRS_HTTP_HOST];\n if (httpHost) {\n return `${httpScheme}://${httpHost}${httpTarget}`;\n } else {\n const netPeerPort = attributes[SEMATTRS_NET_PEER_PORT];\n if (netPeerPort) {\n const netPeerName = attributes[SEMATTRS_NET_PEER_NAME];\n if (netPeerName) {\n return `${httpScheme}://${netPeerName}:${netPeerPort}${httpTarget}`;\n } else {\n const netPeerIp = attributes[SEMATTRS_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[SEMATTRS_PEER_SERVICE];\n const httpHost = attributes[SEMATTRS_HTTP_HOST];\n const httpUrl = attributes[SEMATTRS_HTTP_URL];\n const netPeerName = attributes[SEMATTRS_NET_PEER_NAME];\n const netPeerIp = attributes[SEMATTRS_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 === SEMRESATTRS_TELEMETRY_SDK_VERSION ||\n key === SEMRESATTRS_TELEMETRY_SDK_LANGUAGE ||\n key === SEMRESATTRS_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,5 +1,5 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT license
|
|
2
|
+
// Licensed under the MIT license
|
|
3
3
|
/**
|
|
4
4
|
* AI MS Links.
|
|
5
5
|
* @internal
|
|
@@ -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.22";
|
|
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,
|
|
1
|
+
{"version":3,"file":"applicationinsights.js","sourceRoot":"","sources":["../../../../src/utils/constants/applicationinsights.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,iCAAiC;AAEjC;;;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.22\";\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"]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Licensed under the MIT license.
|
|
3
3
|
import { SpanKind } from "@opentelemetry/api";
|
|
4
4
|
import { hrTimeToMilliseconds } from "@opentelemetry/core";
|
|
5
|
-
import {
|
|
5
|
+
import { SEMATTRS_NET_PEER_NAME } from "@opentelemetry/semantic-conventions";
|
|
6
6
|
import { TIME_SINCE_ENQUEUED, ENQUEUED_TIME } from "./constants/applicationinsights";
|
|
7
7
|
import { AzNamespace, MessageBusDestination, } from "./constants/span/azAttributes";
|
|
8
8
|
/**
|
|
@@ -29,7 +29,7 @@ const getTimeSinceEnqueued = (span) => {
|
|
|
29
29
|
*/
|
|
30
30
|
export const parseEventHubSpan = (span, baseData) => {
|
|
31
31
|
const namespace = span.attributes[AzNamespace];
|
|
32
|
-
const peerAddress = (span.attributes[
|
|
32
|
+
const peerAddress = (span.attributes[SEMATTRS_NET_PEER_NAME] ||
|
|
33
33
|
span.attributes["peer.address"] ||
|
|
34
34
|
"unknown").replace(/\/$/g, ""); // remove trailing "/"
|
|
35
35
|
const messageBusDestination = (span.attributes[MessageBusDestination] || "unknown");
|
|
@@ -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,oB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AG,CAC/B,IAAkB,EAClB,QAA4C,EACtC,EAAE;IACR,MAAM,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC,WAAW,CAA6B,CAAC;IAC3E,MAAM,WAAW,GACf,CAAC,IAAI,CAAC,UAAU,CAAC,sBAAsB,CAAC;QACtC,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC;QAC/B,SAAS,CACZ,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,sBAAsB;IAC7C,MAAM,qBAAqB,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,qBAAqB,CAAC,IAAI,SAAS,CAAW,CAAC;IAE9F,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,QAAQ,CAAC,MAAM;YAClB,QAAQ,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 { SEMATTRS_NET_PEER_NAME } 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[SEMATTRS_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"]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Licensed under the MIT license.
|
|
3
3
|
import { KnownContextTagKeys, KnownSeverityLevel, } from "../generated";
|
|
4
4
|
import { createTagsFromResource, hrTimeToDate } from "./common";
|
|
5
|
-
import {
|
|
5
|
+
import { SEMATTRS_EXCEPTION_MESSAGE, SEMATTRS_EXCEPTION_STACKTRACE, SEMATTRS_EXCEPTION_TYPE, } from "@opentelemetry/semantic-conventions";
|
|
6
6
|
import { diag } from "@opentelemetry/api";
|
|
7
7
|
import { ApplicationInsightsAvailabilityBaseType, ApplicationInsightsAvailabilityName, ApplicationInsightsBaseType, ApplicationInsightsEventBaseType, ApplicationInsightsEventName, ApplicationInsightsExceptionBaseType, ApplicationInsightsExceptionName, ApplicationInsightsMessageBaseType, ApplicationInsightsMessageName, ApplicationInsightsPageViewBaseType, ApplicationInsightsPageViewName, } from "./constants/applicationinsights";
|
|
8
8
|
/**
|
|
@@ -20,10 +20,10 @@ export function logToEnvelope(log, ikey) {
|
|
|
20
20
|
let baseData;
|
|
21
21
|
if (!log.attributes[ApplicationInsightsBaseType]) {
|
|
22
22
|
// Get Exception attributes if available
|
|
23
|
-
const exceptionType = log.attributes[
|
|
23
|
+
const exceptionType = log.attributes[SEMATTRS_EXCEPTION_TYPE];
|
|
24
24
|
if (exceptionType) {
|
|
25
|
-
const exceptionMessage = log.attributes[
|
|
26
|
-
const exceptionStacktrace = log.attributes[
|
|
25
|
+
const exceptionMessage = log.attributes[SEMATTRS_EXCEPTION_MESSAGE];
|
|
26
|
+
const exceptionStacktrace = log.attributes[SEMATTRS_EXCEPTION_STACKTRACE];
|
|
27
27
|
name = ApplicationInsightsExceptionName;
|
|
28
28
|
baseType = ApplicationInsightsExceptionBaseType;
|
|
29
29
|
const exceptionDetails = {
|
|
@@ -92,9 +92,9 @@ function createPropertiesFromLog(log) {
|
|
|
92
92
|
for (const key of Object.keys(log.attributes)) {
|
|
93
93
|
// Avoid duplication ignoring fields already mapped.
|
|
94
94
|
if (!(key.startsWith("_MS.") ||
|
|
95
|
-
key ===
|
|
96
|
-
key ===
|
|
97
|
-
key ===
|
|
95
|
+
key === SEMATTRS_EXCEPTION_TYPE ||
|
|
96
|
+
key === SEMATTRS_EXCEPTION_MESSAGE ||
|
|
97
|
+
key === SEMATTRS_EXCEPTION_STACKTRACE)) {
|
|
98
98
|
properties[key] = log.attributes[key];
|
|
99
99
|
}
|
|
100
100
|
}
|
|
@@ -151,19 +151,19 @@ function getLegacyApplicationInsightsBaseData(log) {
|
|
|
151
151
|
try {
|
|
152
152
|
switch (log.attributes[ApplicationInsightsBaseType]) {
|
|
153
153
|
case ApplicationInsightsAvailabilityBaseType:
|
|
154
|
-
baseData =
|
|
154
|
+
baseData = log.body;
|
|
155
155
|
break;
|
|
156
156
|
case ApplicationInsightsExceptionBaseType:
|
|
157
|
-
baseData =
|
|
157
|
+
baseData = log.body;
|
|
158
158
|
break;
|
|
159
159
|
case ApplicationInsightsMessageBaseType:
|
|
160
|
-
baseData =
|
|
160
|
+
baseData = log.body;
|
|
161
161
|
break;
|
|
162
162
|
case ApplicationInsightsPageViewBaseType:
|
|
163
|
-
baseData =
|
|
163
|
+
baseData = log.body;
|
|
164
164
|
break;
|
|
165
165
|
case ApplicationInsightsEventBaseType:
|
|
166
|
-
baseData =
|
|
166
|
+
baseData = log.body;
|
|
167
167
|
break;
|
|
168
168
|
}
|
|
169
169
|
if (typeof (baseData === null || baseData === void 0 ? void 0 : baseData.message) === "object") {
|
|
@@ -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,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,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC;QACb,IAAI,CAAC;YACH,QAAQ,GAAG,CAAC,UAAU,CAAC,2BAA2B,CAAC,EAAE,CAAC;gBACpD,KAAK,uCAAuC;oBAC1C,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAqB,CAAC;oBACpD,MAAM;gBACR,KAAK,oCAAoC;oBACvC,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAA2B,CAAC;oBAC1D,MAAM;gBACR,KAAK,kCAAkC;oBACrC,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAgB,CAAC;oBAC/C,MAAM;gBACR,KAAK,mCAAmC;oBACtC,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAiB,CAAC;oBAChD,MAAM;gBACR,KAAK,gCAAgC;oBACnC,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAuB,CAAC;oBACtD,MAAM;YACV,CAAC;YACD,IAAI,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"]}
|
|
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,U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C;oBAC1C,QAAQ,GAAG,GAAG,CAAC,IAAwB,CAAC;oBACxC,MAAM;gBACR,KAAK,oCAAoC;oBACvC,QAAQ,GAAG,GAAG,CAAC,IAA8B,CAAC;oBAC9C,MAAM;gBACR,KAAK,kCAAkC;oBACrC,QAAQ,GAAG,GAAG,CAAC,IAAmB,CAAC;oBACnC,MAAM;gBACR,KAAK,mCAAmC;oBACtC,QAAQ,GAAG,GAAG,CAAC,IAAoB,CAAC;oBACpC,MAAM;gBACR,KAAK,gCAAgC;oBACnC,QAAQ,GAAG,GAAG,CAAC,IAA0B,CAAC;oBAC1C,MAAM;YACV,CAAC;YACD,IAAI,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 {\n SEMATTRS_EXCEPTION_MESSAGE,\n SEMATTRS_EXCEPTION_STACKTRACE,\n SEMATTRS_EXCEPTION_TYPE,\n} 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[SEMATTRS_EXCEPTION_TYPE];\n if (exceptionType) {\n const exceptionMessage = log.attributes[SEMATTRS_EXCEPTION_MESSAGE];\n const exceptionStacktrace = log.attributes[SEMATTRS_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 === SEMATTRS_EXCEPTION_TYPE ||\n key === SEMATTRS_EXCEPTION_MESSAGE ||\n key === SEMATTRS_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 = log.body as AvailabilityData;\n break;\n case ApplicationInsightsExceptionBaseType:\n baseData = log.body as TelemetryExceptionData;\n break;\n case ApplicationInsightsMessageBaseType:\n baseData = log.body as MessageData;\n break;\n case ApplicationInsightsPageViewBaseType:\n baseData = log.body as PageViewData;\n break;\n case ApplicationInsightsEventBaseType:\n baseData = 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"]}
|