@azure/monitor-opentelemetry-exporter 1.0.0-beta.5 → 1.0.0-beta.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +11 -13
  2. package/dist/index.js +706 -245
  3. package/dist-esm/src/Declarations/Constants.js +1 -1
  4. package/dist-esm/src/Declarations/Constants.js.map +1 -1
  5. package/dist-esm/src/config.js +2 -4
  6. package/dist-esm/src/config.js.map +1 -1
  7. package/dist-esm/src/export/base.js +172 -0
  8. package/dist-esm/src/export/base.js.map +1 -0
  9. package/dist-esm/src/export/metric.js +50 -0
  10. package/dist-esm/src/export/metric.js.map +1 -0
  11. package/dist-esm/src/export/trace.js +14 -145
  12. package/dist-esm/src/export/trace.js.map +1 -1
  13. package/dist-esm/src/generated/applicationInsightsClient.js.map +1 -1
  14. package/dist-esm/src/generated/applicationInsightsClientContext.js +2 -2
  15. package/dist-esm/src/generated/applicationInsightsClientContext.js.map +1 -1
  16. package/dist-esm/src/generated/models/index.js.map +1 -1
  17. package/dist-esm/src/index.js +2 -0
  18. package/dist-esm/src/index.js.map +1 -1
  19. package/dist-esm/src/platform/nodejs/constants.js +1 -1
  20. package/dist-esm/src/platform/nodejs/constants.js.map +1 -1
  21. package/dist-esm/src/platform/nodejs/httpSender.js +12 -3
  22. package/dist-esm/src/platform/nodejs/httpSender.js.map +1 -1
  23. package/dist-esm/src/platform/nodejs/persist/fileAccessControl.js +171 -0
  24. package/dist-esm/src/platform/nodejs/persist/fileAccessControl.js.map +1 -0
  25. package/dist-esm/src/platform/nodejs/persist/fileSystemHelpers.js.map +1 -1
  26. package/dist-esm/src/platform/nodejs/persist/fileSystemPersist.js +40 -19
  27. package/dist-esm/src/platform/nodejs/persist/fileSystemPersist.js.map +1 -1
  28. package/dist-esm/src/utils/breezeUtils.js +5 -4
  29. package/dist-esm/src/utils/breezeUtils.js.map +1 -1
  30. package/dist-esm/src/utils/constants/applicationinsights.js +1 -1
  31. package/dist-esm/src/utils/constants/applicationinsights.js.map +1 -1
  32. package/dist-esm/src/utils/eventhub.js +1 -1
  33. package/dist-esm/src/utils/eventhub.js.map +1 -1
  34. package/dist-esm/src/utils/metricUtils.js +53 -0
  35. package/dist-esm/src/utils/metricUtils.js.map +1 -0
  36. package/dist-esm/src/utils/resourceUtils.js +35 -0
  37. package/dist-esm/src/utils/resourceUtils.js.map +1 -0
  38. package/dist-esm/src/utils/spanUtils.js +118 -49
  39. package/dist-esm/src/utils/spanUtils.js.map +1 -1
  40. package/package.json +25 -26
  41. package/types/monitor-opentelemetry-exporter.d.ts +110 -7
  42. package/CHANGELOG.md +0 -38
@@ -4,7 +4,7 @@ import { SpanKind } from "@opentelemetry/api";
4
4
  import { hrTimeToMilliseconds } from "@opentelemetry/core";
5
5
  import { SemanticAttributes } from "@opentelemetry/semantic-conventions";
6
6
  import { TIME_SINCE_ENQUEUED, ENQUEUED_TIME } from "./constants/applicationinsights";
7
- import { AzNamespace, MessageBusDestination } from "./constants/span/azAttributes";
7
+ import { AzNamespace, MessageBusDestination, } from "./constants/span/azAttributes";
8
8
  /**
9
9
  * Average span.links[].attributes.enqueuedTime
10
10
  */
