Skip to content

Commit adca25c

Browse files
authored
allow custom span end time (#106)
1 parent 2aca61a commit adca25c

File tree

6 files changed

+60
-17
lines changed

6 files changed

+60
-17
lines changed

BugsnagPerformance/Assets/BugsnagPerformance/Scripts/Public/Span.cs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,7 @@ public Span(string name, SpanKind kind, string id, string traceId, string parent
4040
_onSpanEnd = onSpanEnd;
4141
}
4242

43-
public void End()
44-
{
45-
lock (_endLock)
46-
{
47-
if (Ended)
48-
{
49-
return;
50-
}
51-
Ended = true;
52-
}
53-
EndTime = DateTimeOffset.UtcNow;
54-
_onSpanEnd(this);
55-
}
56-
57-
internal void End(DateTimeOffset? endTime)
43+
public void End(DateTimeOffset? endTime = null)
5844
{
5945
lock (_endLock)
6046
{
@@ -110,7 +96,7 @@ internal void EndNetworkSpan(BugsnagUnityWebRequest request)
11096
_onSpanEnd(this);
11197
}
11298

113-
public void EndNetworkSpan(int statusCode = -1, int requestContentLength = -1, int responseContentLength = -1)
99+
public void EndNetworkSpan(int statusCode = -1, int requestContentLength = -1, int responseContentLength = -1, DateTimeOffset? endTime = null)
114100
{
115101
lock (_endLock)
116102
{
@@ -121,7 +107,7 @@ public void EndNetworkSpan(int statusCode = -1, int requestContentLength = -1, i
121107
Ended = true;
122108
}
123109

124-
EndTime = DateTimeOffset.UtcNow;
110+
EndTime = endTime == null ? DateTimeOffset.UtcNow : endTime.Value;
125111

126112
if (statusCode > -1)
127113
{

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
### Bug Fixes
66

7+
- Fixed issue where spans could not be ended with a custom end time. [#106](https://github.com/bugsnag/bugsnag-unity-performance/pull/106)
8+
79
- Fixed issue where custom spans with the SpanOption IsFirstClass set to false still had it reported as true. [#107](https://github.com/bugsnag/bugsnag-unity-performance/pull/107)
810

911

features/fixtures/mazerunner/Assets/Scenes/MainScene.unity

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ GameObject:
268268
m_Component:
269269
- component: {fileID: 259057445}
270270
- component: {fileID: 259057446}
271+
- component: {fileID: 259057447}
271272
m_Layer: 0
272273
m_Name: ManualSpans
273274
m_TagString: Untagged
@@ -302,6 +303,18 @@ MonoBehaviour:
302303
m_Script: {fileID: 11500000, guid: cb0c44dcd373341599ace342676625b4, type: 3}
303304
m_Name:
304305
m_EditorClassIdentifier:
306+
--- !u!114 &259057447
307+
MonoBehaviour:
308+
m_ObjectHideFlags: 0
309+
m_CorrespondingSourceObject: {fileID: 0}
310+
m_PrefabInstance: {fileID: 0}
311+
m_PrefabAsset: {fileID: 0}
312+
m_GameObject: {fileID: 259057444}
313+
m_Enabled: 1
314+
m_EditorHideFlags: 0
315+
m_Script: {fileID: 11500000, guid: b1acdfac80082464180a997600222189, type: 3}
316+
m_Name:
317+
m_EditorClassIdentifier:
305318
--- !u!1 &320782971
306319
GameObject:
307320
m_ObjectHideFlags: 0
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using BugsnagUnityPerformance;
4+
using UnityEngine;
5+
6+
public class CustomStartAndEndTime : Scenario
7+
{
8+
9+
public override void PrepareConfig(string apiKey, string host)
10+
{
11+
base.PrepareConfig(apiKey, host);
12+
SetMaxBatchSize(1);
13+
}
14+
15+
public override void Run()
16+
{
17+
base.Run();
18+
BugsnagPerformance.StartSpan("CustomStartAndEndTime",
19+
new SpanOptions {StartTime = new System.DateTimeOffset(1985,1,1,1,1,1,System.TimeSpan.Zero)})
20+
.End(new System.DateTimeOffset(1986, 1, 1, 1, 1, 1, System.TimeSpan.Zero));
21+
}
22+
23+
24+
}

features/fixtures/mazerunner/Assets/Scripts/Scenarios/Spans/CustomStartAndEndTime.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

features/manual_spans.feature

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,10 @@ Feature: Manual creation of spans
5757
* the trace payload field "resourceSpans.0.resource" string attribute "device.manufacturer" exists
5858
* the trace payload field "resourceSpans.0.resource" string attribute "host.arch" exists
5959
* the trace payload field "resourceSpans.0.resource" string attribute "bugsnag.app.bundle_version" exists
60+
61+
Scenario: Custom timings
62+
When I run the game in the "CustomStartAndEndTime" state
63+
And I wait for 1 span
64+
* the trace payload field "resourceSpans.0.scopeSpans.0.spans.0.name" equals "CustomStartAndEndTime"
65+
* every span field "startTimeUnixNano" equals "473389261000000000"
66+
* every span field "endTimeUnixNano" equals "504925261000000000"

0 commit comments

Comments
 (0)