@azure/monitor-opentelemetry-exporter 1.0.0-beta.8 → 1.0.0-beta.9
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/README.md +47 -9
- package/dist/index.js +294 -134
- package/dist-esm/src/config.js +1 -14
- package/dist-esm/src/config.js.map +1 -1
- package/dist-esm/src/export/base.js +20 -18
- package/dist-esm/src/export/base.js.map +1 -1
- package/dist-esm/src/export/metric.js +22 -8
- package/dist-esm/src/export/metric.js.map +1 -1
- package/dist-esm/src/export/trace.js +12 -1
- package/dist-esm/src/export/trace.js.map +1 -1
- package/dist-esm/src/generated/applicationInsightsClient.js +36 -3
- package/dist-esm/src/generated/applicationInsightsClient.js.map +1 -1
- package/dist-esm/src/generated/index.js +0 -1
- package/dist-esm/src/generated/index.js.map +1 -1
- package/dist-esm/src/generated/models/index.js +35 -0
- package/dist-esm/src/generated/models/index.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/httpSender.js +5 -8
- package/dist-esm/src/platform/nodejs/httpSender.js.map +1 -1
- package/dist-esm/src/platform/nodejs/persist/fileSystemHelpers.js +2 -1
- package/dist-esm/src/platform/nodejs/persist/fileSystemHelpers.js.map +1 -1
- package/dist-esm/src/platform/nodejs/persist/fileSystemPersist.js +10 -5
- package/dist-esm/src/platform/nodejs/persist/fileSystemPersist.js.map +1 -1
- package/dist-esm/src/sampling.js +81 -0
- package/dist-esm/src/sampling.js.map +1 -0
- package/dist-esm/src/utils/breezeUtils.js +3 -1
- package/dist-esm/src/utils/breezeUtils.js.map +1 -1
- package/dist-esm/src/utils/constants/applicationinsights.js +2 -1
- package/dist-esm/src/utils/constants/applicationinsights.js.map +1 -1
- package/dist-esm/src/utils/metricUtils.js +34 -20
- package/dist-esm/src/utils/metricUtils.js.map +1 -1
- package/dist-esm/src/utils/spanUtils.js +21 -11
- package/dist-esm/src/utils/spanUtils.js.map +1 -1
- package/package.json +14 -14
- package/types/monitor-opentelemetry-exporter.d.ts +94 -24
- package/dist-esm/src/generated/applicationInsightsClientContext.js +0 -34
- package/dist-esm/src/generated/applicationInsightsClientContext.js.map +0 -1
|
@@ -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,EAAwB,MAAM,oBAAoB,CAAC;AAC1F,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAEzF,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,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,EAML,mBAAmB,GAEpB,MAAM,cAAc,CAAC;AAEtB,SAAS,yBAAyB,CAAC,IAAkB;IACnD,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,CAAC,mBAAmB,CAAC,mBAAmB,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC;KACnE;IACD,MAAM,aAAa,GAAG,IAAI,CAAC,UAAU,CAAC,kBAAkB,CA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;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}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AE,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, 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 { 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?: 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 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 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 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"]}
|
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.9",
|
|
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",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"pack": "npm pack 2>&1"
|
|
40
40
|
},
|
|
41
41
|
"engines": {
|
|
42
|
-
"node": ">=
|
|
42
|
+
"node": ">=14.0.0"
|
|
43
43
|
},
|
|
44
44
|
"files": [
|
|
45
45
|
"dist-esm/src/",
|
|
@@ -85,12 +85,12 @@
|
|
|
85
85
|
"devDependencies": {
|
|
86
86
|
"@azure/dev-tool": "^1.0.0",
|
|
87
87
|
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
|
|
88
|
-
"@microsoft/api-extractor": "7.
|
|
89
|
-
"@opentelemetry/instrumentation": "^0.
|
|
90
|
-
"@opentelemetry/instrumentation-http": "^0.
|
|
91
|
-
"@opentelemetry/sdk-trace-node": "^1.
|
|
88
|
+
"@microsoft/api-extractor": "^7.31.1",
|
|
89
|
+
"@opentelemetry/instrumentation": "^0.33.0",
|
|
90
|
+
"@opentelemetry/instrumentation-http": "^0.33.0",
|
|
91
|
+
"@opentelemetry/sdk-trace-node": "^1.7.0",
|
|
92
92
|
"@types/mocha": "^7.0.2",
|
|
93
|
-
"@types/node": "^
|
|
93
|
+
"@types/node": "^14.0.0",
|
|
94
94
|
"dotenv": "^8.2.0",
|
|
95
95
|
"eslint": "^8.0.0",
|
|
96
96
|
"eslint-plugin-node": "^11.1.0",
|
|
@@ -107,13 +107,13 @@
|
|
|
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.
|
|
111
|
-
"@opentelemetry/api-metrics": "0.
|
|
112
|
-
"@opentelemetry/core": "^1.
|
|
113
|
-
"@opentelemetry/resources": "^1.
|
|
114
|
-
"@opentelemetry/sdk-metrics
|
|
115
|
-
"@opentelemetry/sdk-trace-base": "^1.
|
|
116
|
-
"@opentelemetry/semantic-conventions": "^1.
|
|
110
|
+
"@opentelemetry/api": "^1.2.0",
|
|
111
|
+
"@opentelemetry/api-metrics": "^0.33.0",
|
|
112
|
+
"@opentelemetry/core": "^1.7.0",
|
|
113
|
+
"@opentelemetry/resources": "^1.7.0",
|
|
114
|
+
"@opentelemetry/sdk-metrics": "^0.33.0",
|
|
115
|
+
"@opentelemetry/sdk-trace-base": "^1.7.0",
|
|
116
|
+
"@opentelemetry/semantic-conventions": "^1.7.0",
|
|
117
117
|
"tslib": "^2.2.0"
|
|
118
118
|
},
|
|
119
119
|
"sideEffects": false,
|
|
@@ -1,28 +1,57 @@
|
|
|
1
|
-
import { AggregationTemporality } from '@opentelemetry/sdk-metrics
|
|
1
|
+
import { AggregationTemporality } from '@opentelemetry/sdk-metrics';
|
|
2
|
+
import { Attributes } from '@opentelemetry/api';
|
|
3
|
+
import { Context } from '@opentelemetry/api';
|
|
4
|
+
import * as coreClient from '@azure/core-client';
|
|
2
5
|
import { ExportResult } from '@opentelemetry/core';
|
|
3
|
-
import {
|
|
6
|
+
import { InstrumentType } from '@opentelemetry/sdk-metrics';
|
|
7
|
+
import { Link } from '@opentelemetry/api';
|
|
8
|
+
import { PushMetricExporter } from '@opentelemetry/sdk-metrics';
|
|
4
9
|
import { ReadableSpan } from '@opentelemetry/sdk-trace-base';
|
|
5
|
-
import { ResourceMetrics } from '@opentelemetry/sdk-metrics
|
|
10
|
+
import { ResourceMetrics } from '@opentelemetry/sdk-metrics';
|
|
11
|
+
import { Sampler } from '@opentelemetry/sdk-trace-base';
|
|
12
|
+
import { SamplingResult } from '@opentelemetry/sdk-trace-base';
|
|
6
13
|
import { SpanExporter } from '@opentelemetry/sdk-trace-base';
|
|
14
|
+
import { SpanKind } from '@opentelemetry/api';
|
|
7
15
|
import { TokenCredential } from '@azure/core-auth';
|
|
8
16
|
|
|
17
|
+
/** Optional parameters. */
|
|
18
|
+
export declare interface ApplicationInsightsClientOptionalParams extends coreClient.ServiceClientOptions {
|
|
19
|
+
/** Breeze endpoint: https://dc.services.visualstudio.com */
|
|
20
|
+
host?: string;
|
|
21
|
+
/** Overrides client endpoint. */
|
|
22
|
+
endpoint?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
9
25
|
/**
|
|
10
|
-
*
|
|
26
|
+
* ApplicationInsightsSampler is responsible for the following:
|
|
27
|
+
* Implements same trace id hashing algorithm so that traces are sampled the same across multiple nodes
|
|
28
|
+
* Adds item count to span attribute if span is sampled (needed for ingestion service)
|
|
29
|
+
* @param samplingRatio - 0 to 1 value.
|
|
11
30
|
*/
|
|
12
|
-
export declare
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
*
|
|
24
|
-
|
|
25
|
-
|
|
31
|
+
export declare class ApplicationInsightsSampler implements Sampler {
|
|
32
|
+
private readonly _sampleRate;
|
|
33
|
+
private readonly _samplingRatio;
|
|
34
|
+
constructor(samplingRatio?: number);
|
|
35
|
+
/**
|
|
36
|
+
* Checks whether span needs to be created and tracked.
|
|
37
|
+
*
|
|
38
|
+
* @param context Parent Context which may contain a span.
|
|
39
|
+
* @param traceId of the span to be created. It can be different from the
|
|
40
|
+
* traceId in the {@link SpanContext}. Typically in situations when the
|
|
41
|
+
* span to be created starts a new trace.
|
|
42
|
+
* @param spanName of the span to be created.
|
|
43
|
+
* @param spanKind of the span to be created.
|
|
44
|
+
* @param attributes Initial set of SpanAttributes for the Span being constructed.
|
|
45
|
+
* @param links Collection of links that will be associated with the Span to
|
|
46
|
+
* be created. Typically useful for batch operations.
|
|
47
|
+
* @returns a {@link SamplingResult}.
|
|
48
|
+
*/
|
|
49
|
+
shouldSample(context: Context, traceId: string, spanName: string, spanKind: SpanKind, attributes: Attributes, links: Link[]): SamplingResult;
|
|
50
|
+
/**
|
|
51
|
+
* Return Sampler description
|
|
52
|
+
*/
|
|
53
|
+
toString(): string;
|
|
54
|
+
private _getSamplingHashCode;
|
|
26
55
|
}
|
|
27
56
|
|
|
28
57
|
/**
|
|
@@ -32,20 +61,22 @@ export declare abstract class AzureMonitorBaseExporter {
|
|
|
32
61
|
/**
|
|
33
62
|
* Instrumentation key to be used for exported envelopes
|
|
34
63
|
*/
|
|
35
|
-
protected
|
|
64
|
+
protected _instrumentationKey: string;
|
|
36
65
|
private readonly _persister;
|
|
37
66
|
private readonly _sender;
|
|
38
67
|
private _numConsecutiveRedirects;
|
|
39
68
|
private _retryTimer;
|
|
69
|
+
private _endpointUrl;
|
|
70
|
+
private _batchSendRetryIntervalMs;
|
|
40
71
|
/**
|
|
41
72
|
* Exporter internal configuration
|
|
42
73
|
*/
|
|
43
74
|
private readonly _options;
|
|
44
75
|
/**
|
|
45
76
|
* Initializes a new instance of the AzureMonitorBaseExporter class.
|
|
46
|
-
* @param
|
|
77
|
+
* @param AzureMonitorExporterOptions - Exporter configuration.
|
|
47
78
|
*/
|
|
48
|
-
constructor(options?:
|
|
79
|
+
constructor(options?: AzureMonitorExporterOptions);
|
|
49
80
|
/**
|
|
50
81
|
* Persist envelopes to disk
|
|
51
82
|
*/
|
|
@@ -62,15 +93,50 @@ export declare abstract class AzureMonitorBaseExporter {
|
|
|
62
93
|
private _isNetworkError;
|
|
63
94
|
}
|
|
64
95
|
|
|
96
|
+
/**
|
|
97
|
+
* Provides configuration options for AzureMonitorTraceExporter.
|
|
98
|
+
*/
|
|
99
|
+
export declare interface AzureMonitorExporterOptions extends ApplicationInsightsClientOptionalParams {
|
|
100
|
+
/**
|
|
101
|
+
* Azure Monitor Connection String, if not provided the exporter will try to use environment variable APPLICATIONINSIGHTS_CONNECTION_STRING
|
|
102
|
+
* Ex: "InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://dc.services.visualstudio.com"
|
|
103
|
+
*/
|
|
104
|
+
connectionString?: string;
|
|
105
|
+
/**
|
|
106
|
+
* Azure service API version.
|
|
107
|
+
*/
|
|
108
|
+
apiVersion?: ServiceApiVersion;
|
|
109
|
+
/**
|
|
110
|
+
* Azure Active Directory Credential
|
|
111
|
+
*/
|
|
112
|
+
aadTokenCredential?: TokenCredential;
|
|
113
|
+
/**
|
|
114
|
+
* Directory to store retriable telemetry when it fails to export.
|
|
115
|
+
*/
|
|
116
|
+
storageDirectory?: string;
|
|
117
|
+
/**
|
|
118
|
+
* Disable offline storage when telemetry cannot be exported.
|
|
119
|
+
*/
|
|
120
|
+
disableOfflineStorage?: boolean;
|
|
121
|
+
}
|
|
122
|
+
|
|
65
123
|
/**
|
|
66
124
|
* Azure Monitor OpenTelemetry Metric Exporter.
|
|
67
125
|
*/
|
|
68
126
|
export declare class AzureMonitorMetricExporter extends AzureMonitorBaseExporter implements PushMetricExporter {
|
|
127
|
+
/**
|
|
128
|
+
* Flag to determine if Exporter is shutdown.
|
|
129
|
+
*/
|
|
130
|
+
private _isShutdown;
|
|
131
|
+
/**
|
|
132
|
+
* Aggregation temporality.
|
|
133
|
+
*/
|
|
134
|
+
private _aggregationTemporality;
|
|
69
135
|
/**
|
|
70
136
|
* Initializes a new instance of the AzureMonitorMetricExporter class.
|
|
71
137
|
* @param AzureExporterConfig - Exporter configuration.
|
|
72
138
|
*/
|
|
73
|
-
constructor(options?:
|
|
139
|
+
constructor(options?: AzureMonitorExporterOptions);
|
|
74
140
|
/**
|
|
75
141
|
* Export OpenTelemetry resource metrics.
|
|
76
142
|
* @param metrics - Resource metrics to export.
|
|
@@ -84,7 +150,7 @@ export declare class AzureMonitorMetricExporter extends AzureMonitorBaseExporter
|
|
|
84
150
|
/**
|
|
85
151
|
* Select aggregation temporality
|
|
86
152
|
*/
|
|
87
|
-
selectAggregationTemporality(): AggregationTemporality;
|
|
153
|
+
selectAggregationTemporality(_instrumentType: InstrumentType): AggregationTemporality;
|
|
88
154
|
/**
|
|
89
155
|
* Force flush
|
|
90
156
|
*/
|
|
@@ -95,11 +161,15 @@ export declare class AzureMonitorMetricExporter extends AzureMonitorBaseExporter
|
|
|
95
161
|
* Azure Monitor OpenTelemetry Trace Exporter.
|
|
96
162
|
*/
|
|
97
163
|
export declare class AzureMonitorTraceExporter extends AzureMonitorBaseExporter implements SpanExporter {
|
|
164
|
+
/**
|
|
165
|
+
* Flag to determine if Exporter is shutdown.
|
|
166
|
+
*/
|
|
167
|
+
private _isShutdown;
|
|
98
168
|
/**
|
|
99
169
|
* Initializes a new instance of the AzureMonitorTraceExporter class.
|
|
100
170
|
* @param AzureExporterConfig - Exporter configuration.
|
|
101
171
|
*/
|
|
102
|
-
constructor(options?:
|
|
172
|
+
constructor(options?: AzureMonitorExporterOptions);
|
|
103
173
|
/**
|
|
104
174
|
* Export OpenTelemetry spans.
|
|
105
175
|
* @param spans - Spans to export.
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Microsoft Corporation.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*
|
|
5
|
-
* Code generated by Microsoft (R) AutoRest Code Generator.
|
|
6
|
-
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
|
|
7
|
-
*/
|
|
8
|
-
import * as coreClient from "@azure/core-client";
|
|
9
|
-
export class ApplicationInsightsClientContext extends coreClient.ServiceClient {
|
|
10
|
-
/**
|
|
11
|
-
* Initializes a new instance of the ApplicationInsightsClientContext class.
|
|
12
|
-
* @param options The parameter options
|
|
13
|
-
*/
|
|
14
|
-
constructor(options) {
|
|
15
|
-
// Initializing default values for options
|
|
16
|
-
if (!options) {
|
|
17
|
-
options = {};
|
|
18
|
-
}
|
|
19
|
-
const defaults = {
|
|
20
|
-
requestContentType: "application/json; charset=utf-8"
|
|
21
|
-
};
|
|
22
|
-
const packageDetails = `azsdk-js-monitor-opentelemetry-exporter/1.0.0-beta.7`;
|
|
23
|
-
const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
|
|
24
|
-
? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
|
|
25
|
-
: `${packageDetails}`;
|
|
26
|
-
const optionsWithDefaults = Object.assign(Object.assign(Object.assign({}, defaults), options), { userAgentOptions: {
|
|
27
|
-
userAgentPrefix
|
|
28
|
-
}, baseUri: options.endpoint || "{Host}/v2.1" });
|
|
29
|
-
super(optionsWithDefaults);
|
|
30
|
-
// Assigning values to Constant parameters
|
|
31
|
-
this.host = options.host || "https://dc.services.visualstudio.com";
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=applicationInsightsClientContext.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"applicationInsightsClientContext.js","sourceRoot":"","sources":["../../../src/generated/applicationInsightsClientContext.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,UAAU,MAAM,oBAAoB,CAAC;AAGjD,MAAM,OAAO,gCAAiC,SAAQ,UAAU,CAAC,aAAa;IAG5E;;;OAGG;IACH,YAAY,OAAiD;QAC3D,0CAA0C;QAC1C,IAAI,CAAC,OAAO,EAAE;YACZ,OAAO,GAAG,EAAE,CAAC;SACd;QACD,MAAM,QAAQ,GAA4C;YACxD,kBAAkB,EAAE,iCAAiC;SACtD,CAAC;QAEF,MAAM,cAAc,GAAG,sDAAsD,CAAC;QAC9E,MAAM,eAAe,GACnB,OAAO,CAAC,gBAAgB,IAAI,OAAO,CAAC,gBAAgB,CAAC,eAAe;YAClE,CAAC,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAC,eAAe,IAAI,cAAc,EAAE;YACjE,CAAC,CAAC,GAAG,cAAc,EAAE,CAAC;QAE1B,MAAM,mBAAmB,iDACpB,QAAQ,GACR,OAAO,KACV,gBAAgB,EAAE;gBAChB,eAAe;aAChB,EACD,OAAO,EAAE,OAAO,CAAC,QAAQ,IAAI,aAAa,GAC3C,CAAC;QACF,KAAK,CAAC,mBAAmB,CAAC,CAAC;QAE3B,0CAA0C;QAC1C,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,sCAAsC,CAAC;IACrE,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * Code generated by Microsoft (R) AutoRest Code Generator.\n * Changes may cause incorrect behavior and will be lost if the code is regenerated.\n */\n\nimport * as coreClient from \"@azure/core-client\";\nimport { ApplicationInsightsClientOptionalParams } from \"./models\";\n\nexport class ApplicationInsightsClientContext extends coreClient.ServiceClient {\n host: string;\n\n /**\n * Initializes a new instance of the ApplicationInsightsClientContext class.\n * @param options The parameter options\n */\n constructor(options?: ApplicationInsightsClientOptionalParams) {\n // Initializing default values for options\n if (!options) {\n options = {};\n }\n const defaults: ApplicationInsightsClientOptionalParams = {\n requestContentType: \"application/json; charset=utf-8\"\n };\n\n const packageDetails = `azsdk-js-monitor-opentelemetry-exporter/1.0.0-beta.7`;\n const userAgentPrefix =\n options.userAgentOptions && options.userAgentOptions.userAgentPrefix\n ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`\n : `${packageDetails}`;\n\n const optionsWithDefaults = {\n ...defaults,\n ...options,\n userAgentOptions: {\n userAgentPrefix\n },\n baseUri: options.endpoint || \"{Host}/v2.1\"\n };\n super(optionsWithDefaults);\n\n // Assigning values to Constant parameters\n this.host = options.host || \"https://dc.services.visualstudio.com\";\n }\n}\n"]}
|