question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 3 years ago
  • Comments:24 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
nulltokencommented, Feb 12, 2021

@hectorhdzg Thanks for getting back to me.

Is there a specific telemetry event you are expecting?

Hmmm. The repro code doesn’t filter much…

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;
};

I’m going to create a dedicated repository to hold the repro case in order to make it easier to troubleshoot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dependency tracking in Application Insights - Azure Monitor
Tracing from requests to dependencies ... Select the Performance tab on the left and select the Dependencies tab at the top. Select a...
Read more >
Disable tracking dependencies in Azure Function Application ...
My current bill for Application Insights is now $32. And I never look at or use the dependencies, requests, etc… I'm only using...
Read more >
Custom Events and Metrics :: Application Insights (5 of 6)
ObjectiveThis course demonstrates the processes for configuring a web application to use Application Insights for performance tracking, ...
Read more >
Collecting Cosmos DB dependency telemetry with Application ...
In this article, we will use Application Insights to collect the requests made to Azure Cosmos DB so... Tagged with azure, cosmosdb, dotnet, ......
Read more >
First look at Application Insights - Andrei Dzimchuk
If you deploy to Azure Web Apps you can enable dependency tracking by adding an extension to your app. On the new portal...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found