0

Is there a way to set the time of events manually sent in App Insights? I'm using the ApplicationInsights package from @microsoft/applicationinsights-web in a react app. As an example, I want to execute something like this at 6:00pm ETC Apr 26, 2022:

    appInsights.trackEvent({
        name: "my cool event",
        properties: {
            greeting: "hello world"
        },
    });

But have it logged in my azure portal as happening at 5:00pm ETC Apr 26, 2022. I figured there would be a time property or something I could set on the parameter object, but that doesn't seem to be the case.

DireDrop
  • 13
  • 4

1 Answers1

0

AFAIK, We have trackDependencyData, which is the IDependencyTelemetry interface, which has startTime as a parameter to know the telemetry event start time.

Sample code:-

var success = false;
var startTime = new Date().getTime();
try
{
    success = dependency.Call();
}
finally
{
    var elapsed = new Date() - startTime;
    telemetry.trackDependency({
        dependencyTypeName: "myDependency",
        name: "myCall",
        duration: elapsed,
        success: success
    });
}

For more information please refer the below links:-

AjayKumarGhose
  • 4,257
  • 2
  • 4
  • 15
  • Is this method available in appinsights react sdk as well? I tried this --> `const ai = useAppInsightsContext(); ai.trackDependencyData({/* props */})`, but its not working. – Pavindu Jun 03 '22 at 06:17