@@ -1 +1 @@
1
- {"version":3,"file":"eventhub.js","sourceRoot":"","sources":["../../../src/utils/eventhub.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AAGzE,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AACrF,OAAO,EACL,WAAW,EACX,qBAAqB,EAEtB,MAAM,+BAA+B,CAAC;AAEvC;;GAEG;AACH,MAAM,oBAAoB,GAAG,CAAC,IAAkB,EAAE,EAAE;IAClD,IAAI,iBAAiB,G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E,CAAC;YAC5D,MAAM;QACR,KAAK,QAAQ,CAAC,QAAQ;YACpB,QAAQ,CAAC,IAAI,GAAG,mBAAmB,SAAS,EAAE,CAAC;YAC/C,QAAQ,CAAC,MAAM,GAAG,GAAG,WAAW,IAAI,qBAAqB,EAAE,CAAC;YAC5D,MAAM;QACR,KAAK,QAAQ,CAAC,QAAQ;YACpB,QAAQ,CAAC,IAAI,GAAG,mBAAmB,SAAS,EAAE,CAAC;YAC9C,QAAgB,CAAC,MAAM,GAAG,GAAG,WAAW,IAAI,qBAAqB,EAAE,CAAC;YACrE,QAAQ,CAAC,YAAY,mCAChB,QAAQ,CAAC,YAAY,KACxB,CAAC,mBAAmB,CAAC,EAAE,oBAAoB,CAAC,IAAI,CAAC,GAClD,CAAC;YACF,MAAM;QACR,QAAQ,CAAC,QAAQ;KAClB;AACH,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { SpanKind } from \"@opentelemetry/api\";\nimport { hrTimeToMilliseconds } from \"@opentelemetry/core\";\nimport { SemanticAttributes } from \"@opentelemetry/semantic-conventions\";\nimport { ReadableSpan } from \"@opentelemetry/tracing\";\nimport { RemoteDependencyData, RequestData } from \"../generated\";\nimport { TIME_SINCE_ENQUEUED, ENQUEUED_TIME } from \"./constants/applicationinsights\";\nimport {\n AzNamespace,\n MessageBusDestination,\n MicrosoftEventHub\n} from \"./constants/span/azAttributes\";\n\n/**\n * Average span.links[].attributes.enqueuedTime\n */\nconst getTimeSinceEnqueued = (span: ReadableSpan) => {\n let countEnqueueDiffs = 0;\n let sumEnqueueDiffs = 0;\n const startTimeMs = hrTimeToMilliseconds(span.startTime);\n\n span.links.forEach(({ attributes }) => {\n const enqueuedTime = attributes?.[ENQUEUED_TIME] as string | number;\n if (enqueuedTime) {\n countEnqueueDiffs += 1;\n sumEnqueueDiffs += startTimeMs - (parseFloat(enqueuedTime.toString()) || 0);\n }\n });\n\n return Math.max(sumEnqueueDiffs / (countEnqueueDiffs || 1), 0);\n};\n\n/**\n * Implementation of Mapping to Azure Monitor\n *\n * https://gist.github.com/lmolkova/e4215c0f44a49ef824983382762e6b92#mapping-to-azure-monitor-application-insights-telemetry\n * @internal\n */\nexport const parseEventHubSpan = (\n span: ReadableSpan,\n baseData: RequestData | RemoteDependencyData\n): void => {\n const namespace = span.attributes[AzNamespace] as typeof MicrosoftEventHub;\n const peerAddress = ((span.attributes[SemanticAttributes.NET_PEER_NAME] ||\n span.attributes[\"peer.address\"] ||\n \"unknown\") as string).replace(/\\/$/g, \"\"); // remove trailing \"/\"\n const messageBusDestination = (span.attributes[MessageBusDestination] || \"unknown\") as string;\n\n switch (span.kind) {\n case SpanKind.CLIENT:\n baseData.type = namespace;\n baseData.target = `${peerAddress}/${messageBusDestination}`;\n break;\n case SpanKind.PRODUCER:\n baseData.type = `Queue Message | ${namespace}`;\n baseData.target = `${peerAddress}/${messageBusDestination}`;\n break;\n case SpanKind.CONSUMER:\n baseData.type = `Queue Message | ${namespace}`;\n (baseData as any).source = `${peerAddress}/${messageBusDestination}`;\n baseData.measurements = {\n ...baseData.measurements,\n [TIME_SINCE_ENQUEUED]: getTimeSinceEnqueued(span)\n };\n break;\n default: // no op\n }\n};\n"]}
1
+ {"version":3,"file":"eventhub.js","sourceRoot":"","sources":["../../../src/utils/eventhub.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AAGzE,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AACrF,OAAO,EACL,WAAW,EACX,qBAAqB,GAEtB,MAAM,+BAA+B,CAAC;AAEvC;;GAEG;AACH,MAAM,oBAAoB,GAAG,CAAC,IAAkB,EAAE,EAAE;IAClD,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AI,qBAAqB,EAAE,CAAC;YAC5D,MAAM;QACR,KAAK,QAAQ,CAAC,QAAQ;YACpB,QAAQ,CAAC,IAAI,GAAG,mBAAmB,SAAS,EAAE,CAAC;YAC/C,QAAQ,CAAC,MAAM,GAAG,GAAG,WAAW,IAAI,qBAAqB,EAAE,CAAC;YAC5D,MAAM;QACR,KAAK,QAAQ,CAAC,QAAQ;YACpB,QAAQ,CAAC,IAAI,GAAG,mBAAmB,SAAS,EAAE,CAAC;YAC9C,QAAgB,CAAC,MAAM,GAAG,GAAG,WAAW,IAAI,qBAAqB,EAAE,CAAC;YACrE,QAAQ,CAAC,YAAY,mCAChB,QAAQ,CAAC,YAAY,KACxB,CAAC,mBAAmB,CAAC,EAAE,oBAAoB,CAAC,IAAI,CAAC,GAClD,CAAC;YACF,MAAM;QACR,QAAQ,CAAC,QAAQ;KAClB;AACH,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { SpanKind } from \"@opentelemetry/api\";\nimport { hrTimeToMilliseconds } from \"@opentelemetry/core\";\nimport { SemanticAttributes } from \"@opentelemetry/semantic-conventions\";\nimport { ReadableSpan } from \"@opentelemetry/sdk-trace-base\";\nimport { RemoteDependencyData, RequestData } from \"../generated\";\nimport { TIME_SINCE_ENQUEUED, ENQUEUED_TIME } from \"./constants/applicationinsights\";\nimport {\n AzNamespace,\n MessageBusDestination,\n MicrosoftEventHub,\n} from \"./constants/span/azAttributes\";\n\n/**\n * Average span.links[].attributes.enqueuedTime\n */\nconst getTimeSinceEnqueued = (span: ReadableSpan) => {\n let countEnqueueDiffs = 0;\n let sumEnqueueDiffs = 0;\n const startTimeMs = hrTimeToMilliseconds(span.startTime);\n\n span.links.forEach(({ attributes }) => {\n const enqueuedTime = attributes?.[ENQUEUED_TIME] as string | number;\n if (enqueuedTime) {\n countEnqueueDiffs += 1;\n sumEnqueueDiffs += startTimeMs - (parseFloat(enqueuedTime.toString()) || 0);\n }\n });\n\n return Math.max(sumEnqueueDiffs / (countEnqueueDiffs || 1), 0);\n};\n\n/**\n * Implementation of Mapping to Azure Monitor\n *\n * https://gist.github.com/lmolkova/e4215c0f44a49ef824983382762e6b92#mapping-to-azure-monitor-application-insights-telemetry\n * @internal\n */\nexport const parseEventHubSpan = (\n span: ReadableSpan,\n baseData: RequestData | RemoteDependencyData\n): void => {\n const namespace = span.attributes[AzNamespace] as typeof MicrosoftEventHub;\n const peerAddress = (\n (span.attributes[SemanticAttributes.NET_PEER_NAME] ||\n span.attributes[\"peer.address\"] ||\n \"unknown\") as string\n ).replace(/\\/$/g, \"\"); // remove trailing \"/\"\n const messageBusDestination = (span.attributes[MessageBusDestination] || \"unknown\") as string;\n\n switch (span.kind) {\n case SpanKind.CLIENT:\n baseData.type = namespace;\n baseData.target = `${peerAddress}/${messageBusDestination}`;\n break;\n case SpanKind.PRODUCER:\n baseData.type = `Queue Message | ${namespace}`;\n baseData.target = `${peerAddress}/${messageBusDestination}`;\n break;\n case SpanKind.CONSUMER:\n baseData.type = `Queue Message | ${namespace}`;\n (baseData as any).source = `${peerAddress}/${messageBusDestination}`;\n baseData.measurements = {\n ...baseData.measurements,\n [TIME_SINCE_ENQUEUED]: getTimeSinceEnqueued(span),\n };\n break;\n default: // no op\n }\n};\n"]}
@@ -0,0 +1,53 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT license.
3
+ import { DataPointType } from "@opentelemetry/sdk-metrics-base";
4
+ import { createTagsFromResource } from "./resourceUtils";
5
+ /**
6
+ * Metric to Azure envelope parsing.
7
+ * @internal
8
+ */
9
+ export function resourceMetricsToEnvelope(metrics, ikey) {
10
+ let envelopes = [];
11
+ const time = new Date();
12
+ const instrumentationKey = ikey;
13
+ const tags = createTagsFromResource(metrics.resource);
14
+ metrics.scopeMetrics.forEach((scopeMetric) => {
15
+ let baseData = {
16
+ metrics: [],
17
+ version: 2,
18
+ };
19
+ scopeMetric.metrics.forEach((metric) => {
20
+ metric.dataPoints.forEach((dataPoint) => {
21
+ var metricDataPoint = {
22
+ name: metric.descriptor.name,
23
+ value: 0,
24
+ dataPointType: "Aggregation",
25
+ };
26
+ if (metric.dataPointType == DataPointType.SINGULAR) {
27
+ metricDataPoint.value = dataPoint.value;
28
+ metricDataPoint.count = 1;
29
+ }
30
+ else {
31
+ metricDataPoint.value = dataPoint.value.sum;
32
+ metricDataPoint.count = dataPoint.value.count;
33
+ }
34
+ baseData.metrics.push(metricDataPoint);
35
+ });
36
+ });
37
+ let envelope = {
38
+ name: "Microsoft.ApplicationInsights.Metric",
39
+ time: time,
40
+ sampleRate: 100,
41
+ instrumentationKey: instrumentationKey,
42
+ tags: tags,
43
+ version: 1,
44
+ data: {
45
+ baseType: "MetricData",
46
+ baseData: Object.assign({}, baseData),
47
+ },
48
+ };
49
+ envelopes.push(envelope);
50
+ });
51
+ return envelopes;
52
+ }
53
+ //# sourceMappingURL=metricUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metricUtils.js","sourceRoot":"","sources":["../../../src/utils/metricUtils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,aAAa,EAA8B,MAAM,iCAAiC,CAAC;AAE5F,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAEzD;;;GAGG;AACH,MAAM,UAAU,yBAAyB,CAAC,OAAwB,EAAE,IAAY;IAC9E,IAAI,SAAS,GAAe,EAAE,CAAC;IAC/B,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;IACxB,MAAM,kBAAkB,GAAG,IAAI,CAAC;IAChC,MAAM,IAAI,GAAG,sBAAsB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAEtD,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE;QAC3C,IAAI,QAAQ,GAAgB;YAC1B,OAAO,EAAE,EAAE;YACX,OAAO,EAAE,CAAC;SACX,CAAC;QACF,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;YACrC,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE;gBACtC,IAAI,eAAe,GAAoB;oBACrC,IAAI,EAAE,MAAM,CAAC,UAAU,CAAC,IAAI;oBAC5B,KAAK,EAAE,CAAC;oBACR,aAAa,EAAE,aAAa;iBAC7B,CAAC;gBACF,IAAI,MAAM,CAAC,aAAa,IAAI,aAAa,CAAC,QAAQ,EAAE;oBAClD,eAAe,CAAC,KAAK,GAAG,SAAS,CAAC,KAAe,CAAC;oBAClD,eAAe,CAAC,KAAK,GAAG,CAAC,CAAC;iBAC3B;qBAAM;oBACL,eAAe,CAAC,KAAK,GAAI,SAAS,CAAC,KAAmB,CAAC,GAAG,CAAC;oBAC3D,eAAe,CAAC,KAAK,GAAI,SAAS,CAAC,KAAmB,CAAC,KAAK,CAAC;iBAC9D;gBACD,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;YACzC,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QACH,IAAI,QAAQ,GAAa;YACvB,IAAI,EAAE,sCAAsC;YAC5C,IAAI,EAAE,IAAI;YACV,UAAU,EAAE,GAAG;YACf,kBAAkB,EAAE,kBAAkB;YACtC,IAAI,EAAE,IAAI;YACV,OAAO,EAAE,CAAC;YACV,IAAI,EAAE;gBACJ,QAAQ,EAAE,YAAY;gBACtB,QAAQ,oBACH,QAAQ,CACZ;aACF;SACF,CAAC;QACF,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;IAEH,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { DataPointType, Histogram, ResourceMetrics } from \"@opentelemetry/sdk-metrics-base\";\nimport { TelemetryItem as Envelope, MetricsData, MetricDataPoint } from \"../generated\";\nimport { createTagsFromResource } from \"./resourceUtils\";\n\n/**\n * Metric to Azure envelope parsing.\n * @internal\n */\nexport function resourceMetricsToEnvelope(metrics: ResourceMetrics, ikey: string): Envelope[] {\n let envelopes: Envelope[] = [];\n const time = new Date();\n const instrumentationKey = ikey;\n const tags = createTagsFromResource(metrics.resource);\n\n metrics.scopeMetrics.forEach((scopeMetric) => {\n let baseData: MetricsData = {\n metrics: [],\n version: 2,\n };\n scopeMetric.metrics.forEach((metric) => {\n metric.dataPoints.forEach((dataPoint) => {\n var metricDataPoint: MetricDataPoint = {\n name: metric.descriptor.name,\n value: 0,\n dataPointType: \"Aggregation\",\n };\n if (metric.dataPointType == DataPointType.SINGULAR) {\n metricDataPoint.value = dataPoint.value as number;\n metricDataPoint.count = 1;\n } else {\n metricDataPoint.value = (dataPoint.value as Histogram).sum;\n metricDataPoint.count = (dataPoint.value as Histogram).count;\n }\n baseData.metrics.push(metricDataPoint);\n });\n });\n let envelope: Envelope = {\n name: \"Microsoft.ApplicationInsights.Metric\",\n time: time,\n sampleRate: 100,\n instrumentationKey: instrumentationKey,\n tags: tags,\n version: 1,\n data: {\n baseType: \"MetricData\",\n baseData: {\n ...baseData,\n },\n },\n };\n envelopes.push(envelope);\n });\n\n return envelopes;\n}\n"]}
@@ -0,0 +1,35 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT license.
3
+ import os from "os";
4
+ import { SemanticResourceAttributes, SemanticAttributes, } from "@opentelemetry/semantic-conventions";
5
+ import { getInstance } from "../platform";
6
+ import { KnownContextTagKeys } from "../generated";
7
+ export function createTagsFromResource(resource) {
8
+ const context = getInstance();
9
+ const tags = Object.assign({}, context.tags);
10
+ if (resource && resource.attributes) {
11
+ const serviceName = resource.attributes[SemanticResourceAttributes.SERVICE_NAME];
12
+ const serviceNamespace = resource.attributes[SemanticResourceAttributes.SERVICE_NAMESPACE];
13
+ if (serviceName) {
14
+ if (serviceNamespace) {
15
+ tags[KnownContextTagKeys.AiCloudRole] = `${serviceNamespace}.${serviceName}`;
16
+ }
17
+ else {
18
+ tags[KnownContextTagKeys.AiCloudRole] = String(serviceName);
19
+ }
20
+ }
21
+ const serviceInstanceId = resource.attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID];
22
+ if (serviceInstanceId) {
23
+ tags[KnownContextTagKeys.AiCloudRoleInstance] = String(serviceInstanceId);
24
+ }
25
+ else {
26
+ tags[KnownContextTagKeys.AiCloudRoleInstance] = os && os.hostname();
27
+ }
28
+ const endUserId = resource.attributes[SemanticAttributes.ENDUSER_ID];
29
+ if (endUserId) {
30
+ tags[KnownContextTagKeys.AiUserId] = String(endUserId);
31
+ }
32
+ }
33
+ return tags;
34
+ }
35
+ //# sourceMappingURL=resourceUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resourceUtils.js","sourceRoot":"","sources":["../../../src/utils/resourceUtils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EACL,0BAA0B,EAC1B,kBAAkB,GACnB,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAGnD,MAAM,UAAU,sBAAsB,CAAC,QAAkB;IACvD,MAAM,OAAO,GAAG,WAAW,EAAE,CAAC;IAC9B,MAAM,IAAI,qBAAc,OAAO,CAAC,IAAI,CAAE,CAAC;IACvC,IAAI,QAAQ,IAAI,QAAQ,CAAC,UAAU,EAAE;QACnC,MAAM,WAAW,GAAG,QAAQ,CAAC,UAAU,CAAC,0BAA0B,CAAC,YAAY,CAAC,CAAC;QACjF,MAAM,gBAAgB,GAAG,QAAQ,CAAC,UAAU,CAAC,0BAA0B,CAAC,iBAAiB,CAAC,CAAC;QAC3F,IAAI,WAAW,EAAE;YACf,IAAI,gBAAgB,EAAE;gBACpB,IAAI,CAAC,mBAAmB,CAAC,WAAW,CAAC,GAAG,GAAG,gBAAgB,IAAI,WAAW,EAAE,CAAC;aAC9E;iBAAM;gBACL,IAAI,CAAC,mBAAmB,CAAC,WAAW,CAAC,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;aAC7D;SACF;QACD,MAAM,iBAAiB,GAAG,QAAQ,CAAC,UAAU,CAAC,0BAA0B,CAAC,mBAAmB,CAAC,CAAC;QAC9F,IAAI,iBAAiB,EAAE;YACrB,IAAI,CAAC,mBAAmB,CAAC,mBAAmB,CAAC,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC;SAC3E;aAAM;YACL,IAAI,CAAC,mBAAmB,CAAC,mBAAmB,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,QAAQ,EAAE,CAAC;SACrE;QACD,MAAM,SAAS,GAAG,QAAQ,CAAC,UAAU,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC;QACrE,IAAI,SAAS,EAAE;YACb,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;SACxD;KACF;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport os from \"os\";\nimport {\n SemanticResourceAttributes,\n SemanticAttributes,\n} from \"@opentelemetry/semantic-conventions\";\nimport { Tags } from \"../types\";\nimport { getInstance } from \"../platform\";\nimport { KnownContextTagKeys } from \"../generated\";\nimport { Resource } from \"@opentelemetry/resources\";\n\nexport function createTagsFromResource(resource: Resource): Tags {\n const context = getInstance();\n const tags: Tags = { ...context.tags };\n if (resource && resource.attributes) {\n const serviceName = resource.attributes[SemanticResourceAttributes.SERVICE_NAME];\n const serviceNamespace = resource.attributes[SemanticResourceAttributes.SERVICE_NAMESPACE];\n if (serviceName) {\n if (serviceNamespace) {\n tags[KnownContextTagKeys.AiCloudRole] = `${serviceNamespace}.${serviceName}`;\n } else {\n tags[KnownContextTagKeys.AiCloudRole] = String(serviceName);\n }\n }\n const serviceInstanceId = resource.attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID];\n if (serviceInstanceId) {\n tags[KnownContextTagKeys.AiCloudRoleInstance] = String(serviceInstanceId);\n } else {\n tags[KnownContextTagKeys.AiCloudRoleInstance] = os && os.hostname();\n }\n const endUserId = resource.attributes[SemanticAttributes.ENDUSER_ID];\n if (endUserId) {\n tags[KnownContextTagKeys.AiUserId] = String(endUserId);\n }\n }\n return tags;\n}\n"]}
@@ -1,46 +1,30 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT license.
3
- import os from "os";
4
3
  import { URL } from "url";
