@azure/monitor-opentelemetry-exporter 1.0.0-beta.28 → 1.0.0-beta.29
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 +56 -47
- package/dist/commonjs/Declarations/Constants.d.ts +20 -0
- package/dist/commonjs/Declarations/Constants.d.ts.map +1 -1
- package/dist/commonjs/Declarations/Constants.js +21 -1
- package/dist/commonjs/Declarations/Constants.js.map +1 -1
- package/dist/commonjs/export/statsbeat/longIntervalStatsbeatMetrics.d.ts.map +1 -1
- package/dist/commonjs/export/statsbeat/longIntervalStatsbeatMetrics.js +2 -1
- package/dist/commonjs/export/statsbeat/longIntervalStatsbeatMetrics.js.map +1 -1
- package/dist/commonjs/export/statsbeat/networkStatsbeatMetrics.d.ts.map +1 -1
- package/dist/commonjs/export/statsbeat/networkStatsbeatMetrics.js +2 -1
- package/dist/commonjs/export/statsbeat/networkStatsbeatMetrics.js.map +1 -1
- package/dist/commonjs/export/statsbeat/statsbeatMetrics.js +1 -1
- package/dist/commonjs/export/statsbeat/statsbeatMetrics.js.map +1 -1
- package/dist/commonjs/export/statsbeat/types.d.ts +5 -0
- package/dist/commonjs/export/statsbeat/types.d.ts.map +1 -1
- package/dist/commonjs/export/statsbeat/types.js +7 -1
- package/dist/commonjs/export/statsbeat/types.js.map +1 -1
- package/dist/commonjs/generated/applicationInsightsClient.js +1 -1
- package/dist/commonjs/generated/applicationInsightsClient.js.map +1 -1
- package/dist/commonjs/tsdoc-metadata.json +1 -1
- package/dist/commonjs/types.d.ts +10 -0
- package/dist/commonjs/types.d.ts.map +1 -1
- package/dist/commonjs/types.js +51 -1
- package/dist/commonjs/types.js.map +1 -1
- package/dist/commonjs/utils/common.d.ts.map +1 -1
- package/dist/commonjs/utils/common.js +13 -12
- package/dist/commonjs/utils/common.js.map +1 -1
- package/dist/commonjs/utils/constants/applicationinsights.d.ts +2 -1
- package/dist/commonjs/utils/constants/applicationinsights.d.ts.map +1 -1
- package/dist/commonjs/utils/constants/applicationinsights.js +3 -2
- package/dist/commonjs/utils/constants/applicationinsights.js.map +1 -1
- package/dist/commonjs/utils/logUtils.d.ts.map +1 -1
- package/dist/commonjs/utils/logUtils.js +43 -31
- package/dist/commonjs/utils/logUtils.js.map +1 -1
- package/dist/commonjs/utils/metricUtils.d.ts +6 -1
- package/dist/commonjs/utils/metricUtils.d.ts.map +1 -1
- package/dist/commonjs/utils/metricUtils.js +43 -1
- package/dist/commonjs/utils/metricUtils.js.map +1 -1
- package/dist/commonjs/utils/spanUtils.d.ts +14 -0
- package/dist/commonjs/utils/spanUtils.d.ts.map +1 -1
- package/dist/commonjs/utils/spanUtils.js +144 -89
- package/dist/commonjs/utils/spanUtils.js.map +1 -1
- package/dist/esm/Declarations/Constants.d.ts +20 -0
- package/dist/esm/Declarations/Constants.d.ts.map +1 -1
- package/dist/esm/Declarations/Constants.js +20 -0
- package/dist/esm/Declarations/Constants.js.map +1 -1
- package/dist/esm/export/statsbeat/longIntervalStatsbeatMetrics.d.ts.map +1 -1
- package/dist/esm/export/statsbeat/longIntervalStatsbeatMetrics.js +2 -1
- package/dist/esm/export/statsbeat/longIntervalStatsbeatMetrics.js.map +1 -1
- package/dist/esm/export/statsbeat/networkStatsbeatMetrics.d.ts.map +1 -1
- package/dist/esm/export/statsbeat/networkStatsbeatMetrics.js +2 -1
- package/dist/esm/export/statsbeat/networkStatsbeatMetrics.js.map +1 -1
- package/dist/esm/export/statsbeat/statsbeatMetrics.js +1 -1
- package/dist/esm/export/statsbeat/statsbeatMetrics.js.map +1 -1
- package/dist/esm/export/statsbeat/types.d.ts +5 -0
- package/dist/esm/export/statsbeat/types.d.ts.map +1 -1
- package/dist/esm/export/statsbeat/types.js +6 -0
- package/dist/esm/export/statsbeat/types.js.map +1 -1
- package/dist/esm/generated/applicationInsightsClient.js +1 -1
- package/dist/esm/generated/applicationInsightsClient.js.map +1 -1
- package/dist/esm/types.d.ts +10 -0
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/types.js +50 -0
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/common.d.ts.map +1 -1
- package/dist/esm/utils/common.js +14 -13
- package/dist/esm/utils/common.js.map +1 -1
- package/dist/esm/utils/constants/applicationinsights.d.ts +2 -1
- package/dist/esm/utils/constants/applicationinsights.d.ts.map +1 -1
- package/dist/esm/utils/constants/applicationinsights.js +2 -1
- package/dist/esm/utils/constants/applicationinsights.js.map +1 -1
- package/dist/esm/utils/logUtils.d.ts.map +1 -1
- package/dist/esm/utils/logUtils.js +44 -32
- package/dist/esm/utils/logUtils.js.map +1 -1
- package/dist/esm/utils/metricUtils.d.ts +6 -1
- package/dist/esm/utils/metricUtils.d.ts.map +1 -1
- package/dist/esm/utils/metricUtils.js +39 -1
- package/dist/esm/utils/metricUtils.js.map +1 -1
- package/dist/esm/utils/spanUtils.d.ts +14 -0
- package/dist/esm/utils/spanUtils.d.ts.map +1 -1
- package/dist/esm/utils/spanUtils.js +135 -92
- package/dist/esm/utils/spanUtils.js.map +1 -1
- package/package.json +18 -18
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logUtils.js","sourceRoot":"","sources":["../../../src/utils/logUtils.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAyClC,sCA6EC;AA1GD,oDAAgF;AAChF,2CAAuF;AAEvF,8EAI6C;AAE7C,0CAAiD;AACjD,4CAA0C;AAC1C,+EAY4C;AAE5C;;;GAGG;AACH,SAAgB,aAAa,CAAC,GAAsB,EAAE,IAAY;IAChE,MAAM,IAAI,GAAG,IAAA,wBAAY,EAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACtC,MAAM,UAAU,GAAG,GAAG,CAAC;IACvB,MAAM,kBAAkB,GAAG,IAAI,CAAC;IAChC,MAAM,IAAI,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC;IACpC,wCAAwC;IACxC,IAAI,CAAC,UAAU,EAAE,YAAY,CAAC,GAAG,uBAAuB,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,0CAAE,YAAY,EAAE,CAAC;QAC9C,YAAY,qBAAS,GAAG,CAAC,IAAsB,CAAC,YAAY,CAAE,CAAC;IACjE,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,SAAS,oCAAoC,CAAC,GAAsB;IAClE,IAAI,QAAQ,GAAkB;QAC5B,OAAO,EAAE,CAAC;KACX,CAAC;IACF,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC;QACb,IAAI,CAAC;YACH,QAAQ,GAAG,CAAC,UAAU,CAAC,oDAA2B,CAAC,EAAE,CAAC;gBACpD,KAAK,gEAAuC;oBAC1C,QAAQ,GAAG,GAAG,CAAC,IAAwB,CAAC;oBACxC,MAAM;gBACR,KAAK,6DAAoC;oBACvC,QAAQ,GAAG,GAAG,CAAC,IAA8B,CAAC;oBAC9C,MAAM;gBACR,KAAK,2DAAkC;oBACrC,QAAQ,GAAG,GAAG,CAAC,IAAmB,CAAC;oBACnC,MAAM;gBACR,KAAK,4DAAmC;oBACtC,QAAQ,GAAG,GAAG,CAAC,IAAoB,CAAC;oBACpC,MAAM;gBACR,KAAK,yDAAgC;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,UAAI,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 type {\n AvailabilityData,\n TelemetryItem as Envelope,\n MessageData,\n MonitorDomain,\n PageViewData,\n TelemetryEventData,\n TelemetryExceptionData,\n TelemetryExceptionDetails,\n} from \"../generated/index.js\";\nimport { KnownContextTagKeys, KnownSeverityLevel } from \"../generated/index.js\";\nimport { createTagsFromResource, hrTimeToDate, serializeAttribute } from \"./common.js\";\nimport type { ReadableLogRecord } from \"@opentelemetry/sdk-logs\";\nimport {\n ATTR_EXCEPTION_MESSAGE,\n ATTR_EXCEPTION_STACKTRACE,\n ATTR_EXCEPTION_TYPE,\n} from \"@opentelemetry/semantic-conventions\";\nimport type { Measurements, Properties, Tags } from \"../types.js\";\nimport { MaxPropertyLengths } from \"../types.js\";\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.js\";\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 // eslint-disable-next-line prefer-const\n let [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[ATTR_EXCEPTION_TYPE];\n if (exceptionType) {\n const exceptionMessage = log.attributes[ATTR_EXCEPTION_MESSAGE];\n const exceptionStacktrace = log.attributes[ATTR_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 measurements = getLegacyApplicationInsightsMeasurements(log);\n if (!baseData) {\n // Failed to parse log\n return;\n }\n }\n // Truncate properties\n if (baseData.message) {\n baseData.message = String(baseData.message).substring(0, MaxPropertyLengths.FIFTEEN_BIT);\n }\n if (properties) {\n for (const key of Object.keys(properties)) {\n properties[key] = String(properties[key]).substring(0, MaxPropertyLengths.THIRTEEN_BIT);\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 if (log.attributes[KnownContextTagKeys.AiOperationName]) {\n tags[KnownContextTagKeys.AiOperationName] = log.attributes[\n KnownContextTagKeys.AiOperationName\n ] as string;\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 === ATTR_EXCEPTION_TYPE ||\n key === ATTR_EXCEPTION_MESSAGE ||\n key === ATTR_EXCEPTION_STACKTRACE ||\n key === (KnownContextTagKeys.AiOperationName as string)\n )\n ) {\n properties[key] = serializeAttribute(log.attributes[key]);\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 getLegacyApplicationInsightsMeasurements(log: ReadableLogRecord): Measurements {\n let measurements: Measurements = {};\n if ((log.body as MonitorDomain)?.measurements) {\n measurements = { ...(log.body as MonitorDomain).measurements };\n }\n return measurements;\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"]}
|
|
1
|
+
{"version":3,"file":"logUtils.js","sourceRoot":"","sources":["../../../src/utils/logUtils.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AA0ClC,sCAwFC;AAtHD,oDAAgF;AAChF,2CAAuF;AAEvF,8EAI6C;AAE7C,0CAAiD;AACjD,4CAA0C;AAC1C,+EAa4C;AAE5C;;;GAGG;AACH,SAAgB,aAAa,CAAC,GAAsB,EAAE,IAAY;IAChE,MAAM,IAAI,GAAG,IAAA,wBAAY,EAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACtC,MAAM,UAAU,GAAG,GAAG,CAAC;IACvB,MAAM,kBAAkB,GAAG,IAAI,CAAC;IAChC,MAAM,IAAI,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC;IACpC,wCAAwC;IACxC,IAAI,CAAC,UAAU,EAAE,YAAY,CAAC,GAAG,uBAAuB,CAAC,GAAG,CAAC,CAAC;IAC9D,IAAI,IAAY,CAAC;IACjB,IAAI,QAAgB,CAAC;IACrB,IAAI,QAAuB,CAAC;IAE5B,MAAM,mBAAmB,GAAG,GAAG,CAAC,UAAU,CAAC,gDAAyB,CAAC,CAAC;IACtE,MAAM,aAAa,GAAG,GAAG,CAAC,UAAU,CAAC,0CAAmB,CAAC,CAA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C,QAAQ,CAAC,OAAO,CAAC,CAAC;YACtD,CAAC;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,UAAI,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 type {\n AvailabilityData,\n TelemetryItem as Envelope,\n MessageData,\n MonitorDomain,\n PageViewData,\n TelemetryEventData,\n TelemetryExceptionData,\n TelemetryExceptionDetails,\n} from \"../generated/index.js\";\nimport { KnownContextTagKeys, KnownSeverityLevel } from \"../generated/index.js\";\nimport { createTagsFromResource, hrTimeToDate, serializeAttribute } from \"./common.js\";\nimport type { ReadableLogRecord } from \"@opentelemetry/sdk-logs\";\nimport {\n ATTR_EXCEPTION_MESSAGE,\n ATTR_EXCEPTION_STACKTRACE,\n ATTR_EXCEPTION_TYPE,\n} from \"@opentelemetry/semantic-conventions\";\nimport type { Measurements, Properties, Tags } from \"../types.js\";\nimport { MaxPropertyLengths } from \"../types.js\";\nimport { diag } from \"@opentelemetry/api\";\nimport {\n ApplicationInsightsAvailabilityBaseType,\n ApplicationInsightsAvailabilityName,\n ApplicationInsightsBaseType,\n ApplicationInsightsCustomEventName,\n ApplicationInsightsEventBaseType,\n ApplicationInsightsEventName,\n ApplicationInsightsExceptionBaseType,\n ApplicationInsightsExceptionName,\n ApplicationInsightsMessageBaseType,\n ApplicationInsightsMessageName,\n ApplicationInsightsPageViewBaseType,\n ApplicationInsightsPageViewName,\n} from \"./constants/applicationinsights.js\";\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 // eslint-disable-next-line prefer-const\n let [properties, measurements] = createPropertiesFromLog(log);\n let name: string;\n let baseType: string;\n let baseData: MonitorDomain;\n\n const exceptionStacktrace = log.attributes[ATTR_EXCEPTION_STACKTRACE];\n const exceptionType = log.attributes[ATTR_EXCEPTION_TYPE];\n const isExceptionType: boolean = !!(exceptionType && exceptionStacktrace) || false;\n const isMessageType: boolean =\n !log.attributes[ApplicationInsightsBaseType] &&\n !log.attributes[ApplicationInsightsCustomEventName] &&\n !exceptionType;\n if (isExceptionType) {\n const exceptionMessage = log.attributes[ATTR_EXCEPTION_MESSAGE];\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 if (log.attributes[ApplicationInsightsCustomEventName]) {\n name = ApplicationInsightsEventName;\n baseType = ApplicationInsightsEventBaseType;\n const eventData: TelemetryEventData = {\n name: String(log.attributes[ApplicationInsightsCustomEventName]),\n version: 2,\n };\n baseData = eventData;\n measurements = getLegacyApplicationInsightsMeasurements(log);\n } else if (isMessageType) {\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 } else {\n // If Legacy Application Insights Log\n baseType = String(log.attributes[ApplicationInsightsBaseType]);\n name = getLegacyApplicationInsightsName(log);\n baseData = getLegacyApplicationInsightsBaseData(log);\n measurements = getLegacyApplicationInsightsMeasurements(log);\n if (!baseData) {\n // Failed to parse log\n return;\n }\n }\n // Truncate properties\n if (baseData.message) {\n baseData.message = String(baseData.message).substring(0, MaxPropertyLengths.FIFTEEN_BIT);\n }\n if (properties) {\n for (const key of Object.keys(properties)) {\n properties[key] = String(properties[key]).substring(0, MaxPropertyLengths.THIRTEEN_BIT);\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 if (log.attributes[KnownContextTagKeys.AiOperationName]) {\n tags[KnownContextTagKeys.AiOperationName] = log.attributes[\n KnownContextTagKeys.AiOperationName\n ] as string;\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.startsWith(\"microsoft\") ||\n key === ATTR_EXCEPTION_TYPE ||\n key === ATTR_EXCEPTION_MESSAGE ||\n key === ATTR_EXCEPTION_STACKTRACE ||\n key === (KnownContextTagKeys.AiOperationName as string)\n )\n ) {\n properties[key] = serializeAttribute(log.attributes[key]);\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 getLegacyApplicationInsightsMeasurements(log: ReadableLogRecord): Measurements {\n let measurements: Measurements = {};\n if ((log.body as MonitorDomain)?.measurements) {\n measurements = { ...(log.body as MonitorDomain).measurements };\n }\n return measurements;\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"]}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import type { ResourceMetrics } from "@opentelemetry/sdk-metrics";
|
|
1
|
+
import type { DataPoint, ExponentialHistogram, Histogram, ResourceMetrics } from "@opentelemetry/sdk-metrics";
|
|
2
2
|
import type { TelemetryItem as Envelope } from "../generated/index.js";
|
|
3
|
+
import { AttachTypeName } from "../export/statsbeat/types.js";
|
|
3
4
|
/**
|
|
4
5
|
* Metric to Azure envelope parsing.
|
|
5
6
|
* @internal
|
|
6
7
|
*/
|
|
7
8
|
export declare function resourceMetricsToEnvelope(metrics: ResourceMetrics, ikey: string, isStatsbeat?: boolean): Envelope[];
|
|
9
|
+
export declare function isAksAttach(): boolean;
|
|
10
|
+
export declare function shouldSendToOtlp(): boolean;
|
|
11
|
+
export declare function isStandardMetric(dataPoint: DataPoint<number> | DataPoint<Histogram> | DataPoint<ExponentialHistogram>): boolean;
|
|
12
|
+
export declare function getAttachType(): AttachTypeName;
|
|
8
13
|
//# sourceMappingURL=metricUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metricUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/metricUtils.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"metricUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/metricUtils.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,SAAS,EACT,oBAAoB,EACpB,SAAS,EACT,eAAe,EAChB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EACV,aAAa,IAAI,QAAQ,EAG1B,MAAM,uBAAuB,CAAC;AAS/B,OAAO,EAAE,cAAc,EAA6B,MAAM,8BAA8B,CAAC;AAwBzF;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,MAAM,EACZ,WAAW,CAAC,EAAE,OAAO,GACpB,QAAQ,EAAE,CAoFZ;AAED,wBAAgB,WAAW,IAAI,OAAO,CAIrC;AAED,wBAAgB,gBAAgB,IAAI,OAAO,CAK1C;AAED,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC,oBAAoB,CAAC,GACpF,OAAO,CAET;AAED,wBAAgB,aAAa,IAAI,cAAc,CAK9C"}
|
|
@@ -3,9 +3,16 @@
|
|
|
3
3
|
// Licensed under the MIT License.
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.resourceMetricsToEnvelope = resourceMetricsToEnvelope;
|
|
6
|
+
exports.isAksAttach = isAksAttach;
|
|
7
|
+
exports.shouldSendToOtlp = shouldSendToOtlp;
|
|
8
|
+
exports.isStandardMetric = isStandardMetric;
|
|
9
|
+
exports.getAttachType = getAttachType;
|
|
6
10
|
const sdk_metrics_1 = require("@opentelemetry/sdk-metrics");
|
|
7
11
|
const common_js_1 = require("./common.js");
|
|
8
12
|
const types_js_1 = require("../types.js");
|
|
13
|
+
const Constants_js_1 = require("../Declarations/Constants.js");
|
|
14
|
+
const types_js_2 = require("../export/statsbeat/types.js");
|
|
15
|
+
const index_js_1 = require("../platform/index.js");
|
|
9
16
|
const breezePerformanceCountersMap = new Map([
|
|
10
17
|
[types_js_1.OTelPerformanceCounterNames.PRIVATE_BYTES, types_js_1.BreezePerformanceCounterNames.PRIVATE_BYTES],
|
|
11
18
|
[types_js_1.OTelPerformanceCounterNames.AVAILABLE_BYTES, types_js_1.BreezePerformanceCounterNames.AVAILABLE_BYTES],
|
|
@@ -31,13 +38,16 @@ function resourceMetricsToEnvelope(metrics, ikey, isStatsbeat) {
|
|
|
31
38
|
const envelopes = [];
|
|
32
39
|
const time = new Date();
|
|
33
40
|
const instrumentationKey = ikey;
|
|
34
|
-
|
|
41
|
+
let tags;
|
|
35
42
|
let envelopeName;
|
|
36
43
|
if (isStatsbeat) {
|
|
37
44
|
envelopeName = "Microsoft.ApplicationInsights.Statsbeat";
|
|
45
|
+
const context = (0, index_js_1.getInstance)();
|
|
46
|
+
tags = Object.assign({}, context.tags);
|
|
38
47
|
}
|
|
39
48
|
else {
|
|
40
49
|
envelopeName = "Microsoft.ApplicationInsights.Metric";
|
|
50
|
+
tags = (0, common_js_1.createTagsFromResource)(metrics.resource);
|
|
41
51
|
}
|
|
42
52
|
metrics.scopeMetrics.forEach((scopeMetric) => {
|
|
43
53
|
scopeMetric.metrics.forEach((metric) => {
|
|
@@ -48,6 +58,20 @@ function resourceMetricsToEnvelope(metrics, ikey, isStatsbeat) {
|
|
|
48
58
|
properties: {},
|
|
49
59
|
};
|
|
50
60
|
baseData.properties = createPropertiesFromMetricAttributes(dataPoint.attributes);
|
|
61
|
+
// If we're not exporting statsbeat, the metric is *not* a standard metric and the env var is set to false, we should not send the metric.
|
|
62
|
+
if (shouldSendToOtlp() &&
|
|
63
|
+
isAksAttach() &&
|
|
64
|
+
!isStandardMetric(dataPoint) &&
|
|
65
|
+
process.env[Constants_js_1.ENV_APPLICATIONINSIGHTS_METRICS_TO_LOGANALYTICS_ENABLED] === "false" &&
|
|
66
|
+
!isStatsbeat) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (shouldSendToOtlp() && isAksAttach() && !isStatsbeat) {
|
|
70
|
+
baseData.properties["_MS.SentToAMW"] = "True";
|
|
71
|
+
}
|
|
72
|
+
else if (isAksAttach() && !isStatsbeat) {
|
|
73
|
+
baseData.properties["_MS.SentToAMW"] = "False";
|
|
74
|
+
}
|
|
51
75
|
let perfCounterName;
|
|
52
76
|
if (breezePerformanceCountersMap.has(metric.descriptor.name)) {
|
|
53
77
|
perfCounterName = breezePerformanceCountersMap.get(metric.descriptor.name);
|
|
@@ -87,4 +111,22 @@ function resourceMetricsToEnvelope(metrics, ikey, isStatsbeat) {
|
|
|
87
111
|
});
|
|
88
112
|
return envelopes;
|
|
89
113
|
}
|
|
114
|
+
function isAksAttach() {
|
|
115
|
+
return !!(process.env[Constants_js_1.ENV_AZURE_MONITOR_AUTO_ATTACH] === "true" && process.env.AKS_ARM_NAMESPACE_ID);
|
|
116
|
+
}
|
|
117
|
+
function shouldSendToOtlp() {
|
|
118
|
+
var _a;
|
|
119
|
+
return !!(process.env[Constants_js_1.ENV_OTLP_METRICS_ENDPOINT] &&
|
|
120
|
+
((_a = process.env[Constants_js_1.ENV_OTEL_METRICS_EXPORTER]) === null || _a === void 0 ? void 0 : _a.includes("otlp")));
|
|
121
|
+
}
|
|
122
|
+
function isStandardMetric(dataPoint) {
|
|
123
|
+
var _a;
|
|
124
|
+
return ((_a = dataPoint.attributes) === null || _a === void 0 ? void 0 : _a["_MS.IsAutocollected"]) === "True";
|
|
125
|
+
}
|
|
126
|
+
function getAttachType() {
|
|
127
|
+
if (process.env[types_js_2.AZURE_MONITOR_AUTO_ATTACH] === "true") {
|
|
128
|
+
return types_js_2.AttachTypeName.INTEGRATED_AUTO;
|
|
129
|
+
}
|
|
130
|
+
return types_js_2.AttachTypeName.MANUAL;
|
|
131
|
+
}
|
|
90
132
|
//# sourceMappingURL=metricUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metricUtils.js","sourceRoot":"","sources":["../../../src/utils/metricUtils.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;
|
|
1
|
+
{"version":3,"file":"metricUtils.js","sourceRoot":"","sources":["../../../src/utils/metricUtils.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAmDlC,8DAwFC;AAED,kCAIC;AAED,4CAKC;AAED,4CAIC;AAED,sCAKC;AA5JD,4DAA2D;AAM3D,2CAAqD;AACrD,0CAA+F;AAC/F,+DAKsC;AACtC,2DAAyF;AACzF,mDAAmD;AAEnD,MAAM,4BAA4B,GAAG,IAAI,GAAG,CAAiB;IAC3D,CAAC,sCAA2B,CAAC,aAAa,EAAE,wCAA6B,CAAC,aAAa,CAAC;IACxF,CAAC,sCAA2B,CAAC,eAAe,EAAE,wCAA6B,CAAC,eAAe,CAAC;IAC5F,CAAC,sCAA2B,CAAC,cAAc,EAAE,wCAA6B,CAAC,cAAc,CAAC;IAC1F,CAAC,sCAA2B,CAAC,YAAY,EAAE,wCAA6B,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,CAAC,CAAA,CACzD,CAAC;AACJ,CAAC;AAED,SAAgB,gBAAgB,CAC9B,SAAqF;;IAErF,OAAO,CAAA,MAAA,SAAS,CAAC,UAAU,0CAAG,qBAAqB,CAAC,MAAK,MAAM,CAAC;AAClE,CAAC;AAED,SAAgB,aAAa;IAC3B,IAAI,OAAO,CAAC,GAAG,CAAC,oCAAyB,CAAC,KAAK,MAAM,EAAE,CAAC;QACtD,OAAO,yBAAc,CAAC,eAAe,CAAC;IACxC,CAAC;IACD,OAAO,yBAAc,CAAC,MAAM,CAAC;AAC/B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { Attributes } from \"@opentelemetry/api\";\nimport type {\n DataPoint,\n ExponentialHistogram,\n Histogram,\n ResourceMetrics,\n} from \"@opentelemetry/sdk-metrics\";\nimport { DataPointType } from \"@opentelemetry/sdk-metrics\";\nimport type {\n TelemetryItem as Envelope,\n MetricsData,\n MetricDataPoint,\n} from \"../generated/index.js\";\nimport { createTagsFromResource } from \"./common.js\";\nimport { BreezePerformanceCounterNames, OTelPerformanceCounterNames, Tags } from \"../types.js\";\nimport {\n ENV_OTEL_METRICS_EXPORTER,\n ENV_OTLP_METRICS_ENDPOINT,\n ENV_AZURE_MONITOR_AUTO_ATTACH,\n ENV_APPLICATIONINSIGHTS_METRICS_TO_LOGANALYTICS_ENABLED,\n} from \"../Declarations/Constants.js\";\nimport { AttachTypeName, AZURE_MONITOR_AUTO_ATTACH } from \"../export/statsbeat/types.js\";\nimport { getInstance } from \"../platform/index.js\";\n\nconst breezePerformanceCountersMap = new Map<string, string>([\n [OTelPerformanceCounterNames.PRIVATE_BYTES, BreezePerformanceCounterNames.PRIVATE_BYTES],\n [OTelPerformanceCounterNames.AVAILABLE_BYTES, BreezePerformanceCounterNames.AVAILABLE_BYTES],\n [OTelPerformanceCounterNames.PROCESSOR_TIME, BreezePerformanceCounterNames.PROCESSOR_TIME],\n [OTelPerformanceCounterNames.PROCESS_TIME, BreezePerformanceCounterNames.PROCESS_TIME],\n [OTelPerformanceCounterNames.REQUEST_RATE, BreezePerformanceCounterNames.REQUEST_RATE],\n [OTelPerformanceCounterNames.REQUEST_DURATION, BreezePerformanceCounterNames.REQUEST_DURATION],\n]);\n\nfunction createPropertiesFromMetricAttributes(attributes?: Attributes): {\n [propertyName: string]: string;\n} {\n const properties: { [propertyName: string]: string } = {};\n if (attributes) {\n for (const key of Object.keys(attributes)) {\n properties[key] = attributes[key] as string;\n }\n }\n return properties;\n}\n\n/**\n * Metric to Azure envelope parsing.\n * @internal\n */\nexport function resourceMetricsToEnvelope(\n metrics: ResourceMetrics,\n ikey: string,\n isStatsbeat?: boolean,\n): Envelope[] {\n const envelopes: Envelope[] = [];\n const time = new Date();\n const instrumentationKey = ikey;\n let tags: Tags;\n let envelopeName: string;\n\n if (isStatsbeat) {\n envelopeName = \"Microsoft.ApplicationInsights.Statsbeat\";\n const context = getInstance();\n tags = { ...context.tags };\n } else {\n envelopeName = \"Microsoft.ApplicationInsights.Metric\";\n tags = createTagsFromResource(metrics.resource);\n }\n\n metrics.scopeMetrics.forEach((scopeMetric) => {\n scopeMetric.metrics.forEach((metric) => {\n metric.dataPoints.forEach((dataPoint) => {\n const baseData: MetricsData = {\n metrics: [],\n version: 2,\n properties: {},\n };\n baseData.properties = createPropertiesFromMetricAttributes(dataPoint.attributes);\n\n // If we're not exporting statsbeat, the metric is *not* a standard metric and the env var is set to false, we should not send the metric.\n if (\n shouldSendToOtlp() &&\n isAksAttach() &&\n !isStandardMetric(dataPoint) &&\n process.env[ENV_APPLICATIONINSIGHTS_METRICS_TO_LOGANALYTICS_ENABLED] === \"false\" &&\n !isStatsbeat\n ) {\n return;\n }\n\n if (shouldSendToOtlp() && isAksAttach() && !isStatsbeat) {\n baseData.properties[\"_MS.SentToAMW\"] = \"True\";\n } else if (isAksAttach() && !isStatsbeat) {\n baseData.properties[\"_MS.SentToAMW\"] = \"False\";\n }\n let perfCounterName;\n if (breezePerformanceCountersMap.has(metric.descriptor.name)) {\n perfCounterName = breezePerformanceCountersMap.get(metric.descriptor.name);\n }\n const metricDataPoint: MetricDataPoint = {\n name: perfCounterName ? perfCounterName : metric.descriptor.name,\n value: 0,\n dataPointType: \"Aggregation\",\n };\n if (\n metric.dataPointType === DataPointType.SUM ||\n metric.dataPointType === DataPointType.GAUGE\n ) {\n metricDataPoint.value = dataPoint.value as number;\n metricDataPoint.count = 1;\n } else {\n metricDataPoint.value = (dataPoint.value as Histogram).sum || 0;\n metricDataPoint.count = (dataPoint.value as Histogram).count;\n metricDataPoint.max = (dataPoint.value as Histogram).max;\n metricDataPoint.min = (dataPoint.value as Histogram).min;\n }\n baseData.metrics.push(metricDataPoint);\n const envelope: Envelope = {\n name: envelopeName,\n time: time,\n sampleRate: 100, // Metrics are never sampled\n instrumentationKey: instrumentationKey,\n tags: tags,\n version: 1,\n data: {\n baseType: \"MetricData\",\n baseData: {\n ...baseData,\n },\n },\n };\n envelopes.push(envelope);\n });\n });\n });\n\n return envelopes;\n}\n\nexport function isAksAttach(): boolean {\n return !!(\n process.env[ENV_AZURE_MONITOR_AUTO_ATTACH] === \"true\" && process.env.AKS_ARM_NAMESPACE_ID\n );\n}\n\nexport function shouldSendToOtlp(): boolean {\n return !!(\n process.env[ENV_OTLP_METRICS_ENDPOINT] &&\n process.env[ENV_OTEL_METRICS_EXPORTER]?.includes(\"otlp\")\n );\n}\n\nexport function isStandardMetric(\n dataPoint: DataPoint<number> | DataPoint<Histogram> | DataPoint<ExponentialHistogram>,\n): boolean {\n return dataPoint.attributes?.[\"_MS.IsAutocollected\"] === \"True\";\n}\n\nexport function getAttachType(): AttachTypeName {\n if (process.env[AZURE_MONITOR_AUTO_ATTACH] === \"true\") {\n return AttachTypeName.INTEGRATED_AUTO;\n }\n return AttachTypeName.MANUAL;\n}\n"]}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { ReadableSpan } from "@opentelemetry/sdk-trace-base";
|
|
2
|
+
import type { Attributes, AttributeValue } from "@opentelemetry/api";
|
|
3
|
+
import type { Tags } from "../types.js";
|
|
2
4
|
import type { TelemetryItem as Envelope } from "../generated/index.js";
|
|
3
5
|
/**
|
|
4
6
|
* Span to Azure envelope parsing.
|
|
@@ -10,4 +12,16 @@ export declare function readableSpanToEnvelope(span: ReadableSpan, ikey: string)
|
|
|
10
12
|
* @internal
|
|
11
13
|
*/
|
|
12
14
|
export declare function spanEventsToEnvelopes(span: ReadableSpan, ikey: string): Envelope[];
|
|
15
|
+
export declare function getPeerIp(attributes: Attributes): AttributeValue | undefined;
|
|
16
|
+
export declare function getLocationIp(tags: Tags, attributes: Attributes): void;
|
|
17
|
+
export declare function getHttpClientIp(attributes: Attributes): AttributeValue | undefined;
|
|
18
|
+
export declare function getUserAgent(attributes: Attributes): AttributeValue | undefined;
|
|
19
|
+
export declare function getHttpUrl(attributes: Attributes): AttributeValue | undefined;
|
|
20
|
+
export declare function getHttpMethod(attributes: Attributes): AttributeValue | undefined;
|
|
21
|
+
export declare function getHttpStatusCode(attributes: Attributes): AttributeValue | undefined;
|
|
22
|
+
export declare function getHttpScheme(attributes: Attributes): AttributeValue | undefined;
|
|
23
|
+
export declare function getHttpTarget(attributes: Attributes): AttributeValue | undefined;
|
|
24
|
+
export declare function getHttpHost(attributes: Attributes): AttributeValue | undefined;
|
|
25
|
+
export declare function getNetPeerName(attributes: Attributes): AttributeValue | undefined;
|
|
26
|
+
export declare function getNetPeerPort(attributes: Attributes): AttributeValue | undefined;
|
|
13
27
|
//# sourceMappingURL=spanUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spanUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/spanUtils.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAc,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"spanUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/spanUtils.ts"],"names":[],"mappings":"AAGA,OA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,wBAAgB,cAAc,CAAC,UAAU,EAAE,UAAU,GAAG,cAAc,GAAG,SAAS,CAKjF;AAED,wBAAgB,cAAc,CAAC,UAAU,EAAE,UAAU,GAAG,cAAc,GAAG,SAAS,CASjF"}
|
|
@@ -4,6 +4,18 @@
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.readableSpanToEnvelope = readableSpanToEnvelope;
|
|
6
6
|
exports.spanEventsToEnvelopes = spanEventsToEnvelopes;
|
|
7
|
+
exports.getPeerIp = getPeerIp;
|
|
8
|
+
exports.getLocationIp = getLocationIp;
|
|
9
|
+
exports.getHttpClientIp = getHttpClientIp;
|
|
10
|
+
exports.getUserAgent = getUserAgent;
|
|
11
|
+
exports.getHttpUrl = getHttpUrl;
|
|
12
|
+
exports.getHttpMethod = getHttpMethod;
|
|
13
|
+
exports.getHttpStatusCode = getHttpStatusCode;
|
|
14
|
+
exports.getHttpScheme = getHttpScheme;
|
|
15
|
+
exports.getHttpTarget = getHttpTarget;
|
|
16
|
+
exports.getHttpHost = getHttpHost;
|
|
17
|
+
exports.getNetPeerName = getNetPeerName;
|
|
18
|
+
exports.getNetPeerPort = getNetPeerPort;
|
|
7
19
|
const core_1 = require("@opentelemetry/core");
|
|
8
20
|
const api_1 = require("@opentelemetry/api");
|
|
9
21
|
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
|
|
@@ -24,21 +36,20 @@ function createTagsFromSpan(span) {
|
|
|
24
36
|
if (endUserId) {
|
|
25
37
|
tags[index_js_1.KnownContextTagKeys.AiUserId] = String(endUserId);
|
|
26
38
|
}
|
|
27
|
-
const httpUserAgent = span.attributes
|
|
39
|
+
const httpUserAgent = getUserAgent(span.attributes);
|
|
28
40
|
if (httpUserAgent) {
|
|
29
41
|
// TODO: Not exposed in Swagger, need to update def
|
|
30
42
|
tags["ai.user.userAgent"] = String(httpUserAgent);
|
|
31
43
|
}
|
|
32
44
|
if (span.kind === api_1.SpanKind.SERVER) {
|
|
33
|
-
const httpMethod = span.attributes
|
|
34
|
-
|
|
35
|
-
const netPeerIp = span.attributes[semantic_conventions_1.SEMATTRS_NET_PEER_IP];
|
|
45
|
+
const httpMethod = getHttpMethod(span.attributes);
|
|
46
|
+
getLocationIp(tags, span.attributes);
|
|
36
47
|
if (httpMethod) {
|
|
37
|
-
const httpRoute = span.attributes[semantic_conventions_1.
|
|
38
|
-
const httpUrl = span.attributes
|
|
48
|
+
const httpRoute = span.attributes[semantic_conventions_1.ATTR_HTTP_ROUTE];
|
|
49
|
+
const httpUrl = getHttpUrl(span.attributes);
|
|
39
50
|
tags[index_js_1.KnownContextTagKeys.AiOperationName] = span.name; // Default
|
|
40
51
|
if (httpRoute) {
|
|
41
|
-
// AiOperationName max
|
|
52
|
+
// AiOperationName max length is 1024
|
|
42
53
|
// https://github.com/MohanGsk/ApplicationInsights-Home/blob/master/EndpointSpecs/Schemas/Bond/ContextTagKeys.bond
|
|
43
54
|
tags[index_js_1.KnownContextTagKeys.AiOperationName] = String(`${httpMethod} ${httpRoute}`).substring(0, types_js_1.MaxPropertyLengths.TEN_BIT);
|
|
44
55
|
}
|
|
@@ -51,18 +62,9 @@ function createTagsFromSpan(span) {
|
|
|
51
62
|
/* no-op */
|
|
52
63
|
}
|
|
53
64
|
}
|
|
54
|
-
if (httpClientIp) {
|
|
55
|
-
tags[index_js_1.KnownContextTagKeys.AiLocationIp] = String(httpClientIp);
|
|
56
|
-
}
|
|
57
|
-
else if (netPeerIp) {
|
|
58
|
-
tags[index_js_1.KnownContextTagKeys.AiLocationIp] = String(netPeerIp);
|
|
59
|
-
}
|
|
60
65
|
}
|
|
61
66
|
else {
|
|
62
67
|
tags[index_js_1.KnownContextTagKeys.AiOperationName] = span.name;
|
|
63
|
-
if (netPeerIp) {
|
|
64
|
-
tags[index_js_1.KnownContextTagKeys.AiLocationIp] = String(netPeerIp);
|
|
65
|
-
}
|
|
66
68
|
}
|
|
67
69
|
}
|
|
68
70
|
else {
|
|
@@ -80,24 +82,8 @@ function createPropertiesFromSpanAttributes(attributes) {
|
|
|
80
82
|
// Avoid duplication ignoring fields already mapped.
|
|
81
83
|
if (!(key.startsWith("_MS.") ||
|
|
82
84
|
key.startsWith("microsoft.") ||
|
|
83
|
-
key
|
|
84
|
-
key
|
|
85
|
-
key === semantic_conventions_1.SEMATTRS_PEER_SERVICE ||
|
|
86
|
-
key === semantic_conventions_1.SEMATTRS_HTTP_METHOD ||
|
|
87
|
-
key === semantic_conventions_1.SEMATTRS_HTTP_URL ||
|
|
88
|
-
key === semantic_conventions_1.SEMATTRS_HTTP_STATUS_CODE ||
|
|
89
|
-
key === semantic_conventions_1.SEMATTRS_HTTP_ROUTE ||
|
|
90
|
-
key === semantic_conventions_1.SEMATTRS_HTTP_HOST ||
|
|
91
|
-
key === semantic_conventions_1.SEMATTRS_HTTP_URL ||
|
|
92
|
-
key === semantic_conventions_1.SEMATTRS_DB_SYSTEM ||
|
|
93
|
-
key === semantic_conventions_1.SEMATTRS_DB_STATEMENT ||
|
|
94
|
-
key === semantic_conventions_1.SEMATTRS_DB_OPERATION ||
|
|
95
|
-
key === semantic_conventions_1.SEMATTRS_DB_NAME ||
|
|
96
|
-
key === semantic_conventions_1.SEMATTRS_RPC_SYSTEM ||
|
|
97
|
-
key === semantic_conventions_1.SEMATTRS_RPC_GRPC_STATUS_CODE ||
|
|
98
|
-
key === semantic_conventions_1.SEMATTRS_EXCEPTION_TYPE ||
|
|
99
|
-
key === semantic_conventions_1.SEMATTRS_EXCEPTION_MESSAGE ||
|
|
100
|
-
key === semantic_conventions_1.SEMATTRS_EXCEPTION_STACKTRACE ||
|
|
85
|
+
types_js_1.legacySemanticValues.includes(key) ||
|
|
86
|
+
types_js_1.httpSemanticValues.includes(key) ||
|
|
101
87
|
key === index_js_1.KnownContextTagKeys.AiOperationName)) {
|
|
102
88
|
properties[key] = (0, common_js_1.serializeAttribute)(attributes[key]);
|
|
103
89
|
}
|
|
@@ -134,12 +120,12 @@ function createDependencyData(span) {
|
|
|
134
120
|
if (span.kind === api_1.SpanKind.INTERNAL && span.parentSpanId) {
|
|
135
121
|
remoteDependencyData.type = applicationinsights_js_1.DependencyTypes.InProc;
|
|
136
122
|
}
|
|
137
|
-
const httpMethod = span.attributes
|
|
123
|
+
const httpMethod = getHttpMethod(span.attributes);
|
|
138
124
|
const dbSystem = span.attributes[semantic_conventions_1.SEMATTRS_DB_SYSTEM];
|
|
139
125
|
const rpcSystem = span.attributes[semantic_conventions_1.SEMATTRS_RPC_SYSTEM];
|
|
140
126
|
// HTTP Dependency
|
|
141
127
|
if (httpMethod) {
|
|
142
|
-
const httpUrl = span.attributes
|
|
128
|
+
const httpUrl = getHttpUrl(span.attributes);
|
|
143
129
|
if (httpUrl) {
|
|
144
130
|
try {
|
|
145
131
|
const dependencyUrl = new URL(String(httpUrl));
|
|
@@ -151,7 +137,7 @@ function createDependencyData(span) {
|
|
|
151
137
|
}
|
|
152
138
|
remoteDependencyData.type = applicationinsights_js_1.DependencyTypes.Http;
|
|
153
139
|
remoteDependencyData.data = (0, common_js_1.getUrl)(span.attributes);
|
|
154
|
-
const httpStatusCode = span.attributes
|
|
140
|
+
const httpStatusCode = getHttpStatusCode(span.attributes);
|
|
155
141
|
if (httpStatusCode) {
|
|
156
142
|
remoteDependencyData.resultCode = String(httpStatusCode);
|
|
157
143
|
}
|
|
@@ -241,17 +227,17 @@ function createRequestData(span) {
|
|
|
241
227
|
const requestData = {
|
|
242
228
|
id: `${span.spanContext().spanId}`,
|
|
243
229
|
success: span.status.code !== api_1.SpanStatusCode.ERROR &&
|
|
244
|
-
(Number(span.attributes
|
|
230
|
+
(Number(getHttpStatusCode(span.attributes)) || 0) < 400,
|
|
245
231
|
responseCode: "0",
|
|
246
232
|
duration: (0, breezeUtils_js_1.msToTimeSpan)((0, core_1.hrTimeToMilliseconds)(span.duration)),
|
|
247
233
|
version: 2,
|
|
248
234
|
source: undefined,
|
|
249
235
|
};
|
|
250
|
-
const httpMethod = span.attributes
|
|
236
|
+
const httpMethod = getHttpMethod(span.attributes);
|
|
251
237
|
const grpcStatusCode = span.attributes[semantic_conventions_1.SEMATTRS_RPC_GRPC_STATUS_CODE];
|
|
252
238
|
if (httpMethod) {
|
|
253
239
|
requestData.url = (0, common_js_1.getUrl)(span.attributes);
|
|
254
|
-
const httpStatusCode = span.attributes
|
|
240
|
+
const httpStatusCode = getHttpStatusCode(span.attributes);
|
|
255
241
|
if (httpStatusCode) {
|
|
256
242
|
requestData.responseCode = String(httpStatusCode);
|
|
257
243
|
}
|
|
@@ -366,57 +352,39 @@ function spanEventsToEnvelopes(span, ikey) {
|
|
|
366
352
|
}
|
|
367
353
|
// Only generate exception telemetry for incoming requests
|
|
368
354
|
if (event.name === "exception") {
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
if (event.attributes) {
|
|
389
|
-
typeName = String(event.attributes[semantic_conventions_1.SEMATTRS_EXCEPTION_TYPE]);
|
|
390
|
-
stack = String(event.attributes[semantic_conventions_1.SEMATTRS_EXCEPTION_STACKTRACE]);
|
|
391
|
-
if (stack) {
|
|
392
|
-
hasFullStack = true;
|
|
393
|
-
}
|
|
394
|
-
const exceptionMsg = event.attributes[semantic_conventions_1.SEMATTRS_EXCEPTION_MESSAGE];
|
|
395
|
-
if (exceptionMsg) {
|
|
396
|
-
message = String(exceptionMsg);
|
|
397
|
-
}
|
|
398
|
-
const escaped = event.attributes[semantic_conventions_1.SEMATTRS_EXCEPTION_ESCAPED];
|
|
399
|
-
if (escaped !== undefined) {
|
|
400
|
-
properties[semantic_conventions_1.SEMATTRS_EXCEPTION_ESCAPED] = String(escaped);
|
|
401
|
-
}
|
|
355
|
+
name = "Microsoft.ApplicationInsights.Exception";
|
|
356
|
+
baseType = "ExceptionData";
|
|
357
|
+
let typeName = "";
|
|
358
|
+
let message = "Exception";
|
|
359
|
+
let stack = "";
|
|
360
|
+
let hasFullStack = false;
|
|
361
|
+
if (event.attributes) {
|
|
362
|
+
typeName = String(event.attributes[semantic_conventions_1.SEMATTRS_EXCEPTION_TYPE]);
|
|
363
|
+
stack = String(event.attributes[semantic_conventions_1.SEMATTRS_EXCEPTION_STACKTRACE]);
|
|
364
|
+
if (stack) {
|
|
365
|
+
hasFullStack = true;
|
|
366
|
+
}
|
|
367
|
+
const exceptionMsg = event.attributes[semantic_conventions_1.SEMATTRS_EXCEPTION_MESSAGE];
|
|
368
|
+
if (exceptionMsg) {
|
|
369
|
+
message = String(exceptionMsg);
|
|
370
|
+
}
|
|
371
|
+
const escaped = event.attributes[semantic_conventions_1.SEMATTRS_EXCEPTION_ESCAPED];
|
|
372
|
+
if (escaped !== undefined) {
|
|
373
|
+
properties[semantic_conventions_1.SEMATTRS_EXCEPTION_ESCAPED] = String(escaped);
|
|
402
374
|
}
|
|
403
|
-
const exceptionDetails = {
|
|
404
|
-
typeName: typeName,
|
|
405
|
-
message: message,
|
|
406
|
-
stack: stack,
|
|
407
|
-
hasFullStack: hasFullStack,
|
|
408
|
-
};
|
|
409
|
-
const exceptionData = {
|
|
410
|
-
exceptions: [exceptionDetails],
|
|
411
|
-
version: 2,
|
|
412
|
-
properties: properties,
|
|
413
|
-
};
|
|
414
|
-
baseData = exceptionData;
|
|
415
|
-
}
|
|
416
|
-
else {
|
|
417
|
-
// Drop non-server exception span events
|
|
418
|
-
return;
|
|
419
375
|
}
|
|
376
|
+
const exceptionDetails = {
|
|
377
|
+
typeName: typeName,
|
|
378
|
+
message: message,
|
|
379
|
+
stack: stack,
|
|
380
|
+
hasFullStack: hasFullStack,
|
|
381
|
+
};
|
|
382
|
+
const exceptionData = {
|
|
383
|
+
exceptions: [exceptionDetails],
|
|
384
|
+
version: 2,
|
|
385
|
+
properties: properties,
|
|
386
|
+
};
|
|
387
|
+
baseData = exceptionData;
|
|
420
388
|
}
|
|
421
389
|
else {
|
|
422
390
|
name = "Microsoft.ApplicationInsights.Message";
|
|
@@ -458,4 +426,91 @@ function spanEventsToEnvelopes(span, ikey) {
|
|
|
458
426
|
}
|
|
459
427
|
return envelopes;
|
|
460
428
|
}
|
|
429
|
+
function getPeerIp(attributes) {
|
|
430
|
+
if (attributes) {
|
|
431
|
+
return attributes[semantic_conventions_1.ATTR_NETWORK_PEER_ADDRESS] || attributes[semantic_conventions_1.SEMATTRS_NET_PEER_IP];
|
|
432
|
+
}
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
function getLocationIp(tags, attributes) {
|
|
436
|
+
if (attributes) {
|
|
437
|
+
const httpClientIp = getHttpClientIp(attributes);
|
|
438
|
+
const netPeerIp = getPeerIp(attributes);
|
|
439
|
+
if (httpClientIp) {
|
|
440
|
+
tags[index_js_1.KnownContextTagKeys.AiLocationIp] = String(httpClientIp);
|
|
441
|
+
}
|
|
442
|
+
else if (netPeerIp) {
|
|
443
|
+
tags[index_js_1.KnownContextTagKeys.AiLocationIp] = String(netPeerIp);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
function getHttpClientIp(attributes) {
|
|
448
|
+
if (attributes) {
|
|
449
|
+
return attributes[semantic_conventions_1.ATTR_CLIENT_ADDRESS] || attributes[semantic_conventions_1.SEMATTRS_HTTP_CLIENT_IP];
|
|
450
|
+
}
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
function getUserAgent(attributes) {
|
|
454
|
+
if (attributes) {
|
|
455
|
+
return attributes[semantic_conventions_1.ATTR_USER_AGENT_ORIGINAL] || attributes[semantic_conventions_1.SEMATTRS_HTTP_USER_AGENT];
|
|
456
|
+
}
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
function getHttpUrl(attributes) {
|
|
460
|
+
// Stable sem conv only supports populating url from `url.full`
|
|
461
|
+
if (attributes) {
|
|
462
|
+
return attributes[semantic_conventions_1.ATTR_URL_FULL] || attributes[semantic_conventions_1.SEMATTRS_HTTP_URL];
|
|
463
|
+
}
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
function getHttpMethod(attributes) {
|
|
467
|
+
if (attributes) {
|
|
468
|
+
return attributes[semantic_conventions_1.ATTR_HTTP_REQUEST_METHOD] || attributes[semantic_conventions_1.SEMATTRS_HTTP_METHOD];
|
|
469
|
+
}
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
function getHttpStatusCode(attributes) {
|
|
473
|
+
if (attributes) {
|
|
474
|
+
return attributes[semantic_conventions_1.ATTR_HTTP_RESPONSE_STATUS_CODE] || attributes[semantic_conventions_1.SEMATTRS_HTTP_STATUS_CODE];
|
|
475
|
+
}
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
function getHttpScheme(attributes) {
|
|
479
|
+
if (attributes) {
|
|
480
|
+
return attributes[semantic_conventions_1.ATTR_URL_SCHEME] || attributes[semantic_conventions_1.SEMATTRS_HTTP_SCHEME];
|
|
481
|
+
}
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
function getHttpTarget(attributes) {
|
|
485
|
+
if (attributes) {
|
|
486
|
+
if (attributes[semantic_conventions_1.ATTR_URL_PATH]) {
|
|
487
|
+
return attributes[semantic_conventions_1.ATTR_URL_PATH];
|
|
488
|
+
}
|
|
489
|
+
if (attributes[semantic_conventions_1.ATTR_URL_QUERY]) {
|
|
490
|
+
return attributes[semantic_conventions_1.ATTR_URL_QUERY];
|
|
491
|
+
}
|
|
492
|
+
return attributes[semantic_conventions_1.SEMATTRS_HTTP_TARGET];
|
|
493
|
+
}
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
function getHttpHost(attributes) {
|
|
497
|
+
if (attributes) {
|
|
498
|
+
return attributes[semantic_conventions_1.ATTR_SERVER_ADDRESS] || attributes[semantic_conventions_1.SEMATTRS_HTTP_HOST];
|
|
499
|
+
}
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
function getNetPeerName(attributes) {
|
|
503
|
+
if (attributes) {
|
|
504
|
+
return attributes[semantic_conventions_1.ATTR_CLIENT_ADDRESS] || attributes[semantic_conventions_1.SEMATTRS_NET_PEER_NAME];
|
|
505
|
+
}
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
function getNetPeerPort(attributes) {
|
|
509
|
+
if (attributes) {
|
|
510
|
+
return (attributes[semantic_conventions_1.ATTR_CLIENT_PORT] ||
|
|
511
|
+
attributes[semantic_conventions_1.ATTR_SERVER_PORT] ||
|
|
512
|
+
attributes[semantic_conventions_1.SEMATTRS_NET_PEER_PORT]);
|
|
513
|
+
}
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
461
516
|
//# sourceMappingURL=spanUtils.js.map
|