Allow tracking of https requests to storage account as ApplicationInsights dependencies
See original GitHub issue- Package Name: @azure/storage-blob
- Package Version: 12.4.0
- Operating system: Windows
- nodejs
- version: 14.15
- typescript
- version: 4.13
Describe the bug
It seems that leveraging BlobClient
doesn’t (by default) allow interception of underlying https calls through the https://github.com/microsoft/applicationInsights-node.js library.
To Reproduce Steps to reproduce the behavior: Following piece of code demonstrates the issue. It makes 3 external https calls and logs to the console the intercepted dependencies
- One to github (Leveraging node-fetch (same library azure-sdk-for js relies on)) => This call is properly intercepted
- A download of a blob from a storage account => This call isn’t intercepted
- Another one to github (Also through node-fetch) => This call is properly intercepted
import { setup, defaultClient } from 'applicationinsights';
import { Contracts } from "applicationinsights";
import { Data, ExceptionData, RemoteDependencyData } from "applicationinsights/out/Declarations/Contracts";
import fetch from 'node-fetch';
import { BlobClient } from "@azure/storage-blob";
const telemetryConsoleLogger = (envelope: Contracts.Envelope, _contextObjects?: {
[name: string]: unknown;
}): boolean => {
switch (envelope.data.baseType) {
case "RemoteDependencyData": {
console.log("## DEPENDENCY ######################################################");
const data = envelope.data as Data<RemoteDependencyData>;
console.log(data.baseData.data);
console.log("########################################################");
break;
}
case "ExceptionData": {
console.log("## EXCEPTION ######################################################");
const data = envelope.data as Data<ExceptionData>;
data.baseData.exceptions.forEach(e => { console.log(e.message); });
console.log("########################################################");
break;
}
default:
break;
}
return true;
};
void (async function () {
setup("_your_ikey_").start();
defaultClient.addTelemetryProcessor(telemetryConsoleLogger);
const depUrl1 = 'https://github.com/';
const response1 = await fetch(depUrl1);
const body1 = await response1.text();
console.log(depUrl1, body1.length);
const cn = "BlobEndpoint=https://...."; // Connection string
const containerName = "yourContainerName";
const blobPath = "yourBlobPath";
const bc = new BlobClient(cn, containerName, blobPath);
const buf = await bc.downloadToBuffer();
console.log("Size of downloaded blob", buf.byteLength);
const depUrl2 = 'https://github.com/Azure/azure-sdk-for-js';
const response2 = await fetch(depUrl2);
const body2 = await response2.text();
console.log(depUrl2, body2.length);
})();
When run, this code generates the following output in the console.
## DEPENDENCY ######################################################
https://github.com/
########################################################
https://github.com/ 191001
Size of downloaded blob 15111288
## DEPENDENCY ######################################################
https://github.com/Azure/azure-sdk-for-js
########################################################
https://github.com/Azure/azure-sdk-for-js 212053
As one can see, direct calls through node-fetch
are intercepted, and although the blob is properly downloaded (and its bytes length displayed in the console), it’s not intercepted by ApplicationInsights library.
Expected behavior Monitoring of dependencies is of great importance in production, in order to ensure the overall ecosystem is working as expected. We are currently relying on AWS S3 for storage and are transitioning to Azure storage accounts. Interception of calls made with the aws sdk work perfectly.
Not being to leverage Microsoft ApplicationInsights node library when working with Microsoft Azure sdk library is a bit of a showstopper from an ops standpoint for us.
It’s possible that customizing the instantiation of the BlobClient
may help, however going through the options, I’ve been unable to see one that would help me.
Any help helping us see those dependencies being tracked would be greatly appreciated.
Issue Analytics
- State:
- Created 3 years ago
- Comments:24 (12 by maintainers)
Top GitHub Comments
https://github.com/microsoft/ApplicationInsights-node.js/pull/723
@hectorhdzg Thanks for getting back to me.
Hmmm. The repro code doesn’t filter much…
I’m going to create a dedicated repository to hold the repro case in order to make it easier to troubleshoot.