@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.
Files changed (33) hide show
  1. package/dist/index.js +401 -128
  2. package/dist-esm/src/Declarations/Constants.js +5 -0
  3. package/dist-esm/src/Declarations/Constants.js.map +1 -1
  4. package/dist-esm/src/export/base.js +2 -2
  5. package/dist-esm/src/export/base.js.map +1 -1
  6. package/dist-esm/src/export/log.js +53 -0
  7. package/dist-esm/src/export/log.js.map +1 -0
  8. package/dist-esm/src/export/trace.js +17 -8
  9. package/dist-esm/src/export/trace.js.map +1 -1
  10. package/dist-esm/src/generated/applicationInsightsClient.js +1 -1
  11. package/dist-esm/src/generated/applicationInsightsClient.js.map +1 -1
  12. package/dist-esm/src/index.js +1 -0
  13. package/dist-esm/src/index.js.map +1 -1
  14. package/dist-esm/src/platform/nodejs/context/context.js +11 -3
  15. package/dist-esm/src/platform/nodejs/context/context.js.map +1 -1
  16. package/dist-esm/src/platform/nodejs/persist/fileAccessControl.js +2 -1
  17. package/dist-esm/src/platform/nodejs/persist/fileAccessControl.js.map +1 -1
  18. package/dist-esm/src/platform/nodejs/persist/fileSystemPersist.js +2 -1
  19. package/dist-esm/src/platform/nodejs/persist/fileSystemPersist.js.map +1 -1
  20. package/dist-esm/src/utils/common.js +101 -15
  21. package/dist-esm/src/utils/common.js.map +1 -1
  22. package/dist-esm/src/utils/connectionStringParser.js +2 -1
  23. package/dist-esm/src/utils/connectionStringParser.js.map +1 -1
  24. package/dist-esm/src/utils/constants/applicationinsights.js +12 -30
  25. package/dist-esm/src/utils/constants/applicationinsights.js.map +1 -1
  26. package/dist-esm/src/utils/logUtils.js +177 -0
  27. package/dist-esm/src/utils/logUtils.js.map +1 -0
  28. package/dist-esm/src/utils/metricUtils.js +2 -42
  29. package/dist-esm/src/utils/metricUtils.js.map +1 -1
  30. package/dist-esm/src/utils/spanUtils.js +35 -31
  31. package/dist-esm/src/utils/spanUtils.js.map +1 -1
  32. package/package.json +13 -11
  33. package/types/monitor-opentelemetry-exporter.d.ts +27 -0
@@ -34,7 +34,7 @@ function createTagsFromSpan(span) {
34
34
  }
