Application Insights TrackEvent nigdy nie został utrwalony na platformie Azure

Dec 17 2020

Próbuję zaimplementować pakiet SDK dla Node, aby śledzić zdarzenia niestandardowe w naszej bazie kodu. Napisana przeze mnie usługa jest wywoływana z łańcucha metod asynchronicznych i działa w Azure Functions:

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")
    }
}

Sama usługa wygląda następująco:

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()
    }
}

Jednak zdarzenia, które wysyłam, nigdy nie są widoczne w witrynie Azure Portal, gdy wykonuję zapytanie dotyczące customEventstabeli. Czekałem> 10 minut, ponieważ wiem, że mogą wystąpić opóźnienia w analizach aplikacji.

Próbowałem zamiast tego wywołać opróżnianie asynchroniczne i używać go awaitpodczas wywoływania, ale to też nie pomaga:

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

Zmienna środowiskowa APPLICATION_INSIGHTS_CONNECTION_STRINGma format InstrumentationKey=xxx;IngestionEndpoint=https://westeurope-1.in.applicationinsights.azure.com/.

Mój problem wydaje się bardzo podobny do błędu C # Application Insight: TrackEvent nie wysyła do usługi Azure Application Insight , ale czy naprawdę muszę spać / limit czasu, aby uwzględnić chronometraż?

Dane wyjściowe dziennika, gdy to uruchomię, nic nie mówią, nie ma błędów i nic nie wydaje się być wyłączone:

[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)

czego mi brakuje?

Aktualizacja

Więc najwyraźniej istnieje JavaScript i Węzeł SDK, aby rzeczy bardziej skomplikowane. Spróbuję z Node SDK, ale nie rozumiem, dlaczego ten pierwszy nie miałby działać.

Rozwiązanie

Następująca konstrukcja ApplicationInsightsService działa:

// 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)
    }
}

W przypadku aplikacji węzłowych:

Zrób :npm install --save applicationinsights

Nie :npm install --save @microsoft/applicationinsights-web

Odpowiedzi

jokarl Dec 17 2020 at 18:42

Następująca konstrukcja ApplicationInsightsServicerobót:

// 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)
    }
}

W przypadku aplikacji węzłowych:

Zrób :npm install --save applicationinsights

Nie :npm install --save @microsoft/applicationinsights-web