Application Insights TrackEvent wurde in Azure nie beibehalten
Ich versuche, das SDK für Node zu implementieren, um benutzerdefinierte Ereignisse in unserer Codebasis zu verfolgen. Der von mir geschriebene Dienst wird aus einer asynchronen Methodenkette aufgerufen und in Azure-Funktionen ausgeführt:
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")
}
}
Der Service selbst sieht folgendermaßen aus:
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()
}
}
Die von mir gesendeten Ereignisse sind jedoch in Azure Portal niemals sichtbar, wenn ich die customEvents
Tabelle abfrage . Ich habe> 10 Minuten gewartet, da ich weiß, dass es zu Verzögerungen bei den Anwendungserkenntnissen kommen kann.
Ich habe versucht, den Aufruf stattdessen asynchron zu spülen und await
beim Aufrufen zu verwenden, aber das hilft auch nicht:
Promise.resolve(this._instance.flush(true))
Die Umgebungsvariable APPLICATION_INSIGHTS_CONNECTION_STRING
hat das Format InstrumentationKey=xxx;IngestionEndpoint=https://westeurope-1.in.applicationinsights.azure.com/
.
Mein Problem scheint dem C # Application Insight-Fehler sehr ähnlich zu sein : TrackEvent Wird nicht an Azure Application Insight gesendet , aber muss ich wirklich schlafen gehen / eine Zeitüberschreitung , um das Timing zu berücksichtigen?
Die Protokollausgabe, wenn ich dies ausführe, sagt nichts, es werden keine Fehler erzeugt und nichts scheint aus zu sein:
[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)
Was vermisse ich?
Aktualisieren
Anscheinend gibt es also ein JavaScript und ein Node SDK, um die Dinge verwirrender zu machen. Ich werde es mit dem Node SDK versuchen, aber ich verstehe nicht, warum das erstere nicht funktionieren sollte.
Lösung
Die folgende Konstruktion des ApplicationInsightsService funktioniert:
// 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)
}
}
Für Knotenanwendungen:
Tun Sie :npm install --save applicationinsights
Nicht :npm install --save @microsoft/applicationinsights-web
Antworten
Die folgende Konstruktion der ApplicationInsightsService
Werke:
// 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)
}
}
Für Knotenanwendungen:
Tun Sie :npm install --save applicationinsights
Nicht :npm install --save @microsoft/applicationinsights-web