35
35
  else if (httpUrl) {
36
36
  try {
37
- let url = new URL(String(httpUrl));
37
+ const url = new URL(String(httpUrl));
38
38
  tags[KnownContextTagKeys.AiOperationName] = `${httpMethod} ${url.pathname}`;
39
39
  }
40
40
  catch (ex) { }
@@ -60,19 +60,23 @@ function createPropertiesFromSpanAttributes(attributes) {
60
60
  const properties = {};
61
61
  if (attributes) {
62
62
  for (const key of Object.keys(attributes)) {
63
- if (!(key.startsWith("http.") ||
64
- key.startsWith("rpc.") ||
65
- key.startsWith("db.") ||
66
- key.startsWith("peer.") ||
67
- key.startsWith("message.") ||
68
- key.startsWith("messaging.") ||
69
- key.startsWith("enduser.") ||
70
- key.startsWith("net.") ||
71
- key.startsWith("exception.") ||
72
- key.startsWith("thread.") ||
73
- key.startsWith("faas.") ||
74
- key.startsWith("code.") ||
75
- key.startsWith("_MS."))) {
63
+ // Avoid duplication ignoring fields already mapped.
64
+ if (!(key.startsWith("_MS.") ||
65
+ key == SemanticAttributes.NET_PEER_IP ||
66
+ key == SemanticAttributes.NET_PEER_NAME ||
67
+ key == SemanticAttributes.PEER_SERVICE ||
68
+ key == SemanticAttributes.HTTP_METHOD ||
69
+ key == SemanticAttributes.HTTP_URL ||
70
+ key == SemanticAttributes.HTTP_STATUS_CODE ||
71
+ key == SemanticAttributes.HTTP_ROUTE ||
72
+ key == SemanticAttributes.HTTP_HOST ||
73
+ key == SemanticAttributes.HTTP_URL ||
74
+ key == SemanticAttributes.DB_SYSTEM ||
75
+ key == SemanticAttributes.DB_STATEMENT ||
76
+ key == SemanticAttributes.DB_OPERATION ||
77
+ key == SemanticAttributes.DB_NAME ||
78
+ key == SemanticAttributes.RPC_SYSTEM ||
79
+ key == SemanticAttributes.RPC_GRPC_STATUS_CODE)) {
76
80
  properties[key] = attributes[key];
77
81
  }
78
82
  }
@@ -115,7 +119,7 @@ function createDependencyData(span) {
115
119
  const httpUrl = span.attributes[SemanticAttributes.HTTP_URL];
116
120
  if (httpUrl) {
117
121
  try {
118
- let dependencyUrl = new URL(String(httpUrl));
122
+ const dependencyUrl = new URL(String(httpUrl));
119
123
  remoteDependencyData.name = `${httpMethod} ${dependencyUrl.pathname}`;
120
124
  }
121
125
  catch (ex) { }
@@ -130,11 +134,11 @@ function createDependencyData(span) {
130
134
  if (target) {
131
135
  try {
132
136
  // Remove default port
133
- let portRegex = new RegExp(/(https?)(:\/\/.*)(:\d+)(\S*)/);
134
- let res = portRegex.exec(target);
137
+ const portRegex = new RegExp(/(https?)(:\/\/.*)(:\d+)(\S*)/);
138
+ const res = portRegex.exec(target);
135
139
  if (res != null) {
136
- let protocol = res[1];
137
- let port = res[3];
140
+ const protocol = res[1];
141
+ const port = res[3];
138
142
  if ((protocol == "https" && port == ":443") || (protocol == "http" && port == ":80")) {
139
143
  // Drop port
140
144
  target = res[1] + res[2] + res[4];
@@ -174,7 +178,7 @@ function createDependencyData(span) {
174
178
  else if (dbOperation) {
175
179
  remoteDependencyData.data = String(dbOperation);
176
180
  }
177
- let target = getDependencyTarget(span.attributes);
181
+ const target = getDependencyTarget(span.attributes);
178
182
  const dbName = span.attributes[SemanticAttributes.DB_NAME];
179
183
  if (target) {
180
184
  remoteDependencyData.target = dbName ? `${target}|${dbName}` : `${target}`;
@@ -190,7 +194,7 @@ function createDependencyData(span) {
190
194
  if (grpcStatusCode) {
191
195
  remoteDependencyData.resultCode = String(grpcStatusCode);
192
196
  }
193
- let target = getDependencyTarget(span.attributes);
197
+ const target = getDependencyTarget(span.attributes);
194
198
  if (target) {
195
199
  remoteDependencyData.target = `${target}`;
196
200
  }
@@ -287,18 +291,18 @@ export function readableSpanToEnvelope(span, ikey) {
287
291
  * @internal
288
292
  */
289
293
  export function spanEventsToEnvelopes(span, ikey) {
290
- let envelopes = [];
294
+ const envelopes = [];
291
295
  if (span.events) {
292
296
  span.events.forEach((event) => {
293
297
  var _a;
294
298
  let baseType;
295
- let time = new Date(hrTimeToMilliseconds(event.time));
299
+ const time = new Date(hrTimeToMilliseconds(event.time));
296
300
  let name = "";
297
301
  let baseData;
298
302
  const properties = createPropertiesFromSpanAttributes(event.attributes);
299
- let tags = createTagsFromResource(span.resource);
303
+ const tags = createTagsFromResource(span.resource);
300
304
  tags[KnownContextTagKeys.AiOperationId] = span.spanContext().traceId;
301
- let spanId = (_a = span.spanContext()) === null || _a === void 0 ? void 0 : _a.spanId;
305
+ const spanId = (_a = span.spanContext()) === null || _a === void 0 ? void 0 : _a.spanId;
302
306
  if (spanId) {
303
307
  tags[KnownContextTagKeys.AiOperationParentId] = spanId;
304
308
  }
@@ -316,22 +320,22 @@ export function spanEventsToEnvelopes(span, ikey) {
316
320
  if (stack) {
317
321
  hasFullStack = true;
318
322
  }
319
- let exceptionMsg = event.attributes[SemanticAttributes.EXCEPTION_MESSAGE];
323
+ const exceptionMsg = event.attributes[SemanticAttributes.EXCEPTION_MESSAGE];
320
324
  if (exceptionMsg) {
321
325
  message = String(exceptionMsg);
322
326
  }
323
- let escaped = event.attributes[SemanticAttributes.EXCEPTION_ESCAPED];
327
+ const escaped = event.attributes[SemanticAttributes.EXCEPTION_ESCAPED];
324
328
  if (escaped != undefined) {
325
329
  properties[SemanticAttributes.EXCEPTION_ESCAPED] = String(escaped);
326
330
  }
327
331
  }
328
- let exceptionDetails = {
332
+ const exceptionDetails = {
329
333
  typeName: typeName,
330
334
  message: message,
331
335
  stack: stack,
332
336
  hasFullStack: hasFullStack,
333
337
  };
334
- let exceptionData = {
338
+ const exceptionData = {
335
339
  exceptions: [exceptionDetails],
336
340
  version: 2,
337
341
  properties: properties,
@@ -341,7 +345,7 @@ export function spanEventsToEnvelopes(span, ikey) {
341
345
  else {
342
346
  name = "Microsoft.ApplicationInsights.Message";
343
347
  baseType = "MessageData";
344
- let messageData = {
348
+ const messageData = {
345
349
  message: event.name,
346
350
  version: 2,
347
351
  properties: properties,
@@ -352,7 +356,7 @@ export function spanEventsToEnvelopes(span, ikey) {
352
356
  if (span.attributes[AzureMonitorSampleRate]) {
353
357
  sampleRate = Number(span.attributes[AzureMonitorSampleRate]);
354
358
  }
355
- let env = {
359
+ const env = {
356
360
  name: name,
357
361
  time: time,
358
362
  instrumentationKey: ikey,
@@ -1 +1 @@
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,EAAoB,MAAM,oBAAoB,CAAC;AACtF,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAEzF,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAExF,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AACpG,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAC/E,OAAO,EAML,mBAAmB,GAEpB,MAAM,cAAc,CAAC;AAEtB,SAAS,kBAAkB,CAAC,IAAkB;IAC5C,MAAM,IAAI,GAAS,sBAAsB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACzD,IAAI,CAAC,mBAAmB,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC;IACrE,IAAI,IAAI,CAAC,YAAY,EAAE;QACrB,IAAI,CAA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AAU,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,UAAU,GAAG,GAAG,CAAC;YACrB,IAAI,IAAI,CAAC,UAAU,CAAC,sBAAsB,CAAC,EAAE;gBAC3C,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,sBAAsB,CAAC,CAAC,CAAC;aAC9D;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, Attributes } from \"@opentelemetry/api\";\nimport { SemanticAttributes, DbSystemValues } from \"@opentelemetry/semantic-conventions\";\n\nimport { createTagsFromResource, getDependencyTarget, getUrl, isSqlDB } from \"./common\";\nimport { Tags, Properties, MSLink, Measurements } from \"../types\";\nimport { msToTimeSpan } from \"./breezeUtils\";\nimport { parseEventHubSpan } from \"./eventhub\";\nimport { AzureMonitorSampleRate, 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 createTagsFromSpan(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 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?: Attributes): {\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 key.startsWith(\"_MS.\")\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 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.attributes);\n const httpStatusCode = span.attributes[SemanticAttributes.HTTP_STATUS_CODE];\n if (httpStatusCode) {\n remoteDependencyData.resultCode = String(httpStatusCode);\n }\n let target = getDependencyTarget(span.attributes);\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.attributes);\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.attributes);\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.attributes);\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 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 let sampleRate = 100;\n if (span.attributes[AzureMonitorSampleRate]) {\n sampleRate = Number(span.attributes[AzureMonitorSampleRate]);\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 let time = new Date(hrTimeToMilliseconds(event.time));\n let name = \"\";\n let baseData: TelemetryExceptionData | MessageData;\n const properties = createPropertiesFromSpanAttributes(event.attributes);\n\n let tags: Tags = createTagsFromResource(span.resource);\n tags[KnownContextTagKeys.AiOperationId] = span.spanContext().traceId;\n let spanId = span.spanContext()?.spanId;\n if (spanId) {\n tags[KnownContextTagKeys.AiOperationParentId] = spanId;\n }\n\n // Only generate exception telemetry for incoming requests\n if (event.name == \"exception\" && span.kind == SpanKind.SERVER) {\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 sampleRate = 100;\n if (span.attributes[AzureMonitorSampleRate]) {\n sampleRate = Number(span.attributes[AzureMonitorSampleRate]);\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"]}
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,EAAoB,MAAM,oBAAoB,CAAC;AACtF,OAA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AAsB,CAAC,EAAE;gBAC3C,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,sBAAsB,CAAC,CAAC,CAAC;aAC9D;YACD,MAAM,GAAG,GAAa;gBACpB,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, Attributes } from \"@opentelemetry/api\";\nimport { SemanticAttributes, DbSystemValues } from \"@opentelemetry/semantic-conventions\";\n\nimport { createTagsFromResource, getDependencyTarget, getUrl, isSqlDB } from \"./common\";\nimport { Tags, Properties, MSLink, Measurements } from \"../types\";\nimport { msToTimeSpan } from \"./breezeUtils\";\nimport { parseEventHubSpan } from \"./eventhub\";\nimport { AzureMonitorSampleRate, 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 createTagsFromSpan(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 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 const 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?: Attributes): {\n [propertyName: string]: string;\n} {\n const properties: { [propertyName: string]: string } = {};\n if (attributes) {\n for (const key of Object.keys(attributes)) {\n // Avoid duplication ignoring fields already mapped.\n if (\n !(\n key.startsWith(\"_MS.\") ||\n key == SemanticAttributes.NET_PEER_IP ||\n key == SemanticAttributes.NET_PEER_NAME ||\n key == SemanticAttributes.PEER_SERVICE ||\n key == SemanticAttributes.HTTP_METHOD ||\n key == SemanticAttributes.HTTP_URL ||\n key == SemanticAttributes.HTTP_STATUS_CODE ||\n key == SemanticAttributes.HTTP_ROUTE ||\n key == SemanticAttributes.HTTP_HOST ||\n key == SemanticAttributes.HTTP_URL ||\n key == SemanticAttributes.DB_SYSTEM ||\n key == SemanticAttributes.DB_STATEMENT ||\n key == SemanticAttributes.DB_OPERATION ||\n key == SemanticAttributes.DB_NAME ||\n key == SemanticAttributes.RPC_SYSTEM ||\n key == SemanticAttributes.RPC_GRPC_STATUS_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 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 const 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.attributes);\n const httpStatusCode = span.attributes[SemanticAttributes.HTTP_STATUS_CODE];\n if (httpStatusCode) {\n remoteDependencyData.resultCode = String(httpStatusCode);\n }\n let target = getDependencyTarget(span.attributes);\n if (target) {\n try {\n // Remove default port\n const portRegex = new RegExp(/(https?)(:\\/\\/.*)(:\\d+)(\\S*)/);\n const res = portRegex.exec(target);\n if (res != null) {\n const protocol = res[1];\n const 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 const target = getDependencyTarget(span.attributes);\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 const target = getDependencyTarget(span.attributes);\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.attributes);\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 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 let sampleRate = 100;\n if (span.attributes[AzureMonitorSampleRate]) {\n sampleRate = Number(span.attributes[AzureMonitorSampleRate]);\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 const envelopes: Envelope[] = [];\n if (span.events) {\n span.events.forEach((event: TimedEvent) => {\n let baseType: \"ExceptionData\" | \"MessageData\";\n const time = new Date(hrTimeToMilliseconds(event.time));\n let name = \"\";\n let baseData: TelemetryExceptionData | MessageData;\n const properties = createPropertiesFromSpanAttributes(event.attributes);\n\n const tags: Tags = createTagsFromResource(span.resource);\n tags[KnownContextTagKeys.AiOperationId] = span.spanContext().traceId;\n const spanId = span.spanContext()?.spanId;\n if (spanId) {\n tags[KnownContextTagKeys.AiOperationParentId] = spanId;\n }\n\n // Only generate exception telemetry for incoming requests\n if (event.name == \"exception\" && span.kind == SpanKind.SERVER) {\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 const exceptionMsg = event.attributes[SemanticAttributes.EXCEPTION_MESSAGE];\n if (exceptionMsg) {\n message = String(exceptionMsg);\n }\n const escaped = event.attributes[SemanticAttributes.EXCEPTION_ESCAPED];\n if (escaped != undefined) {\n properties[SemanticAttributes.EXCEPTION_ESCAPED] = String(escaped);\n }\n }\n const exceptionDetails: TelemetryExceptionDetails = {\n typeName: typeName,\n message: message,\n stack: stack,\n hasFullStack: hasFullStack,\n };\n const 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 const messageData: MessageData = {\n message: event.name,\n version: 2,\n properties: properties,\n };\n baseData = messageData;\n }\n let sampleRate = 100;\n if (span.attributes[AzureMonitorSampleRate]) {\n sampleRate = Number(span.attributes[AzureMonitorSampleRate]);\n }\n const 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,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.11",
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.35.0",
90
- "@opentelemetry/instrumentation-http": "^0.35.0",
91
- "@opentelemetry/sdk-trace-node": "^1.9.0",
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": "~4.8.0"
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
- "@opentelemetry/api": "^1.4.0",
111
- "@opentelemetry/core": "^1.9.0",
112
- "@opentelemetry/resources": "^1.9.0",
113
- "@opentelemetry/sdk-metrics": "^1.9.0",
114
- "@opentelemetry/sdk-trace-base": "^1.9.0",
115
- "@opentelemetry/semantic-conventions": "^1.9.0",
110
+ "@opentelemetry/api": "^1.4.1",
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
  */