Skip to content

Commit b0fc43e

Browse files
authored
fix: Read and send unfinished spans (#3533)
1 parent 80a8d06 commit b0fc43e

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Fixes
6+
7+
- Unfinished spans are now correctly stored and retrieved by the CachingTransport ([#3533](https://github.com/getsentry/sentry-dotnet/pull/3533))
8+
39
## 4.10.0
410

511
### Features

src/Sentry/SentrySpan.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public static SentrySpan FromJson(JsonElement json)
154154
var parentSpanId = json.GetPropertyOrNull("parent_span_id")?.Pipe(SpanId.FromJson);
155155
var traceId = json.GetPropertyOrNull("trace_id")?.Pipe(SentryId.FromJson) ?? SentryId.Empty;
156156
var startTimestamp = json.GetProperty("start_timestamp").GetDateTimeOffset();
157-
var endTimestamp = json.GetProperty("timestamp").GetDateTimeOffset();
157+
var endTimestamp = json.GetPropertyOrNull("timestamp")?.GetDateTimeOffset();
158158
var operation = json.GetPropertyOrNull("op")?.GetString() ?? "unknown";
159159
var description = json.GetPropertyOrNull("description")?.GetString();
160160
var status = json.GetPropertyOrNull("status")?.GetString()?.Replace("_", "").ParseEnum<SpanStatus>();

test/Sentry.Tests/Protocol/SentryTransactionTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,27 @@ public void SerializeObject_AllPropertiesSetToNonDefault_SerializesValidObject()
246246
});
247247
}
248248

249+
[Fact]
250+
public void SerializeObject_TransactionContainsUnfinishedSpan_SerializesDeserializesValidObject()
251+
{
252+
// Arrange
253+
SentryTransaction capturedTransaction = null;
254+
var hub = Substitute.For<IHub>();
255+
hub.CaptureTransaction(Arg.Do<SentryTransaction>(t => capturedTransaction = t));
256+
257+
var transaction = new TransactionTracer(hub, "test.name", "test.operation");
258+
transaction.StartChild("child_op123", "child_desc123");
259+
transaction.Finish(SpanStatus.Aborted);
260+
261+
// Act
262+
var actualString = capturedTransaction.ToJsonString(_testOutputLogger);
263+
var actualTransaction = Json.Parse(actualString, SentryTransaction.FromJson);
264+
265+
// Assert
266+
Assert.Single(actualTransaction.Spans); // Sanity Check
267+
Assert.Null(actualTransaction.Spans.First().EndTimestamp);
268+
}
269+
249270
[Fact]
250271
public void StartChild_LevelOne_Works()
251272
{

0 commit comments

Comments
 (0)