Skip to content

Fix #3211: Default unset Timestamp to UtcNow in TrackDependency/TrackRequest - #3219

Merged
Matthew Sainsbury (Microsoft) (mattsains-msft) merged 3 commits into
mainfrom
rajrang/fixTrackTimestampDefault
Sep 25, 2026
Merged

Matthew Sainsbury (Microsoft) (mattsains-msft) merged 3 commits into
mainfrom
rajrang/fixTrackTimestampDefault

Conversation

@rajkumar-rangaraj

Copy link
Copy Markdown
Member

Fixes #3211

Problem

TelemetryClient.TrackDependency(DependencyTelemetry) and TelemetryClient.TrackRequest(RequestTelemetry) copied telemetry.Timestamp straight into the backing Activity's start and end times without checking whether it had been set. Code that builds the telemetry without a timestamp (for example new DependencyTelemetry(type, target, name, data) or new RequestTelemetry { ... }) therefore emitted time = 0001-01-01T00:00:00Z. Ingestion rejects these items with a 206 partial success (error 103).

In 2.x, TelemetryClient set an unset Timestamp itself (see the CHANGELOG: "Timestamp will be added automatically by TelemetryClient"). StartOperation/StopOperation and TrackAvailability are not affected.

Fix

In both methods, if Timestamp == default, set it to DateTimeOffset.UtcNow before creating the Activity. This restores 2.x behavior, including writing the value back to the telemetry object. Timestamps set explicitly by the caller are unchanged.

Tests

  • TrackDependencyWithoutTimestampDefaultsToUtcNow / TrackRequestWithoutTimestampDefaultsToUtcNow: the start time is the time of the call, the duration is kept, and the timestamp is written back. Both tests fail without the fix.
  • TrackDependencyWithExplicitTimestampPreservesTimestamp / TrackRequestWithExplicitTimestampPreservesTimestamp: an explicit timestamp and duration come through unchanged.
  • All TelemetryClient* tests pass on net8.0 and net462 (162 on each).

Changes

  • CHANGELOG.md updated
  • Public API changes (none)

)

TrackDependency(DependencyTelemetry) and TrackRequest(RequestTelemetry) assigned Timestamp directly to Activity start/end time without checking for default, emitting 0001-01-01T00:00:00Z which ingestion rejects (error 103). Restore 2.x behavior by defaulting an unset Timestamp to DateTimeOffset.UtcNow.

Fixes #3211

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings September 24, 2026 23:56
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

No unresolved review issues were identified.

Review effort: Lite
Findings: None

What changed in this PR

Fixes unset request and dependency timestamps by defaulting them to DateTimeOffset.UtcNow.

Changes:

  • Added timestamp fallback in TrackRequest and TrackDependency.
  • Added regression tests for default and explicit timestamps.
  • Documented the fix in the changelog.
File Summary
CHANGELOG.md Documents the timestamp behavior fix.
BASE/​Test/​Microsoft.ApplicationInsights.Test/​Microsoft.ApplicationInsights.Tests/​TelemetryClientTest.cs Adds timestamp regression tests.
BASE/​src/​Microsoft.ApplicationInsights/​TelemetryClient.cs Applies the UTC timestamp fallback.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@mattsains-msft
Matthew Sainsbury (Microsoft) (mattsains-msft) merged commit 07099fc into main Sep 25, 2026
18 checks passed
@mattsains-msft
Matthew Sainsbury (Microsoft) (mattsains-msft) deleted the rajrang/fixTrackTimestampDefault branch September 25, 2026 17:28
This was referenced Oct 12, 2026
This was referenced Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TelemetryClient.TrackDependency no longer default an uninitialized ITelemetry.Timestamp to UtcNow when creating the backing Activity

4 participants