5
4
  import { hrTimeToMilliseconds } from "@opentelemetry/core";
6
5
  import { diag, SpanKind, SpanStatusCode } from "@opentelemetry/api";
7
- import { SemanticResourceAttributes, SemanticAttributes, DbSystemValues } from "@opentelemetry/semantic-conventions";
6
+ import { SemanticAttributes, DbSystemValues } from "@opentelemetry/semantic-conventions";
7
+ import { createTagsFromResource } from "./resourceUtils";
8
8
  import { msToTimeSpan } from "./breezeUtils";
9
- import { getInstance } from "../platform";
10
9
  import { parseEventHubSpan } from "./eventhub";
11
10
  import { DependencyTypes, MS_LINKS } from "./constants/applicationinsights";
12
11
  import { AzNamespace, MicrosoftEventHub } from "./constants/span/azAttributes";
13
- import { KnownContextTagKeys } from "../generated";
14
- function createTagsFromSpan(span) {
15
- const context = getInstance();
16
- const tags = Object.assign({}, context.tags);
12
+ import { KnownContextTagKeys, } from "../generated";
13
+ function createGenericTagsFromSpan(span) {
14
+ const tags = createTagsFromResource(span.resource);
17
15
  tags[KnownContextTagKeys.AiOperationId] = span.spanContext().traceId;
18
16
  if (span.parentSpanId) {
19
17
  tags[KnownContextTagKeys.AiOperationParentId] = span.parentSpanId;
20
18
  }
21
- if (span.resource && span.resource.attributes) {
22
- const serviceName = span.resource.attributes[SemanticResourceAttributes.SERVICE_NAME];
23
- const serviceNamespace = span.resource.attributes[SemanticResourceAttributes.SERVICE_NAMESPACE];
24
- if (serviceName) {
25
- if (serviceNamespace) {
26
- tags[KnownContextTagKeys.AiCloudRole] = `${serviceNamespace}.${serviceName}`;
27
- }
28
- else {
29
- tags[KnownContextTagKeys.AiCloudRole] = String(serviceName);
30
- }
31
- }
32
- const serviceInstanceId = span.resource.attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID];
33
- if (serviceInstanceId) {
34
- tags[KnownContextTagKeys.AiCloudRoleInstance] = String(serviceInstanceId);
35
- }
36
- else {
37
- tags[KnownContextTagKeys.AiCloudRoleInstance] = os && os.hostname();
38
- }
39
- const endUserId = span.resource.attributes[SemanticAttributes.ENDUSER_ID];
40
- if (endUserId) {
41
- tags[KnownContextTagKeys.AiUserId] = String(endUserId);
42
- }
19
+ const httpUserAgent = span.attributes[SemanticAttributes.HTTP_USER_AGENT];
20
+ if (httpUserAgent) {
21
+ // TODO: Not exposed in Swagger, need to update def
22
+ tags["ai.user.userAgent"] = String(httpUserAgent);
43
23
  }
24
+ return tags;
25
+ }
26
+ function createTagsFromSpan(span) {
27
+ const tags = createGenericTagsFromSpan(span);
44
28
  if (span.kind === SpanKind.SERVER) {
45
29
  const httpMethod = span.attributes[SemanticAttributes.HTTP_METHOD];
46
30
  const httpClientIp = span.attributes[SemanticAttributes.HTTP_CLIENT_IP];
@@ -74,28 +58,36 @@ function createTagsFromSpan(span) {
74
58
  }
75
59
  }
76
60
  // TODO: Operation Name and Location IP TBD for non server spans
77
- const httpUserAgent = span.attributes[SemanticAttributes.HTTP_USER_AGENT];
78
- if (httpUserAgent) {
79
- // TODO: Not exposed in Swagger, need to update def
80
- tags["ai.user.userAgent"] = String(httpUserAgent);
81
- }
82
61
  return tags;
83
62
  }
84
- function createPropertiesFromSpan(span) {
63
+ function createPropertiesFromSpanAttributes(attributes) {
85
64
  const properties = {};
86
- const measurements = {};
87
- for (const key of Object.keys(span.attributes)) {
88
- if (!(key.startsWith("http.") ||
89
- key.startsWith("rpc.") ||
90
- key.startsWith("db.") ||
91
- key.startsWith("peer.") ||
92
- key.startsWith("net."))) {
93
- properties[key] = span.attributes[key];
65
+ if (attributes) {
66
+ for (const key of Object.keys(attributes)) {
67
+ if (!(key.startsWith("http.") ||
68
+ key.startsWith("rpc.") ||
69
+ key.startsWith("db.") ||
70
+ key.startsWith("peer.") ||
71
+ key.startsWith("message.") ||
72
+ key.startsWith("messaging.") ||
73
+ key.startsWith("enduser.") ||
74
+ key.startsWith("net.") ||
75
+ key.startsWith("exception.") ||
76
+ key.startsWith("thread.") ||
77
+ key.startsWith("faas.") ||
78
+ key.startsWith("code."))) {
79
+ properties[key] = attributes[key];
80
+ }
94
81
  }
95
82
  }
83
+ return properties;
84
+ }
85
+ function createPropertiesFromSpan(span) {
86
+ const properties = createPropertiesFromSpanAttributes(span.attributes);
87
+ const measurements = {};
96
88
  const links = span.links.map((link) => ({
97
89
  operation_Id: link.context.traceId,
98
- id: link.context.spanId
90
+ id: link.context.spanId,
99
91
  }));
100
92
  if (links.length > 0) {
101
93
  properties[MS_LINKS] = JSON.stringify(links);
@@ -179,7 +171,7 @@ function createDependencyData(span) {
179
171
  resultCode: "0",
180
172
  type: "Dependency",
181
173
  duration: msToTimeSpan(hrTimeToMilliseconds(span.duration)),
182
- version: 2
174
+ version: 2,
183
175
  };
184
176
  if (span.kind === SpanKind.PRODUCER) {
185
177
  remoteDependencyData.type = DependencyTypes.QueueMessage;
@@ -221,7 +213,7 @@ function createDependencyData(span) {
221
213
  }
222
214
  }
223
215
  }
224
- catch (error) { }
216
+ catch (ex) { }
225
217
  remoteDependencyData.target = `${target}`;
226
218
  }
227
219
  }
@@ -287,7 +279,7 @@ function createRequestData(span) {
287
279
  responseCode: "0",
288
280
  duration: msToTimeSpan(hrTimeToMilliseconds(span.duration)),
289
281
  version: 2,
290
- source: undefined
282
+ source: undefined,
291
283
  };
292
284
  const httpMethod = span.attributes[SemanticAttributes.HTTP_METHOD];
293
285
  const grpcStatusCode = span.attributes[SemanticAttributes.RPC_GRPC_STATUS_CODE];
@@ -355,8 +347,85 @@ export function readableSpanToEnvelope(span, ikey) {
355
347
  data: {
356
348
  baseType,
357
349
  baseData: Object.assign(Object.assign({}, baseData), { properties,
358
- measurements })
359
- }
350
+ measurements }),
351
+ },
360
352
  };
