microsoft / ApplicationInsights-node.js

Microsoft Application Insights SDK for Node.js
MIT License
322 stars 138 forks source link

TypeError: telemetry.time.toISOString is not a function when using vanilla applicationinsights 1.0.2 #374

Closed jordan112 closed 6 years ago

jordan112 commented 6 years ago

I'm using this in conjunction with Bot Framework on Node.js. Is there a ES6 polyfill that I need? It seems internal to Telemetry

TypeError: telemetry.time.toISOString is not a function
    at NodeClient.TelemetryClient.track (/Users/<user>/Documents/repos/Amway/DurablesServices-WarrantyRegistration-Bot/node_modules/applicationinsights/out/Library/TelemetryClient.js:105:48)
    at NodeClient.TelemetryClient.trackRequest (/Users/<user>/Documents/repos/Amway/DurablesServices-WarrantyRegistration-Bot/node_modules/applicationinsights/out/Library/TelemetryClient.js:71:14)

Here is my setup to AppInsights

//Setup appInsights
var appInsightsKey = (process.env.APPINSIGHTS_INSTRUMENTATIONKEY ? process.env.APPINSIGHTS_INSTRUMENTATIONKEY : "<my-awesome-key>");
console.log('setup appInsights with key: ', appInsightsKey);
appInsights.setup(appInsightsKey)
    .setAutoDependencyCorrelation(true)
    .setAutoCollectRequests(true)
    .setAutoCollectPerformance(true)
    .setAutoCollectExceptions(true)
    .setAutoCollectDependencies(true)
    .setAutoCollectConsole(true)
    .setUseDiskRetryCaching(true)
    .start();
jordan112 commented 6 years ago

It looks like its this line

envelope.time = telemetry.time.toISOString();

within this method in the TelemetryClient.ts

    /**
     * Generic track method for all telemetry types
     * @param data the telemetry to send
     * @param telemetryType specify the type of telemetry you are tracking from the list of Contracts.DataTypes
     */
    public track(telemetry: Contracts.Telemetry, telemetryType: Contracts.TelemetryType) {
        if (telemetry && Contracts.telemetryTypeToBaseType(telemetryType)) {
            var envelope = EnvelopeFactory.createEnvelope(telemetry, telemetryType, this.commonProperties, this.context, this.config);

            // Set time on the envelope if it was set on the telemetry item
            if (telemetry.time) {
                envelope.time = telemetry.time.toISOString();
            }

            var accepted = this.runTelemetryProcessors(envelope, telemetry.contextObjects);

            // Ideally we would have a central place for "internal" telemetry processors and users can configure which ones are in use.
            // This will do for now. Otherwise clearTelemetryProcessors() would be problematic.
            accepted = accepted && TelemetryProcessors.samplingTelemetryProcessor(envelope, { correlationContext: CorrelationContextManager.getCurrentContext() });

            if (accepted) {
                this.channel.send(envelope);
            }
        }
        else {
            Logging.warn("track() requires telemetry object and telemetryType to be specified.")
        }

https://github.com/Microsoft/ApplicationInsights-node.js/blob/05b70a06d47f5ee2ee72ca8d8a6d340eb7915de6/Library/TelemetryClient.ts

jordan112 commented 6 years ago

Okay, i figured it out. I didn't properly upgrade my track calls

For example, with the previous version, I had:

client.trackEvent('start', telemetry);

when it should have been

client.trackEvent({name: 'start'});