Application Insights TrackEvent는 Azure에서 지속되지 않습니다.

Dec 17 2020

코드베이스에서 사용자 지정 이벤트를 추적하기 위해 Node 용 SDK를 구현하려고합니다. 내가 작성한 서비스는 비동기 메서드 체인에서 호출되며 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")
    }
}

서비스 자체는 다음과 같습니다.

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

그러나 내가 보내는 이벤트는 customEvents테이블을 쿼리 할 때 Azure Portal에 표시되지 않습니다 . 애플리케이션 인사이트가 지연 될 수 있음을 알고 있으므로 10 분 이상을 기다렸습니다.

대신 비동기 플러시 호출을 시도하고 호출 할 await때 사용 했지만 도움이되지 않습니다.

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

환경 변수 APPLICATION_INSIGHTS_CONNECTION_STRING의 형식은 InstrumentationKey=xxx;IngestionEndpoint=https://westeurope-1.in.applicationinsights.azure.com/.

내 문제는 매우 유사 보인다 C # 응용 프로그램 인사이트 실패 : TrackEvent합니까는 푸른 응용 프로그램 인사이트에 전송하지 ,하지만 난 않는 정말 타이밍에 대한 계정에서 수면 / 시간이 필요하십니까?

이것을 실행할 때의 로그 출력은 아무것도 말하지 않고 오류가 발생하지 않으며 아무것도 꺼져 있지 않은 것 같습니다.

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

내가 무엇을 놓치고 있습니까?

최신 정보

그래서 분명히 거기에 자바 스크립트 노드 SDK가 일을 더 혼란하게 할 수 있습니다. Node SDK를 사용해 보 겠지만 전자가 왜 작동하지 않는지 모르겠습니다.

해결책

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