361
353
  }
354
+ /**
355
+ * Span Events to Azure envelopes parsing.
356
+ * @internal
357
+ */
358
+ export function spanEventsToEnvelopes(span, ikey) {
359
+ let envelopes = [];
360
+ if (span.events) {
361
+ span.events.forEach((event) => {
362
+ let baseType;
363
+ const sampleRate = 100;
364
+ let time = new Date(hrTimeToMilliseconds(event.time));
365
+ let name = "";
366
+ let baseData;
367
+ const properties = createPropertiesFromSpanAttributes(event.attributes);
368
+ const tags = createGenericTagsFromSpan(span);
369
+ if (event.name == "exception") {
370
+ name = "Microsoft.ApplicationInsights.Exception";
371
+ baseType = "ExceptionData";
372
+ let typeName = "";
373
+ let message = "Exception";
374
+ let stack = "";
375
+ let hasFullStack = false;
376
+ if (event.attributes) {
377
+ typeName = String(event.attributes[SemanticAttributes.EXCEPTION_TYPE]);
378
+ stack = String(event.attributes[SemanticAttributes.EXCEPTION_STACKTRACE]);
379
+ if (stack) {
380
+ hasFullStack = true;
381
+ }
382
+ let exceptionMsg = event.attributes[SemanticAttributes.EXCEPTION_MESSAGE];
383
+ if (exceptionMsg) {
384
+ message = String(exceptionMsg);
385
+ }
386
+ let escaped = event.attributes[SemanticAttributes.EXCEPTION_ESCAPED];
387
+ if (escaped != undefined) {
388
+ properties[SemanticAttributes.EXCEPTION_ESCAPED] = String(escaped);
389
+ }
390
+ }
391
+ let exceptionDetails = {
392
+ typeName: typeName,
393
+ message: message,
394
+ stack: stack,
395
+ hasFullStack: hasFullStack,
396
+ };
397
+ let exceptionData = {
398
+ exceptions: [exceptionDetails],
399
+ version: 2,
400
+ properties: properties,
401
+ };
402
+ baseData = exceptionData;
403
+ }
404
+ else {
405
+ name = "Microsoft.ApplicationInsights.Message";
406
+ baseType = "MessageData";
407
+ let messageData = {
408
+ message: event.name,
409
+ version: 2,
410
+ properties: properties,
411
+ };
412
+ baseData = messageData;
413
+ }
414
+ let env = {
415
+ name: name,
416
+ time: time,
417
+ instrumentationKey: ikey,
418
+ version: 1,
419
+ sampleRate: sampleRate,
420
+ data: {
421
+ baseType: baseType,
422
+ baseData: baseData,
423
+ },
424
+ tags: tags,
425
+ };
426
+ envelopes.push(env);
427
+ });
428
+ }
429
+ return envelopes;
430
+ }
362
431
  //# sourceMappingURL=spanUtils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"spanUtils.js","sourceRoot":"","sources":["../../../src/utils/spanUtils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc,EAAQ,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EACL,0BAA0B,EAC1B,kBAAkB,EAClB,cAAc,EACf,MAAM,qCAAqC,CAAC;AAG7C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAC/E,OAAO,EAIL,mBAAmB,EACpB,MAAM,cAAc,CAAC;AAEtB,SAAS,kBAAkB,CAAC,IAAkB;IAC5C,MAAM,OAAO,GAAG,WAAW,EAAE,CAAC;IAC9B,MAAM,IAAI,qBAAc,OAAO,CAAC,IAAI,CAAE,CAAC;IAEvC,IAAI,CAAC,mBAAmB,CAAC,aAAa,CAAC,GAAG,IAA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,uCAAuC,CAAC;YAC/C,QAAQ,GAAG,aAAa,CAAC;YACzB,QAAQ,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;YACnC,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAC,mBAAmB,CAAC,eAAe,CAAC,CAAC;YAC1D,MAAM;QACR;YACE,QAAQ;YACR,IAAI,CAAC,KAAK,CAAC,yBAAyB,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;YACjD,MAAM,IAAI,KAAK,CAAC,yBAAyB,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;KACzD;IAED,YAAY;IACZ,IAAI,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE;QAChC,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,QAAQ,EAAE;YACnC,QAAQ,CAAC,IAAI,GAAG,GAAG,eAAe,CAAC,MAAM,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;SAC/E;QACD,IAAI,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,KAAK,iBAAiB,EAAE;YACtD,iBAAiB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;SACnC;KACF;IAED,OAAO;QACL,IAAI;QACJ,UAAU;QACV,IAAI;QACJ,kBAAkB;QAClB,IAAI;QACJ,OAAO,EAAE,CAAC;QACV,IAAI,EAAE;YACJ,QAAQ;YACR,QAAQ,kCACH,QAAQ,KACX,UAAU;gBACV,YAAY,GACb;SACF;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport os from \"os\";\nimport { URL } from \"url\";\nimport { ReadableSpan } from \"@opentelemetry/tracing\";\nimport { hrTimeToMilliseconds } from \"@opentelemetry/core\";\nimport { diag, SpanKind, SpanStatusCode, Link } from \"@opentelemetry/api\";\nimport {\n SemanticResourceAttributes,\n SemanticAttributes,\n DbSystemValues\n} from \"@opentelemetry/semantic-conventions\";\n\nimport { Tags, Properties, MSLink, Measurements } from \"../types\";\nimport { msToTimeSpan } from \"./breezeUtils\";\nimport { getInstance } from \"../platform\";\nimport { parseEventHubSpan } from \"./eventhub\";\nimport { DependencyTypes, MS_LINKS } from \"./constants/applicationinsights\";\nimport { AzNamespace, MicrosoftEventHub } from \"./constants/span/azAttributes\";\nimport {\n RemoteDependencyData,\n RequestData,\n TelemetryItem as Envelope,\n KnownContextTagKeys\n} from \"../generated\";\n\nfunction createTagsFromSpan(span: ReadableSpan): Tags {\n const context = getInstance();\n const tags: Tags = { ...context.tags };\n\n tags[KnownContextTagKeys.AiOperationId] = span.spanContext().traceId;\n if (span.parentSpanId) {\n tags[KnownContextTagKeys.AiOperationParentId] = span.parentSpanId;\n }\n if (span.resource && span.resource.attributes) {\n const serviceName = span.resource.attributes[SemanticResourceAttributes.SERVICE_NAME];\n const serviceNamespace = span.resource.attributes[SemanticResourceAttributes.SERVICE_NAMESPACE];\n if (serviceName) {\n if (serviceNamespace) {\n tags[KnownContextTagKeys.AiCloudRole] = `${serviceNamespace}.${serviceName}`;\n } else {\n tags[KnownContextTagKeys.AiCloudRole] = String(serviceName);\n }\n }\n const serviceInstanceId =\n span.resource.attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID];\n if (serviceInstanceId) {\n tags[KnownContextTagKeys.AiCloudRoleInstance] = String(serviceInstanceId);\n } else {\n tags[KnownContextTagKeys.AiCloudRoleInstance] = os && os.hostname();\n }\n const endUserId = span.resource.attributes[SemanticAttributes.ENDUSER_ID];\n if (endUserId) {\n tags[KnownContextTagKeys.AiUserId] = String(endUserId);\n }\n }\n if (span.kind === SpanKind.SERVER) {\n const httpMethod = span.attributes[SemanticAttributes.HTTP_METHOD];\n const httpClientIp = span.attributes[SemanticAttributes.HTTP_CLIENT_IP];\n const netPeerIp = span.attributes[SemanticAttributes.NET_PEER_IP];\n if (httpMethod) {\n const httpRoute = span.attributes[SemanticAttributes.HTTP_ROUTE];\n const httpUrl = span.attributes[SemanticAttributes.HTTP_URL];\n tags[KnownContextTagKeys.AiOperationName] = span.name; // Default\n if (httpRoute) {\n tags[\n KnownContextTagKeys.AiOperationName\n ] = `${httpMethod as string} ${httpRoute as string}`;\n } else if (httpUrl) {\n try {\n let url = new URL(String(httpUrl));\n tags[KnownContextTagKeys.AiOperationName] = `${httpMethod} ${url.pathname}`;\n } catch (ex) {}\n }\n if (httpClientIp) {\n tags[KnownContextTagKeys.AiLocationIp] = String(httpClientIp);\n } else if (netPeerIp) {\n tags[KnownContextTagKeys.AiLocationIp] = String(netPeerIp);\n }\n } else {\n tags[KnownContextTagKeys.AiOperationName] = span.name;\n if (netPeerIp) {\n tags[KnownContextTagKeys.AiLocationIp] = String(netPeerIp);\n }\n }\n }\n // TODO: Operation Name and Location IP TBD for non server spans\n\n const httpUserAgent = span.attributes[SemanticAttributes.HTTP_USER_AGENT];\n if (httpUserAgent) {\n // TODO: Not exposed in Swagger, need to update def\n tags[\"ai.user.userAgent\"] = String(httpUserAgent);\n }\n\n return tags;\n}\n\nfunction createPropertiesFromSpan(span: ReadableSpan): [Properties, Measurements] {\n const properties: Properties = {};\n const measurements: Measurements = {};\n\n for (const key of Object.keys(span.attributes)) {\n if (\n !(\n key.startsWith(\"http.\") ||\n key.startsWith(\"rpc.\") ||\n key.startsWith(\"db.\") ||\n key.startsWith(\"peer.\") ||\n key.startsWith(\"net.\")\n )\n ) {\n properties[key] = span.attributes[key] as string;\n }\n }\n\n const links: MSLink[] = span.links.map((link: Link) => ({\n operation_Id: link.context.traceId,\n id: link.context.spanId\n }));\n\n if (links.length > 0) {\n properties[MS_LINKS] = JSON.stringify(links);\n }\n\n return [properties, measurements];\n}\n\nfunction isSqlDB(dbSystem: string) {\n return (\n dbSystem === DbSystemValues.DB2 ||\n dbSystem === DbSystemValues.DERBY ||\n dbSystem === DbSystemValues.MARIADB ||\n dbSystem === DbSystemValues.MSSQL ||\n dbSystem === DbSystemValues.ORACLE ||\n dbSystem === DbSystemValues.SQLITE ||\n dbSystem === DbSystemValues.OTHER_SQL ||\n dbSystem === DbSystemValues.HSQLDB ||\n dbSystem === DbSystemValues.H2\n );\n}\n\nfunction getUrl(span: ReadableSpan): string {\n const httpMethod = span.attributes[SemanticAttributes.HTTP_METHOD];\n if (httpMethod) {\n const httpUrl = span.attributes[SemanticAttributes.HTTP_URL];\n if (httpUrl) {\n return String(httpUrl);\n } else {\n const httpScheme = span.attributes[SemanticAttributes.HTTP_SCHEME];\n const httpTarget = span.attributes[SemanticAttributes.HTTP_TARGET];\n if (httpScheme && httpTarget) {\n const httpHost = span.attributes[SemanticAttributes.HTTP_HOST];\n if (httpHost) {\n return `${httpScheme}://${httpHost}${httpTarget}`;\n } else {\n const netPeerPort = span.attributes[SemanticAttributes.NET_PEER_PORT];\n if (netPeerPort) {\n const netPeerName = span.attributes[SemanticAttributes.NET_PEER_NAME];\n if (netPeerName) {\n return `${httpScheme}://${netPeerName}:${netPeerPort}${httpTarget}`;\n } else {\n const netPeerIp = span.attributes[SemanticAttributes.NET_PEER_IP];\n if (netPeerIp) {\n return `${httpScheme}://${netPeerIp}:${netPeerPort}${httpTarget}`;\n }\n }\n }\n }\n }\n }\n }\n return \"\";\n}\n\nfunction getDependencyTarget(span: ReadableSpan): string {\n const peerService = span.attributes[SemanticAttributes.PEER_SERVICE];\n const httpHost = span.attributes[SemanticAttributes.HTTP_HOST];\n const httpUrl = span.attributes[SemanticAttributes.HTTP_URL];\n const netPeerName = span.attributes[SemanticAttributes.NET_PEER_NAME];\n const netPeerIp = span.attributes[SemanticAttributes.NET_PEER_IP];\n if (peerService) {\n return String(peerService);\n } else if (httpHost) {\n return String(httpHost);\n } else if (httpUrl) {\n return String(httpUrl);\n } else if (netPeerName) {\n return String(netPeerName);\n } else if (netPeerIp) {\n return String(netPeerIp);\n }\n return \"\";\n}\n\nfunction createDependencyData(span: ReadableSpan): RemoteDependencyData {\n const remoteDependencyData: RemoteDependencyData = {\n name: span.name, //Default\n id: `${span.spanContext().spanId}`,\n success: span.status.code != SpanStatusCode.ERROR,\n resultCode: \"0\",\n type: \"Dependency\",\n duration: msToTimeSpan(hrTimeToMilliseconds(span.duration)),\n version: 2\n };\n if (span.kind === SpanKind.PRODUCER) {\n remoteDependencyData.type = DependencyTypes.QueueMessage;\n }\n if (span.kind === SpanKind.INTERNAL && span.parentSpanId) {\n remoteDependencyData.type = DependencyTypes.InProc;\n }\n\n const httpMethod = span.attributes[SemanticAttributes.HTTP_METHOD];\n const dbSystem = span.attributes[SemanticAttributes.DB_SYSTEM];\n const rpcSystem = span.attributes[SemanticAttributes.RPC_SYSTEM];\n // HTTP Dependency\n if (httpMethod) {\n const httpUrl = span.attributes[SemanticAttributes.HTTP_URL];\n if (httpUrl) {\n try {\n let dependencyUrl = new URL(String(httpUrl));\n remoteDependencyData.name = `${httpMethod} ${dependencyUrl.pathname}`;\n } catch (ex) {}\n }\n remoteDependencyData.type = DependencyTypes.Http;\n remoteDependencyData.data = getUrl(span);\n const httpStatusCode = span.attributes[SemanticAttributes.HTTP_STATUS_CODE];\n if (httpStatusCode) {\n remoteDependencyData.resultCode = String(httpStatusCode);\n }\n let target = getDependencyTarget(span);\n if (target) {\n try {\n // Remove default port\n let portRegex = new RegExp(/(https?)(:\\/\\/.*)(:\\d+)(\\S*)/);\n let res = portRegex.exec(target);\n if (res != null) {\n let protocol = res[1];\n let port = res[3];\n if ((protocol == \"https\" && port == \":443\") || (protocol == \"http\" && port == \":80\")) {\n // Drop port\n target = res[1] + res[2] + res[4];\n }\n }\n } catch (error) {}\n remoteDependencyData.target = `${target}`;\n }\n }\n // DB Dependency\n else if (dbSystem) {\n // TODO: Remove special logic when Azure UX supports OpenTelemetry dbSystem\n if (String(dbSystem) === DbSystemValues.MYSQL) {\n remoteDependencyData.type = \"mysql\";\n } else if (String(dbSystem) === DbSystemValues.POSTGRESQL) {\n remoteDependencyData.type = \"postgresql\";\n } else if (String(dbSystem) === DbSystemValues.MONGODB) {\n remoteDependencyData.type = \"mongodb\";\n } else if (String(dbSystem) === DbSystemValues.REDIS) {\n remoteDependencyData.type = \"redis\";\n } else if (isSqlDB(String(dbSystem))) {\n remoteDependencyData.type = \"SQL\";\n } else {\n remoteDependencyData.type = String(dbSystem);\n }\n const dbStatement = span.attributes[SemanticAttributes.DB_STATEMENT];\n const dbOperation = span.attributes[SemanticAttributes.DB_OPERATION];\n if (dbStatement) {\n remoteDependencyData.data = String(dbStatement);\n } else if (dbOperation) {\n remoteDependencyData.data = String(dbOperation);\n }\n let target = getDependencyTarget(span);\n const dbName = span.attributes[SemanticAttributes.DB_NAME];\n if (target) {\n remoteDependencyData.target = dbName ? `${target}|${dbName}` : `${target}`;\n } else {\n remoteDependencyData.target = dbName ? `${dbName}` : `${dbSystem}`;\n }\n }\n // grpc Dependency\n else if (rpcSystem) {\n remoteDependencyData.type = DependencyTypes.Grpc;\n const grpcStatusCode = span.attributes[SemanticAttributes.RPC_GRPC_STATUS_CODE];\n if (grpcStatusCode) {\n remoteDependencyData.resultCode = String(grpcStatusCode);\n }\n let target = getDependencyTarget(span);\n if (target) {\n remoteDependencyData.target = `${target}`;\n } else if (rpcSystem) {\n remoteDependencyData.target = String(rpcSystem);\n }\n }\n return remoteDependencyData;\n}\n\nfunction createRequestData(span: ReadableSpan): RequestData {\n const requestData: RequestData = {\n id: `${span.spanContext().spanId}`,\n success: span.status.code != SpanStatusCode.ERROR,\n responseCode: \"0\",\n duration: msToTimeSpan(hrTimeToMilliseconds(span.duration)),\n version: 2,\n source: undefined\n };\n const httpMethod = span.attributes[SemanticAttributes.HTTP_METHOD];\n const grpcStatusCode = span.attributes[SemanticAttributes.RPC_GRPC_STATUS_CODE];\n if (httpMethod) {\n requestData.url = getUrl(span);\n const httpStatusCode = span.attributes[SemanticAttributes.HTTP_STATUS_CODE];\n if (httpStatusCode) {\n requestData.responseCode = String(httpStatusCode);\n }\n } else if (grpcStatusCode) {\n requestData.responseCode = String(grpcStatusCode);\n }\n return requestData;\n}\n\n/**\n * Span to Azure envelope parsing.\n * @internal\n */\nexport function readableSpanToEnvelope(span: ReadableSpan, ikey: string): Envelope {\n let name: string;\n let baseType: \"RemoteDependencyData\" | \"RequestData\";\n const sampleRate = 100;\n let baseData: RemoteDependencyData | RequestData;\n\n const time = new Date(hrTimeToMilliseconds(span.startTime));\n const instrumentationKey = ikey;\n const tags = createTagsFromSpan(span);\n const [properties, measurements] = createPropertiesFromSpan(span);\n switch (span.kind) {\n case SpanKind.CLIENT:\n case SpanKind.PRODUCER:\n case SpanKind.INTERNAL:\n name = \"Microsoft.ApplicationInsights.RemoteDependency\";\n baseType = \"RemoteDependencyData\";\n baseData = createDependencyData(span);\n break;\n case SpanKind.SERVER:\n case SpanKind.CONSUMER:\n name = \"Microsoft.ApplicationInsights.Request\";\n baseType = \"RequestData\";\n baseData = createRequestData(span);\n baseData.name = tags[KnownContextTagKeys.AiOperationName];\n break;\n default:\n // never\n diag.error(`Unsupported span kind ${span.kind}`);\n throw new Error(`Unsupported span kind ${span.kind}`);\n }\n\n // Azure SDK\n if (span.attributes[AzNamespace]) {\n if (span.kind === SpanKind.INTERNAL) {\n baseData.type = `${DependencyTypes.InProc} | ${span.attributes[AzNamespace]}`;\n }\n if (span.attributes[AzNamespace] === MicrosoftEventHub) {\n parseEventHubSpan(span, baseData);\n }\n }\n\n return {\n name,\n sampleRate,\n time,\n instrumentationKey,\n tags,\n version: 1,\n data: {\n baseType,\n baseData: {\n ...baseData,\n properties,\n measurements\n }\n }\n };\n}\n"]}
