@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
package/dist/index.js
CHANGED
|
@@ -66,7 +66,7 @@ const TIME_SINCE_ENQUEUED = "timeSinceEnqueued";
|
|
|
66
66
|
* AzureMonitorTraceExporter version.
|
|
67
67
|
* @internal
|
|
68
68
|
*/
|
|
69
|
-
const packageVersion = "1.0.0-beta.
|
|
69
|
+
const packageVersion = "1.0.0-beta.13";
|
|
70
70
|
var DependencyTypes;
|
|
71
71
|
(function (DependencyTypes) {
|
|
72
72
|
DependencyTypes["InProc"] = "InProc";
|
|
@@ -76,6 +76,17 @@ var DependencyTypes;
|
|
|
76
76
|
DependencyTypes["Grpc"] = "GRPC";
|
|
77
77
|
})(DependencyTypes || (DependencyTypes = {}));
|
|
78
78
|
const AzureMonitorSampleRate = "_MS.sampleRate";
|
|
79
|
+
const ApplicationInsightsBaseType = "_MS.baseType";
|
|
80
|
+
const ApplicationInsightsMessageName = "Microsoft.ApplicationInsights.Message";
|
|
81
|
+
const ApplicationInsightsExceptionName = "Microsoft.ApplicationInsights.Exception";
|
|
82
|
+
const ApplicationInsightsPageViewName = "Microsoft.ApplicationInsights.PageView";
|
|
83
|
+
const ApplicationInsightsAvailabilityName = "Microsoft.ApplicationInsights.Availability";
|
|
84
|
+
const ApplicationInsightsEventName = "Microsoft.ApplicationInsights.Event";
|
|
85
|
+
const ApplicationInsightsMessageBaseType = "MessageData";
|
|
86
|
+
const ApplicationInsightsExceptionBaseType = "TelemetryExceptionData";
|
|
87
|
+
const ApplicationInsightsPageViewBaseType = "PageViewData";
|
|
88
|
+
const ApplicationInsightsAvailabilityBaseType = "AvailabilityData";
|
|
89
|
+
const ApplicationInsightsEventBaseType = "TelemetryEventData";
|
|
79
90
|
|
|
80
91
|
/**
|
|
81
92
|
* ApplicationInsightsSampler is responsible for the following:
|
|
@@ -188,6 +199,11 @@ const DEFAULT_LIVEMETRICS_ENDPOINT = "https://rt.services.visualstudio.com";
|
|
|
188
199
|
* @internal
|
|
189
200
|
*/
|
|
190
201
|
const ENV_CONNECTION_STRING = "APPLICATIONINSIGHTS_CONNECTION_STRING";
|
|
202
|
+
/**
|
|
203
|
+
* Disable Statsbeat environment variable name.
|
|
204
|
+
* @internal
|
|
205
|
+
*/
|
|
206
|
+
const ENV_DISABLE_STATSBEAT = "APPLICATION_INSIGHTS_NO_STATSBEAT";
|
|
191
207
|
/**
|
|
192
208
|
* QuickPulse metric counter names.
|
|
193
209
|
* @internal
|
|
@@ -1727,7 +1743,7 @@ class ApplicationInsightsClient extends coreClient__namespace.ServiceClient {
|
|
|
1727
1743
|
const defaults = {
|
|
1728
1744
|
requestContentType: "application/json; charset=utf-8"
|
|
1729
1745
|
};
|
|
1730
|
-
const packageDetails = `azsdk-js-monitor-opentelemetry-exporter/1.0.0-beta.
|
|
1746
|
+
const packageDetails = `azsdk-js-monitor-opentelemetry-exporter/1.0.0-beta.13`;
|
|
1731
1747
|
const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
|
|
1732
1748
|
? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
|
|
1733
1749
|
: `${packageDetails}`;
|
|
@@ -2483,7 +2499,7 @@ class AzureMonitorBaseExporter {
|
|
|
2483
2499
|
}
|
|
2484
2500
|
this._sender = new HttpSender(this._endpointUrl, this._options);
|
|
2485
2501
|
this._persister = new FileSystemPersist(this._instrumentationKey, this._options);
|
|
2486
|
-
if (!this._isStatsbeatExporter) {
|
|
2502
|
+
if (!this._isStatsbeatExporter && !process.env[ENV_DISABLE_STATSBEAT]) {
|
|
2487
2503
|
// Initialize statsbeatMetrics
|
|
2488
2504
|
this._networkStatsbeatMetrics = new NetworkStatsbeatMetrics({
|
|
2489
2505
|
instrumentationKey: this._instrumentationKey,
|
|
@@ -2673,29 +2689,80 @@ function createTagsFromResource(resource) {
|
|
|
2673
2689
|
const context = getInstance$1();
|
|
2674
2690
|
const tags = Object.assign({}, context.tags);
|
|
2675
2691
|
if (resource && resource.attributes) {
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2692
|
+
tags[KnownContextTagKeys.AiCloudRole] = getCloudRole(resource);
|
|
2693
|
+
tags[KnownContextTagKeys.AiCloudRoleInstance] = getCloudRoleInstance(resource);
|
|
2694
|
+
const endUserId = resource.attributes[semanticConventions.SemanticAttributes.ENDUSER_ID];
|
|
2695
|
+
if (endUserId) {
|
|
2696
|
+
tags[KnownContextTagKeys.AiUserId] = String(endUserId);
|
|
2697
|
+
}
|
|
2698
|
+
}
|
|
2699
|
+
return tags;
|
|
2700
|
+
}
|
|
2701
|
+
function getCloudRole(resource) {
|
|
2702
|
+
let cloudRole = "";
|
|
2703
|
+
// Service attributes
|
|
2704
|
+
const serviceName = resource.attributes[semanticConventions.SemanticResourceAttributes.SERVICE_NAME];
|
|
2705
|
+
const serviceNamespace = resource.attributes[semanticConventions.SemanticResourceAttributes.SERVICE_NAMESPACE];
|
|
2706
|
+
if (serviceName) {
|
|
2707
|
+
// Custom Service name provided by customer is highest precedence
|
|
2708
|
+
if (!String(serviceName).startsWith("unknown_service")) {
|
|
2679
2709
|
if (serviceNamespace) {
|
|
2680
|
-
|
|
2710
|
+
return `${serviceNamespace}.${serviceName}`;
|
|
2681
2711
|
}
|
|
2682
2712
|
else {
|
|
2683
|
-
|
|
2713
|
+
return String(serviceName);
|
|
2684
2714
|
}
|
|
2685
2715
|
}
|
|
2686
|
-
const serviceInstanceId = resource.attributes[semanticConventions.SemanticResourceAttributes.SERVICE_INSTANCE_ID];
|
|
2687
|
-
if (serviceInstanceId) {
|
|
2688
|
-
tags[KnownContextTagKeys.AiCloudRoleInstance] = String(serviceInstanceId);
|
|
2689
|
-
}
|
|
2690
2716
|
else {
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2717
|
+
// Service attributes will be only used if K8S attributes are not present
|
|
2718
|
+
if (serviceNamespace) {
|
|
2719
|
+
cloudRole = `${serviceNamespace}.${serviceName}`;
|
|
2720
|
+
}
|
|
2721
|
+
else {
|
|
2722
|
+
cloudRole = String(serviceName);
|
|
2723
|
+
}
|
|
2696
2724
|
}
|
|
2697
2725
|
}
|
|
2698
|
-
|
|
2726
|
+
// Kubernetes attributes should take precedence
|
|
2727
|
+
const kubernetesDeploymentName = resource.attributes[semanticConventions.SemanticResourceAttributes.K8S_DEPLOYMENT_NAME];
|
|
2728
|
+
if (kubernetesDeploymentName) {
|
|
2729
|
+
return String(kubernetesDeploymentName);
|
|
2730
|
+
}
|
|
2731
|
+
const kuberneteReplicasetName = resource.attributes[semanticConventions.SemanticResourceAttributes.K8S_REPLICASET_NAME];
|
|
2732
|
+
if (kuberneteReplicasetName) {
|
|
2733
|
+
return String(kuberneteReplicasetName);
|
|
2734
|
+
}
|
|
2735
|
+
const kubernetesStatefulSetName = resource.attributes[semanticConventions.SemanticResourceAttributes.K8S_STATEFULSET_NAME];
|
|
2736
|
+
if (kubernetesStatefulSetName) {
|
|
2737
|
+
return String(kubernetesStatefulSetName);
|
|
2738
|
+
}
|
|
2739
|
+
const kubernetesJobName = resource.attributes[semanticConventions.SemanticResourceAttributes.K8S_JOB_NAME];
|
|
2740
|
+
if (kubernetesJobName) {
|
|
2741
|
+
return String(kubernetesJobName);
|
|
2742
|
+
}
|
|
2743
|
+
const kubernetesCronjobName = resource.attributes[semanticConventions.SemanticResourceAttributes.K8S_CRONJOB_NAME];
|
|
2744
|
+
if (kubernetesCronjobName) {
|
|
2745
|
+
return String(kubernetesCronjobName);
|
|
2746
|
+
}
|
|
2747
|
+
const kubernetesDaemonsetName = resource.attributes[semanticConventions.SemanticResourceAttributes.K8S_DAEMONSET_NAME];
|
|
2748
|
+
if (kubernetesDaemonsetName) {
|
|
2749
|
+
return String(kubernetesDaemonsetName);
|
|
2750
|
+
}
|
|
2751
|
+
return cloudRole;
|
|
2752
|
+
}
|
|
2753
|
+
function getCloudRoleInstance(resource) {
|
|
2754
|
+
// Kubernetes attributes should take precedence
|
|
2755
|
+
const kubernetesPodName = resource.attributes[semanticConventions.SemanticResourceAttributes.K8S_POD_NAME];
|
|
2756
|
+
if (kubernetesPodName) {
|
|
2757
|
+
return String(kubernetesPodName);
|
|
2758
|
+
}
|
|
2759
|
+
// Service attributes
|
|
2760
|
+
const serviceInstanceId = resource.attributes[semanticConventions.SemanticResourceAttributes.SERVICE_INSTANCE_ID];
|
|
2761
|
+
if (serviceInstanceId) {
|
|
2762
|
+
return String(serviceInstanceId);
|
|
2763
|
+
}
|
|
2764
|
+
// Default
|
|
2765
|
+
return os__default["default"] && os__default["default"].hostname();
|
|
2699
2766
|
}
|
|
2700
2767
|
function isSqlDB(dbSystem) {
|
|
2701
2768
|
return (dbSystem === semanticConventions.DbSystemValues.DB2 ||
|
|
@@ -2772,6 +2839,41 @@ function getDependencyTarget(attributes) {
|
|
|
2772
2839
|
}
|
|
2773
2840
|
return "";
|
|
2774
2841
|
}
|
|
2842
|
+
function createResourceMetricEnvelope(resource, instrumentationKey) {
|
|
2843
|
+
if (resource && resource.attributes) {
|
|
2844
|
+
const tags = createTagsFromResource(resource);
|
|
2845
|
+
const resourceAttributes = {};
|
|
2846
|
+
for (const key of Object.keys(resource.attributes)) {
|
|
2847
|
+
// Avoid duplication ignoring fields already mapped.
|
|
2848
|
+
if (!(key.startsWith("_MS.") ||
|
|
2849
|
+
key == semanticConventions.SemanticResourceAttributes.TELEMETRY_SDK_VERSION ||
|
|
2850
|
+
key == semanticConventions.SemanticResourceAttributes.TELEMETRY_SDK_LANGUAGE ||
|
|
2851
|
+
key == semanticConventions.SemanticResourceAttributes.TELEMETRY_SDK_NAME)) {
|
|
2852
|
+
resourceAttributes[key] = resource.attributes[key];
|
|
2853
|
+
}
|
|
2854
|
+
}
|
|
2855
|
+
// Only send event when resource attributes are available
|
|
2856
|
+
if (Object.keys(resourceAttributes).length > 0) {
|
|
2857
|
+
let envelope = {
|
|
2858
|
+
name: "_APPRESOURCEPREVIEW_",
|
|
2859
|
+
time: new Date(),
|
|
2860
|
+
sampleRate: 100,
|
|
2861
|
+
instrumentationKey: instrumentationKey,
|
|
2862
|
+
version: 1,
|
|
2863
|
+
data: {
|
|
2864
|
+
baseType: "MetricData",
|
|
2865
|
+
baseData: {
|
|
2866
|
+
version: 2,
|
|
2867
|
+
properties: resourceAttributes,
|
|
2868
|
+
},
|
|
2869
|
+
},
|
|
2870
|
+
tags: tags,
|
|
2871
|
+
};
|
|
2872
|
+
return envelope;
|
|
2873
|
+
}
|
|
2874
|
+
}
|
|
2875
|
+
return;
|
|
2876
|
+
}
|
|
2775
2877
|
|
|
2776
2878
|
// Copyright (c) Microsoft Corporation.
|
|
2777
2879
|
// Licensed under the MIT license.
|
|
@@ -3231,15 +3333,23 @@ class AzureMonitorTraceExporter extends AzureMonitorBaseExporter {
|
|
|
3231
3333
|
return;
|
|
3232
3334
|
}
|
|
3233
3335
|
api.diag.info(`Exporting ${spans.length} span(s). Converting to envelopes...`);
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3336
|
+
if (spans.length > 0) {
|
|
3337
|
+
let envelopes = [];
|
|
3338
|
+
const resourceMetricEnvelope = createResourceMetricEnvelope(spans[0].resource, this._instrumentationKey);
|
|
3339
|
+
if (resourceMetricEnvelope) {
|
|
3340
|
+
envelopes.push(resourceMetricEnvelope);
|
|
3341
|
+
}
|
|
3342
|
+
spans.forEach((span) => {
|
|
3343
|
+
envelopes.push(readableSpanToEnvelope(span, this._instrumentationKey));
|
|
3344
|
+
let spanEventEnvelopes = spanEventsToEnvelopes(span, this._instrumentationKey);
|
|
3345
|
+
if (spanEventEnvelopes.length > 0) {
|
|
3346
|
+
envelopes.push(...spanEventEnvelopes);
|
|
3347
|
+
}
|
|
3348
|
+
});
|
|
3349
|
+
resultCallback(await this._exportEnvelopes(envelopes));
|
|
3350
|
+
}
|
|
3351
|
+
// No data to export
|
|
3352
|
+
resultCallback({ code: core.ExportResultCode.SUCCESS });
|
|
3243
3353
|
}
|
|
3244
3354
|
/**
|
|
3245
3355
|
* Shutdown AzureMonitorTraceExporter.
|
|
@@ -3380,6 +3490,224 @@ class AzureMonitorMetricExporter extends AzureMonitorBaseExporter {
|
|
|
3380
3490
|
}
|
|
3381
3491
|
}
|
|
3382
3492
|
|
|
3493
|
+
// Copyright (c) Microsoft Corporation.
|
|
3494
|
+
/**
|
|
3495
|
+
* Log to Azure envelope parsing.
|
|
3496
|
+
* @internal
|
|
3497
|
+
*/
|
|
3498
|
+
function logToEnvelope(log, ikey) {
|
|
3499
|
+
const time = log.hrTime ? new Date(core.hrTimeToMilliseconds(log.hrTime)) : new Date();
|
|
3500
|
+
let sampleRate = 100;
|
|
3501
|
+
const instrumentationKey = ikey;
|
|
3502
|
+
const tags = createTagsFromLog(log);
|
|
3503
|
+
const [properties, measurements] = createPropertiesFromLog(log);
|
|
3504
|
+
let name;
|
|
3505
|
+
let baseType;
|
|
3506
|
+
let baseData;
|
|
3507
|
+
if (!log.attributes[ApplicationInsightsBaseType]) {
|
|
3508
|
+
// Get Exception attributes if available
|
|
3509
|
+
let exceptionType = log.attributes[semanticConventions.SemanticAttributes.EXCEPTION_TYPE];
|
|
3510
|
+
if (exceptionType) {
|
|
3511
|
+
let exceptionMessage = log.attributes[semanticConventions.SemanticAttributes.EXCEPTION_MESSAGE];
|
|
3512
|
+
let exceptionStacktrace = log.attributes[semanticConventions.SemanticAttributes.EXCEPTION_STACKTRACE];
|
|
3513
|
+
name = ApplicationInsightsExceptionName;
|
|
3514
|
+
baseType = ApplicationInsightsExceptionBaseType;
|
|
3515
|
+
let exceptionDetails = {
|
|
3516
|
+
typeName: String(exceptionType),
|
|
3517
|
+
message: String(exceptionMessage),
|
|
3518
|
+
hasFullStack: exceptionStacktrace ? true : false,
|
|
3519
|
+
stack: String(exceptionStacktrace),
|
|
3520
|
+
};
|
|
3521
|
+
const exceptionData = {
|
|
3522
|
+
exceptions: [exceptionDetails],
|
|
3523
|
+
severityLevel: String(getSeverity(log.severityNumber)),
|
|
3524
|
+
version: 2,
|
|
3525
|
+
};
|
|
3526
|
+
baseData = exceptionData;
|
|
3527
|
+
}
|
|
3528
|
+
else {
|
|
3529
|
+
name = ApplicationInsightsMessageName;
|
|
3530
|
+
baseType = ApplicationInsightsMessageBaseType;
|
|
3531
|
+
const messageData = {
|
|
3532
|
+
message: String(log.body),
|
|
3533
|
+
severityLevel: String(getSeverity(log.severityNumber)),
|
|
3534
|
+
version: 2,
|
|
3535
|
+
};
|
|
3536
|
+
baseData = messageData;
|
|
3537
|
+
}
|
|
3538
|
+
}
|
|
3539
|
+
else {
|
|
3540
|
+
// If Legacy Application Insights Log
|
|
3541
|
+
baseType = String(log.attributes[ApplicationInsightsBaseType]);
|
|
3542
|
+
name = getLegacyApplicationInsightsName(log);
|
|
3543
|
+
baseData = getLegacyApplicationInsightsBaseData(log);
|
|
3544
|
+
if (!baseData) {
|
|
3545
|
+
// Failed to parse log
|
|
3546
|
+
return;
|
|
3547
|
+
}
|
|
3548
|
+
}
|
|
3549
|
+
return {
|
|
3550
|
+
name,
|
|
3551
|
+
sampleRate,
|
|
3552
|
+
time,
|
|
3553
|
+
instrumentationKey,
|
|
3554
|
+
tags,
|
|
3555
|
+
version: 1,
|
|
3556
|
+
data: {
|
|
3557
|
+
baseType,
|
|
3558
|
+
baseData: Object.assign(Object.assign({}, baseData), { properties,
|
|
3559
|
+
measurements }),
|
|
3560
|
+
},
|
|
3561
|
+
};
|
|
3562
|
+
}
|
|
3563
|
+
function createTagsFromLog(log) {
|
|
3564
|
+
var _a, _b;
|
|
3565
|
+
const tags = createTagsFromResource(log.resource);
|
|
3566
|
+
if ((_a = log.spanContext) === null || _a === void 0 ? void 0 : _a.traceId) {
|
|
3567
|
+
tags[KnownContextTagKeys.AiOperationId] = log.spanContext.traceId;
|
|
3568
|
+
}
|
|
3569
|
+
if ((_b = log.spanContext) === null || _b === void 0 ? void 0 : _b.spanId) {
|
|
3570
|
+
tags[KnownContextTagKeys.AiOperationParentId] = log.spanContext.spanId;
|
|
3571
|
+
}
|
|
3572
|
+
return tags;
|
|
3573
|
+
}
|
|
3574
|
+
function createPropertiesFromLog(log) {
|
|
3575
|
+
const measurements = {};
|
|
3576
|
+
const properties = {};
|
|
3577
|
+
if (log.attributes) {
|
|
3578
|
+
for (const key of Object.keys(log.attributes)) {
|
|
3579
|
+
// Avoid duplication ignoring fields already mapped.
|
|
3580
|
+
if (!(key.startsWith("_MS.") ||
|
|
3581
|
+
key == semanticConventions.SemanticAttributes.EXCEPTION_TYPE ||
|
|
3582
|
+
key == semanticConventions.SemanticAttributes.EXCEPTION_MESSAGE ||
|
|
3583
|
+
key == semanticConventions.SemanticAttributes.EXCEPTION_STACKTRACE)) {
|
|
3584
|
+
properties[key] = log.attributes[key];
|
|
3585
|
+
}
|
|
3586
|
+
}
|
|
3587
|
+
}
|
|
3588
|
+
return [properties, measurements];
|
|
3589
|
+
}
|
|
3590
|
+
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/data-model.md#field-severitynumber
|
|
3591
|
+
function getSeverity(severityNumber) {
|
|
3592
|
+
if (severityNumber) {
|
|
3593
|
+
if (severityNumber > 0 && severityNumber < 9) {
|
|
3594
|
+
return KnownSeverityLevel.Verbose;
|
|
3595
|
+
}
|
|
3596
|
+
else if (severityNumber >= 9 && severityNumber < 13) {
|
|
3597
|
+
return KnownSeverityLevel.Information;
|
|
3598
|
+
}
|
|
3599
|
+
else if (severityNumber >= 13 && severityNumber < 17) {
|
|
3600
|
+
return KnownSeverityLevel.Warning;
|
|
3601
|
+
}
|
|
3602
|
+
else if (severityNumber >= 17 && severityNumber < 21) {
|
|
3603
|
+
return KnownSeverityLevel.Error;
|
|
3604
|
+
}
|
|
3605
|
+
else if (severityNumber >= 21 && severityNumber < 25) {
|
|
3606
|
+
return KnownSeverityLevel.Critical;
|
|
3607
|
+
}
|
|
3608
|
+
}
|
|
3609
|
+
return;
|
|
3610
|
+
}
|
|
3611
|
+
function getLegacyApplicationInsightsName(log) {
|
|
3612
|
+
let name = "";
|
|
3613
|
+
switch (log.attributes[ApplicationInsightsBaseType]) {
|
|
3614
|
+
case ApplicationInsightsAvailabilityBaseType:
|
|
3615
|
+
name = ApplicationInsightsAvailabilityName;
|
|
3616
|
+
break;
|
|
3617
|
+
case ApplicationInsightsExceptionBaseType:
|
|
3618
|
+
name = ApplicationInsightsExceptionName;
|
|
3619
|
+
break;
|
|
3620
|
+
case ApplicationInsightsMessageBaseType:
|
|
3621
|
+
name = ApplicationInsightsMessageName;
|
|
3622
|
+
break;
|
|
3623
|
+
case ApplicationInsightsPageViewBaseType:
|
|
3624
|
+
name = ApplicationInsightsPageViewName;
|
|
3625
|
+
break;
|
|
3626
|
+
case ApplicationInsightsEventBaseType:
|
|
3627
|
+
name = ApplicationInsightsEventName;
|
|
3628
|
+
break;
|
|
3629
|
+
}
|
|
3630
|
+
return name;
|
|
3631
|
+
}
|
|
3632
|
+
function getLegacyApplicationInsightsBaseData(log) {
|
|
3633
|
+
let baseData = {
|
|
3634
|
+
version: 2,
|
|
3635
|
+
};
|
|
3636
|
+
if (log.body) {
|
|
3637
|
+
try {
|
|
3638
|
+
switch (log.attributes[ApplicationInsightsBaseType]) {
|
|
3639
|
+
case ApplicationInsightsAvailabilityBaseType:
|
|
3640
|
+
baseData = JSON.parse(log.body);
|
|
3641
|
+
break;
|
|
3642
|
+
case ApplicationInsightsExceptionBaseType:
|
|
3643
|
+
baseData = JSON.parse(log.body);
|
|
3644
|
+
break;
|
|
3645
|
+
case ApplicationInsightsMessageBaseType:
|
|
3646
|
+
baseData = JSON.parse(log.body);
|
|
3647
|
+
break;
|
|
3648
|
+
case ApplicationInsightsPageViewBaseType:
|
|
3649
|
+
baseData = JSON.parse(log.body);
|
|
3650
|
+
break;
|
|
3651
|
+
case ApplicationInsightsEventBaseType:
|
|
3652
|
+
baseData = JSON.parse(log.body);
|
|
3653
|
+
break;
|
|
3654
|
+
}
|
|
3655
|
+
}
|
|
3656
|
+
catch (err) {
|
|
3657
|
+
api.diag.error("AzureMonitorLogExporter failed to parse Application Insights Telemetry");
|
|
3658
|
+
}
|
|
3659
|
+
}
|
|
3660
|
+
return baseData;
|
|
3661
|
+
}
|
|
3662
|
+
|
|
3663
|
+
// Copyright (c) Microsoft Corporation.
|
|
3664
|
+
/**
|
|
3665
|
+
* Azure Monitor OpenTelemetry Log Exporter.
|
|
3666
|
+
*/
|
|
3667
|
+
class AzureMonitorLogExporter extends AzureMonitorBaseExporter {
|
|
3668
|
+
/**
|
|
3669
|
+
* Initializes a new instance of the AzureMonitorLogExporter class.
|
|
3670
|
+
* @param AzureExporterConfig - Exporter configuration.
|
|
3671
|
+
*/
|
|
3672
|
+
constructor(options = {}) {
|
|
3673
|
+
super(options);
|
|
3674
|
+
/**
|
|
3675
|
+
* Flag to determine if Exporter is shutdown.
|
|
3676
|
+
*/
|
|
3677
|
+
this._isShutdown = false;
|
|
3678
|
+
api.diag.debug("AzureMonitorLogExporter was successfully setup");
|
|
3679
|
+
}
|
|
3680
|
+
/**
|
|
3681
|
+
* Export OpenTelemetry logs.
|
|
3682
|
+
* @param logs - Logs to export.
|
|
3683
|
+
* @param resultCallback - Result callback.
|
|
3684
|
+
*/
|
|
3685
|
+
async export(logs, resultCallback) {
|
|
3686
|
+
if (this._isShutdown) {
|
|
3687
|
+
api.diag.info("Exporter shut down. Failed to export spans.");
|
|
3688
|
+
setTimeout(() => resultCallback({ code: core.ExportResultCode.FAILED }), 0);
|
|
3689
|
+
return;
|
|
3690
|
+
}
|
|
3691
|
+
api.diag.info(`Exporting ${logs.length} logs(s). Converting to envelopes...`);
|
|
3692
|
+
let envelopes = [];
|
|
3693
|
+
logs.forEach((log) => {
|
|
3694
|
+
let envelope = logToEnvelope(log, this._instrumentationKey);
|
|
3695
|
+
if (envelope) {
|
|
3696
|
+
envelopes.push(envelope);
|
|
3697
|
+
}
|
|
3698
|
+
});
|
|
3699
|
+
resultCallback(await this._exportEnvelopes(envelopes));
|
|
3700
|
+
}
|
|
3701
|
+
/**
|
|
3702
|
+
* Shutdown AzureMonitorLogExporter.
|
|
3703
|
+
*/
|
|
3704
|
+
async shutdown() {
|
|
3705
|
+
this._isShutdown = true;
|
|
3706
|
+
api.diag.info("AzureMonitorLogExporter shutting down");
|
|
3707
|
+
return this._shutdown();
|
|
3708
|
+
}
|
|
3709
|
+
}
|
|
3710
|
+
|
|
3383
3711
|
// Copyright (c) Microsoft Corporation.
|
|
3384
3712
|
/**
|
|
3385
3713
|
* Azure Monitor Statsbeat Exporter
|
|
@@ -3428,6 +3756,7 @@ class AzureMonitorStatsbeatExporter extends AzureMonitorBaseExporter {
|
|
|
3428
3756
|
|
|
3429
3757
|
exports.ApplicationInsightsSampler = ApplicationInsightsSampler;
|
|
3430
3758
|
exports.AzureMonitorBaseExporter = AzureMonitorBaseExporter;
|
|
3759
|
+
exports.AzureMonitorLogExporter = AzureMonitorLogExporter;
|
|
3431
3760
|
exports.AzureMonitorMetricExporter = AzureMonitorMetricExporter;
|
|
3432
3761
|
exports.AzureMonitorStatsbeatExporter = AzureMonitorStatsbeatExporter;
|
|
3433
3762
|
exports.AzureMonitorTraceExporter = AzureMonitorTraceExporter;
|
|
@@ -40,6 +40,11 @@ export const ENV_CONNECTION_STRING = "APPLICATIONINSIGHTS_CONNECTION_STRING";
|
|
|
40
40
|
* @internal
|
|
41
41
|
*/
|
|
42
42
|
export const ENV_INSTRUMENTATION_KEY = "APPINSIGHTS_INSTRUMENTATIONKEY";
|
|
43
|
+
/**
|
|
44
|
+
* Disable Statsbeat environment variable name.
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
47
|
+
export const ENV_DISABLE_STATSBEAT = "APPLICATION_INSIGHTS_NO_STATSBEAT";
|
|
43
48
|
/**
|
|
44
49
|
* QuickPulse metric counter names.
|
|
45
50
|
* @internal
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Constants.js","sourceRoot":"","sources":["../../../src/Declarations/Constants.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;GAEG;AACH,MAAM,CAAN,IAAY,iBAKX;AALD,WAAY,iBAAiB;IAC3B;;OAEG;IACH,8CAAyB,CAAA;AAC3B,CAAC,EALW,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,EAAE,iBAAiB,CAAC,cAAc;CACrE,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/**\n * Azure service API version.\n */\nexport enum ServiceApiVersion {\n /**\n * V2 Version\n */\n V2 = \"2020-09-15_Preview\",\n}\n\n/**\n * Default Breeze endpoint.\n * @internal\n */\nexport const DEFAULT_BREEZE_ENDPOINT = \"https://dc.services.visualstudio.com\";\n/**\n * Default Breeze API version.\n * @internal\n */\nexport const DEFAULT_BREEZE_API_VERSION = ServiceApiVersion.V2;\n/**\n * Default Live Metrics endpoint.\n * @internal\n */\nexport const DEFAULT_LIVEMETRICS_ENDPOINT = \"https://rt.services.visualstudio.com\";\n/**\n * Default Live Metrics host.\n * @internal\n */\nexport const DEFAULT_LIVEMETRICS_HOST = \"rt.services.visualstudio.com\";\n/**\n * Connection string environment variable name.\n * @internal\n */\nexport const ENV_CONNECTION_STRING = \"APPLICATIONINSIGHTS_CONNECTION_STRING\";\n/**\n * Instrumentation key environment variable name.\n * @internal\n */\nexport const ENV_INSTRUMENTATION_KEY = \"APPINSIGHTS_INSTRUMENTATIONKEY\";\n/**\n * Disable Statsbeat environment variable name.\n * @internal\n */\nexport const ENV_DISABLE_STATSBEAT = \"APPLICATION_INSIGHTS_NO_STATSBEAT\";\n\n/**\n * QuickPulse metric counter names.\n * @internal\n */\nexport enum QuickPulseCounter {\n // Memory\n COMMITTED_BYTES = \"\\\\Memory\\\\Committed Bytes\",\n\n // CPU\n PROCESSOR_TIME = \"\\\\Processor(_Total)\\\\% Processor Time\",\n\n // Request\n REQUEST_RATE = \"\\\\ApplicationInsights\\\\Requests/Sec\",\n REQUEST_FAILURE_RATE = \"\\\\ApplicationInsights\\\\Requests Failed/Sec\",\n REQUEST_DURATION = \"\\\\ApplicationInsights\\\\Request Duration\",\n\n // Dependency\n DEPENDENCY_RATE = \"\\\\ApplicationInsights\\\\Dependency Calls/Sec\",\n DEPENDENCY_FAILURE_RATE = \"\\\\ApplicationInsights\\\\Dependency Calls Failed/Sec\",\n DEPENDENCY_DURATION = \"\\\\ApplicationInsights\\\\Dependency Call Duration\",\n\n // Exception\n EXCEPTION_RATE = \"\\\\ApplicationInsights\\\\Exceptions/Sec\",\n}\n\n/**\n * Performance metric counter names.\n * @internal\n */\nexport enum PerformanceCounter {\n // Memory\n PRIVATE_BYTES = \"\\\\Process(??APP_WIN32_PROC??)\\\\Private Bytes\",\n AVAILABLE_BYTES = \"\\\\Memory\\\\Available Bytes\",\n\n // CPU\n PROCESSOR_TIME = \"\\\\Processor(_Total)\\\\% Processor Time\",\n PROCESS_TIME = \"\\\\Process(??APP_WIN32_PROC??)\\\\% Processor Time\",\n\n // Requests\n REQUEST_RATE = \"\\\\ASP.NET Applications(??APP_W3SVC_PROC??)\\\\Requests/Sec\",\n REQUEST_DURATION = \"\\\\ASP.NET Applications(??APP_W3SVC_PROC??)\\\\Request Execution Time\",\n}\n\n/**\n * Map a PerformanceCounter/QuickPulseCounter to a QuickPulseCounter. If no mapping exists, mapping is *undefined*\n * @internal\n */\nexport const PerformanceToQuickPulseCounter: { [key: string]: QuickPulseCounter } = {\n [PerformanceCounter.PROCESSOR_TIME]: QuickPulseCounter.PROCESSOR_TIME,\n [PerformanceCounter.REQUEST_RATE]: QuickPulseCounter.REQUEST_RATE,\n [PerformanceCounter.REQUEST_DURATION]: QuickPulseCounter.REQUEST_DURATION,\n\n // Remap quick pulse only counters\n [QuickPulseCounter.COMMITTED_BYTES]: QuickPulseCounter.COMMITTED_BYTES,\n [QuickPulseCounter.REQUEST_FAILURE_RATE]: QuickPulseCounter.REQUEST_FAILURE_RATE,\n [QuickPulseCounter.DEPENDENCY_RATE]: QuickPulseCounter.DEPENDENCY_RATE,\n [QuickPulseCounter.DEPENDENCY_FAILURE_RATE]: QuickPulseCounter.DEPENDENCY_FAILURE_RATE,\n [QuickPulseCounter.DEPENDENCY_DURATION]: QuickPulseCounter.DEPENDENCY_DURATION,\n [QuickPulseCounter.EXCEPTION_RATE]: QuickPulseCounter.EXCEPTION_RATE,\n};\n\n/**\n * QuickPulse document types.\n * @internal\n */\nexport type QuickPulseDocumentType =\n | \"Event\"\n | \"Exception\"\n | \"Trace\"\n | \"Metric\"\n | \"Request\"\n | \"RemoteDependency\"\n | \"Availability\";\n/**\n * QuickPulse telemetry types.\n * @internal\n */\nexport type QuickPulseType =\n | \"EventTelemetryDocument\"\n | \"ExceptionTelemetryDocument\"\n | \"TraceTelemetryDocument\"\n | \"MetricTelemetryDocument\"\n | \"RequestTelemetryDocument\"\n | \"DependencyTelemetryDocument\"\n | \"AvailabilityTelemetryDocument\";\n"]}
|
|
@@ -5,7 +5,7 @@ import { ExportResultCode } from "@opentelemetry/core";
|
|
|
5
5
|
import { ConnectionStringParser } from "../utils/connectionStringParser";
|
|
6
6
|
import { HttpSender, FileSystemPersist } from "../platform";
|
|
7
7
|
import { isRetriable } from "../utils/breezeUtils";
|
|
8
|
-
import { DEFAULT_BREEZE_ENDPOINT, ENV_CONNECTION_STRING } from "../Declarations/Constants";
|
|
8
|
+
import { DEFAULT_BREEZE_ENDPOINT, ENV_CONNECTION_STRING, ENV_DISABLE_STATSBEAT, } from "../Declarations/Constants";
|
|
9
9
|
import { NetworkStatsbeatMetrics } from "./statsbeat/networkStatsbeatMetrics";
|
|
10
10
|
import { MAX_STATSBEAT_FAILURES } from "./statsbeat/types";
|
|
11
11
|
import { getInstance } from "./statsbeat/longIntervalStatsbeatMetrics";
|
|
@@ -47,7 +47,7 @@ export class AzureMonitorBaseExporter {
|
|
|
47
47
|
}
|
|
48
48
|
this._sender = new HttpSender(this._endpointUrl, this._options);
|
|
49
49
|
this._persister = new FileSystemPersist(this._instrumentationKey, this._options);
|
|
50
|
-
if (!this._isStatsbeatExporter) {
|
|
50
|
+
if (!this._isStatsbeatExporter && !process.env[ENV_DISABLE_STATSBEAT]) {
|
|
51
51
|
// Initialize statsbeatMetrics
|
|
52
52
|
this._networkStatsbeatMetrics = new NetworkStatsbeatMetrics({
|
|
53
53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,IAAI,EAAE,gBAAgB,CAAC,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;SAC5D;IACH,CAAC;IAED,6DAA6D;IACrD,0BAA0B;;QAChC,IAAI,CAAC,sBAAsB,EAAE,CAAC;QAC9B,IAAI,IAAI,CAAC,sBAAsB,GAAG,sBAAsB,EAAE;YACxD,IAAI,CAAC,oBAAoB,GAAG,KAAK,CAAC;YAClC,MAAA,IAAI,CAAC,wBAAwB,0CAAE,QAAQ,EAAE,CAAC;YAC1C,MAAA,IAAI,CAAC,6BAA6B,0CAAE,QAAQ,EAAE,CAAC;YAC/C,IAAI,CAAC,wBAAwB,GAAG,SAAS,CAAC;YAC1C,IAAI,CAAC,sBAAsB,GAAG,CAAC,CAAC;SACjC;IACH,CAAC;IAEO,KAAK,CAAC,uBAAuB;QACnC,IAAI;YACF,MAAM,SAAS,GAAG,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAsB,CAAC;YACvE,IAAI,SAAS,EAAE;gBACb,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;aACpC;SACF;QAAC,OAAO,GAAQ,EAAE;YACjB,IAAI,CAAC,IAAI,CAAC,gCAAgC,EAAE,GAAG,CAAC,CAAC;SAClD;IACH,CAAC;IAEO,eAAe,CAAC,KAAgB;QACtC,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,KAAK,oBAAoB,EAAE;YAC9D,OAAO,IAAI,CAAC;SACb;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { diag } from \"@opentelemetry/api\";\nimport { ExportResult, ExportResultCode } from \"@opentelemetry/core\";\nimport { RestError } from \"@azure/core-rest-pipeline\";\nimport { ConnectionStringParser } from \"../utils/connectionStringParser\";\nimport { HttpSender, FileSystemPersist } from \"../platform\";\nimport { AzureMonitorExporterOptions } from \"../config\";\nimport { PersistentStorage, Sender } from \"../types\";\nimport { isRetriable, BreezeResponse } from \"../utils/breezeUtils\";\nimport { DEFAULT_BREEZE_ENDPOINT, ENV_CONNECTION_STRING } from \"../Declarations/Constants\";\nimport { TelemetryItem as Envelope } from \"../generated\";\nimport { NetworkStatsbeatMetrics } from \"./statsbeat/networkStatsbeatMetrics\";\nimport { MAX_STATSBEAT_FAILURES } from \"./statsbeat/types\";\nimport { getInstance } from \"./statsbeat/longIntervalStatsbeatMetrics\";\n\nconst DEFAULT_BATCH_SEND_RETRY_INTERVAL_MS = 60_000;\n/**\n * Azure Monitor OpenTelemetry Trace Exporter.\n */\nexport abstract class AzureMonitorBaseExporter {\n /**\n * Instrumentation key to be used for exported envelopes\n */\n protected _instrumentationKey: string = \"\";\n private _endpointUrl: string = \"\";\n private readonly _persister: PersistentStorage;\n private readonly _sender: Sender;\n private _numConsecutiveRedirects: number;\n private _retryTimer: NodeJS.Timer | null;\n private _networkStatsbeatMetrics: NetworkStatsbeatMetrics | undefined;\n private _longIntervalStatsbeatMetrics;\n private _isStatsbeatExporter: boolean;\n private _statsbeatFailureCount: number = 0;\n private _batchSendRetryIntervalMs: number = DEFAULT_BATCH_SEND_RETRY_INTERVAL_MS;\n /**\n * Exporter internal configuration\n */\n private readonly _options: AzureMonitorExporterOptions;\n\n /**\n * Initializes a new instance of the AzureMonitorBaseExporter class.\n * @param AzureMonitorExporterOptions - Exporter configuration.\n */\n constructor(options: AzureMonitorExporterOptions = {}, isStatsbeatExporter?: boolean) {\n this._options = options;\n this._numConsecutiveRedirects = 0;\n this._instrumentationKey = \"\";\n this._endpointUrl = DEFAULT_BREEZE_ENDPOINT;\n const connectionString = this._options.connectionString || process.env[ENV_CONNECTION_STRING];\n this._isStatsbeatExporter = isStatsbeatExporter ? isStatsbeatExporter : false;\n\n if (connectionString) {\n const parsedConnectionString = ConnectionStringParser.parse(connectionString);\n this._instrumentationKey =\n parsedConnectionString.instrumentationkey || this._instrumentationKey;\n this._endpointUrl = parsedConnectionString.ingestionendpoint?.trim() || this._endpointUrl;\n }\n\n // Instrumentation key is required\n if (!this._instrumentationKey) {\n const message =\n \"No instrumentation key or connection string was provided to the Azure Monitor Exporter\";\n diag.error(message);\n throw new Error(message);\n }\n this._sender = new HttpSender(this._endpointUrl, this._options);\n this._persister = new FileSystemPersist(this._instrumentationKey, this._options);\n\n if (!this._isStatsbeatExporter) {\n // Initialize statsbeatMetrics\n this._networkStatsbeatMetrics = new NetworkStatsbeatMetrics({\n instrumentationKey: this._instrumentationKey,\n endpointUrl: this._endpointUrl,\n });\n this._longIntervalStatsbeatMetrics = getInstance({\n instrumentationKey: this._instrumentationKey,\n endpointUrl: this._endpointUrl,\n });\n }\n this._retryTimer = null;\n diag.debug(\"AzureMonitorExporter was successfully setup\");\n }\n\n /**\n * Persist envelopes to disk\n */\n private async _persist(envelopes: unknown[]): Promise<ExportResult> {\n try {\n const success = await this._persister.push(envelopes);\n return success\n ? { code: ExportResultCode.SUCCESS }\n : {\n code: ExportResultCode.FAILED,\n error: new Error(\"Failed to persist envelope in disk.\"),\n };\n } catch (ex: any) {\n return { code: ExportResultCode.FAILED, error: ex };\n }\n }\n\n /**\n * Shutdown exporter\n */\n protected async _shutdown(): Promise<void> {\n return this._sender.shutdown();\n }\n\n /**\n * Export envelopes\n */\n protected async _exportEnvelopes(envelopes: Envelope[]): Promise<ExportResult> {\n diag.info(`Exporting ${envelopes.length} envelope(s)`);\n\n if (envelopes.length < 1) {\n return { code: ExportResultCode.SUCCESS };\n }\n\n try {\n const startTime = new Date().getTime();\n const { result, statusCode } = await this._sender.send(envelopes);\n const endTime = new Date().getTime();\n const duration = endTime - startTime;\n this._numConsecutiveRedirects = 0;\n\n if (statusCode === 200) {\n // Success -- @todo: start retry timer\n if (!this._retryTimer) {\n this._retryTimer = setTimeout(() => {\n this._retryTimer = null;\n this._sendFirstPersistedFile();\n }, this._batchSendRetryIntervalMs);\n this._retryTimer.unref();\n }\n // If we are not exportings statsbeat and statsbeat is not disabled -- count success\n this._networkStatsbeatMetrics?.countSuccess(duration);\n return { code: ExportResultCode.SUCCESS };\n } else if (statusCode && isRetriable(statusCode)) {\n // Failed -- persist failed data\n if (statusCode === 429 || statusCode === 439) {\n this._networkStatsbeatMetrics?.countThrottle(statusCode);\n }\n if (result) {\n diag.info(result);\n const breezeResponse = JSON.parse(result) as BreezeResponse;\n const filteredEnvelopes: Envelope[] = [];\n if (breezeResponse.errors) {\n breezeResponse.errors.forEach((error) => {\n if (error.statusCode && isRetriable(error.statusCode)) {\n filteredEnvelopes.push(envelopes[error.index]);\n }\n });\n }\n if (filteredEnvelopes.length > 0) {\n this._networkStatsbeatMetrics?.countRetry(statusCode);\n // calls resultCallback(ExportResult) based on result of persister.push\n return await this._persist(filteredEnvelopes);\n }\n // Failed -- not retriable\n this._networkStatsbeatMetrics?.countFailure(duration, statusCode);\n return {\n code: ExportResultCode.FAILED,\n };\n } else {\n // calls resultCallback(ExportResult) based on result of persister.push\n this._networkStatsbeatMetrics?.countRetry(statusCode);\n return await this._persist(envelopes);\n }\n } else {\n // Failed -- not retriable\n if (this._networkStatsbeatMetrics) {\n if (statusCode) {\n this._networkStatsbeatMetrics.countFailure(duration, statusCode);\n }\n } else {\n this._incrementStatsbeatFailure();\n }\n return {\n code: ExportResultCode.FAILED,\n };\n }\n } catch (error: any) {\n const restError = error as RestError;\n if (\n restError.statusCode &&\n (restError.statusCode === 307 || // Temporary redirect\n restError.statusCode === 308)\n ) {\n // Permanent redirect\n this._numConsecutiveRedirects++;\n // To prevent circular redirects\n if (this._numConsecutiveRedirects < 10) {\n if (restError.response && restError.response.headers) {\n const location = restError.response.headers.get(\"location\");\n if (location) {\n // Update sender URL\n this._sender.handlePermanentRedirect(location);\n // Send to redirect endpoint as HTTPs library doesn't handle redirect automatically\n return this._exportEnvelopes(envelopes);\n }\n }\n } else {\n let redirectError = new Error(\"Circular redirect\");\n this._networkStatsbeatMetrics?.countException(redirectError);\n return { code: ExportResultCode.FAILED, error: redirectError };\n }\n } else if (restError.statusCode && isRetriable(restError.statusCode)) {\n this._networkStatsbeatMetrics?.countRetry(restError.statusCode);\n return await this._persist(envelopes);\n }\n if (this._isNetworkError(restError)) {\n if (restError.statusCode) {\n this._networkStatsbeatMetrics?.countRetry(restError.statusCode);\n }\n diag.error(\n \"Retrying due to transient client side error. Error message:\",\n restError.message\n );\n return await this._persist(envelopes);\n }\n this._networkStatsbeatMetrics?.countException(restError);\n diag.error(\n \"Envelopes could not be exported and are not retriable. Error message:\",\n restError.message\n );\n return { code: ExportResultCode.FAILED, error: restError };\n }\n }\n\n // Disable collection of statsbeat metrics after max failures\n private _incrementStatsbeatFailure() {\n this._statsbeatFailureCount++;\n if (this._statsbeatFailureCount > MAX_STATSBEAT_FAILURES) {\n this._isStatsbeatExporter = false;\n this._networkStatsbeatMetrics?.shutdown();\n this._longIntervalStatsbeatMetrics?.shutdown();\n this._networkStatsbeatMetrics = undefined;\n this._statsbeatFailureCount = 0;\n }\n }\n\n private async _sendFirstPersistedFile(): Promise<void> {\n try {\n const envelopes = (await this._persister.shift()) as Envelope[] | null;\n if (envelopes) {\n await this._sender.send(envelopes);\n }\n } catch (err: any) {\n diag.warn(`Failed to fetch persisted file`, err);\n }\n }\n\n private _isNetworkError(error: RestError): boolean {\n if (error && error.code && error.code === \"REQUEST_SEND_ERROR\") {\n return true;\n }\n return false;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/export/base.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAgB,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAErE,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAG5D,OAAO,EAAE,WAAW,EAAkB,MAAM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0CAAE,QAAQ,EAAE,CAAC;YAC/C,IAAI,CAAC,wBAAwB,GAAG,SAAS,CAAC;YAC1C,IAAI,CAAC,sBAAsB,GAAG,CAAC,CAAC;SACjC;IACH,CAAC;IAEO,KAAK,CAAC,uBAAuB;QACnC,IAAI;YACF,MAAM,SAAS,GAAG,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAsB,CAAC;YACvE,IAAI,SAAS,EAAE;gBACb,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;aACpC;SACF;QAAC,OAAO,GAAQ,EAAE;YACjB,IAAI,CAAC,IAAI,CAAC,gCAAgC,EAAE,GAAG,CAAC,CAAC;SAClD;IACH,CAAC;IAEO,eAAe,CAAC,KAAgB;QACtC,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,KAAK,oBAAoB,EAAE;YAC9D,OAAO,IAAI,CAAC;SACb;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { diag } from \"@opentelemetry/api\";\nimport { ExportResult, ExportResultCode } from \"@opentelemetry/core\";\nimport { RestError } from \"@azure/core-rest-pipeline\";\nimport { ConnectionStringParser } from \"../utils/connectionStringParser\";\nimport { HttpSender, FileSystemPersist } from \"../platform\";\nimport { AzureMonitorExporterOptions } from \"../config\";\nimport { PersistentStorage, Sender } from \"../types\";\nimport { isRetriable, BreezeResponse } from \"../utils/breezeUtils\";\nimport {\n DEFAULT_BREEZE_ENDPOINT,\n ENV_CONNECTION_STRING,\n ENV_DISABLE_STATSBEAT,\n} from \"../Declarations/Constants\";\nimport { TelemetryItem as Envelope } from \"../generated\";\nimport { NetworkStatsbeatMetrics } from \"./statsbeat/networkStatsbeatMetrics\";\nimport { MAX_STATSBEAT_FAILURES } from \"./statsbeat/types\";\nimport { getInstance } from \"./statsbeat/longIntervalStatsbeatMetrics\";\n\nconst DEFAULT_BATCH_SEND_RETRY_INTERVAL_MS = 60_000;\n/**\n * Azure Monitor OpenTelemetry Trace Exporter.\n */\nexport abstract class AzureMonitorBaseExporter {\n /**\n * Instrumentation key to be used for exported envelopes\n */\n protected _instrumentationKey: string = \"\";\n private _endpointUrl: string = \"\";\n private readonly _persister: PersistentStorage;\n private readonly _sender: Sender;\n private _numConsecutiveRedirects: number;\n private _retryTimer: NodeJS.Timer | null;\n private _networkStatsbeatMetrics: NetworkStatsbeatMetrics | undefined;\n private _longIntervalStatsbeatMetrics;\n private _isStatsbeatExporter: boolean;\n private _statsbeatFailureCount: number = 0;\n private _batchSendRetryIntervalMs: number = DEFAULT_BATCH_SEND_RETRY_INTERVAL_MS;\n /**\n * Exporter internal configuration\n */\n private readonly _options: AzureMonitorExporterOptions;\n\n /**\n * Initializes a new instance of the AzureMonitorBaseExporter class.\n * @param AzureMonitorExporterOptions - Exporter configuration.\n */\n constructor(options: AzureMonitorExporterOptions = {}, isStatsbeatExporter?: boolean) {\n this._options = options;\n this._numConsecutiveRedirects = 0;\n this._instrumentationKey = \"\";\n this._endpointUrl = DEFAULT_BREEZE_ENDPOINT;\n const connectionString = this._options.connectionString || process.env[ENV_CONNECTION_STRING];\n this._isStatsbeatExporter = isStatsbeatExporter ? isStatsbeatExporter : false;\n\n if (connectionString) {\n const parsedConnectionString = ConnectionStringParser.parse(connectionString);\n this._instrumentationKey =\n parsedConnectionString.instrumentationkey || this._instrumentationKey;\n this._endpointUrl = parsedConnectionString.ingestionendpoint?.trim() || this._endpointUrl;\n }\n\n // Instrumentation key is required\n if (!this._instrumentationKey) {\n const message =\n \"No instrumentation key or connection string was provided to the Azure Monitor Exporter\";\n diag.error(message);\n throw new Error(message);\n }\n this._sender = new HttpSender(this._endpointUrl, this._options);\n this._persister = new FileSystemPersist(this._instrumentationKey, this._options);\n\n if (!this._isStatsbeatExporter && !process.env[ENV_DISABLE_STATSBEAT]) {\n // Initialize statsbeatMetrics\n this._networkStatsbeatMetrics = new NetworkStatsbeatMetrics({\n instrumentationKey: this._instrumentationKey,\n endpointUrl: this._endpointUrl,\n });\n this._longIntervalStatsbeatMetrics = getInstance({\n instrumentationKey: this._instrumentationKey,\n endpointUrl: this._endpointUrl,\n });\n }\n this._retryTimer = null;\n diag.debug(\"AzureMonitorExporter was successfully setup\");\n }\n\n /**\n * Persist envelopes to disk\n */\n private async _persist(envelopes: unknown[]): Promise<ExportResult> {\n try {\n const success = await this._persister.push(envelopes);\n return success\n ? { code: ExportResultCode.SUCCESS }\n : {\n code: ExportResultCode.FAILED,\n error: new Error(\"Failed to persist envelope in disk.\"),\n };\n } catch (ex: any) {\n return { code: ExportResultCode.FAILED, error: ex };\n }\n }\n\n /**\n * Shutdown exporter\n */\n protected async _shutdown(): Promise<void> {\n return this._sender.shutdown();\n }\n\n /**\n * Export envelopes\n */\n protected async _exportEnvelopes(envelopes: Envelope[]): Promise<ExportResult> {\n diag.info(`Exporting ${envelopes.length} envelope(s)`);\n\n if (envelopes.length < 1) {\n return { code: ExportResultCode.SUCCESS };\n }\n\n try {\n const startTime = new Date().getTime();\n const { result, statusCode } = await this._sender.send(envelopes);\n const endTime = new Date().getTime();\n const duration = endTime - startTime;\n this._numConsecutiveRedirects = 0;\n\n if (statusCode === 200) {\n // Success -- @todo: start retry timer\n if (!this._retryTimer) {\n this._retryTimer = setTimeout(() => {\n this._retryTimer = null;\n this._sendFirstPersistedFile();\n }, this._batchSendRetryIntervalMs);\n this._retryTimer.unref();\n }\n // If we are not exportings statsbeat and statsbeat is not disabled -- count success\n this._networkStatsbeatMetrics?.countSuccess(duration);\n return { code: ExportResultCode.SUCCESS };\n } else if (statusCode && isRetriable(statusCode)) {\n // Failed -- persist failed data\n if (statusCode === 429 || statusCode === 439) {\n this._networkStatsbeatMetrics?.countThrottle(statusCode);\n }\n if (result) {\n diag.info(result);\n const breezeResponse = JSON.parse(result) as BreezeResponse;\n const filteredEnvelopes: Envelope[] = [];\n if (breezeResponse.errors) {\n breezeResponse.errors.forEach((error) => {\n if (error.statusCode && isRetriable(error.statusCode)) {\n filteredEnvelopes.push(envelopes[error.index]);\n }\n });\n }\n if (filteredEnvelopes.length > 0) {\n this._networkStatsbeatMetrics?.countRetry(statusCode);\n // calls resultCallback(ExportResult) based on result of persister.push\n return await this._persist(filteredEnvelopes);\n }\n // Failed -- not retriable\n this._networkStatsbeatMetrics?.countFailure(duration, statusCode);\n return {\n code: ExportResultCode.FAILED,\n };\n } else {\n // calls resultCallback(ExportResult) based on result of persister.push\n this._networkStatsbeatMetrics?.countRetry(statusCode);\n return await this._persist(envelopes);\n }\n } else {\n // Failed -- not retriable\n if (this._networkStatsbeatMetrics) {\n if (statusCode) {\n this._networkStatsbeatMetrics.countFailure(duration, statusCode);\n }\n } else {\n this._incrementStatsbeatFailure();\n }\n return {\n code: ExportResultCode.FAILED,\n };\n }\n } catch (error: any) {\n const restError = error as RestError;\n if (\n restError.statusCode &&\n (restError.statusCode === 307 || // Temporary redirect\n restError.statusCode === 308)\n ) {\n // Permanent redirect\n this._numConsecutiveRedirects++;\n // To prevent circular redirects\n if (this._numConsecutiveRedirects < 10) {\n if (restError.response && restError.response.headers) {\n const location = restError.response.headers.get(\"location\");\n if (location) {\n // Update sender URL\n this._sender.handlePermanentRedirect(location);\n // Send to redirect endpoint as HTTPs library doesn't handle redirect automatically\n return this._exportEnvelopes(envelopes);\n }\n }\n } else {\n let redirectError = new Error(\"Circular redirect\");\n this._networkStatsbeatMetrics?.countException(redirectError);\n return { code: ExportResultCode.FAILED, error: redirectError };\n }\n } else if (restError.statusCode && isRetriable(restError.statusCode)) {\n this._networkStatsbeatMetrics?.countRetry(restError.statusCode);\n return await this._persist(envelopes);\n }\n if (this._isNetworkError(restError)) {\n if (restError.statusCode) {\n this._networkStatsbeatMetrics?.countRetry(restError.statusCode);\n }\n diag.error(\n \"Retrying due to transient client side error. Error message:\",\n restError.message\n );\n return await this._persist(envelopes);\n }\n this._networkStatsbeatMetrics?.countException(restError);\n diag.error(\n \"Envelopes could not be exported and are not retriable. Error message:\",\n restError.message\n );\n return { code: ExportResultCode.FAILED, error: restError };\n }\n }\n\n // Disable collection of statsbeat metrics after max failures\n private _incrementStatsbeatFailure() {\n this._statsbeatFailureCount++;\n if (this._statsbeatFailureCount > MAX_STATSBEAT_FAILURES) {\n this._isStatsbeatExporter = false;\n this._networkStatsbeatMetrics?.shutdown();\n this._longIntervalStatsbeatMetrics?.shutdown();\n this._networkStatsbeatMetrics = undefined;\n this._statsbeatFailureCount = 0;\n }\n }\n\n private async _sendFirstPersistedFile(): Promise<void> {\n try {\n const envelopes = (await this._persister.shift()) as Envelope[] | null;\n if (envelopes) {\n await this._sender.send(envelopes);\n }\n } catch (err: any) {\n diag.warn(`Failed to fetch persisted file`, err);\n }\n }\n\n private _isNetworkError(error: RestError): boolean {\n if (error && error.code && error.code === \"REQUEST_SEND_ERROR\") {\n return true;\n }\n return false;\n }\n}\n"]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT license.
|
|
3
|
+
import { diag } from "@opentelemetry/api";
|
|
4
|
+
import { ExportResultCode } from "@opentelemetry/core";
|
|
5
|
+
import { AzureMonitorBaseExporter } from "./base";
|
|
6
|
+
import { logToEnvelope } from "../utils/logUtils";
|
|
7
|
+
/**
|
|
8
|
+
* Azure Monitor OpenTelemetry Log Exporter.
|
|
9
|
+
*/
|
|
10
|
+
export class AzureMonitorLogExporter extends AzureMonitorBaseExporter {
|
|
11
|
+
/**
|
|
12
|
+
* Initializes a new instance of the AzureMonitorLogExporter class.
|
|
13
|
+
* @param AzureExporterConfig - Exporter configuration.
|
|
14
|
+
*/
|
|
15
|
+
constructor(options = {}) {
|
|
16
|
+
super(options);
|
|
17
|
+
/**
|
|
18
|
+
* Flag to determine if Exporter is shutdown.
|
|
19
|
+
*/
|
|
20
|
+
this._isShutdown = false;
|
|
21
|
+
diag.debug("AzureMonitorLogExporter was successfully setup");
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Export OpenTelemetry logs.
|
|
25
|
+
* @param logs - Logs to export.
|
|
26
|
+
* @param resultCallback - Result callback.
|
|
27
|
+
*/
|
|
28
|
+
async export(logs, resultCallback) {
|
|
29
|
+
if (this._isShutdown) {
|
|
30
|
+
diag.info("Exporter shut down. Failed to export spans.");
|
|
31
|
+
setTimeout(() => resultCallback({ code: ExportResultCode.FAILED }), 0);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
diag.info(`Exporting ${logs.length} logs(s). Converting to envelopes...`);
|
|
35
|
+
let envelopes = [];
|
|
36
|
+
logs.forEach((log) => {
|
|
37
|
+
let envelope = logToEnvelope(log, this._instrumentationKey);
|
|
38
|
+
if (envelope) {
|
|
39
|
+
envelopes.push(envelope);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
resultCallback(await this._exportEnvelopes(envelopes));
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Shutdown AzureMonitorLogExporter.
|
|
46
|
+
*/
|
|
47
|
+
async shutdown() {
|
|
48
|
+
this._isShutdown = true;
|
|
49
|
+
diag.info("AzureMonitorLogExporter shutting down");
|
|
50
|
+
return this._shutdown();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=log.js.map
|