ApplicationInsights-JS icon indicating copy to clipboard operation
ApplicationInsights-JS copied to clipboard

trackDependencyData() TS signature is not clear

Open JRGranell opened this issue 6 years ago • 5 comments

Upgrading the v2 I am trying to update our manual dependency tracking, however it is not clear what the call signature should be.

  • the readme at https://github.com/microsoft/ApplicationInsights-JS Screenshot 2019-06-11 at 08 57 23
  • docs at https://github.com/microsoft/ApplicationInsights-JS/blob/329d77b15250ae8dfa25b86eae0146a65422a62b/vNext/AISKU/API.md is the same Screenshot 2019-06-11 at 08 58 13

However the typescript typings in code is

Screenshot 2019-06-11 at 08 58 28

Which I assume is correct for the server side calls. At the moment I'm using any to cast the call to appInsights.trackDependencyData().

JRGranell avatar Jun 11 '19 08:06 JRGranell

Only id is actually required for the item to be accepted, but as many fields should be set as possible so that the telemetry is actually useful. I will update the docs to account for a useful bare minimum (id + responseCode)

markwolff avatar Jun 11 '19 17:06 markwolff

@markwolff thanks for updating the docs, the primary issue I faced is with the Typescript interfaces not being correct so my code wouldn't compile without the use of any.

JRGranell avatar Jun 12 '19 08:06 JRGranell

@JRGranell actually I believe this is because the docs incorrectly reference resultCode. Use responseCode instead. I've updated the docs to account for this as well!

Also the docs at /vNext/AISKU/API.md have been moved to https://github.com/microsoft/ApplicationInsights-JS/blob/master/API.md

markwolff avatar Jun 12 '19 17:06 markwolff

Hi @markwolff thanks for the updated link, sorry to continue on this, I believe it may be a TypeScript definition or importing issue. Within the applicationinsights-common package IDependencyTelemetry is defined as

{
    id: string;
    name?: string;
    duration?: number;
    success?: boolean;
    responseCode: number;
    correlationContext?: string;
    type?: string;
    data?: string;
    target?: string;
    properties?: {
        [key: string]: any;
    };
    measurements?: {
        [key: string]: number;
    };
}

https://github.com/microsoft/ApplicationInsights-JS/blob/9879276b5a3951d3187de91d9575bfb354aa6e25/vNext/shared/AppInsightsCommon/src/Interfaces/IDependencyTelemetry.ts

and can be imported from

import {
    ApplicationInsights,
    IDependencyTelemetry,
} from '@microsoft/applicationinsights-web';

I initialise using

const ai = new ApplicationInsights({
            config: {
               ...
            }
        });

and the issue is when I try to do

ai.trackDependencyData({
            id,
            method,
            absoluteUrl,
            duration,
            success,
            responseCode,
            properties,
            measurements
        });

An example error would be'method' does not exist on type IDependencyTelemetry.

It may be the case that method, absoluteUrl, commandName (which is what the docs say are supported) could be added to IDependencyTelemetry. However if that definition is also used server side, and is not applicable to server side dependency requests, that could cause confusion.

Many thanks for continuing to look into this.

JRGranell avatar Jun 13 '19 11:06 JRGranell

Sorry to comment in a closed issue, but i think the mismatch still occurs: https://github.com/microsoft/ApplicationInsights-JS/blob/master/API-reference.md#trackdependencydata vs. https://github.com/microsoft/ApplicationInsights-JS/blob/master/shared/AppInsightsCommon/src/Interfaces/IDependencyTelemetry.ts

E.g. the field "method" is not part of the interface. Can this issue be reopened?

BuZZ-T avatar Feb 18 '21 13:02 BuZZ-T

https://github.com/microsoft/ApplicationInsights-JS/blob/master/extensions/applicationinsights-dependencies-js/src/ajaxRecord.ts#L329-L340

MSNev avatar Feb 23 '23 23:02 MSNev