1
+ {"version":3,"file":"spanUtils.js","sourceRoot":"","sources":["../../../src/utils/spanUtils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc,EAAwB,MAAM,oBAAoB,CAAC;AAC1F,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM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pE;iBACF;gBACD,IAAI,gBAAgB,GAA8B;oBAChD,QAAQ,EAAE,QAAQ;oBAClB,OAAO,EAAE,OAAO;oBAChB,KAAK,EAAE,KAAK;oBACZ,YAAY,EAAE,YAAY;iBAC3B,CAAC;gBACF,IAAI,aAAa,GAA2B;oBAC1C,UAAU,EAAE,CAAC,gBAAgB,CAAC;oBAC9B,OAAO,EAAE,CAAC;oBACV,UAAU,EAAE,UAAU;iBACvB,CAAC;gBACF,QAAQ,GAAG,aAAa,CAAC;aAC1B;iBAAM;gBACL,IAAI,GAAG,uCAAuC,CAAC;gBAC/C,QAAQ,GAAG,aAAa,CAAC;gBACzB,IAAI,WAAW,GAAgB;oBAC7B,OAAO,EAAE,KAAK,CAAC,IAAI;oBACnB,OAAO,EAAE,CAAC;oBACV,UAAU,EAAE,UAAU;iBACvB,CAAC;gBACF,QAAQ,GAAG,WAAW,CAAC;aACxB;YACD,IAAI,GAAG,GAAa;gBAClB,IAAI,EAAE,IAAI;gBACV,IAAI,EAAE,IAAI;gBACV,kBAAkB,EAAE,IAAI;gBACxB,OAAO,EAAE,CAAC;gBACV,UAAU,EAAE,UAAU;gBACtB,IAAI,EAAE;oBACJ,QAAQ,EAAE,QAAQ;oBAClB,QAAQ,EAAE,QAAQ;iBACnB;gBACD,IAAI,EAAE,IAAI;aACX,CAAC;YACF,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACtB,CAAC,CAAC,CAAC;KACJ;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { URL } from \"url\";\nimport { ReadableSpan, TimedEvent } from \"@opentelemetry/sdk-trace-base\";\nimport { hrTimeToMilliseconds } from \"@opentelemetry/core\";\nimport { diag, SpanKind, SpanStatusCode, Link, SpanAttributes } from \"@opentelemetry/api\";\nimport { SemanticAttributes, DbSystemValues } from \"@opentelemetry/semantic-conventions\";\n\nimport { createTagsFromResource } from \"./resourceUtils\";\nimport { Tags, Properties, MSLink, Measurements } from \"../types\";\nimport { msToTimeSpan } from \"./breezeUtils\";\nimport { parseEventHubSpan } from \"./eventhub\";\nimport { DependencyTypes, MS_LINKS } from \"./constants/applicationinsights\";\nimport { AzNamespace, MicrosoftEventHub } from \"./constants/span/azAttributes\";\nimport {\n TelemetryExceptionData,\n MessageData,\n RemoteDependencyData,\n RequestData,\n TelemetryItem as Envelope,\n KnownContextTagKeys,\n TelemetryExceptionDetails,\n} from \"../generated\";\n\nfunction createGenericTagsFromSpan(span: ReadableSpan): Tags {\n const tags: Tags = createTagsFromResource(span.resource);\n tags[KnownContextTagKeys.AiOperationId] = span.spanContext().traceId;\n if (span.parentSpanId) {\n tags[KnownContextTagKeys.AiOperationParentId] = span.parentSpanId;\n }\n const httpUserAgent = span.attributes[SemanticAttributes.HTTP_USER_AGENT];\n if (httpUserAgent) {\n // TODO: Not exposed in Swagger, need to update def\n tags[\"ai.user.userAgent\"] = String(httpUserAgent);\n }\n return tags;\n}\n\nfunction createTagsFromSpan(span: ReadableSpan): Tags {\n const tags: Tags = createGenericTagsFromSpan(span);\n if (span.kind === SpanKind.SERVER) {\n const httpMethod = span.attributes[SemanticAttributes.HTTP_METHOD];\n const httpClientIp = span.attributes[SemanticAttributes.HTTP_CLIENT_IP];\n const netPeerIp = span.attributes[SemanticAttributes.NET_PEER_IP];\n if (httpMethod) {\n const httpRoute = span.attributes[SemanticAttributes.HTTP_ROUTE];\n const httpUrl = span.attributes[SemanticAttributes.HTTP_URL];\n tags[KnownContextTagKeys.AiOperationName] = span.name; // Default\n if (httpRoute) {\n tags[KnownContextTagKeys.AiOperationName] = `${httpMethod as string} ${\n httpRoute as string\n }`;\n } else if (httpUrl) {\n try {\n let url = new URL(String(httpUrl));\n tags[KnownContextTagKeys.AiOperationName] = `${httpMethod} ${url.pathname}`;\n } catch (ex: any) {}\n }\n if (httpClientIp) {\n tags[KnownContextTagKeys.AiLocationIp] = String(httpClientIp);\n } else if (netPeerIp) {\n tags[KnownContextTagKeys.AiLocationIp] = String(netPeerIp);\n }\n } else {\n tags[KnownContextTagKeys.AiOperationName] = span.name;\n if (netPeerIp) {\n tags[KnownContextTagKeys.AiLocationIp] = String(netPeerIp);\n }\n }\n }\n // TODO: Operation Name and Location IP TBD for non server spans\n\n return tags;\n}\n\nfunction createPropertiesFromSpanAttributes(attributes?: SpanAttributes): {\n [propertyName: string]: string;\n} {\n const properties: { [propertyName: string]: string } = {};\n if (attributes) {\n for (const key of Object.keys(attributes)) {\n if (\n !(\n key.startsWith(\"http.\") ||\n key.startsWith(\"rpc.\") ||\n key.startsWith(\"db.\") ||\n key.startsWith(\"peer.\") ||\n key.startsWith(\"message.\") ||\n key.startsWith(\"messaging.\") ||\n key.startsWith(\"enduser.\") ||\n key.startsWith(\"net.\") ||\n key.startsWith(\"exception.\") ||\n key.startsWith(\"thread.\") ||\n key.startsWith(\"faas.\") ||\n key.startsWith(\"code.\")\n )\n ) {\n properties[key] = attributes[key] as string;\n }\n }\n }\n return properties;\n}\n\nfunction createPropertiesFromSpan(span: ReadableSpan): [Properties, Measurements] {\n const properties: Properties = createPropertiesFromSpanAttributes(span.attributes);\n const measurements: Measurements = {};\n\n const links: MSLink[] = span.links.map((link: Link) => ({\n operation_Id: link.context.traceId,\n id: link.context.spanId,\n }));\n if (links.length > 0) {\n properties[MS_LINKS] = JSON.stringify(links);\n }\n return [properties, measurements];\n}\n\nfunction isSqlDB(dbSystem: string) {\n return (\n dbSystem === DbSystemValues.DB2 ||\n dbSystem === DbSystemValues.DERBY ||\n dbSystem === DbSystemValues.MARIADB ||\n dbSystem === DbSystemValues.MSSQL ||\n dbSystem === DbSystemValues.ORACLE ||\n dbSystem === DbSystemValues.SQLITE ||\n dbSystem === DbSystemValues.OTHER_SQL ||\n dbSystem === DbSystemValues.HSQLDB ||\n dbSystem === DbSystemValues.H2\n );\n}\n\nfunction getUrl(span: ReadableSpan): string {\n const httpMethod = span.attributes[SemanticAttributes.HTTP_METHOD];\n if (httpMethod) {\n const httpUrl = span.attributes[SemanticAttributes.HTTP_URL];\n if (httpUrl) {\n return String(httpUrl);\n } else {\n const httpScheme = span.attributes[SemanticAttributes.HTTP_SCHEME];\n const httpTarget = span.attributes[SemanticAttributes.HTTP_TARGET];\n if (httpScheme && httpTarget) {\n const httpHost = span.attributes[SemanticAttributes.HTTP_HOST];\n if (httpHost) {\n return `${httpScheme}://${httpHost}${httpTarget}`;\n } else {\n const netPeerPort = span.attributes[SemanticAttributes.NET_PEER_PORT];\n if (netPeerPort) {\n const netPeerName = span.attributes[SemanticAttributes.NET_PEER_NAME];\n if (netPeerName) {\n return `${httpScheme}://${netPeerName}:${netPeerPort}${httpTarget}`;\n } else {\n const netPeerIp = span.attributes[SemanticAttributes.NET_PEER_IP];\n if (netPeerIp) {\n return `${httpScheme}://${netPeerIp}:${netPeerPort}${httpTarget}`;\n }\n }\n }\n }\n }\n }\n }\n return \"\";\n}\n\nfunction getDependencyTarget(span: ReadableSpan): string {\n const peerService = span.attributes[SemanticAttributes.PEER_SERVICE];\n const httpHost = span.attributes[SemanticAttributes.HTTP_HOST];\n const httpUrl = span.attributes[SemanticAttributes.HTTP_URL];\n const netPeerName = span.attributes[SemanticAttributes.NET_PEER_NAME];\n const netPeerIp = span.attributes[SemanticAttributes.NET_PEER_IP];\n if (peerService) {\n return String(peerService);\n } else if (httpHost) {\n return String(httpHost);\n } else if (httpUrl) {\n return String(httpUrl);\n } else if (netPeerName) {\n return String(netPeerName);\n } else if (netPeerIp) {\n return String(netPeerIp);\n }\n return \"\";\n}\n\nfunction createDependencyData(span: ReadableSpan): RemoteDependencyData {\n const remoteDependencyData: RemoteDependencyData = {\n name: span.name, //Default\n id: `${span.spanContext().spanId}`,\n success: span.status.code != SpanStatusCode.ERROR,\n resultCode: \"0\",\n type: \"Dependency\",\n duration: msToTimeSpan(hrTimeToMilliseconds(span.duration)),\n version: 2,\n };\n if (span.kind === SpanKind.PRODUCER) {\n remoteDependencyData.type = DependencyTypes.QueueMessage;\n }\n if (span.kind === SpanKind.INTERNAL && span.parentSpanId) {\n remoteDependencyData.type = DependencyTypes.InProc;\n }\n\n const httpMethod = span.attributes[SemanticAttributes.HTTP_METHOD];\n const dbSystem = span.attributes[SemanticAttributes.DB_SYSTEM];\n const rpcSystem = span.attributes[SemanticAttributes.RPC_SYSTEM];\n // HTTP Dependency\n if (httpMethod) {\n const httpUrl = span.attributes[SemanticAttributes.HTTP_URL];\n if (httpUrl) {\n try {\n let dependencyUrl = new URL(String(httpUrl));\n remoteDependencyData.name = `${httpMethod} ${dependencyUrl.pathname}`;\n } catch (ex: any) {}\n }\n remoteDependencyData.type = DependencyTypes.Http;\n remoteDependencyData.data = getUrl(span);\n const httpStatusCode = span.attributes[SemanticAttributes.HTTP_STATUS_CODE];\n if (httpStatusCode) {\n remoteDependencyData.resultCode = String(httpStatusCode);\n }\n let target = getDependencyTarget(span);\n if (target) {\n try {\n // Remove default port\n let portRegex = new RegExp(/(https?)(:\\/\\/.*)(:\\d+)(\\S*)/);\n let res = portRegex.exec(target);\n if (res != null) {\n let protocol = res[1];\n let port = res[3];\n if ((protocol == \"https\" && port == \":443\") || (protocol == \"http\" && port == \":80\")) {\n // Drop port\n target = res[1] + res[2] + res[4];\n }\n }\n } catch (ex: any) {}\n remoteDependencyData.target = `${target}`;\n }\n }\n // DB Dependency\n else if (dbSystem) {\n // TODO: Remove special logic when Azure UX supports OpenTelemetry dbSystem\n if (String(dbSystem) === DbSystemValues.MYSQL) {\n remoteDependencyData.type = \"mysql\";\n } else if (String(dbSystem) === DbSystemValues.POSTGRESQL) {\n remoteDependencyData.type = \"postgresql\";\n } else if (String(dbSystem) === DbSystemValues.MONGODB) {\n remoteDependencyData.type = \"mongodb\";\n } else if (String(dbSystem) === DbSystemValues.REDIS) {\n remoteDependencyData.type = \"redis\";\n } else if (isSqlDB(String(dbSystem))) {\n remoteDependencyData.type = \"SQL\";\n } else {\n remoteDependencyData.type = String(dbSystem);\n }\n const dbStatement = span.attributes[SemanticAttributes.DB_STATEMENT];\n const dbOperation = span.attributes[SemanticAttributes.DB_OPERATION];\n if (dbStatement) {\n remoteDependencyData.data = String(dbStatement);\n } else if (dbOperation) {\n remoteDependencyData.data = String(dbOperation);\n }\n let target = getDependencyTarget(span);\n const dbName = span.attributes[SemanticAttributes.DB_NAME];\n if (target) {\n remoteDependencyData.target = dbName ? `${target}|${dbName}` : `${target}`;\n } else {\n remoteDependencyData.target = dbName ? `${dbName}` : `${dbSystem}`;\n }\n }\n // grpc Dependency\n else if (rpcSystem) {\n remoteDependencyData.type = DependencyTypes.Grpc;\n const grpcStatusCode = span.attributes[SemanticAttributes.RPC_GRPC_STATUS_CODE];\n if (grpcStatusCode) {\n remoteDependencyData.resultCode = String(grpcStatusCode);\n }\n let target = getDependencyTarget(span);\n if (target) {\n remoteDependencyData.target = `${target}`;\n } else if (rpcSystem) {\n remoteDependencyData.target = String(rpcSystem);\n }\n }\n return remoteDependencyData;\n}\n\nfunction createRequestData(span: ReadableSpan): RequestData {\n const requestData: RequestData = {\n id: `${span.spanContext().spanId}`,\n success: span.status.code != SpanStatusCode.ERROR,\n responseCode: \"0\",\n duration: msToTimeSpan(hrTimeToMilliseconds(span.duration)),\n version: 2,\n source: undefined,\n };\n const httpMethod = span.attributes[SemanticAttributes.HTTP_METHOD];\n const grpcStatusCode = span.attributes[SemanticAttributes.RPC_GRPC_STATUS_CODE];\n if (httpMethod) {\n requestData.url = getUrl(span);\n const httpStatusCode = span.attributes[SemanticAttributes.HTTP_STATUS_CODE];\n if (httpStatusCode) {\n requestData.responseCode = String(httpStatusCode);\n }\n } else if (grpcStatusCode) {\n requestData.responseCode = String(grpcStatusCode);\n }\n return requestData;\n}\n\n/**\n * Span to Azure envelope parsing.\n * @internal\n */\nexport function readableSpanToEnvelope(span: ReadableSpan, ikey: string): Envelope {\n let name: string;\n let baseType: \"RemoteDependencyData\" | \"RequestData\";\n const sampleRate = 100;\n let baseData: RemoteDependencyData | RequestData;\n\n const time = new Date(hrTimeToMilliseconds(span.startTime));\n const instrumentationKey = ikey;\n const tags = createTagsFromSpan(span);\n const [properties, measurements] = createPropertiesFromSpan(span);\n switch (span.kind) {\n case SpanKind.CLIENT:\n case SpanKind.PRODUCER:\n case SpanKind.INTERNAL:\n name = \"Microsoft.ApplicationInsights.RemoteDependency\";\n baseType = \"RemoteDependencyData\";\n baseData = createDependencyData(span);\n break;\n case SpanKind.SERVER:\n case SpanKind.CONSUMER:\n name = \"Microsoft.ApplicationInsights.Request\";\n baseType = \"RequestData\";\n baseData = createRequestData(span);\n baseData.name = tags[KnownContextTagKeys.AiOperationName];\n break;\n default:\n // never\n diag.error(`Unsupported span kind ${span.kind}`);\n throw new Error(`Unsupported span kind ${span.kind}`);\n }\n\n // Azure SDK\n if (span.attributes[AzNamespace]) {\n if (span.kind === SpanKind.INTERNAL) {\n baseData.type = `${DependencyTypes.InProc} | ${span.attributes[AzNamespace]}`;\n }\n if (span.attributes[AzNamespace] === MicrosoftEventHub) {\n parseEventHubSpan(span, baseData);\n }\n }\n\n return {\n name,\n sampleRate,\n time,\n instrumentationKey,\n tags,\n version: 1,\n data: {\n baseType,\n baseData: {\n ...baseData,\n properties,\n measurements,\n },\n },\n };\n}\n\n/**\n * Span Events to Azure envelopes parsing.\n * @internal\n */\nexport function spanEventsToEnvelopes(span: ReadableSpan, ikey: string): Envelope[] {\n let envelopes: Envelope[] = [];\n if (span.events) {\n span.events.forEach((event: TimedEvent) => {\n let baseType: \"ExceptionData\" | \"MessageData\";\n const sampleRate = 100;\n let time = new Date(hrTimeToMilliseconds(event.time));\n let name = \"\";\n let baseData: TelemetryExceptionData | MessageData;\n const properties = createPropertiesFromSpanAttributes(event.attributes);\n const tags: Tags = createGenericTagsFromSpan(span);\n\n if (event.name == \"exception\") {\n name = \"Microsoft.ApplicationInsights.Exception\";\n baseType = \"ExceptionData\";\n let typeName = \"\";\n let message = \"Exception\";\n let stack = \"\";\n let hasFullStack = false;\n if (event.attributes) {\n typeName = String(event.attributes[SemanticAttributes.EXCEPTION_TYPE]);\n stack = String(event.attributes[SemanticAttributes.EXCEPTION_STACKTRACE]);\n if (stack) {\n hasFullStack = true;\n }\n let exceptionMsg = event.attributes[SemanticAttributes.EXCEPTION_MESSAGE];\n if (exceptionMsg) {\n message = String(exceptionMsg);\n }\n let escaped = event.attributes[SemanticAttributes.EXCEPTION_ESCAPED];\n if (escaped != undefined) {\n properties[SemanticAttributes.EXCEPTION_ESCAPED] = String(escaped);\n }\n }\n let exceptionDetails: TelemetryExceptionDetails = {\n typeName: typeName,\n message: message,\n stack: stack,\n hasFullStack: hasFullStack,\n };\n let exceptionData: TelemetryExceptionData = {\n exceptions: [exceptionDetails],\n version: 2,\n properties: properties,\n };\n baseData = exceptionData;\n } else {\n name = \"Microsoft.ApplicationInsights.Message\";\n baseType = \"MessageData\";\n let messageData: MessageData = {\n message: event.name,\n version: 2,\n properties: properties,\n };\n baseData = messageData;\n }\n let env: Envelope = {\n name: name,\n time: time,\n instrumentationKey: ikey,\n version: 1,\n sampleRate: sampleRate,\n data: {\n baseType: baseType,\n baseData: baseData,\n },\n tags: tags,\n };\n envelopes.push(env);\n });\n }\n return envelopes;\n}\n"]}
package/package.json CHANGED
@@ -2,42 +2,41 @@
2
2
  "name": "@azure/monitor-opentelemetry-exporter",
