अनुप्रयोग अंतर्दृष्टि TrackEvent Azure में कभी नहीं बनी रही

Dec 17 2020

मैं हमारे कोड बेस में कस्टम घटनाओं को ट्रैक करने के लिए नोड के लिए एसडीके को लागू करने की कोशिश कर रहा हूं। मेरे द्वारा लिखी गई सेवा को एक अतुल्यकालिक विधि श्रृंखला से कहा जाता है और Azure कार्य में चलता है:

public async handleEvent(event: Event) {
    // Do stuff

    // Then report event
    this.reportEvent(event);
}

private reportEvent(event: Event) {
    if (this._applicationInsightsService) {
        this._applicationInsightsService.reportEvent(event)
        this._context.log("Successfully sent event to application insights")
    } else {
        this._context.log("Could not send metrics to application insights, service is not defined")
    }
}

सेवा स्वयं इस तरह दिखती है:

export class ApplicationInsightsService {

    private _instance: ApplicationInsights

    private constructor(connectionString: string) {
        this._instance = new ApplicationInsights({ 
            config: {
                connectionString: connectionString
            } 
        })
        this._instance.loadAppInsights()
    }

    public static create() {
        if (process.env.APPLICATION_INSIGHTS_CONNECTION_STRING === undefined) {
            throw new Error("APPLICATION_INSIGHTS_CONNECTION_STRING undefined, cannot report metrics")
        }
        return new ApplicationInsightsService(process.env.APPLICATION_INSIGHTS_CONNECTION_STRING)
    }

    public reportEvent(event: Event) {
        this._instance.trackEvent({
            name: event.type,
            properties: event
        })
        this._instance.flush()
    }
}

हालाँकि, मेरे द्वारा भेजी जाने वाली घटनाएँ Azure Portal में कभी दिखाई नहीं देती हैं जब मैं customEventsतालिका की क्वेरी करता हूँ । मुझे 10 मिनट का इंतजार है क्योंकि मुझे पता है कि आवेदन पत्र में देरी हो सकती है।

मैंने कॉल करने के बजाय अतुल्यकालिक को फ्लश करने के लिए कॉल करने की कोशिश की है और इसे कॉल करते awaitसमय उपयोग किया है, लेकिन यह भी मदद नहीं करता है:

Promise.resolve(this._instance.flush(true))

पर्यावरण चर APPLICATION_INSIGHTS_CONNECTION_STRINGका प्रारूप है InstrumentationKey=xxx;IngestionEndpoint=https://westeurope-1.in.applicationinsights.azure.com/

मेरा मुद्दा C # Application Insight Failure से बहुत मिलता-जुलता है : TrackEvent क्या Azure Application Insight को नहीं भेजता है , लेकिन क्या मुझे वाकई सोने / टाइम आउट करने की ज़रूरत है?

जब मैं इसे चलाता हूं तो लॉग आउटपुट कुछ भी नहीं उत्पन्न होता है और कुछ भी बंद नहीं लगता है:

[12/17/2020 11:06:10 AM] Executing 'Functions.EventHandler' (Reason='New ServiceBus message detected on 'integrator-events'.', Id=812ccf8f-3cd3-4c75-8ab4-20614556d597)
[12/17/2020 11:06:10 AM] Trigger Details: MessageId: 125f60d79c5a4b029a417bee68df95d7, DeliveryCount: 1, EnqueuedTime: 12/17/2020 11:06:11 AM, LockedUntil: 12/17/2020 11:07:11 AM, SessionId: (null)
[12/17/2020 11:06:10 AM] Received event
[12/17/2020 11:06:10 AM] Successfully sent event to application insights
[12/17/2020 11:06:10 AM] Executed 'Functions.EventHandler' (Succeeded, Id=812ccf8f-3cd3-4c75-8ab4-20614556d597)

मैं क्या खो रहा हूँ?

अपडेट करें

तो जाहिरा तौर पर चीजों को और अधिक भ्रमित करने के लिए एक जावास्क्रिप्ट और एक नोड एसडीके है। मैं नोड एसडीके के साथ कोशिश करूँगा, लेकिन मैं यह नहीं देखता कि पूर्व को काम क्यों नहीं करना चाहिए।

समाधान

ApplicationInsightsService कार्यों के निम्नलिखित निर्माण:

// Previously:
// import { ApplicationInsights } from "@microsoft/applicationinsights-web"
import { TelemetryClient } from "applicationinsights"

export class ApplicationInsightsService {

    private _instance: TelemetryClient

    private constructor(connectionString: string) {
        this._instance = new TelemetryClient(connectionString)
    }
}

नोड अनुप्रयोगों के लिए:

करें :npm install --save applicationinsights

नहीं :npm install --save @microsoft/applicationinsights-web

जवाब

jokarl Dec 17 2020 at 18:42

ApplicationInsightsServiceकार्यों का निम्नलिखित निर्माण :

// Previously:
// import { ApplicationInsights } from "@microsoft/applicationinsights-web"
import { TelemetryClient } from "applicationinsights"

export class ApplicationInsightsService {

    private _instance: TelemetryClient

    private constructor(connectionString: string) {
        this._instance = new TelemetryClient(connectionString)
    }
}

नोड अनुप्रयोगों के लिए:

करें :npm install --save applicationinsights

नहीं :npm install --save @microsoft/applicationinsights-web