Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Setting StartTime in TransactionTracer #2544

Merged
merged 2 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Fixes

- The SDK no longer creates transactions with their start date set to `Jan 01, 001` ([#2544](https://github.com/getsentry/sentry-dotnet/pull/2544))

### Dependencies

- Bump CLI from v2.20.4 to v2.20.5 ([#2539](https://github.com/getsentry/sentry-dotnet/pull/2539))
Expand Down
1 change: 1 addition & 0 deletions src/Sentry/TransactionTracer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ internal TransactionTracer(IHub hub, ITransactionContext context, TimeSpan? idle
Description = context.Description;
Status = context.Status;
IsSampled = context.IsSampled;
StartTimestamp = _stopwatch.StartDateTimeOffset;

if (context is TransactionContext transactionContext)
{
Expand Down
85 changes: 51 additions & 34 deletions test/Sentry.Tests/Protocol/TransactionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,57 @@ public TransactionTests(ITestOutputHelper output)
_testOutputLogger = new TestOutputDiagnosticLogger(output);
}

[Fact]
public void NewTransactionTracer_ConstructingWithNameAndOperation_HasValidStartTime()
{
var actualTransaction = new TransactionTracer(DisabledHub.Instance, "test-name", "test-operation");

Assert.NotEqual(DateTimeOffset.MinValue, actualTransaction.StartTimestamp);
}

[Fact]
public void NewTransactionTracer_ConstructingWithContext_HasValidStartTime()
{
var context = new TransactionContext("test-name", "test-operation");

var actualTransaction = new TransactionTracer(DisabledHub.Instance, context);

Assert.NotEqual(DateTimeOffset.MinValue, actualTransaction.StartTimestamp);
}

[Fact]
public async Task NewTransactionTracer_IdleTimeoutProvided_AutomaticallyFinishes()
{
// Arrange
var client = Substitute.For<ISentryClient>();
var options = new SentryOptions
{
Dsn = ValidDsn,
Debug = true
};
var hub = new Hub(options, client);
var context = new TransactionContext(
SpanId.Create(),
SpanId.Create(),
SentryId.Create(),
"my name",
"my operation",
"description",
SpanStatus.Ok,
null,
true,
TransactionNameSource.Component
);

var transaction = new TransactionTracer(hub, context, TimeSpan.FromMilliseconds(2));

// Act
await Task.Delay(TimeSpan.FromSeconds(2));

// Assert
transaction.IsFinished.Should().BeTrue();
}

[Fact]
public void Redact_Redacts_Urls()
{
Expand Down Expand Up @@ -561,38 +612,4 @@ public void ISpan_GetTransaction_FromSpan()
// Assert
Assert.Same(transaction, result);
}

[Fact]
public async Task NewTransactionTracer_IdleTimeoutProvided_AutomaticallyFinishes()
{
// Arrange
var client = Substitute.For<ISentryClient>();
var options = new SentryOptions
{
Dsn = ValidDsn,
Debug = true
};
var hub = new Hub(options, client);
var context = new TransactionContext(
SpanId.Create(),
SpanId.Create(),
SentryId.Create(),
"my name",
"my operation",
"description",
SpanStatus.Ok,
null,
true,
TransactionNameSource.Component
);

var transaction = new TransactionTracer(hub, context, TimeSpan.FromMilliseconds(2));

// Act
await Task.Delay(TimeSpan.FromSeconds(2));

// Assert
transaction.IsFinished.Should().BeTrue();
}

}
Loading