3
3
  "author": "Microsoft Corporation",
4
4
  "sdk-type": "client",
5
- "version": "1.0.0-beta.5",
5
+ "version": "1.0.0-beta.8",
6
6
  "description": "Application Insights exporter for the OpenTelemetry JavaScript (Node.js) SDK",
7
7
  "main": "dist/index.js",
8
8
  "module": "dist-esm/src/index.js",
9
9
  "types": "types/monitor-opentelemetry-exporter.d.ts",
10
10
  "scripts": {
11
11
  "clean": "rimraf dist-esm types dist",
12
- "build:autorest": "autorest ./swagger/README.md --typescript --v3",
13
12
  "build:browser": "echo skipped",
14
13
  "build:test": "echo skipped",
15
- "build:node": "tsc -p . && rollup -c 2>&1",
14
+ "build:node": "tsc -p . && dev-tool run bundle --browser-test=false",
15
+ "build:samples": "dev-tool samples publish --force",
16
16
  "build": "npm run build:node && npm run build:browser && api-extractor run --local",
17
17
  "check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
18
+ "execute:samples": "dev-tool samples run samples-dev",
18
19
  "extract-api": "tsc -p . && api-extractor run --local",
19
20
  "format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
21
+ "generate:client": "autorest --typescript ./swagger/README.md",
20
22
  "lint:fix": "eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]",
21
23
  "lint": "eslint package.json api-extractor.json src test --ext .ts -f html -o telemetry-exporter-lintReport.html || exit 0",
22
24
  "test": "npm run test:node && npm run test:browser",
23
25
  "test:node": "npm run unit-test:node",
24
26
  "test:browser": "npm run unit-test:browser",
25
27
  "unit-test:browser": "echo skipped",
26
- "unit-test:node": "nyc mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace \"test/internal/**/*.test.ts\"",
27
- "unit-test:node:debug": "nyc mocha --inspect-brk -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace \"test/internal/**/*.test.ts\"",
28
+ "unit-test:node": "nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace \"dist-esm/test/internal/**/*.test.js\"",
29
+ "unit-test:node:debug": "nyc mocha --inspect-brk -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace \"dist-esm/test/internal/**/*.test.js\"",
28
30
  "unit-test:node:no-timeout": "echo skipped",
29
31
  "unit-test": "npm run unit-test:node && npm run unit-test:browser",
30
- "functional-test": "nyc mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace \"test/internal/functional/*.test.ts\"",
32
+ "functional-test": "nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace \"dist-esm/test/internal/functional/*.test.js\"",
31
33
  "integration-test:browser": "echo skipped",
32
34
  "integration-test:node": "npm run functional-test",
33
35
  "integration-test": "npm run integration-test:node && npm run integration-test:browser",
34
36
  "report": "nyc report --reporter=json",
35
37
  "test-opentelemetry-versions": "node test-opentelemetry-versions.js 2>&1",
36
38
  "prepare": "npm run build",
37
- "pack": "npm pack 2>&1",
38
- "build:samples": "echo Obsolete.",
39
- "execute:samples": "dev-tool samples run samples-dev",
40
- "docs": "typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src"
39
+ "pack": "npm pack 2>&1"
41
40
  },
