Sending backdated telemetry to ApplicationInsights
.NET 5 Console App
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.21.0" />
</ItemGroup>
</Project>
Describe the bug
Backdated telemetry to ApplicationInsights is not recorded .
To Reproduce
When timestamp of telemetry is on current day the telemetry is recorded, any with back dated timestamp are not recorded.
Note: Entire telemetry 100 entries with the current timestamp are recorded and viewable in Application Insights.
foreach ( var backDate in Enumerable.Range( 1, 100 ) )
{
var timeStamp = DateTimeOffset.UtcNow.AddDays(-backDate);
Console.WriteLine($"BackDated event occurred on {timeStamp}");
var telemetry1 = new TraceTelemetry( $"BackDated event occurred on {timeStamp} with event timestamp", SeverityLevel.Information );
telemetry1.Timestamp = timeStamp;
telemetry1.Properties.Add( "ActualEventDate", timeStamp.ToString() );
TelemetryClientInstance.TrackTrace( telemetry1 );
var telemetry2 = new TraceTelemetry( $"BackDated event occurred on {timeStamp} with current timestamp ", SeverityLevel.Information );
telemetry2.Timestamp = DateTimeOffset.UtcNow;
telemetry2.Properties.Add( "ActualEventDate", timeStamp.ToString() );
TelemetryClientInstance.TrackTrace( telemetry2 );
}
Console.WriteLine( "Waiting for 5 secs to flush TelemetryClient." );
await Task.Delay( 5000 );
TelemetryClientInstance.Flush();
Telemetry Payload with event timestamp
Application Insights Telemetry: {
"name": "AppTraces",
"time": "2022-11-04T11:31:01.2050453Z",
"iKey": "--removed--",
"tags": {
"ai.cloud.roleInstance": "SRV-9961",
"ai.internal.sdkVersion": "dotnetc:2.21.0-429"
},
"data": {
"baseType": "MessageData",
"baseData": {
"ver": 2,
"message": "BackDated event occurred on 04/11/2022 11:31:01 +00:00 with event timestamp",
"severityLevel": "Information",
"properties": {
"ActualEventDate": "04/11/2022 11:31:01 +00:00"
}
}
}
}
Telemetry Payload with current timestamp
Application Insights Telemetry: {
"name": "AppTraces",
"time": "2023-02-08T11:31:01.2102101Z",
"iKey": "--removed--",
"tags": {
"ai.cloud.roleInstance": "SRV-9961",
"ai.internal.sdkVersion": "dotnetc:2.21.0-429"
},
"data": {
"baseType": "MessageData",
"baseData": {
"ver": 2,
"message": "BackDated event occurred on 04/11/2022 11:31:01 +00:00 with current timestamp",
"severityLevel": "Information",
"properties": {
"ActualEventDate": "04/11/2022 11:31:01 +00:00"
}
}
}
}
Entire telemetry 100 entries with the current timestamp are recorded and viewable in Application Insights.
traces
| where message contains "BackDated event occurred"
| order by timestamp asc
Not an SDK bug. Backend does not allow older items (48 or so). Even within SDK items older than 48hours gets dropped by ServerTelemetryChannel : https://learn.microsoft.com/en-us/azure/azure-monitor/app/telemetry-channels#does-the-application-insights-channel-guarantee-telemetry-delivery-if-not-what-are-the-scenarios-in-which-telemetry-can-be-lost