@azure/monitor-opentelemetry-exporter 1.0.0-beta.12 → 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 +356 -27
- 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 +2 -1
- 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 -1
- 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/package.json +12 -10
- package/types/monitor-opentelemetry-exporter.d.ts +27 -0
|
@@ -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","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.
|
|
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,qBAAqB,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EACL,uCAAuC,EACvC,mCAAmC,EACnC,2BAA2B,EAC3B,gCAAgC,EAChC,4BAA4B,EAC5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C,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"]}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@azure/monitor-opentelemetry-exporter",
|
|
3
3
|
"author": "Microsoft Corporation",
|
|
4
4
|
"sdk-type": "client",
|
|
5
|
-
"version": "1.0.0-beta.
|
|
5
|
+
"version": "1.0.0-beta.13",
|
|
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",
|
|
@@ -86,9 +86,9 @@
|
|
|
86
86
|
"@azure/dev-tool": "^1.0.0",
|
|
87
87
|
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
|
|
88
88
|
"@microsoft/api-extractor": "^7.31.1",
|
|
89
|
-
"@opentelemetry/instrumentation": "^0.
|
|
90
|
-
"@opentelemetry/instrumentation-http": "^0.
|
|
91
|
-
"@opentelemetry/sdk-trace-node": "^1.
|
|
89
|
+
"@opentelemetry/instrumentation": "^0.39.0",
|
|
90
|
+
"@opentelemetry/instrumentation-http": "^0.39.0",
|
|
91
|
+
"@opentelemetry/sdk-trace-node": "^1.13.0",
|
|
92
92
|
"@types/mocha": "^7.0.2",
|
|
93
93
|
"@types/node": "^14.0.0",
|
|
94
94
|
"dotenv": "^16.0.0",
|
|
@@ -101,18 +101,20 @@
|
|
|
101
101
|
"rimraf": "^3.0.0",
|
|
102
102
|
"sinon": "^9.0.2",
|
|
103
103
|
"ts-node": "^10.0.0",
|
|
104
|
-
"typescript": "~
|
|
104
|
+
"typescript": "~5.0.0"
|
|
105
105
|
},
|
|
106
106
|
"dependencies": {
|
|
107
107
|
"@azure/core-client": "^1.0.0",
|
|
108
108
|
"@azure/core-auth": "^1.3.0",
|
|
109
109
|
"@azure/core-rest-pipeline": "^1.1.0",
|
|
110
110
|
"@opentelemetry/api": "^1.4.1",
|
|
111
|
-
"@opentelemetry/
|
|
112
|
-
"@opentelemetry/
|
|
113
|
-
"@opentelemetry/
|
|
114
|
-
"@opentelemetry/sdk-
|
|
115
|
-
"@opentelemetry/
|
|
111
|
+
"@opentelemetry/api-logs": "0.39.1",
|
|
112
|
+
"@opentelemetry/core": "^1.13.0",
|
|
113
|
+
"@opentelemetry/resources": "^1.13.0",
|
|
114
|
+
"@opentelemetry/sdk-metrics": "^1.13.0",
|
|
115
|
+
"@opentelemetry/sdk-trace-base": "^1.13.0",
|
|
116
|
+
"@opentelemetry/semantic-conventions": "^1.13.0",
|
|
117
|
+
"@opentelemetry/sdk-logs": "0.39.1",
|
|
116
118
|
"tslib": "^2.2.0"
|
|
117
119
|
},
|
|
118
120
|
"sideEffects": false,
|
|
@@ -5,7 +5,9 @@ import * as coreClient from '@azure/core-client';
|
|
|
5
5
|
import { ExportResult } from '@opentelemetry/core';
|
|
6
6
|
import { InstrumentType } from '@opentelemetry/sdk-metrics';
|
|
7
7
|
import { Link } from '@opentelemetry/api';
|
|
8
|
+
import type { LogRecordExporter } from '@opentelemetry/sdk-logs';
|
|
8
9
|
import { PushMetricExporter } from '@opentelemetry/sdk-metrics';
|
|
10
|
+
import type { ReadableLogRecord } from '@opentelemetry/sdk-logs';
|
|
9
11
|
import { ReadableSpan } from '@opentelemetry/sdk-trace-base';
|
|
10
12
|
import { ResourceMetrics } from '@opentelemetry/sdk-metrics';
|
|
11
13
|
import { Sampler } from '@opentelemetry/sdk-trace-base';
|
|
@@ -125,6 +127,31 @@ export declare interface AzureMonitorExporterOptions extends ApplicationInsights
|
|
|
125
127
|
disableOfflineStorage?: boolean;
|
|
126
128
|
}
|
|
127
129
|
|
|
130
|
+
/**
|
|
131
|
+
* Azure Monitor OpenTelemetry Log Exporter.
|
|
132
|
+
*/
|
|
133
|
+
export declare class AzureMonitorLogExporter extends AzureMonitorBaseExporter implements LogRecordExporter {
|
|
134
|
+
/**
|
|
135
|
+
* Flag to determine if Exporter is shutdown.
|
|
136
|
+
*/
|
|
137
|
+
private _isShutdown;
|
|
138
|
+
/**
|
|
139
|
+
* Initializes a new instance of the AzureMonitorLogExporter class.
|
|
140
|
+
* @param AzureExporterConfig - Exporter configuration.
|
|
141
|
+
*/
|
|
142
|
+
constructor(options?: AzureMonitorExporterOptions);
|
|
143
|
+
/**
|
|
144
|
+
* Export OpenTelemetry logs.
|
|
145
|
+
* @param logs - Logs to export.
|
|
146
|
+
* @param resultCallback - Result callback.
|
|
147
|
+
*/
|
|
148
|
+
export(logs: ReadableLogRecord[], resultCallback: (result: ExportResult) => void): Promise<void>;
|
|
149
|
+
/**
|
|
150
|
+
* Shutdown AzureMonitorLogExporter.
|
|
151
|
+
*/
|
|
152
|
+
shutdown(): Promise<void>;
|
|
153
|
+
}
|
|
154
|
+
|
|
128
155
|
/**
|
|
129
156
|
* Azure Monitor OpenTelemetry Metric Exporter.
|
|
130
157
|
*/
|