Application Insights TrackEvent, Azure'da hiçbir zaman kalıcı olmadı
Kod tabanımızdaki özel etkinlikleri izlemek için Node için SDK'yı uygulamaya çalışıyorum. Yazdığım hizmet zaman uyumsuz bir yöntem zincirinden çağrılıyor ve Azure İşlevlerinde çalışıyor:
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")
}
}
Hizmetin kendisi şöyle görünür:
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()
}
}
Ancak, customEvents
tabloyu sorguladığımda gönderdiğim olaylar Azure Portal'da hiçbir zaman görünmüyor . Uygulama bilgilerinde gecikmeler olabileceğini bildiğim için 10 dakikadan fazla bekledim.
Bunun yerine eşzamansız temizleme çağrısı yapmayı ve await
çağırırken kullanmayı denedim , ancak bu da yardımcı olmuyor:
Promise.resolve(this._instance.flush(true))
Ortam değişkeni APPLICATION_INSIGHTS_CONNECTION_STRING
biçime sahiptir InstrumentationKey=xxx;IngestionEndpoint=https://westeurope-1.in.applicationinsights.azure.com/
.
Sorunum C # Application Insight Failure'a çok benziyor : TrackEvent Azure Application Insight'a göndermiyor , ancak zamanlamaları hesaba katmak için gerçekten uyumam / zaman aşımına ihtiyacım var mı?
Bunu çalıştırdığımda günlük çıktısı hiçbir şey söylemiyor, hata üretilmedi ve hiçbir şey kapalı görünmüyor:
[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)
Neyi kaçırıyorum?
Güncelleme
Görünüşe göre , işleri daha kafa karıştırıcı hale getirmek için bir JavaScript ve bir Node SDK var. Node SDK ile deneyeceğim, ancak neden eskisinin çalışmaması gerektiğini anlamıyorum.
Çözüm
ApplicationInsightsService çalışmalarının aşağıdaki yapısı:
// 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)
}
}
Düğüm uygulamaları için:
Yapın :npm install --save applicationinsights
Yapmayın :npm install --save @microsoft/applicationinsights-web
Yanıtlar
ApplicationInsightsService
Eserlerin aşağıdaki inşaatı :
// 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)
}
}
Düğüm uygulamaları için:
Yapın :npm install --save applicationinsights
Yapmayın :npm install --save @microsoft/applicationinsights-web