42
41
  "engines": {
43
42
  "node": ">=12.0.0"
@@ -86,35 +85,35 @@
86
85
  "devDependencies": {
87
86
  "@azure/dev-tool": "^1.0.0",
88
87
  "@azure/eslint-plugin-azure-sdk": "^3.0.0",
89
- "@microsoft/api-extractor": "^7.18.11",
90
- "@opentelemetry/instrumentation": "0.22.0",
91
- "@opentelemetry/instrumentation-http": "0.22.0",
92
- "@opentelemetry/node": "0.22.0",
88
+ "@microsoft/api-extractor": "7.18.11",
89
+ "@opentelemetry/instrumentation": "^0.29.2",
90
+ "@opentelemetry/instrumentation-http": "^0.29.2",
91
+ "@opentelemetry/sdk-trace-node": "^1.3.1",
93
92
  "@types/mocha": "^7.0.2",
94
93
  "@types/node": "^12.0.0",
95
94
  "dotenv": "^8.2.0",
96
- "eslint": "^7.15.0",
95
+ "eslint": "^8.0.0",
97
96
  "eslint-plugin-node": "^11.1.0",
98
- "execa": "^5.0.0",
99
97
  "mocha": "^7.1.1",
100
98
  "nock": "^12.0.3",
101
- "nyc": "^14.0.0",
102
- "prettier": "^1.16.4",
99
+ "nyc": "^15.0.0",
100
+ "prettier": "^2.5.1",
103
101
  "rimraf": "^3.0.0",
104
- "rollup": "^1.16.3",
105
102
  "sinon": "^9.0.2",
106
103
  "ts-node": "^10.0.0",
107
- "typedoc": "0.15.2",
108
- "typescript": "~4.2.0"
104
+ "typescript": "~4.6.0"
109
105
  },
110
106
  "dependencies": {
111
107
  "@azure/core-client": "^1.0.0",
108
+ "@azure/core-auth": "^1.3.0",
112
109
  "@azure/core-rest-pipeline": "^1.1.0",
113
- "@opentelemetry/api": "^1.0.1",
114
- "@opentelemetry/core": "^0.22.0",
115
- "@opentelemetry/resources": "^0.22.0",
116
- "@opentelemetry/semantic-conventions": "^0.24.0",
117
- "@opentelemetry/tracing": "^0.22.0",
110
+ "@opentelemetry/api": "^1.1.0",
111
+ "@opentelemetry/api-metrics": "0.29.2",
112
+ "@opentelemetry/core": "^1.3.1",
113
+ "@opentelemetry/resources": "^1.3.1",
114
+ "@opentelemetry/sdk-metrics-base": "0.29.2",
115
+ "@opentelemetry/sdk-trace-base": "^1.3.1",
116
+ "@opentelemetry/semantic-conventions": "^1.3.1",
118
117
  "tslib": "^2.2.0"
119
118
  },
120
119
  "sideEffects": false,