@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.
Files changed (83) hide show
  1. package/README.md +56 -47
  2. package/dist/commonjs/Declarations/Constants.d.ts +20 -0
  3. package/dist/commonjs/Declarations/Constants.d.ts.map +1 -1
  4. package/dist/commonjs/Declarations/Constants.js +21 -1
  5. package/dist/commonjs/Declarations/Constants.js.map +1 -1
  6. package/dist/commonjs/export/statsbeat/longIntervalStatsbeatMetrics.d.ts.map +1 -1
  7. package/dist/commonjs/export/statsbeat/longIntervalStatsbeatMetrics.js +2 -1
  8. package/dist/commonjs/export/statsbeat/longIntervalStatsbeatMetrics.js.map +1 -1
  9. package/dist/commonjs/export/statsbeat/networkStatsbeatMetrics.d.ts.map +1 -1
  10. package/dist/commonjs/export/statsbeat/networkStatsbeatMetrics.js +2 -1
  11. package/dist/commonjs/export/statsbeat/networkStatsbeatMetrics.js.map +1 -1
  12. package/dist/commonjs/export/statsbeat/statsbeatMetrics.js +1 -1
  13. package/dist/commonjs/export/statsbeat/statsbeatMetrics.js.map +1 -1
  14. package/dist/commonjs/export/statsbeat/types.d.ts +5 -0
  15. package/dist/commonjs/export/statsbeat/types.d.ts.map +1 -1
  16. package/dist/commonjs/export/statsbeat/types.js +7 -1
  17. package/dist/commonjs/export/statsbeat/types.js.map +1 -1
  18. package/dist/commonjs/generated/applicationInsightsClient.js +1 -1
  19. package/dist/commonjs/generated/applicationInsightsClient.js.map +1 -1
  20. package/dist/commonjs/tsdoc-metadata.json +1 -1
  21. package/dist/commonjs/types.d.ts +10 -0
  22. package/dist/commonjs/types.d.ts.map +1 -1
  23. package/dist/commonjs/types.js +51 -1
  24. package/dist/commonjs/types.js.map +1 -1
  25. package/dist/commonjs/utils/common.d.ts.map +1 -1
  26. package/dist/commonjs/utils/common.js +13 -12
  27. package/dist/commonjs/utils/common.js.map +1 -1
  28. package/dist/commonjs/utils/constants/applicationinsights.d.ts +2 -1
  29. package/dist/commonjs/utils/constants/applicationinsights.d.ts.map +1 -1
  30. package/dist/commonjs/utils/constants/applicationinsights.js +3 -2
  31. package/dist/commonjs/utils/constants/applicationinsights.js.map +1 -1
  32. package/dist/commonjs/utils/logUtils.d.ts.map +1 -1
  33. package/dist/commonjs/utils/logUtils.js +43 -31
  34. package/dist/commonjs/utils/logUtils.js.map +1 -1
  35. package/dist/commonjs/utils/metricUtils.d.ts +6 -1
  36. package/dist/commonjs/utils/metricUtils.d.ts.map +1 -1
  37. package/dist/commonjs/utils/metricUtils.js +43 -1
  38. package/dist/commonjs/utils/metricUtils.js.map +1 -1
  39. package/dist/commonjs/utils/spanUtils.d.ts +14 -0
  40. package/dist/commonjs/utils/spanUtils.d.ts.map +1 -1
  41. package/dist/commonjs/utils/spanUtils.js +144 -89
  42. package/dist/commonjs/utils/spanUtils.js.map +1 -1
  43. package/dist/esm/Declarations/Constants.d.ts +20 -0
  44. package/dist/esm/Declarations/Constants.d.ts.map +1 -1
  45. package/dist/esm/Declarations/Constants.js +20 -0
  46. package/dist/esm/Declarations/Constants.js.map +1 -1
  47. package/dist/esm/export/statsbeat/longIntervalStatsbeatMetrics.d.ts.map +1 -1
  48. package/dist/esm/export/statsbeat/longIntervalStatsbeatMetrics.js +2 -1
  49. package/dist/esm/export/statsbeat/longIntervalStatsbeatMetrics.js.map +1 -1
  50. package/dist/esm/export/statsbeat/networkStatsbeatMetrics.d.ts.map +1 -1
  51. package/dist/esm/export/statsbeat/networkStatsbeatMetrics.js +2 -1
  52. package/dist/esm/export/statsbeat/networkStatsbeatMetrics.js.map +1 -1
  53. package/dist/esm/export/statsbeat/statsbeatMetrics.js +1 -1
  54. package/dist/esm/export/statsbeat/statsbeatMetrics.js.map +1 -1
  55. package/dist/esm/export/statsbeat/types.d.ts +5 -0
  56. package/dist/esm/export/statsbeat/types.d.ts.map +1 -1
  57. package/dist/esm/export/statsbeat/types.js +6 -0
  58. package/dist/esm/export/statsbeat/types.js.map +1 -1
  59. package/dist/esm/generated/applicationInsightsClient.js +1 -1
  60. package/dist/esm/generated/applicationInsightsClient.js.map +1 -1
  61. package/dist/esm/types.d.ts +10 -0
  62. package/dist/esm/types.d.ts.map +1 -1
  63. package/dist/esm/types.js +50 -0
  64. package/dist/esm/types.js.map +1 -1
  65. package/dist/esm/utils/common.d.ts.map +1 -1
  66. package/dist/esm/utils/common.js +14 -13
  67. package/dist/esm/utils/common.js.map +1 -1
  68. package/dist/esm/utils/constants/applicationinsights.d.ts +2 -1
  69. package/dist/esm/utils/constants/applicationinsights.d.ts.map +1 -1
  70. package/dist/esm/utils/constants/applicationinsights.js +2 -1
  71. package/dist/esm/utils/constants/applicationinsights.js.map +1 -1
  72. package/dist/esm/utils/logUtils.d.ts.map +1 -1
  73. package/dist/esm/utils/logUtils.js +44 -32
  74. package/dist/esm/utils/logUtils.js.map +1 -1
  75. package/dist/esm/utils/metricUtils.d.ts +6 -1
  76. package/dist/esm/utils/metricUtils.d.ts.map +1 -1
  77. package/dist/esm/utils/metricUtils.js +39 -1
  78. package/dist/esm/utils/metricUtils.js.map +1 -1
  79. package/dist/esm/utils/spanUtils.d.ts +14 -0
  80. package/dist/esm/utils/spanUtils.d.ts.map +1 -1
  81. package/dist/esm/utils/spanUtils.js +135 -92
  82. package/dist/esm/utils/spanUtils.js.map +1 -1
  83. 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;AAYlC,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChF,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEvF,OAAO,EACL,sBAAsB,EACtB,yBAAyB,EACzB,mBAAmB,GACpB,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EA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AQ,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 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;AAYlC,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChF,OAAO,E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(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,EAAa,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7E,OAAO,KAAK,EACV,aAAa,IAAI,QAAQ,EAG1B,MAAM,uBAAuB,CAAC;AAyB/B;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,MAAM,EACZ,WAAW,CAAC,EAAE,OAAO,GACpB,QAAQ,EAAE,CAgEZ"}
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,6 +3,9 @@
3
3
  import { DataPointType } from "@opentelemetry/sdk-metrics";
4
4
  import { createTagsFromResource } from "./common.js";
5
5
  import { BreezePerformanceCounterNames, OTelPerformanceCounterNames } from "../types.js";
6
+ import { ENV_OTEL_METRICS_EXPORTER, ENV_OTLP_METRICS_ENDPOINT, ENV_AZURE_MONITOR_AUTO_ATTACH, ENV_APPLICATIONINSIGHTS_METRICS_TO_LOGANALYTICS_ENABLED, } from "../Declarations/Constants.js";
7
+ import { AttachTypeName, AZURE_MONITOR_AUTO_ATTACH } from "../export/statsbeat/types.js";
8
+ import { getInstance } from "../platform/index.js";
6
9
  const breezePerformanceCountersMap = new Map([
7
10
  [OTelPerformanceCounterNames.PRIVATE_BYTES, BreezePerformanceCounterNames.PRIVATE_BYTES],
8
11
  [OTelPerformanceCounterNames.AVAILABLE_BYTES, BreezePerformanceCounterNames.AVAILABLE_BYTES],
@@ -28,13 +31,16 @@ export function resourceMetricsToEnvelope(metrics, ikey, isStatsbeat) {
28
31
  const envelopes = [];
29
32
  const time = new Date();
30
33
  const instrumentationKey = ikey;
31
- const tags = createTagsFromResource(metrics.resource);
34
+ let tags;
32
35
  let envelopeName;
33
36
  if (isStatsbeat) {
34
37
  envelopeName = "Microsoft.ApplicationInsights.Statsbeat";
38
+ const context = getInstance();
39
+ tags = Object.assign({}, context.tags);
35
40
  }
36
41
  else {
37
42
  envelopeName = "Microsoft.ApplicationInsights.Metric";
43
+ tags = createTagsFromResource(metrics.resource);
38
44
  }
39
45
  metrics.scopeMetrics.forEach((scopeMetric) => {
40
46
  scopeMetric.metrics.forEach((metric) => {
@@ -45,6 +51,20 @@ export function resourceMetricsToEnvelope(metrics, ikey, isStatsbeat) {
45
51
  properties: {},
46
52
  };
47
53
  baseData.properties = createPropertiesFromMetricAttributes(dataPoint.attributes);
54
+ // 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.
55
+ if (shouldSendToOtlp() &&
56
+ isAksAttach() &&
57
+ !isStandardMetric(dataPoint) &&
58
+ process.env[ENV_APPLICATIONINSIGHTS_METRICS_TO_LOGANALYTICS_ENABLED] === "false" &&
59
+ !isStatsbeat) {
60
+ return;
61
+ }
62
+ if (shouldSendToOtlp() && isAksAttach() && !isStatsbeat) {
63
+ baseData.properties["_MS.SentToAMW"] = "True";
64
+ }
65
+ else if (isAksAttach() && !isStatsbeat) {
66
+ baseData.properties["_MS.SentToAMW"] = "False";
67
+ }
48
68
  let perfCounterName;
49
69
  if (breezePerformanceCountersMap.has(metric.descriptor.name)) {
50
70
  perfCounterName = breezePerformanceCountersMap.get(metric.descriptor.name);
@@ -84,4 +104,22 @@ export function resourceMetricsToEnvelope(metrics, ikey, isStatsbeat) {
84
104
  });
85
105
  return envelopes;
86
106
  }
107
+ export function isAksAttach() {
108
+ return !!(process.env[ENV_AZURE_MONITOR_AUTO_ATTACH] === "true" && process.env.AKS_ARM_NAMESPACE_ID);
109
+ }
110
+ export function shouldSendToOtlp() {
111
+ var _a;
112
+ return !!(process.env[ENV_OTLP_METRICS_ENDPOINT] &&
113
+ ((_a = process.env[ENV_OTEL_METRICS_EXPORTER]) === null || _a === void 0 ? void 0 : _a.includes("otlp")));
114
+ }
115
+ export function isStandardMetric(dataPoint) {
116
+ var _a;
117
+ return ((_a = dataPoint.attributes) === null || _a === void 0 ? void 0 : _a["_MS.IsAutocollected"]) === "True";
118
+ }
119
+ export function getAttachType() {
120
+ if (process.env[AZURE_MONITOR_AUTO_ATTACH] === "true") {
121
+ return AttachTypeName.INTEGRATED_AUTO;
122
+ }
123
+ return AttachTypeName.MANUAL;
124
+ }
87
125
  //# sourceMappingURL=metricUtils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"metricUtils.js","sourceRoot":"","sources":["../../../src/utils/metricUtils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAM3D,OAAO,EAAE,sBAAsB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CAAC;oBAC7D,eAAe,CAAC,GAAG,GAAI,SAAS,CAAC,KAAmB,CAAC,GAAG,CAAC;oBACzD,eAAe,CAAC,GAAG,GAAI,SAAS,CAAC,KAAmB,CAAC,GAAG,CAAC;gBAC3D,CAAC;gBACD,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;gBACvC,MAAM,QAAQ,GAAa;oBACzB,IAAI,EAAE,YAAY;oBAClB,IAAI,EAAE,IAAI;oBACV,UAAU,EAAE,GAAG,EAAE,4BAA4B;oBAC7C,kBAAkB,EAAE,kBAAkB;oBACtC,IAAI,EAAE,IAAI;oBACV,OAAO,EAAE,CAAC;oBACV,IAAI,EAAE;wBACJ,QAAQ,EAAE,YAAY;wBACtB,QAAQ,oBACH,QAAQ,CACZ;qBACF;iBACF,CAAC;gBACF,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC3B,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { Attributes } from \"@opentelemetry/api\";\nimport type { Histogram, ResourceMetrics } 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 } from \"../types.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 const tags = createTagsFromResource(metrics.resource);\n let envelopeName: string;\n\n if (isStatsbeat) {\n envelopeName = \"Microsoft.ApplicationInsights.Statsbeat\";\n } else {\n envelopeName = \"Microsoft.ApplicationInsights.Metric\";\n }\n\n metrics.scopeMetrics.forEach((scopeMetric) => {\n scopeMetric.metrics.forEach((metric) => {\n metric.dataPoints.forEach((dataPoint) => {\n const baseData: MetricsData = {\n metrics: [],\n version: 2,\n properties: {},\n };\n baseData.properties = createPropertiesFromMetricAttributes(dataPoint.attributes);\n 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"]}
1
+ {"version":3,"file":"metricUtils.js","sourceRoot":"","sources":["../../../src/utils/metricUtils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AASlC,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAM3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,6BAA6B,EAAE,2BAA2B,EAAQ,MAAM,aAAa,CAAC;AAC/F,OAAO,EACL,yBAAyB,EACzB,yBAAyB,EACzB,6BAA6B,EAC7B,uDAAuD,GACxD,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AACzF,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,MAAM,4BAA4B,GAAG,IAAI,GAAG,CAAiB;IAC3D,CAAC,2BAA2B,CAAC,aAAa,EAAE,6BAA6B,CAAC,aAAa,CAAC;IACxF,CAAC,2BAA2B,CAAC,eAAe,EAAE,6BAA6B,CAAC,eAAe,CAAC;IAC5F,CAAC,2BAA2B,CAAC,cAAc,EAAE,6BAA6B,CAAC,cAAc,CAAC;IAC1F,CAAC,2BAA2B,CAAC,YAAY,EAAE,6BAA6B,CAAC,YAAY,CAAC;IACtF,CAAC,2BAA2B,CAAC,YAAY,EAAE,6BAA6B,CAAC,YAAY,CAAC;IACtF,CAAC,2BAA2B,CAAC,gBAAgB,EAAE,6BAA6B,CAAC,gBAAgB,CAAC;CAC/F,CAAC,CAAC;AAEH,SAAS,oCAAoC,C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IAC3B,IAAI,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,KAAK,MAAM,EAAE,CAAC;QACtD,OAAO,cAAc,CAAC,eAAe,CAAC;IACxC,CAAC;IACD,OAAO,cAAc,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;AAiD9E,OAAO,KAAK,EAKV,aAAa,IAAI,QAAQ,EAE1B,MAAM,uBAAuB,CAAC;AAgQ/B;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,CAyFjF;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,EAAE,CA+GlF"}
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;AAE9E,OAAO,KAAK,EAAQ,UAAU,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gB,cAAc,CAAC,UAAU,EAAE,UAAU,GAAG,cAAc,GAAG,SAAS,CASjF"}
@@ -1,10 +1,10 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT License.
3
3
  import { hrTimeToMilliseconds } from "@opentelemetry/core";
4
- import { diag, SpanKind, SpanStatusCode, isValidTraceId, isValidSpanId } from "@opentelemetry/api";
5
- import { DBSYSTEMVALUES_MONGODB, DBSYSTEMVALUES_MYSQL, DBSYSTEMVALUES_POSTGRESQL, DBSYSTEMVALUES_REDIS, SEMATTRS_DB_NAME, SEMATTRS_DB_OPERATION, SEMATTRS_DB_STATEMENT, SEMATTRS_DB_SYSTEM, SEMATTRS_ENDUSER_ID, SEMATTRS_EXCEPTION_ESCAPED, SEMATTRS_EXCEPTION_MESSAGE, SEMATTRS_EXCEPTION_STACKTRACE, SEMATTRS_EXCEPTION_TYPE, SEMATTRS_HTTP_CLIENT_IP, SEMATTRS_HTTP_HOST, SEMATTRS_HTTP_METHOD, SEMATTRS_HTTP_ROUTE, SEMATTRS_HTTP_STATUS_CODE, SEMATTRS_HTTP_URL, SEMATTRS_HTTP_USER_AGENT, SEMATTRS_NET_PEER_IP, SEMATTRS_NET_PEER_NAME, SEMATTRS_PEER_SERVICE, SEMATTRS_RPC_GRPC_STATUS_CODE, SEMATTRS_RPC_SYSTEM, } from "@opentelemetry/semantic-conventions";
4
+ import { diag, SpanKind, SpanStatusCode } from "@opentelemetry/api";
5
+ import { DBSYSTEMVALUES_MONGODB, DBSYSTEMVALUES_MYSQL, DBSYSTEMVALUES_POSTGRESQL, DBSYSTEMVALUES_REDIS, SEMATTRS_DB_NAME, SEMATTRS_DB_OPERATION, SEMATTRS_DB_STATEMENT, SEMATTRS_DB_SYSTEM, SEMATTRS_ENDUSER_ID, SEMATTRS_EXCEPTION_ESCAPED, SEMATTRS_EXCEPTION_MESSAGE, SEMATTRS_EXCEPTION_STACKTRACE, SEMATTRS_EXCEPTION_TYPE, SEMATTRS_HTTP_CLIENT_IP, SEMATTRS_HTTP_METHOD, SEMATTRS_HTTP_STATUS_CODE, SEMATTRS_HTTP_URL, SEMATTRS_HTTP_USER_AGENT, SEMATTRS_NET_PEER_IP, SEMATTRS_RPC_GRPC_STATUS_CODE, SEMATTRS_RPC_SYSTEM, ATTR_HTTP_REQUEST_METHOD, ATTR_CLIENT_ADDRESS, ATTR_NETWORK_PEER_ADDRESS, ATTR_USER_AGENT_ORIGINAL, ATTR_HTTP_ROUTE, ATTR_URL_FULL, ATTR_HTTP_RESPONSE_STATUS_CODE, SEMATTRS_HTTP_SCHEME, ATTR_URL_SCHEME, SEMATTRS_HTTP_TARGET, ATTR_URL_PATH, ATTR_URL_QUERY, ATTR_SERVER_ADDRESS, SEMATTRS_HTTP_HOST, SEMATTRS_NET_PEER_NAME, ATTR_CLIENT_PORT, ATTR_SERVER_PORT, SEMATTRS_NET_PEER_PORT, } from "@opentelemetry/semantic-conventions";
6
6
  import { createTagsFromResource, getDependencyTarget, getUrl, hrTimeToDate, isSqlDB, serializeAttribute, } from "./common.js";
7
- import { MaxPropertyLengths } from "../types.js";
7
+ import { httpSemanticValues, legacySemanticValues, MaxPropertyLengths } from "../types.js";
8
8
  import { parseEventHubSpan } from "./eventhub.js";
9
9
  import { AzureMonitorSampleRate, DependencyTypes, MS_LINKS, } from "./constants/applicationinsights.js";
10
10
  import { AzNamespace, MicrosoftEventHub } from "./constants/span/azAttributes.js";
@@ -20,21 +20,20 @@ function createTagsFromSpan(span) {
20
20
  if (endUserId) {
21
21
  tags[KnownContextTagKeys.AiUserId] = String(endUserId);
22
22
  }
23
- const httpUserAgent = span.attributes[SEMATTRS_HTTP_USER_AGENT];
23
+ const httpUserAgent = getUserAgent(span.attributes);
24
24
  if (httpUserAgent) {
25
25
  // TODO: Not exposed in Swagger, need to update def
26
26
  tags["ai.user.userAgent"] = String(httpUserAgent);
27
27
  }
28
28
  if (span.kind === SpanKind.SERVER) {
29
- const httpMethod = span.attributes[SEMATTRS_HTTP_METHOD];
30
- const httpClientIp = span.attributes[SEMATTRS_HTTP_CLIENT_IP];
31
- const netPeerIp = span.attributes[SEMATTRS_NET_PEER_IP];
29
+ const httpMethod = getHttpMethod(span.attributes);
30
+ getLocationIp(tags, span.attributes);
32
31
  if (httpMethod) {
33
- const httpRoute = span.attributes[SEMATTRS_HTTP_ROUTE];
34
- const httpUrl = span.attributes[SEMATTRS_HTTP_URL];
32
+ const httpRoute = span.attributes[ATTR_HTTP_ROUTE];
33
+ const httpUrl = getHttpUrl(span.attributes);
35
34
  tags[KnownContextTagKeys.AiOperationName] = span.name; // Default
36
35
  if (httpRoute) {
37
- // AiOperationName max lenght is 1024
36
+ // AiOperationName max length is 1024
38
37
  // https://github.com/MohanGsk/ApplicationInsights-Home/blob/master/EndpointSpecs/Schemas/Bond/ContextTagKeys.bond
39
38
  tags[KnownContextTagKeys.AiOperationName] = String(`${httpMethod} ${httpRoute}`).substring(0, MaxPropertyLengths.TEN_BIT);
40
39
  }
@@ -47,18 +46,9 @@ function createTagsFromSpan(span) {
47
46
  /* no-op */
48
47
  }
49
48
  }
50
- if (httpClientIp) {
51
- tags[KnownContextTagKeys.AiLocationIp] = String(httpClientIp);
52
- }
53
- else if (netPeerIp) {
54
- tags[KnownContextTagKeys.AiLocationIp] = String(netPeerIp);
55
- }
56
49
  }
57
50
  else {
58
51
  tags[KnownContextTagKeys.AiOperationName] = span.name;
59
- if (netPeerIp) {
60
- tags[KnownContextTagKeys.AiLocationIp] = String(netPeerIp);
61
- }
62
52
  }
63
53
  }
64
54
  else {
@@ -76,24 +66,8 @@ function createPropertiesFromSpanAttributes(attributes) {
76
66
  // Avoid duplication ignoring fields already mapped.
77
67
  if (!(key.startsWith("_MS.") ||
78
68
  key.startsWith("microsoft.") ||
79
- key === SEMATTRS_NET_PEER_IP ||
80
- key === SEMATTRS_NET_PEER_NAME ||
81
- key === SEMATTRS_PEER_SERVICE ||
82
- key === SEMATTRS_HTTP_METHOD ||
83
- key === SEMATTRS_HTTP_URL ||
84
- key === SEMATTRS_HTTP_STATUS_CODE ||
85
- key === SEMATTRS_HTTP_ROUTE ||
86
- key === SEMATTRS_HTTP_HOST ||
87
- key === SEMATTRS_HTTP_URL ||
88
- key === SEMATTRS_DB_SYSTEM ||
89
- key === SEMATTRS_DB_STATEMENT ||
90
- key === SEMATTRS_DB_OPERATION ||
91
- key === SEMATTRS_DB_NAME ||
92
- key === SEMATTRS_RPC_SYSTEM ||
93
- key === SEMATTRS_RPC_GRPC_STATUS_CODE ||
94
- key === SEMATTRS_EXCEPTION_TYPE ||
95
- key === SEMATTRS_EXCEPTION_MESSAGE ||
96
- key === SEMATTRS_EXCEPTION_STACKTRACE ||
69
+ legacySemanticValues.includes(key) ||
70
+ httpSemanticValues.includes(key) ||
97
71
  key === KnownContextTagKeys.AiOperationName)) {
98
72
  properties[key] = serializeAttribute(attributes[key]);
99
73
  }
@@ -130,12 +104,12 @@ function createDependencyData(span) {
130
104
  if (span.kind === SpanKind.INTERNAL && span.parentSpanId) {
131
105
  remoteDependencyData.type = DependencyTypes.InProc;
132
106
  }
133
- const httpMethod = span.attributes[SEMATTRS_HTTP_METHOD];
107
+ const httpMethod = getHttpMethod(span.attributes);
134
108
  const dbSystem = span.attributes[SEMATTRS_DB_SYSTEM];
135
109
  const rpcSystem = span.attributes[SEMATTRS_RPC_SYSTEM];
136
110
  // HTTP Dependency
137
111
  if (httpMethod) {
138
- const httpUrl = span.attributes[SEMATTRS_HTTP_URL];
112
+ const httpUrl = getHttpUrl(span.attributes);
139
113
  if (httpUrl) {
140
114
  try {
141
115
  const dependencyUrl = new URL(String(httpUrl));
@@ -147,7 +121,7 @@ function createDependencyData(span) {
147
121
  }
148
122
  remoteDependencyData.type = DependencyTypes.Http;
149
123
  remoteDependencyData.data = getUrl(span.attributes);
150
- const httpStatusCode = span.attributes[SEMATTRS_HTTP_STATUS_CODE];
124
+ const httpStatusCode = getHttpStatusCode(span.attributes);
151
125
  if (httpStatusCode) {
152
126
  remoteDependencyData.resultCode = String(httpStatusCode);
153
127
  }
@@ -237,17 +211,17 @@ function createRequestData(span) {
237
211
  const requestData = {
238
212
  id: `${span.spanContext().spanId}`,
239
213
  success: span.status.code !== SpanStatusCode.ERROR &&
240
- (Number(span.attributes[SEMATTRS_HTTP_STATUS_CODE]) || 0) < 400,
214
+ (Number(getHttpStatusCode(span.attributes)) || 0) < 400,
241
215
  responseCode: "0",
242
216
  duration: msToTimeSpan(hrTimeToMilliseconds(span.duration)),
243
217
  version: 2,
244
218
  source: undefined,
245
219
  };
246
- const httpMethod = span.attributes[SEMATTRS_HTTP_METHOD];
220
+ const httpMethod = getHttpMethod(span.attributes);
247
221
  const grpcStatusCode = span.attributes[SEMATTRS_RPC_GRPC_STATUS_CODE];
248
222
  if (httpMethod) {
249
223
  requestData.url = getUrl(span.attributes);
250
- const httpStatusCode = span.attributes[SEMATTRS_HTTP_STATUS_CODE];
224
+ const httpStatusCode = getHttpStatusCode(span.attributes);
251
225
  if (httpStatusCode) {
252
226
  requestData.responseCode = String(httpStatusCode);
253
227
  }
@@ -362,57 +336,39 @@ export function spanEventsToEnvelopes(span, ikey) {
362
336
  }
363
337
  // Only generate exception telemetry for incoming requests
364
338
  if (event.name === "exception") {
365
- let isValidParent = false;
366
- const parentSpanContext = span.parentSpanId
367
- ? span.spanContext()
368
- : undefined;
369
- if (parentSpanContext) {
370
- isValidParent =
371
- isValidTraceId(parentSpanContext.traceId) && isValidSpanId(parentSpanContext.spanId);
372
- }
373
- /*
374
- * Only generate exception telemetry for children of a remote span,
375
- * internal spans, and top level spans. This is to avoid unresolvable exceptions from outgoing calls.
376
- */
377
- if (!isValidParent || (parentSpanContext === null || parentSpanContext === void 0 ? void 0 : parentSpanContext.isRemote) || span.kind === SpanKind.INTERNAL) {
378
- name = "Microsoft.ApplicationInsights.Exception";
379
- baseType = "ExceptionData";
380
- let typeName = "";
381
- let message = "Exception";
382
- let stack = "";
383
- let hasFullStack = false;
384
- if (event.attributes) {
385
- typeName = String(event.attributes[SEMATTRS_EXCEPTION_TYPE]);
386
- stack = String(event.attributes[SEMATTRS_EXCEPTION_STACKTRACE]);
387
- if (stack) {
388
- hasFullStack = true;
389
- }
390
- const exceptionMsg = event.attributes[SEMATTRS_EXCEPTION_MESSAGE];
391
- if (exceptionMsg) {
392
- message = String(exceptionMsg);
393
- }
394
- const escaped = event.attributes[SEMATTRS_EXCEPTION_ESCAPED];
395
- if (escaped !== undefined) {
396
- properties[SEMATTRS_EXCEPTION_ESCAPED] = String(escaped);
397
- }
339
+ name = "Microsoft.ApplicationInsights.Exception";
340
+ baseType = "ExceptionData";
341
+ let typeName = "";
342
+ let message = "Exception";
343
+ let stack = "";
344
+ let hasFullStack = false;
345
+ if (event.attributes) {
346
+ typeName = String(event.attributes[SEMATTRS_EXCEPTION_TYPE]);
347
+ stack = String(event.attributes[SEMATTRS_EXCEPTION_STACKTRACE]);
348
+ if (stack) {
349
+ hasFullStack = true;
350
+ }
351
+ const exceptionMsg = event.attributes[SEMATTRS_EXCEPTION_MESSAGE];
352
+ if (exceptionMsg) {
353
+ message = String(exceptionMsg);
354
+ }
355
+ const escaped = event.attributes[SEMATTRS_EXCEPTION_ESCAPED];
356
+ if (escaped !== undefined) {
357
+ properties[SEMATTRS_EXCEPTION_ESCAPED] = String(escaped);
398
358
  }
399
- const exceptionDetails = {
400
- typeName: typeName,
401
- message: message,
402
- stack: stack,
403
- hasFullStack: hasFullStack,
404
- };
405
- const exceptionData = {
406
- exceptions: [exceptionDetails],
407
- version: 2,
408
- properties: properties,
409
- };
410
- baseData = exceptionData;
411
- }
412
- else {
413
- // Drop non-server exception span events
414
- return;
415
359
  }
360
+ const exceptionDetails = {
361
+ typeName: typeName,
362
+ message: message,
363
+ stack: stack,
364
+ hasFullStack: hasFullStack,
365
+ };
366
+ const exceptionData = {
367
+ exceptions: [exceptionDetails],
368
+ version: 2,
369
+ properties: properties,
370
+ };
371
+ baseData = exceptionData;
416
372
  }
417
373
  else {
418
374
  name = "Microsoft.ApplicationInsights.Message";
@@ -454,4 +410,91 @@ export function spanEventsToEnvelopes(span, ikey) {
454
410
  }
455
411
  return envelopes;
456
412
  }
413
+ export function getPeerIp(attributes) {
414
+ if (attributes) {
415
+ return attributes[ATTR_NETWORK_PEER_ADDRESS] || attributes[SEMATTRS_NET_PEER_IP];
416
+ }
417
+ return;
418
+ }
419
+ export function getLocationIp(tags, attributes) {
420
+ if (attributes) {
421
+ const httpClientIp = getHttpClientIp(attributes);
422
+ const netPeerIp = getPeerIp(attributes);
423
+ if (httpClientIp) {
424
+ tags[KnownContextTagKeys.AiLocationIp] = String(httpClientIp);
425
+ }
426
+ else if (netPeerIp) {
427
+ tags[KnownContextTagKeys.AiLocationIp] = String(netPeerIp);
428
+ }
429
+ }
430
+ }
431
+ export function getHttpClientIp(attributes) {
432
+ if (attributes) {
433
+ return attributes[ATTR_CLIENT_ADDRESS] || attributes[SEMATTRS_HTTP_CLIENT_IP];
434
+ }
435
+ return;
436
+ }
437
+ export function getUserAgent(attributes) {
438
+ if (attributes) {
439
+ return attributes[ATTR_USER_AGENT_ORIGINAL] || attributes[SEMATTRS_HTTP_USER_AGENT];
440
+ }
441
+ return;
442
+ }
443
+ export function getHttpUrl(attributes) {
444
+ // Stable sem conv only supports populating url from `url.full`
445
+ if (attributes) {
446
+ return attributes[ATTR_URL_FULL] || attributes[SEMATTRS_HTTP_URL];
447
+ }
448
+ return;
449
+ }
450
+ export function getHttpMethod(attributes) {
451
+ if (attributes) {
452
+ return attributes[ATTR_HTTP_REQUEST_METHOD] || attributes[SEMATTRS_HTTP_METHOD];
453
+ }
454
+ return;
455
+ }
456
+ export function getHttpStatusCode(attributes) {
457
+ if (attributes) {
458
+ return attributes[ATTR_HTTP_RESPONSE_STATUS_CODE] || attributes[SEMATTRS_HTTP_STATUS_CODE];
459
+ }
460
+ return;
461
+ }
462
+ export function getHttpScheme(attributes) {
463
+ if (attributes) {
464
+ return attributes[ATTR_URL_SCHEME] || attributes[SEMATTRS_HTTP_SCHEME];
465
+ }
466
+ return;
467
+ }
468
+ export function getHttpTarget(attributes) {
469
+ if (attributes) {
470
+ if (attributes[ATTR_URL_PATH]) {
471
+ return attributes[ATTR_URL_PATH];
472
+ }
473
+ if (attributes[ATTR_URL_QUERY]) {
474
+ return attributes[ATTR_URL_QUERY];
475
+ }
476
+ return attributes[SEMATTRS_HTTP_TARGET];
477
+ }
478
+ return;
479
+ }
480
+ export function getHttpHost(attributes) {
481
+ if (attributes) {
482
+ return attributes[ATTR_SERVER_ADDRESS] || attributes[SEMATTRS_HTTP_HOST];
483
+ }
484
+ return;
485
+ }
486
+ export function getNetPeerName(attributes) {
487
+ if (attributes) {
488
+ return attributes[ATTR_CLIENT_ADDRESS] || attributes[SEMATTRS_NET_PEER_NAME];
489
+ }
490
+ return;
491
+ }
492
+ export function getNetPeerPort(attributes) {
493
+ if (attributes) {
494
+ return (attributes[ATTR_CLIENT_PORT] ||
495
+ attributes[ATTR_SERVER_PORT] ||
496
+ attributes[SEMATTRS_NET_PEER_PORT]);
497
+ }
498
+ return;
499
+ }
457
500
  //# sourceMappingURL=spanUtils.js.map