Azure / azure-sdk-for-js

This repository is for active development of the Azure SDK for JavaScript (NodeJS & Browser). For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/javascript/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-js.
MIT License
2.03k stars 1.19k forks source link

Incorrect start time in App Insights dependency trace #26610

Open michaellperry opened 1 year ago

michaellperry commented 1 year ago

Describe the bug The start time for the SecretClient.getSecret and ManagedIdentityCredential.getToken methods are not properly captured in the call to App Insights trackDependency. As a result, the time bars are shifted in App Insights so as to appear to begin when they should actually end.

To Reproduce Steps to reproduce the behavior:

  1. Deploy a Node.JS application using managed identity to access Azure Key Vault following these instructions.
  2. Monitor the app using App Insights following these instructions.
  3. Use the following code to access a secret in Azure Key Vault:
const keyVaultUrl = process.env.KEY_VAULT_URL;
const secretName = process.env.SECRET_NAME;

const client = new SecretClient(keyVaultUrl, new ManagedIdentityCredential());
const secret = await client.getSecret(secretName);

Expected behavior The bars in the App Insights timeline will begin at the point that the call initiated, and end when the call ended. All child dependencies within the tree will fall between the begin and end point of the parent bar. And the bar will end before the end of the request.

Screenshots Please see the example below. Notice the two bars that extend to the left beyond the end of the request. AppInsightsTimeline

Additional context I ran into this same issue in my own code. By default, the App Insights client assumes that the trace starts at the time you call trackDependency. Of course, this could not be the case, since you need to pass in the duration and the result. However, you can also pass in the start time. This optional parameter is apparently missing.

jeremymeng commented 1 year ago

@mpodwysocki is this related to our tracing or not?