@azure/monitor-opentelemetry-exporter 1.0.0-beta.11 → 1.0.0-beta.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +401 -128
- package/dist-esm/src/Declarations/Constants.js +5 -0
- package/dist-esm/src/Declarations/Constants.js.map +1 -1
- package/dist-esm/src/export/base.js +2 -2
- package/dist-esm/src/export/base.js.map +1 -1
- package/dist-esm/src/export/log.js +53 -0
- package/dist-esm/src/export/log.js.map +1 -0
- package/dist-esm/src/export/trace.js +17 -8
- package/dist-esm/src/export/trace.js.map +1 -1
- package/dist-esm/src/generated/applicationInsightsClient.js +1 -1
- package/dist-esm/src/generated/applicationInsightsClient.js.map +1 -1
- package/dist-esm/src/index.js +1 -0
- package/dist-esm/src/index.js.map +1 -1
- package/dist-esm/src/platform/nodejs/context/context.js +11 -3
- package/dist-esm/src/platform/nodejs/context/context.js.map +1 -1
- package/dist-esm/src/platform/nodejs/persist/fileAccessControl.js +2 -1
- package/dist-esm/src/platform/nodejs/persist/fileAccessControl.js.map +1 -1
- package/dist-esm/src/platform/nodejs/persist/fileSystemPersist.js +2 -1
- package/dist-esm/src/platform/nodejs/persist/fileSystemPersist.js.map +1 -1
- package/dist-esm/src/utils/common.js +101 -15
- package/dist-esm/src/utils/common.js.map +1 -1
- package/dist-esm/src/utils/connectionStringParser.js +2 -1
- package/dist-esm/src/utils/connectionStringParser.js.map +1 -1
- package/dist-esm/src/utils/constants/applicationinsights.js +12 -30
- package/dist-esm/src/utils/constants/applicationinsights.js.map +1 -1
- package/dist-esm/src/utils/logUtils.js +177 -0
- package/dist-esm/src/utils/logUtils.js.map +1 -0
- package/dist-esm/src/utils/metricUtils.js +2 -42
- package/dist-esm/src/utils/metricUtils.js.map +1 -1
- package/dist-esm/src/utils/spanUtils.js +35 -31
- package/dist-esm/src/utils/spanUtils.js.map +1 -1
- package/package.json +13 -11
- package/types/monitor-opentelemetry-exporter.d.ts +27 -0
|
@@ -8,29 +8,80 @@ export function createTagsFromResource(resource) {
|
|
|
8
8
|
const context = getInstance();
|
|
9
9
|
const tags = Object.assign({}, context.tags);
|
|
10
10
|
if (resource && resource.attributes) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
tags[KnownContextTagKeys.AiCloudRole] = getCloudRole(resource);
|
|
12
|
+
tags[KnownContextTagKeys.AiCloudRoleInstance] = getCloudRoleInstance(resource);
|
|
13
|
+
const endUserId = resource.attributes[SemanticAttributes.ENDUSER_ID];
|
|
14
|
+
if (endUserId) {
|
|
15
|
+
tags[KnownContextTagKeys.AiUserId] = String(endUserId);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return tags;
|
|
19
|
+
}
|
|
20
|
+
function getCloudRole(resource) {
|
|
21
|
+
let cloudRole = "";
|
|
22
|
+
// Service attributes
|
|
23
|
+
const serviceName = resource.attributes[SemanticResourceAttributes.SERVICE_NAME];
|
|
24
|
+
const serviceNamespace = resource.attributes[SemanticResourceAttributes.SERVICE_NAMESPACE];
|
|
25
|
+
if (serviceName) {
|
|
26
|
+
// Custom Service name provided by customer is highest precedence
|
|
27
|
+
if (!String(serviceName).startsWith("unknown_service")) {
|
|
14
28
|
if (serviceNamespace) {
|
|
15
|
-
|
|
29
|
+
return `${serviceNamespace}.${serviceName}`;
|
|
16
30
|
}
|
|
17
31
|
else {
|
|
18
|
-
|
|
32
|
+
return String(serviceName);
|
|
19
33
|
}
|
|
20
34
|
}
|
|
21
|
-
const serviceInstanceId = resource.attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID];
|
|
22
|
-
if (serviceInstanceId) {
|
|
23
|
-
tags[KnownContextTagKeys.AiCloudRoleInstance] = String(serviceInstanceId);
|
|
24
|
-
}
|
|
25
35
|
else {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
36
|
+
// Service attributes will be only used if K8S attributes are not present
|
|
37
|
+
if (serviceNamespace) {
|
|
38
|
+
cloudRole = `${serviceNamespace}.${serviceName}`;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
cloudRole = String(serviceName);
|
|
42
|
+
}
|
|
31
43
|
}
|
|
32
44
|
}
|
|
33
|
-
|
|
45
|
+
// Kubernetes attributes should take precedence
|
|
46
|
+
const kubernetesDeploymentName = resource.attributes[SemanticResourceAttributes.K8S_DEPLOYMENT_NAME];
|
|
47
|
+
if (kubernetesDeploymentName) {
|
|
48
|
+
return String(kubernetesDeploymentName);
|
|
49
|
+
}
|
|
50
|
+
const kuberneteReplicasetName = resource.attributes[SemanticResourceAttributes.K8S_REPLICASET_NAME];
|
|
51
|
+
if (kuberneteReplicasetName) {
|
|
52
|
+
return String(kuberneteReplicasetName);
|
|
53
|
+
}
|
|
54
|
+
const kubernetesStatefulSetName = resource.attributes[SemanticResourceAttributes.K8S_STATEFULSET_NAME];
|
|
55
|
+
if (kubernetesStatefulSetName) {
|
|
56
|
+
return String(kubernetesStatefulSetName);
|
|
57
|
+
}
|
|
58
|
+
const kubernetesJobName = resource.attributes[SemanticResourceAttributes.K8S_JOB_NAME];
|
|
59
|
+
if (kubernetesJobName) {
|
|
60
|
+
return String(kubernetesJobName);
|
|
61
|
+
}
|
|
62
|
+
const kubernetesCronjobName = resource.attributes[SemanticResourceAttributes.K8S_CRONJOB_NAME];
|
|
63
|
+
if (kubernetesCronjobName) {
|
|
64
|
+
return String(kubernetesCronjobName);
|
|
65
|
+
}
|
|
66
|
+
const kubernetesDaemonsetName = resource.attributes[SemanticResourceAttributes.K8S_DAEMONSET_NAME];
|
|
67
|
+
if (kubernetesDaemonsetName) {
|
|
68
|
+
return String(kubernetesDaemonsetName);
|
|
69
|
+
}
|
|
70
|
+
return cloudRole;
|
|
71
|
+
}
|
|
72
|
+
function getCloudRoleInstance(resource) {
|
|
73
|
+
// Kubernetes attributes should take precedence
|
|
74
|
+
const kubernetesPodName = resource.attributes[SemanticResourceAttributes.K8S_POD_NAME];
|
|
75
|
+
if (kubernetesPodName) {
|
|
76
|
+
return String(kubernetesPodName);
|
|
77
|
+
}
|
|
78
|
+
// Service attributes
|
|
79
|
+
const serviceInstanceId = resource.attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID];
|
|
80
|
+
if (serviceInstanceId) {
|
|
81
|
+
return String(serviceInstanceId);
|
|
82
|
+
}
|
|
83
|
+
// Default
|
|
84
|
+
return os && os.hostname();
|
|
34
85
|
}
|
|
35
86
|
export function isSqlDB(dbSystem) {
|
|
36
87
|
return (dbSystem === DbSystemValues.DB2 ||
|
|
@@ -107,4 +158,39 @@ export function getDependencyTarget(attributes) {
|
|
|
107
158
|
}
|
|
108
159
|
return "";
|
|
109
160
|
}
|
|
161
|
+
export function createResourceMetricEnvelope(resource, instrumentationKey) {
|
|
162
|
+
if (resource && resource.attributes) {
|
|
163
|
+
const tags = createTagsFromResource(resource);
|
|
164
|
+
const resourceAttributes = {};
|
|
165
|
+
for (const key of Object.keys(resource.attributes)) {
|
|
166
|
+
// Avoid duplication ignoring fields already mapped.
|
|
167
|
+
if (!(key.startsWith("_MS.") ||
|
|
168
|
+
key == SemanticResourceAttributes.TELEMETRY_SDK_VERSION ||
|
|
169
|
+
key == SemanticResourceAttributes.TELEMETRY_SDK_LANGUAGE ||
|
|
170
|
+
key == SemanticResourceAttributes.TELEMETRY_SDK_NAME)) {
|
|
171
|
+
resourceAttributes[key] = resource.attributes[key];
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
// Only send event when resource attributes are available
|
|
175
|
+
if (Object.keys(resourceAttributes).length > 0) {
|
|
176
|
+
let envelope = {
|
|
177
|
+
name: "_APPRESOURCEPREVIEW_",
|
|
178
|
+
time: new Date(),
|
|
179
|
+
sampleRate: 100,
|
|
180
|
+
instrumentationKey: instrumentationKey,
|
|
181
|
+
version: 1,
|
|
182
|
+
data: {
|
|
183
|
+
baseType: "MetricData",
|
|
184
|
+
baseData: {
|
|
185
|
+
version: 2,
|
|
186
|
+
properties: resourceAttributes,
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
tags: tags,
|
|
190
|
+
};
|
|
191
|
+
return envelope;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
110
196
|
//# sourceMappingURL=common.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/utils/common.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EACL,0BAA0B,EAC1B,kBAAkB,EAClB,cAAc,GACf,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAInD,MAAM,UAAU,sBAAsB,CAAC,QAAkB;IACvD,MAAM,OAAO,GAAG,WAAW,EAAE,CAAC;IAC9B,MAAM,IAAI,qBAAc,OAAO,CAAC,IAAI,CAAE,CAAC;IACvC,IAAI,QAAQ,IAAI,QAAQ,CAAC,UAAU,EAAE;QACnC,MAAM,WAAW,GAAG,QAAQ,CAAC,UAAU,CAAC,0BAA0B,CAAC,YAAY,CAAC,CAAC;QACjF,MAAM,gBAAgB,GAAG,QAAQ,CAAC,UAAU,CAAC,0BAA0B,CAAC,iBAAiB,CAAC,CAAC;QAC3F,IAAI,WAAW,EAAE;YACf,IAAI,gBAAgB,EAAE;gBACpB,IAAI,CAAC,mBAAmB,CAAC,WAAW,CAAC,GAAG,GAAG,gBAAgB,IAAI,WAAW,EAAE,CAAC;aAC9E;iBAAM;gBACL,IAAI,CAAC,mBAAmB,CAAC,WAAW,CAAC,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;aAC7D;SACF;QACD,MAAM,iBAAiB,GAAG,QAAQ,CAAC,UAAU,CAAC,0BAA0B,CAAC,mBAAmB,CAAC,CAAC;QAC9F,IAAI,iBAAi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,CAAC,WAAW,CAAC,CAAC;IAC7D,IAAI,WAAW,EAAE;QACf,OAAO,MAAM,CAAC,WAAW,CAAC,CAAC;KAC5B;SAAM,IAAI,QAAQ,EAAE;QACnB,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC;KACzB;SAAM,IAAI,OAAO,EAAE;QAClB,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC;KACxB;SAAM,IAAI,WAAW,EAAE;QACtB,OAAO,MAAM,CAAC,WAAW,CAAC,CAAC;KAC5B;SAAM,IAAI,SAAS,EAAE;QACpB,OAAO,MAAM,CAAC,SAAS,CAAC,CAAC;KAC1B;IACD,OAAO,EAAE,CAAC;AACZ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport os from \"os\";\nimport {\n SemanticResourceAttributes,\n SemanticAttributes,\n DbSystemValues,\n} from \"@opentelemetry/semantic-conventions\";\nimport { Tags } from \"../types\";\nimport { getInstance } from \"../platform\";\nimport { KnownContextTagKeys } from \"../generated\";\nimport { Resource } from \"@opentelemetry/resources\";\nimport { Attributes } from \"@opentelemetry/api\";\n\nexport function createTagsFromResource(resource: Resource): Tags {\n const context = getInstance();\n const tags: Tags = { ...context.tags };\n if (resource && resource.attributes) {\n const serviceName = resource.attributes[SemanticResourceAttributes.SERVICE_NAME];\n const serviceNamespace = resource.attributes[SemanticResourceAttributes.SERVICE_NAMESPACE];\n if (serviceName) {\n if (serviceNamespace) {\n tags[KnownContextTagKeys.AiCloudRole] = `${serviceNamespace}.${serviceName}`;\n } else {\n tags[KnownContextTagKeys.AiCloudRole] = String(serviceName);\n }\n }\n const serviceInstanceId = resource.attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID];\n if (serviceInstanceId) {\n tags[KnownContextTagKeys.AiCloudRoleInstance] = String(serviceInstanceId);\n } else {\n tags[KnownContextTagKeys.AiCloudRoleInstance] = os && os.hostname();\n }\n const endUserId = resource.attributes[SemanticAttributes.ENDUSER_ID];\n if (endUserId) {\n tags[KnownContextTagKeys.AiUserId] = String(endUserId);\n }\n }\n return tags;\n}\n\nexport function isSqlDB(dbSystem: string) {\n return (\n dbSystem === DbSystemValues.DB2 ||\n dbSystem === DbSystemValues.DERBY ||\n dbSystem === DbSystemValues.MARIADB ||\n dbSystem === DbSystemValues.MSSQL ||\n dbSystem === DbSystemValues.ORACLE ||\n dbSystem === DbSystemValues.SQLITE ||\n dbSystem === DbSystemValues.OTHER_SQL ||\n dbSystem === DbSystemValues.HSQLDB ||\n dbSystem === DbSystemValues.H2\n );\n}\n\nexport function getUrl(attributes: Attributes): string {\n if (!attributes) {\n return \"\";\n }\n const httpMethod = attributes[SemanticAttributes.HTTP_METHOD];\n if (httpMethod) {\n const httpUrl = attributes[SemanticAttributes.HTTP_URL];\n if (httpUrl) {\n return String(httpUrl);\n } else {\n const httpScheme = attributes[SemanticAttributes.HTTP_SCHEME];\n const httpTarget = attributes[SemanticAttributes.HTTP_TARGET];\n if (httpScheme && httpTarget) {\n const httpHost = attributes[SemanticAttributes.HTTP_HOST];\n if (httpHost) {\n return `${httpScheme}://${httpHost}${httpTarget}`;\n } else {\n const netPeerPort = attributes[SemanticAttributes.NET_PEER_PORT];\n if (netPeerPort) {\n const netPeerName = attributes[SemanticAttributes.NET_PEER_NAME];\n if (netPeerName) {\n return `${httpScheme}://${netPeerName}:${netPeerPort}${httpTarget}`;\n } else {\n const netPeerIp = attributes[SemanticAttributes.NET_PEER_IP];\n if (netPeerIp) {\n return `${httpScheme}://${netPeerIp}:${netPeerPort}${httpTarget}`;\n }\n }\n }\n }\n }\n }\n }\n return \"\";\n}\n\nexport function getDependencyTarget(attributes: Attributes): string {\n if (!attributes) {\n return \"\";\n }\n const peerService = attributes[SemanticAttributes.PEER_SERVICE];\n const httpHost = attributes[SemanticAttributes.HTTP_HOST];\n const httpUrl = attributes[SemanticAttributes.HTTP_URL];\n const netPeerName = attributes[SemanticAttributes.NET_PEER_NAME];\n const netPeerIp = attributes[SemanticAttributes.NET_PEER_IP];\n if (peerService) {\n return String(peerService);\n } else if (httpHost) {\n return String(httpHost);\n } else if (httpUrl) {\n return String(httpUrl);\n } else if (netPeerName) {\n return String(netPeerName);\n } else if (netPeerIp) {\n return String(netPeerIp);\n }\n return \"\";\n}\n"]}
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/utils/common.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EACL,0BAA0B,EAC1B,kBAAkB,EAClB,cAAc,GACf,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAA6B,MAAM,cAAc,CAAC;AAI9E,MAAM,UAAU,sBAAsB,CAAC,QAAkB;IACvD,MAAM,OAAO,GAAG,WAAW,EAAE,CAAC;IAC9B,MAAM,IAAI,qBAAc,OAAO,CAAC,IAAI,CAAE,CAAC;IACvC,IAAI,QAAQ,IAAI,QAAQ,CAAC,UAAU,EAAE;QACnC,IAAI,CAAC,mBAAmB,CAAC,WAAW,CAAC,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;QAC/D,IAAI,CAAC,mBAAmB,CAAC,mBAAmB,CAAC,GAAG,oBAAoB,CAAC,QAAQ,CAAC,CAAC;QAC/E,MAAM,SAAS,GAAG,QAAQ,CAAC,UAAU,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC;QACrE,IAAI,SAAS,EAAE;YACb,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;SACxD;KACF;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,YAAY,CAAC,QAAkB;IACtC,IAAI,SAAS,GAAG,EAAE,CAAC;IACnB,qBAAqB;IACrB,MAAM,WAAW,GAAG,QAAQ,CAAC,UAAU,CAAC,0BAA0B,CAAC,YAAY,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0B,CAAC,sBAAsB;gBACxD,GAAG,IAAI,0BAA0B,CAAC,kBAAkB,CACrD,EACD;gBACA,kBAAkB,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAW,CAAC;aAC9D;SACF;QACD,yDAAyD;QACzD,IAAI,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;YAC9C,IAAI,QAAQ,GAAa;gBACvB,IAAI,EAAE,sBAAsB;gBAC5B,IAAI,EAAE,IAAI,IAAI,EAAE;gBAChB,UAAU,EAAE,GAAG;gBACf,kBAAkB,EAAE,kBAAkB;gBACtC,OAAO,EAAE,CAAC;gBACV,IAAI,EAAE;oBACJ,QAAQ,EAAE,YAAY;oBACtB,QAAQ,EAAE;wBACR,OAAO,EAAE,CAAC;wBACV,UAAU,EAAE,kBAAkB;qBAC/B;iBACF;gBACD,IAAI,EAAE,IAAI;aACX,CAAC;YACF,OAAO,QAAQ,CAAC;SACjB;KACF;IACD,OAAO;AACT,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport os from \"os\";\nimport {\n SemanticResourceAttributes,\n SemanticAttributes,\n DbSystemValues,\n} from \"@opentelemetry/semantic-conventions\";\nimport { Tags } from \"../types\";\nimport { getInstance } from \"../platform\";\nimport { KnownContextTagKeys, TelemetryItem as Envelope } from \"../generated\";\nimport { Resource } from \"@opentelemetry/resources\";\nimport { Attributes } from \"@opentelemetry/api\";\n\nexport function createTagsFromResource(resource: Resource): Tags {\n const context = getInstance();\n const tags: Tags = { ...context.tags };\n if (resource && resource.attributes) {\n tags[KnownContextTagKeys.AiCloudRole] = getCloudRole(resource);\n tags[KnownContextTagKeys.AiCloudRoleInstance] = getCloudRoleInstance(resource);\n const endUserId = resource.attributes[SemanticAttributes.ENDUSER_ID];\n if (endUserId) {\n tags[KnownContextTagKeys.AiUserId] = String(endUserId);\n }\n }\n return tags;\n}\n\nfunction getCloudRole(resource: Resource): string {\n let cloudRole = \"\";\n // Service attributes\n const serviceName = resource.attributes[SemanticResourceAttributes.SERVICE_NAME];\n const serviceNamespace = resource.attributes[SemanticResourceAttributes.SERVICE_NAMESPACE];\n if (serviceName) {\n // Custom Service name provided by customer is highest precedence\n if (!String(serviceName).startsWith(\"unknown_service\")) {\n if (serviceNamespace) {\n return `${serviceNamespace}.${serviceName}`;\n } else {\n return String(serviceName);\n }\n } else {\n // Service attributes will be only used if K8S attributes are not present\n if (serviceNamespace) {\n cloudRole = `${serviceNamespace}.${serviceName}`;\n } else {\n cloudRole = String(serviceName);\n }\n }\n }\n // Kubernetes attributes should take precedence\n const kubernetesDeploymentName =\n resource.attributes[SemanticResourceAttributes.K8S_DEPLOYMENT_NAME];\n if (kubernetesDeploymentName) {\n return String(kubernetesDeploymentName);\n }\n const kuberneteReplicasetName =\n resource.attributes[SemanticResourceAttributes.K8S_REPLICASET_NAME];\n if (kuberneteReplicasetName) {\n return String(kuberneteReplicasetName);\n }\n const kubernetesStatefulSetName =\n resource.attributes[SemanticResourceAttributes.K8S_STATEFULSET_NAME];\n if (kubernetesStatefulSetName) {\n return String(kubernetesStatefulSetName);\n }\n const kubernetesJobName = resource.attributes[SemanticResourceAttributes.K8S_JOB_NAME];\n if (kubernetesJobName) {\n return String(kubernetesJobName);\n }\n const kubernetesCronjobName = resource.attributes[SemanticResourceAttributes.K8S_CRONJOB_NAME];\n if (kubernetesCronjobName) {\n return String(kubernetesCronjobName);\n }\n const kubernetesDaemonsetName =\n resource.attributes[SemanticResourceAttributes.K8S_DAEMONSET_NAME];\n if (kubernetesDaemonsetName) {\n return String(kubernetesDaemonsetName);\n }\n return cloudRole;\n}\n\nfunction getCloudRoleInstance(resource: Resource): string {\n // Kubernetes attributes should take precedence\n const kubernetesPodName = resource.attributes[SemanticResourceAttributes.K8S_POD_NAME];\n if (kubernetesPodName) {\n return String(kubernetesPodName);\n }\n // Service attributes\n const serviceInstanceId = resource.attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID];\n if (serviceInstanceId) {\n return String(serviceInstanceId);\n }\n // Default\n return os && os.hostname();\n}\n\nexport function isSqlDB(dbSystem: string) {\n return (\n dbSystem === DbSystemValues.DB2 ||\n dbSystem === DbSystemValues.DERBY ||\n dbSystem === DbSystemValues.MARIADB ||\n dbSystem === DbSystemValues.MSSQL ||\n dbSystem === DbSystemValues.ORACLE ||\n dbSystem === DbSystemValues.SQLITE ||\n dbSystem === DbSystemValues.OTHER_SQL ||\n dbSystem === DbSystemValues.HSQLDB ||\n dbSystem === DbSystemValues.H2\n );\n}\n\nexport function getUrl(attributes: Attributes): string {\n if (!attributes) {\n return \"\";\n }\n const httpMethod = attributes[SemanticAttributes.HTTP_METHOD];\n if (httpMethod) {\n const httpUrl = attributes[SemanticAttributes.HTTP_URL];\n if (httpUrl) {\n return String(httpUrl);\n } else {\n const httpScheme = attributes[SemanticAttributes.HTTP_SCHEME];\n const httpTarget = attributes[SemanticAttributes.HTTP_TARGET];\n if (httpScheme && httpTarget) {\n const httpHost = attributes[SemanticAttributes.HTTP_HOST];\n if (httpHost) {\n return `${httpScheme}://${httpHost}${httpTarget}`;\n } else {\n const netPeerPort = attributes[SemanticAttributes.NET_PEER_PORT];\n if (netPeerPort) {\n const netPeerName = attributes[SemanticAttributes.NET_PEER_NAME];\n if (netPeerName) {\n return `${httpScheme}://${netPeerName}:${netPeerPort}${httpTarget}`;\n } else {\n const netPeerIp = attributes[SemanticAttributes.NET_PEER_IP];\n if (netPeerIp) {\n return `${httpScheme}://${netPeerIp}:${netPeerPort}${httpTarget}`;\n }\n }\n }\n }\n }\n }\n }\n return \"\";\n}\n\nexport function getDependencyTarget(attributes: Attributes): string {\n if (!attributes) {\n return \"\";\n }\n const peerService = attributes[SemanticAttributes.PEER_SERVICE];\n const httpHost = attributes[SemanticAttributes.HTTP_HOST];\n const httpUrl = attributes[SemanticAttributes.HTTP_URL];\n const netPeerName = attributes[SemanticAttributes.NET_PEER_NAME];\n const netPeerIp = attributes[SemanticAttributes.NET_PEER_IP];\n if (peerService) {\n return String(peerService);\n } else if (httpHost) {\n return String(httpHost);\n } else if (httpUrl) {\n return String(httpUrl);\n } else if (netPeerName) {\n return String(netPeerName);\n } else if (netPeerIp) {\n return String(netPeerIp);\n }\n return \"\";\n}\n\nexport function createResourceMetricEnvelope(\n resource: Resource,\n instrumentationKey: string\n): Envelope | undefined {\n if (resource && resource.attributes) {\n const tags = createTagsFromResource(resource);\n const resourceAttributes: { [propertyName: string]: string } = {};\n for (const key of Object.keys(resource.attributes)) {\n // Avoid duplication ignoring fields already mapped.\n if (\n !(\n key.startsWith(\"_MS.\") ||\n key == SemanticResourceAttributes.TELEMETRY_SDK_VERSION ||\n key == SemanticResourceAttributes.TELEMETRY_SDK_LANGUAGE ||\n key == SemanticResourceAttributes.TELEMETRY_SDK_NAME\n )\n ) {\n resourceAttributes[key] = resource.attributes[key] as string;\n }\n }\n // Only send event when resource attributes are available\n if (Object.keys(resourceAttributes).length > 0) {\n let envelope: Envelope = {\n name: \"_APPRESOURCEPREVIEW_\",\n time: new Date(),\n sampleRate: 100, // Metrics are never sampled\n instrumentationKey: instrumentationKey,\n version: 1,\n data: {\n baseType: \"MetricData\",\n baseData: {\n version: 2,\n properties: resourceAttributes,\n },\n },\n tags: tags,\n };\n return envelope;\n }\n }\n return;\n}\n"]}
|
|
@@ -6,7 +6,7 @@ import * as Constants from "../Declarations/Constants";
|
|
|
6
6
|
* ConnectionString parser.
|
|
7
7
|
* @internal
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
class ConnectionStringParser {
|
|
10
10
|
static parse(connectionString) {
|
|
11
11
|
if (!connectionString) {
|
|
12
12
|
return {};
|
|
@@ -65,4 +65,5 @@ export class ConnectionStringParser {
|
|
|
65
65
|
}
|
|
66
66
|
ConnectionStringParser.FIELDS_SEPARATOR = ";";
|
|
67
67
|
ConnectionStringParser.FIELD_KEY_VALUE_SEPARATOR = "=";
|
|
68
|
+
export { ConnectionStringParser };
|
|
68
69
|
//# sourceMappingURL=connectionStringParser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connectionStringParser.js","sourceRoot":"","sources":["../../../src/utils/connectionStringParser.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAG1C,OAAO,KAAK,SAAS,MAAM,2BAA2B,CAAC;AAEvD;;;GAGG;AACH,
|
|
1
|
+
{"version":3,"file":"connectionStringParser.js","sourceRoot":"","sources":["../../../src/utils/connectionStringParser.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAG1C,OAAO,KAAK,SAAS,MAAM,2BAA2B,CAAC;AAEvD;;;GAGG;AACH,MAAa,sBAAsB;IAK1B,MAAM,CAAC,KAAK,CAAC,gBAAyB;QAC3C,IAAI,CAAC,gBAAgB,EAAE;YACrB,OAAO,EAAE,CAAC;SACX;QAED,MAAM,OAAO,GAAG,gBAAgB,CAAC,KAAK,CAAC,sBAAsB,CAAC,gBAAgB,CAAC,CAAC;QAChF,IAAI,OAAO,GAAG,IAAI,CAAC;QAEnB,MAAM,MAAM,GAAqB,OAAO,CAAC,MAAM,CAAC,CAAC,MAAwB,EAAE,EAAU,EAAE,EAAE;YACvF,MAAM,OAAO,GAAG,EAAE,CAAC,KAAK,CAAC,sBAAsB,CAAC,yBAAyB,CAAC,CAAC;YAE3E,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;gBACxB,sCAAsC;gBACtC,MAAM,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,WAAW,EAAyB,CAAC;gBAC5D,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;gBACzB,uCAAY,MAAM,KAAE,CAAC,GAAG,CAAC,EAAE,KAAK,IAAG;aACpC;YACD,IAAI,CAAC,KAAK,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,yEAAyE,EACzE,gBAAgB,CACjB,CAAC;SACH;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAEM,MAAM,CAAC,WAAW,CAAC,GAAW;QACnC,IAAI,MAAM,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;QACxB,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;YAClC,8BAA8B;YAC9B,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;SAChD;QACD,gCAAgC;QAChC,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,GAAG,EAAE;YACpC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;SAC9B;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;;AA1EuB,uCAAgB,GAAG,GAAG,CAAC;AAEvB,gDAAyB,GAAG,GAAG,CAAC;SAH7C,sBAAsB","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { diag } from \"@opentelemetry/api\";\nimport { ConnectionString, ConnectionStringKey } from \"../Declarations/Contracts\";\n\nimport * as Constants from \"../Declarations/Constants\";\n\n/**\n * ConnectionString parser.\n * @internal\n */\nexport class ConnectionStringParser {\n private static readonly FIELDS_SEPARATOR = \";\";\n\n private static readonly FIELD_KEY_VALUE_SEPARATOR = \"=\";\n\n public static parse(connectionString?: string): ConnectionString {\n if (!connectionString) {\n return {};\n }\n\n const kvPairs = connectionString.split(ConnectionStringParser.FIELDS_SEPARATOR);\n let isValid = true;\n\n const result: ConnectionString = kvPairs.reduce((fields: ConnectionString, kv: string) => {\n const kvParts = kv.split(ConnectionStringParser.FIELD_KEY_VALUE_SEPARATOR);\n\n if (kvParts.length === 2) {\n // only save fields with valid formats\n const key = kvParts[0].toLowerCase() as ConnectionStringKey;\n const value = kvParts[1];\n return { ...fields, [key]: value };\n }\n diag.error(\n `Connection string key-value pair is invalid: ${kv}`,\n `Entire connection string will be discarded`,\n connectionString\n );\n isValid = false;\n return fields;\n }, {});\n\n if (isValid && Object.keys(result).length > 0) {\n // this is a valid connection string, so parse the results\n\n if (result.endpointsuffix) {\n // use endpoint suffix where overrides are not provided\n const locationPrefix = result.location ? `${result.location}.` : \"\";\n result.ingestionendpoint =\n result.ingestionendpoint || `https://${locationPrefix}dc.${result.endpointsuffix}`;\n result.liveendpoint =\n result.liveendpoint || `https://${locationPrefix}live.${result.endpointsuffix}`;\n }\n\n result.ingestionendpoint = result.ingestionendpoint\n ? ConnectionStringParser.sanitizeUrl(result.ingestionendpoint)\n : Constants.DEFAULT_BREEZE_ENDPOINT;\n result.liveendpoint = result.liveendpoint\n ? ConnectionStringParser.sanitizeUrl(result.liveendpoint)\n : Constants.DEFAULT_LIVEMETRICS_ENDPOINT;\n if (result.authorization && result.authorization.toLowerCase() !== \"ikey\") {\n diag.warn(\n `Connection String contains an unsupported 'Authorization' value: ${result.authorization!}. Defaulting to 'Authorization=ikey'. Instrumentation Key ${result.instrumentationkey!}`\n );\n }\n } else {\n diag.error(\n \"An invalid connection string was passed in. There may be telemetry loss\",\n connectionString\n );\n }\n\n return result;\n }\n\n public static sanitizeUrl(url: string) {\n let newUrl = url.trim();\n if (newUrl.indexOf(\"https://\") < 0) {\n // Try to update http to https\n newUrl = newUrl.replace(\"http://\", \"https://\");\n }\n // Remove final slash if present\n if (newUrl[newUrl.length - 1] == \"/\") {\n newUrl = newUrl.slice(0, -1);\n }\n return newUrl;\n }\n}\n"]}
|
|
@@ -19,7 +19,7 @@ export const TIME_SINCE_ENQUEUED = "timeSinceEnqueued";
|
|
|
19
19
|
* AzureMonitorTraceExporter version.
|
|
20
20
|
* @internal
|
|
21
21
|
*/
|
|
22
|
-
export const packageVersion = "1.0.0-beta.
|
|
22
|
+
export const packageVersion = "1.0.0-beta.13";
|
|
23
23
|
export var DependencyTypes;
|
|
24
24
|
(function (DependencyTypes) {
|
|
25
25
|
DependencyTypes["InProc"] = "InProc";
|
|
@@ -29,33 +29,15 @@ export var DependencyTypes;
|
|
|
29
29
|
DependencyTypes["Grpc"] = "GRPC";
|
|
30
30
|
})(DependencyTypes || (DependencyTypes = {}));
|
|
31
31
|
export const AzureMonitorSampleRate = "_MS.sampleRate";
|
|
32
|
-
export
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
export
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
StandardMetricIds["EXCEPTION_COUNT"] = "exceptions/count";
|
|
44
|
-
StandardMetricIds["TRACE_COUNT"] = "traces/count";
|
|
45
|
-
})(StandardMetricIds || (StandardMetricIds = {}));
|
|
46
|
-
// Names expected in Breeze side for dimensions
|
|
47
|
-
export const PreAggregatedMetricPropertyNames = {
|
|
48
|
-
cloudRoleInstance: "cloud/roleInstance",
|
|
49
|
-
cloudRoleName: "cloud/roleName",
|
|
50
|
-
operationSynthetic: "operation/synthetic",
|
|
51
|
-
requestSuccess: "Request.Success",
|
|
52
|
-
requestResultCode: "request/resultCode",
|
|
53
|
-
dependencyType: "Dependency.Type",
|
|
54
|
-
dependencyTarget: "dependency/target",
|
|
55
|
-
dependencySuccess: "Dependency.Success",
|
|
56
|
-
dependencyResultCode: "dependency/resultCode",
|
|
57
|
-
traceSeverityLevel: "trace/severityLevel",
|
|
58
|
-
metricId: "_MS.MetricId",
|
|
59
|
-
IsAutocollected: "_MS.IsAutocollected",
|
|
60
|
-
};
|
|
32
|
+
export const ApplicationInsightsBaseType = "_MS.baseType";
|
|
33
|
+
export const ApplicationInsightsMessageName = "Microsoft.ApplicationInsights.Message";
|
|
34
|
+
export const ApplicationInsightsExceptionName = "Microsoft.ApplicationInsights.Exception";
|
|
35
|
+
export const ApplicationInsightsPageViewName = "Microsoft.ApplicationInsights.PageView";
|
|
36
|
+
export const ApplicationInsightsAvailabilityName = "Microsoft.ApplicationInsights.Availability";
|
|
37
|
+
export const ApplicationInsightsEventName = "Microsoft.ApplicationInsights.Event";
|
|
38
|
+
export const ApplicationInsightsMessageBaseType = "MessageData";
|
|
39
|
+
export const ApplicationInsightsExceptionBaseType = "TelemetryExceptionData";
|
|
40
|
+
export const ApplicationInsightsPageViewBaseType = "PageViewData";
|
|
41
|
+
export const ApplicationInsightsAvailabilityBaseType = "AvailabilityData";
|
|
42
|
+
export const ApplicationInsightsEventBaseType = "TelemetryEventData";
|
|
61
43
|
//# sourceMappingURL=applicationinsights.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applicationinsights.js","sourceRoot":"","sources":["../../../../src/utils/constants/applicationinsights.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,WAAW,CAAC;AACpC;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,cAAc,CAAC;AAC5C;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,mBAAmB,CAAC;AACvD;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,eAAe,CAAC;AAE9C,MAAM,CAAN,IAAY,eAMX;AAND,WAAY,eAAe;IACzB,oCAAiB,CAAA;IACjB,iDAA8B,CAAA;IAC9B,8BAAW,CAAA;IACX,gCAAa,CAAA;IACb,gCAAa,CAAA;AACf,CAAC,EANW,eAAe,KAAf,eAAe,QAM1B;AAED,MAAM,CAAC,MAAM,sBAAsB,GAAG,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"applicationinsights.js","sourceRoot":"","sources":["../../../../src/utils/constants/applicationinsights.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,WAAW,CAAC;AACpC;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,cAAc,CAAC;AAC5C;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,mBAAmB,CAAC;AACvD;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,eAAe,CAAC;AAE9C,MAAM,CAAN,IAAY,eAMX;AAND,WAAY,eAAe;IACzB,oCAAiB,CAAA;IACjB,iDAA8B,CAAA;IAC9B,8BAAW,CAAA;IACX,gCAAa,CAAA;IACb,gCAAa,CAAA;AACf,CAAC,EANW,eAAe,KAAf,eAAe,QAM1B;AAED,MAAM,CAAC,MAAM,sBAAsB,GAAG,gBAAgB,CAAC;AACvD,MAAM,CAAC,MAAM,2BAA2B,GAAG,cAAc,CAAC;AAE1D,MAAM,CAAC,MAAM,8BAA8B,GAAG,uCAAuC,CAAC;AACtF,MAAM,CAAC,MAAM,gCAAgC,GAAG,yCAAyC,CAAC;AAC1F,MAAM,CAAC,MAAM,+BAA+B,GAAG,wCAAwC,CAAC;AACxF,MAAM,CAAC,MAAM,mCAAmC,GAAG,4CAA4C,CAAC;AAChG,MAAM,CAAC,MAAM,4BAA4B,GAAG,qCAAqC,CAAC;AAElF,MAAM,CAAC,MAAM,kCAAkC,GAAG,aAAa,CAAC;AAChE,MAAM,CAAC,MAAM,oCAAoC,GAAG,wBAAwB,CAAC;AAC7E,MAAM,CAAC,MAAM,mCAAmC,GAAG,cAAc,CAAC;AAClE,MAAM,CAAC,MAAM,uCAAuC,GAAG,kBAAkB,CAAC;AAC1E,MAAM,CAAC,MAAM,gCAAgC,GAAG,oBAAoB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/**\n * AI MS Links.\n * @internal\n */\nexport const MS_LINKS = \"_MS.links\";\n/**\n * AI enqueued time attribute.\n * @internal\n */\nexport const ENQUEUED_TIME = \"enqueuedTime\";\n/**\n * AI time since enqueued attribute.\n * @internal\n */\nexport const TIME_SINCE_ENQUEUED = \"timeSinceEnqueued\";\n/**\n * AzureMonitorTraceExporter version.\n * @internal\n */\nexport const packageVersion = \"1.0.0-beta.13\";\n\nexport enum DependencyTypes {\n InProc = \"InProc\",\n QueueMessage = \"Queue Message\",\n Sql = \"SQL\",\n Http = \"Http\",\n Grpc = \"GRPC\",\n}\n\nexport const AzureMonitorSampleRate = \"_MS.sampleRate\";\nexport const ApplicationInsightsBaseType = \"_MS.baseType\";\n\nexport const ApplicationInsightsMessageName = \"Microsoft.ApplicationInsights.Message\";\nexport const ApplicationInsightsExceptionName = \"Microsoft.ApplicationInsights.Exception\";\nexport const ApplicationInsightsPageViewName = \"Microsoft.ApplicationInsights.PageView\";\nexport const ApplicationInsightsAvailabilityName = \"Microsoft.ApplicationInsights.Availability\";\nexport const ApplicationInsightsEventName = \"Microsoft.ApplicationInsights.Event\";\n\nexport const ApplicationInsightsMessageBaseType = \"MessageData\";\nexport const ApplicationInsightsExceptionBaseType = \"TelemetryExceptionData\";\nexport const ApplicationInsightsPageViewBaseType = \"PageViewData\";\nexport const ApplicationInsightsAvailabilityBaseType = \"AvailabilityData\";\nexport const ApplicationInsightsEventBaseType = \"TelemetryEventData\";\n"]}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT license.
|
|
3
|
+
import { KnownContextTagKeys, KnownSeverityLevel, } from "../generated";
|
|
4
|
+
import { createTagsFromResource } from "./common";
|
|
5
|
+
import { SemanticAttributes } from "@opentelemetry/semantic-conventions";
|
|
6
|
+
import { hrTimeToMilliseconds } from "@opentelemetry/core";
|
|
7
|
+
import { diag } from "@opentelemetry/api";
|
|
8
|
+
import { ApplicationInsightsAvailabilityBaseType, ApplicationInsightsAvailabilityName, ApplicationInsightsBaseType, ApplicationInsightsEventBaseType, ApplicationInsightsEventName, ApplicationInsightsExceptionBaseType, ApplicationInsightsExceptionName, ApplicationInsightsMessageBaseType, ApplicationInsightsMessageName, ApplicationInsightsPageViewBaseType, ApplicationInsightsPageViewName, } from "./constants/applicationinsights";
|
|
9
|
+
/**
|
|
10
|
+
* Log to Azure envelope parsing.
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export function logToEnvelope(log, ikey) {
|
|
14
|
+
const time = log.hrTime ? new Date(hrTimeToMilliseconds(log.hrTime)) : new Date();
|
|
15
|
+
let sampleRate = 100;
|
|
16
|
+
const instrumentationKey = ikey;
|
|
17
|
+
const tags = createTagsFromLog(log);
|
|
18
|
+
const [properties, measurements] = createPropertiesFromLog(log);
|
|
19
|
+
let name;
|
|
20
|
+
let baseType;
|
|
21
|
+
let baseData;
|
|
22
|
+
if (!log.attributes[ApplicationInsightsBaseType]) {
|
|
23
|
+
// Get Exception attributes if available
|
|
24
|
+
let exceptionType = log.attributes[SemanticAttributes.EXCEPTION_TYPE];
|
|
25
|
+
if (exceptionType) {
|
|
26
|
+
let exceptionMessage = log.attributes[SemanticAttributes.EXCEPTION_MESSAGE];
|
|
27
|
+
let exceptionStacktrace = log.attributes[SemanticAttributes.EXCEPTION_STACKTRACE];
|
|
28
|
+
name = ApplicationInsightsExceptionName;
|
|
29
|
+
baseType = ApplicationInsightsExceptionBaseType;
|
|
30
|
+
let exceptionDetails = {
|
|
31
|
+
typeName: String(exceptionType),
|
|
32
|
+
message: String(exceptionMessage),
|
|
33
|
+
hasFullStack: exceptionStacktrace ? true : false,
|
|
34
|
+
stack: String(exceptionStacktrace),
|
|
35
|
+
};
|
|
36
|
+
const exceptionData = {
|
|
37
|
+
exceptions: [exceptionDetails],
|
|
38
|
+
severityLevel: String(getSeverity(log.severityNumber)),
|
|
39
|
+
version: 2,
|
|
40
|
+
};
|
|
41
|
+
baseData = exceptionData;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
name = ApplicationInsightsMessageName;
|
|
45
|
+
baseType = ApplicationInsightsMessageBaseType;
|
|
46
|
+
const messageData = {
|
|
47
|
+
message: String(log.body),
|
|
48
|
+
severityLevel: String(getSeverity(log.severityNumber)),
|
|
49
|
+
version: 2,
|
|
50
|
+
};
|
|
51
|
+
baseData = messageData;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
// If Legacy Application Insights Log
|
|
56
|
+
baseType = String(log.attributes[ApplicationInsightsBaseType]);
|
|
57
|
+
name = getLegacyApplicationInsightsName(log);
|
|
58
|
+
baseData = getLegacyApplicationInsightsBaseData(log);
|
|
59
|
+
if (!baseData) {
|
|
60
|
+
// Failed to parse log
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
name,
|
|
66
|
+
sampleRate,
|
|
67
|
+
time,
|
|
68
|
+
instrumentationKey,
|
|
69
|
+
tags,
|
|
70
|
+
version: 1,
|
|
71
|
+
data: {
|
|
72
|
+
baseType,
|
|
73
|
+
baseData: Object.assign(Object.assign({}, baseData), { properties,
|
|
74
|
+
measurements }),
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function createTagsFromLog(log) {
|
|
79
|
+
var _a, _b;
|
|
80
|
+
const tags = createTagsFromResource(log.resource);
|
|
81
|
+
if ((_a = log.spanContext) === null || _a === void 0 ? void 0 : _a.traceId) {
|
|
82
|
+
tags[KnownContextTagKeys.AiOperationId] = log.spanContext.traceId;
|
|
83
|
+
}
|
|
84
|
+
if ((_b = log.spanContext) === null || _b === void 0 ? void 0 : _b.spanId) {
|
|
85
|
+
tags[KnownContextTagKeys.AiOperationParentId] = log.spanContext.spanId;
|
|
86
|
+
}
|
|
87
|
+
return tags;
|
|
88
|
+
}
|
|
89
|
+
function createPropertiesFromLog(log) {
|
|
90
|
+
const measurements = {};
|
|
91
|
+
const properties = {};
|
|
92
|
+
if (log.attributes) {
|
|
93
|
+
for (const key of Object.keys(log.attributes)) {
|
|
94
|
+
// Avoid duplication ignoring fields already mapped.
|
|
95
|
+
if (!(key.startsWith("_MS.") ||
|
|
96
|
+
key == SemanticAttributes.EXCEPTION_TYPE ||
|
|
97
|
+
key == SemanticAttributes.EXCEPTION_MESSAGE ||
|
|
98
|
+
key == SemanticAttributes.EXCEPTION_STACKTRACE)) {
|
|
99
|
+
properties[key] = log.attributes[key];
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return [properties, measurements];
|
|
104
|
+
}
|
|
105
|
+
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/data-model.md#field-severitynumber
|
|
106
|
+
function getSeverity(severityNumber) {
|
|
107
|
+
if (severityNumber) {
|
|
108
|
+
if (severityNumber > 0 && severityNumber < 9) {
|
|
109
|
+
return KnownSeverityLevel.Verbose;
|
|
110
|
+
}
|
|
111
|
+
else if (severityNumber >= 9 && severityNumber < 13) {
|
|
112
|
+
return KnownSeverityLevel.Information;
|
|
113
|
+
}
|
|
114
|
+
else if (severityNumber >= 13 && severityNumber < 17) {
|
|
115
|
+
return KnownSeverityLevel.Warning;
|
|
116
|
+
}
|
|
117
|
+
else if (severityNumber >= 17 && severityNumber < 21) {
|
|
118
|
+
return KnownSeverityLevel.Error;
|
|
119
|
+
}
|
|
120
|
+
else if (severityNumber >= 21 && severityNumber < 25) {
|
|
121
|
+
return KnownSeverityLevel.Critical;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
function getLegacyApplicationInsightsName(log) {
|
|
127
|
+
let name = "";
|
|
128
|
+
switch (log.attributes[ApplicationInsightsBaseType]) {
|
|
129
|
+
case ApplicationInsightsAvailabilityBaseType:
|
|
130
|
+
name = ApplicationInsightsAvailabilityName;
|
|
131
|
+
break;
|
|
132
|
+
case ApplicationInsightsExceptionBaseType:
|
|
133
|
+
name = ApplicationInsightsExceptionName;
|
|
134
|
+
break;
|
|
135
|
+
case ApplicationInsightsMessageBaseType:
|
|
136
|
+
name = ApplicationInsightsMessageName;
|
|
137
|
+
break;
|
|
138
|
+
case ApplicationInsightsPageViewBaseType:
|
|
139
|
+
name = ApplicationInsightsPageViewName;
|
|
140
|
+
break;
|
|
141
|
+
case ApplicationInsightsEventBaseType:
|
|
142
|
+
name = ApplicationInsightsEventName;
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
return name;
|
|
146
|
+
}
|
|
147
|
+
function getLegacyApplicationInsightsBaseData(log) {
|
|
148
|
+
let baseData = {
|
|
149
|
+
version: 2,
|
|
150
|
+
};
|
|
151
|
+
if (log.body) {
|
|
152
|
+
try {
|
|
153
|
+
switch (log.attributes[ApplicationInsightsBaseType]) {
|
|
154
|
+
case ApplicationInsightsAvailabilityBaseType:
|
|
155
|
+
baseData = JSON.parse(log.body);
|
|
156
|
+
break;
|
|
157
|
+
case ApplicationInsightsExceptionBaseType:
|
|
158
|
+
baseData = JSON.parse(log.body);
|
|
159
|
+
break;
|
|
160
|
+
case ApplicationInsightsMessageBaseType:
|
|
161
|
+
baseData = JSON.parse(log.body);
|
|
162
|
+
break;
|
|
163
|
+
case ApplicationInsightsPageViewBaseType:
|
|
164
|
+
baseData = JSON.parse(log.body);
|
|
165
|
+
break;
|
|
166
|
+
case ApplicationInsightsEventBaseType:
|
|
167
|
+
baseData = JSON.parse(log.body);
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
catch (err) {
|
|
172
|
+
diag.error("AzureMonitorLogExporter failed to parse Application Insights Telemetry");
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return baseData;
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=logUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logUtils.js","sourceRoot":"","sources":["../../../src/utils/logUtils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAGL,mBAAmB,EACnB,kBAAkB,GAOnB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAElD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AAEzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,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AAQ,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAA2B,CAAC;oBAC1D,MAAM;gBACR,KAAK,kCAAkC;oBACrC,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAgB,CAAC;oBAC/C,MAAM;gBACR,KAAK,mCAAmC;oBACtC,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAiB,CAAC;oBAChD,MAAM;gBACR,KAAK,gCAAgC;oBACnC,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAuB,CAAC;oBACtD,MAAM;aACT;SACF;QAAC,OAAO,GAAG,EAAE;YACZ,IAAI,CAAC,KAAK,CAAC,wEAAwE,CAAC,CAAC;SACtF;KACF;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n AvailabilityData,\n TelemetryItem as Envelope,\n KnownContextTagKeys,\n KnownSeverityLevel,\n MessageData,\n MonitorDomain,\n PageViewData,\n TelemetryEventData,\n TelemetryExceptionData,\n TelemetryExceptionDetails,\n} from \"../generated\";\nimport { createTagsFromResource } from \"./common\";\nimport { ReadableLogRecord } from \"@opentelemetry/sdk-logs\";\nimport { SemanticAttributes } from \"@opentelemetry/semantic-conventions\";\nimport { Measurements, Properties, Tags } from \"../types\";\nimport { hrTimeToMilliseconds } from \"@opentelemetry/core\";\nimport { diag } from \"@opentelemetry/api\";\nimport {\n ApplicationInsightsAvailabilityBaseType,\n ApplicationInsightsAvailabilityName,\n ApplicationInsightsBaseType,\n ApplicationInsightsEventBaseType,\n ApplicationInsightsEventName,\n ApplicationInsightsExceptionBaseType,\n ApplicationInsightsExceptionName,\n ApplicationInsightsMessageBaseType,\n ApplicationInsightsMessageName,\n ApplicationInsightsPageViewBaseType,\n ApplicationInsightsPageViewName,\n} from \"./constants/applicationinsights\";\n\n/**\n * Log to Azure envelope parsing.\n * @internal\n */\nexport function logToEnvelope(log: ReadableLogRecord, ikey: string): Envelope | undefined {\n const time = log.hrTime ? new Date(hrTimeToMilliseconds(log.hrTime)) : new Date();\n let sampleRate = 100;\n const instrumentationKey = ikey;\n const tags = createTagsFromLog(log);\n const [properties, measurements] = createPropertiesFromLog(log);\n let name: string;\n let baseType: string;\n let baseData: MonitorDomain;\n\n if (!log.attributes[ApplicationInsightsBaseType]) {\n // Get Exception attributes if available\n let exceptionType = log.attributes[SemanticAttributes.EXCEPTION_TYPE];\n if (exceptionType) {\n let exceptionMessage = log.attributes[SemanticAttributes.EXCEPTION_MESSAGE];\n let exceptionStacktrace = log.attributes[SemanticAttributes.EXCEPTION_STACKTRACE];\n name = ApplicationInsightsExceptionName;\n baseType = ApplicationInsightsExceptionBaseType;\n let exceptionDetails: TelemetryExceptionDetails = {\n typeName: String(exceptionType),\n message: String(exceptionMessage),\n hasFullStack: exceptionStacktrace ? true : false,\n stack: String(exceptionStacktrace),\n };\n const exceptionData: TelemetryExceptionData = {\n exceptions: [exceptionDetails],\n severityLevel: String(getSeverity(log.severityNumber)),\n version: 2,\n };\n baseData = exceptionData;\n } else {\n name = ApplicationInsightsMessageName;\n baseType = ApplicationInsightsMessageBaseType;\n const messageData: MessageData = {\n message: String(log.body),\n severityLevel: String(getSeverity(log.severityNumber)),\n version: 2,\n };\n baseData = messageData;\n }\n } else {\n // If Legacy Application Insights Log\n baseType = String(log.attributes[ApplicationInsightsBaseType]);\n name = getLegacyApplicationInsightsName(log);\n baseData = getLegacyApplicationInsightsBaseData(log);\n if (!baseData) {\n // Failed to parse log\n return;\n }\n }\n return {\n name,\n sampleRate,\n time,\n instrumentationKey,\n tags,\n version: 1,\n data: {\n baseType,\n baseData: {\n ...baseData,\n properties,\n measurements,\n },\n },\n };\n}\n\nfunction createTagsFromLog(log: ReadableLogRecord): Tags {\n const tags: Tags = createTagsFromResource(log.resource);\n if (log.spanContext?.traceId) {\n tags[KnownContextTagKeys.AiOperationId] = log.spanContext.traceId;\n }\n if (log.spanContext?.spanId) {\n tags[KnownContextTagKeys.AiOperationParentId] = log.spanContext.spanId;\n }\n return tags;\n}\n\nfunction createPropertiesFromLog(log: ReadableLogRecord): [Properties, Measurements] {\n const measurements: Measurements = {};\n const properties: { [propertyName: string]: string } = {};\n if (log.attributes) {\n for (const key of Object.keys(log.attributes)) {\n // Avoid duplication ignoring fields already mapped.\n if (\n !(\n key.startsWith(\"_MS.\") ||\n key == SemanticAttributes.EXCEPTION_TYPE ||\n key == SemanticAttributes.EXCEPTION_MESSAGE ||\n key == SemanticAttributes.EXCEPTION_STACKTRACE\n )\n ) {\n properties[key] = log.attributes[key] as string;\n }\n }\n }\n return [properties, measurements];\n}\n\n// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/data-model.md#field-severitynumber\nfunction getSeverity(severityNumber: number | undefined): KnownSeverityLevel | undefined {\n if (severityNumber) {\n if (severityNumber > 0 && severityNumber < 9) {\n return KnownSeverityLevel.Verbose;\n } else if (severityNumber >= 9 && severityNumber < 13) {\n return KnownSeverityLevel.Information;\n } else if (severityNumber >= 13 && severityNumber < 17) {\n return KnownSeverityLevel.Warning;\n } else if (severityNumber >= 17 && severityNumber < 21) {\n return KnownSeverityLevel.Error;\n } else if (severityNumber >= 21 && severityNumber < 25) {\n return KnownSeverityLevel.Critical;\n }\n }\n return;\n}\n\nfunction getLegacyApplicationInsightsName(log: ReadableLogRecord): string {\n let name = \"\";\n switch (log.attributes[ApplicationInsightsBaseType]) {\n case ApplicationInsightsAvailabilityBaseType:\n name = ApplicationInsightsAvailabilityName;\n break;\n case ApplicationInsightsExceptionBaseType:\n name = ApplicationInsightsExceptionName;\n break;\n case ApplicationInsightsMessageBaseType:\n name = ApplicationInsightsMessageName;\n break;\n case ApplicationInsightsPageViewBaseType:\n name = ApplicationInsightsPageViewName;\n break;\n case ApplicationInsightsEventBaseType:\n name = ApplicationInsightsEventName;\n break;\n }\n return name;\n}\n\nfunction getLegacyApplicationInsightsBaseData(log: ReadableLogRecord): MonitorDomain {\n let baseData: MonitorDomain = {\n version: 2,\n };\n if (log.body) {\n try {\n switch (log.attributes[ApplicationInsightsBaseType]) {\n case ApplicationInsightsAvailabilityBaseType:\n baseData = JSON.parse(log.body) as AvailabilityData;\n break;\n case ApplicationInsightsExceptionBaseType:\n baseData = JSON.parse(log.body) as TelemetryExceptionData;\n break;\n case ApplicationInsightsMessageBaseType:\n baseData = JSON.parse(log.body) as MessageData;\n break;\n case ApplicationInsightsPageViewBaseType:\n baseData = JSON.parse(log.body) as PageViewData;\n break;\n case ApplicationInsightsEventBaseType:\n baseData = JSON.parse(log.body) as TelemetryEventData;\n break;\n }\n } catch (err) {\n diag.error(\"AzureMonitorLogExporter failed to parse Application Insights Telemetry\");\n }\n }\n return baseData;\n}\n"]}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT license.
|
|
3
3
|
import { DataPointType } from "@opentelemetry/sdk-metrics";
|
|
4
|
-
import {
|
|
5
|
-
import { PreAggregatedMetricPropertyNames, StandardMetricIds, StandardMetrics, } from "./constants/applicationinsights";
|
|
6
|
-
import { createTagsFromResource, getDependencyTarget } from "./common";
|
|
4
|
+
import { createTagsFromResource } from "./common";
|
|
7
5
|
function createPropertiesFromMetricAttributes(attributes) {
|
|
8
6
|
const properties = {};
|
|
9
7
|
if (attributes) {
|
|
@@ -31,20 +29,13 @@ export function resourceMetricsToEnvelope(metrics, ikey, isStatsbeat) {
|
|
|
31
29
|
}
|
|
32
30
|
metrics.scopeMetrics.forEach((scopeMetric) => {
|
|
33
31
|
scopeMetric.metrics.forEach((metric) => {
|
|
34
|
-
var _a, _b;
|
|
35
|
-
const isStandardMetric = (_b = (_a = metric.descriptor) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.startsWith("azureMonitor.");
|
|
36
32
|
metric.dataPoints.forEach((dataPoint) => {
|
|
37
33
|
let baseData = {
|
|
38
34
|
metrics: [],
|
|
39
35
|
version: 2,
|
|
40
36
|
properties: {},
|
|
41
37
|
};
|
|
42
|
-
|
|
43
|
-
baseData.properties = createStandardMetricsProperties(metric.descriptor.name, dataPoint.attributes, tags);
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
baseData.properties = createPropertiesFromMetricAttributes(dataPoint.attributes);
|
|
47
|
-
}
|
|
38
|
+
baseData.properties = createPropertiesFromMetricAttributes(dataPoint.attributes);
|
|
48
39
|
var metricDataPoint = {
|
|
49
40
|
name: metric.descriptor.name,
|
|
50
41
|
value: 0,
|
|
@@ -80,35 +71,4 @@ export function resourceMetricsToEnvelope(metrics, ikey, isStatsbeat) {
|
|
|
80
71
|
});
|
|
81
72
|
return envelopes;
|
|
82
73
|
}
|
|
83
|
-
function createStandardMetricsProperties(name, attributes, tags) {
|
|
84
|
-
const properties = {};
|
|
85
|
-
properties[PreAggregatedMetricPropertyNames.IsAutocollected] = "True";
|
|
86
|
-
properties[PreAggregatedMetricPropertyNames.cloudRoleInstance] =
|
|
87
|
-
tags[KnownContextTagKeys.AiCloudRoleInstance];
|
|
88
|
-
properties[PreAggregatedMetricPropertyNames.cloudRoleName] =
|
|
89
|
-
tags[KnownContextTagKeys.AiCloudRole];
|
|
90
|
-
if (name == StandardMetrics.HTTP_REQUEST_DURATION) {
|
|
91
|
-
properties[PreAggregatedMetricPropertyNames.metricId] = StandardMetricIds.REQUEST_DURATION;
|
|
92
|
-
let statusCode = String(attributes["http.status_code"]);
|
|
93
|
-
properties[PreAggregatedMetricPropertyNames.requestResultCode] = statusCode;
|
|
94
|
-
properties[PreAggregatedMetricPropertyNames.requestSuccess] =
|
|
95
|
-
statusCode == "200" ? "True" : "False";
|
|
96
|
-
}
|
|
97
|
-
else if (name == StandardMetrics.HTTP_DEPENDENCY_DURATION) {
|
|
98
|
-
properties[PreAggregatedMetricPropertyNames.metricId] = StandardMetricIds.DEPENDENCY_DURATION;
|
|
99
|
-
let statusCode = String(attributes["http.status_code"]);
|
|
100
|
-
properties[PreAggregatedMetricPropertyNames.dependencyTarget] = getDependencyTarget(attributes);
|
|
101
|
-
properties[PreAggregatedMetricPropertyNames.dependencyResultCode] = statusCode;
|
|
102
|
-
properties[PreAggregatedMetricPropertyNames.dependencyType] = "http";
|
|
103
|
-
properties[PreAggregatedMetricPropertyNames.dependencySuccess] =
|
|
104
|
-
statusCode == "200" ? "True" : "False";
|
|
105
|
-
}
|
|
106
|
-
else if (name == StandardMetrics.TRACE_COUNT) {
|
|
107
|
-
properties[PreAggregatedMetricPropertyNames.metricId] = StandardMetricIds.TRACE_COUNT;
|
|
108
|
-
}
|
|
109
|
-
else if (name == StandardMetrics.EXCEPTION_COUNT) {
|
|
110
|
-
properties[PreAggregatedMetricPropertyNames.metricId] = StandardMetricIds.EXCEPTION_COUNT;
|
|
111
|
-
}
|
|
112
|
-
return properties;
|
|
113
|
-
}
|
|
114
74
|
//# sourceMappingURL=metricUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metricUtils.js","sourceRoot":"","sources":["../../../src/utils/metricUtils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,aAAa,EAA8B,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"metricUtils.js","sourceRoot":"","sources":["../../../src/utils/metricUtils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,aAAa,EAA8B,MAAM,4BAA4B,CAAC;AAEvF,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAElD,SAAS,oCAAoC,CAAC,UAAuB;IAGnE,MAAM,UAAU,GAAuC,EAAE,CAAC;IAC1D,IAAI,UAAU,EAAE;QACd,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;YACzC,UAAU,CAAC,GAAG,CAAC,GAAG,UAA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L,eAAe,CAAC,KAAK,GAAI,SAAS,CAAC,KAAmB,CAAC,GAAG,IAAI,CAAC,CAAC;oBAChE,eAAe,CAAC,KAAK,GAAI,SAAS,CAAC,KAAmB,CAAC,KAAK,CAAC;oBAC7D,eAAe,CAAC,GAAG,GAAI,SAAS,CAAC,KAAmB,CAAC,GAAG,CAAC;oBACzD,eAAe,CAAC,GAAG,GAAI,SAAS,CAAC,KAAmB,CAAC,GAAG,CAAC;iBAC1D;gBACD,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;gBACvC,IAAI,QAAQ,GAAa;oBACvB,IAAI,EAAE,YAAY;oBAClB,IAAI,EAAE,IAAI;oBACV,UAAU,EAAE,GAAG;oBACf,kBAAkB,EAAE,kBAAkB;oBACtC,IAAI,EAAE,IAAI;oBACV,OAAO,EAAE,CAAC;oBACV,IAAI,EAAE;wBACJ,QAAQ,EAAE,YAAY;wBACtB,QAAQ,oBACH,QAAQ,CACZ;qBACF;iBACF,CAAC;gBACF,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC3B,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { Attributes } from \"@opentelemetry/api\";\nimport { DataPointType, Histogram, ResourceMetrics } from \"@opentelemetry/sdk-metrics\";\nimport { TelemetryItem as Envelope, MetricsData, MetricDataPoint } from \"../generated\";\nimport { createTagsFromResource } from \"./common\";\n\nfunction createPropertiesFromMetricAttributes(attributes?: Attributes): {\n [propertyName: string]: string;\n} {\n const properties: { [propertyName: string]: string } = {};\n if (attributes) {\n for (const key of Object.keys(attributes)) {\n properties[key] = attributes[key] as string;\n }\n }\n return properties;\n}\n\n/**\n * Metric to Azure envelope parsing.\n * @internal\n */\nexport function resourceMetricsToEnvelope(\n metrics: ResourceMetrics,\n ikey: string,\n isStatsbeat?: boolean\n): Envelope[] {\n let 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 let baseData: MetricsData = {\n metrics: [],\n version: 2,\n properties: {},\n };\n baseData.properties = createPropertiesFromMetricAttributes(dataPoint.attributes);\n var metricDataPoint: MetricDataPoint = {\n name: metric.descriptor.name,\n value: 0,\n dataPointType: \"Aggregation\",\n };\n if (\n metric.dataPointType == DataPointType.SUM ||\n metric.dataPointType == DataPointType.GAUGE\n ) {\n metricDataPoint.value = dataPoint.value as number;\n metricDataPoint.count = 1;\n } else {\n metricDataPoint.value = (dataPoint.value as Histogram).sum || 0;\n metricDataPoint.count = (dataPoint.value as Histogram).count;\n metricDataPoint.max = (dataPoint.value as Histogram).max;\n metricDataPoint.min = (dataPoint.value as Histogram).min;\n }\n baseData.metrics.push(metricDataPoint);\n let 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"]}
|