Skip to content

Commit 5f2e6f4

Browse files
authored
Add API allowing to start/finish transactions and spans with explicit timings (#715)
1 parent 049e516 commit 5f2e6f4

29 files changed

+263
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Features
66

7+
- Add API allowing to start/finish transactions and spans with explicit timings ([#715](https://github.com/getsentry/sentry-unreal/pull/715))
78
- Add GPU crash dump attachments ([#712](https://github.com/getsentry/sentry-unreal/pull/712))
89

910
### Dependencies
@@ -14,12 +15,9 @@
1415
- Bump Java SDK (Android) from v7.18.1 to v7.19.0 ([#709](https://github.com/getsentry/sentry-unreal/pull/709))
1516
- [changelog](https://github.com/getsentry/sentry-java/blob/main/CHANGELOG.md#7190)
1617
- [diff](https://github.com/getsentry/sentry-java/compare/7.18.1...7.19.0)
17-
- Bump Cocoa SDK (iOS and Mac) from v8.41.0 to v8.42.0 ([#716](https://github.com/getsentry/sentry-unreal/pull/716))
18-
- [changelog](https://github.com/getsentry/sentry-cocoa/blob/main/CHANGELOG.md#8420)
19-
- [diff](https://github.com/getsentry/sentry-cocoa/compare/8.41.0...8.42.0)
20-
- Bump Cocoa SDK (iOS and Mac) from v8.42.0 to v8.42.1 ([#719](https://github.com/getsentry/sentry-unreal/pull/719))
18+
- Bump Cocoa SDK (iOS and Mac) from v8.41.0 to v8.42.1 ([#716](https://github.com/getsentry/sentry-unreal/pull/716), [#719](https://github.com/getsentry/sentry-unreal/pull/719))
2119
- [changelog](https://github.com/getsentry/sentry-cocoa/blob/main/CHANGELOG.md#8421)
22-
- [diff](https://github.com/getsentry/sentry-cocoa/compare/8.42.0...8.42.1)
20+
- [diff](https://github.com/getsentry/sentry-cocoa/compare/8.41.0...8.42.1)
2321

2422
## 0.21.1
2523

plugin-dev/Source/Sentry/Private/Android/SentrySpanAndroid.cpp

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

33
#include "SentrySpanAndroid.h"
44

5+
#include "SentryDefines.h"
6+
57
#include "Infrastructure/SentryConvertorsAndroid.h"
68
#include "Infrastructure/SentryJavaClasses.h"
79

@@ -13,18 +15,37 @@ SentrySpanAndroid::SentrySpanAndroid(jobject span)
1315

1416
void SentrySpanAndroid::SetupClassMethods()
1517
{
18+
StartChildMethod = GetMethod("startChild", "(Ljava/lang/String;Ljava/lang/String;)Lio/sentry/ISpan;");
1619
FinishMethod = GetMethod("finish", "()V");
1720
IsFinishedMethod = GetMethod("isFinished", "()Z");
1821
SetTagMethod = GetMethod("setTag", "(Ljava/lang/String;Ljava/lang/String;)V");
1922
SetDataMethod = GetMethod("setData", "(Ljava/lang/String;Ljava/lang/Object;)V");
2023
ToSentryTraceMethod = GetMethod("toSentryTrace", "()Lio/sentry/SentryTraceHeader;");
2124
}
2225

26+
TSharedPtr<ISentrySpan> SentrySpanAndroid::StartChild(const FString& operation, const FString& desctiption)
27+
{
28+
auto span = CallObjectMethod<jobject>(StartChildMethod, *GetJString(operation), *GetJString(desctiption));
29+
return MakeShareable(new SentrySpanAndroid(*span));
30+
}
31+
32+
TSharedPtr<ISentrySpan> SentrySpanAndroid::StartChildWithTimestamp(const FString& operation, const FString& desctiption, int64 timestamp)
33+
{
34+
UE_LOG(LogSentrySdk, Log, TEXT("Starting child span with explicit timestamp not supported on Android."));
35+
return StartChild(operation, desctiption);
36+
}
37+
2338
void SentrySpanAndroid::Finish()
2439
{
2540
CallMethod<void>(FinishMethod);
2641
}
2742

43+
void SentrySpanAndroid::FinishWithTimestamp(int64 timestamp)
44+
{
45+
UE_LOG(LogSentrySdk, Log, TEXT("Finishing span with explicit timestamp not supported on Android."));
46+
Finish();
47+
}
48+
2849
bool SentrySpanAndroid::IsFinished() const
2950
{
3051
return CallMethod<bool>(IsFinishedMethod);;

plugin-dev/Source/Sentry/Private/Android/SentrySpanAndroid.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ class SentrySpanAndroid : public ISentrySpan, public FSentryJavaObjectWrapper
1313

1414
void SetupClassMethods();
1515

16+
virtual TSharedPtr<ISentrySpan> StartChild(const FString& operation, const FString& desctiption) override;
17+
virtual TSharedPtr<ISentrySpan> StartChildWithTimestamp(const FString& operation, const FString& desctiption, int64 timestamp) override;
1618
virtual void Finish() override;
19+
virtual void FinishWithTimestamp(int64 timestamp) override;
1720
virtual bool IsFinished() const override;
1821
virtual void SetTag(const FString& key, const FString& value) override;
1922
virtual void RemoveTag(const FString& key) override;
@@ -22,6 +25,7 @@ class SentrySpanAndroid : public ISentrySpan, public FSentryJavaObjectWrapper
2225
virtual void GetTrace(FString& name, FString& value) override;
2326

2427
private:
28+
FSentryJavaMethod StartChildMethod;
2529
FSentryJavaMethod FinishMethod;
2630
FSentryJavaMethod IsFinishedMethod;
2731
FSentryJavaMethod SetTagMethod;

plugin-dev/Source/Sentry/Private/Android/SentrySubsystemAndroid.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,12 @@ TSharedPtr<ISentryTransaction> SentrySubsystemAndroid::StartTransactionWithConte
274274
return MakeShareable(new SentryTransactionAndroid(*transaction));
275275
}
276276

277+
TSharedPtr<ISentryTransaction> SentrySubsystemAndroid::StartTransactionWithContextAndTimestamp(TSharedPtr<ISentryTransactionContext> context, int64 timestamp)
278+
{
279+
UE_LOG(LogSentrySdk, Log, TEXT("Setting transaction timestamp explicitly not supported on Android."));
280+
return StartTransactionWithContext(context);
281+
}
282+
277283
TSharedPtr<ISentryTransaction> SentrySubsystemAndroid::StartTransactionWithContextAndOptions(TSharedPtr<ISentryTransactionContext> context, const TMap<FString, FString>& options)
278284
{
279285
TSharedPtr<SentryTransactionContextAndroid> transactionContextAndroid = StaticCastSharedPtr<SentryTransactionContextAndroid>(context);

plugin-dev/Source/Sentry/Private/Android/SentrySubsystemAndroid.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class SentrySubsystemAndroid : public ISentrySubsystem
3333
virtual void EndSession() override;
3434
virtual TSharedPtr<ISentryTransaction> StartTransaction(const FString& name, const FString& operation) override;
3535
virtual TSharedPtr<ISentryTransaction> StartTransactionWithContext(TSharedPtr<ISentryTransactionContext> context) override;
36+
virtual TSharedPtr<ISentryTransaction> StartTransactionWithContextAndTimestamp(TSharedPtr<ISentryTransactionContext> context, int64 timestamp) override;
3637
virtual TSharedPtr<ISentryTransaction> StartTransactionWithContextAndOptions(TSharedPtr<ISentryTransactionContext> context, const TMap<FString, FString>& options) override;
3738
virtual TSharedPtr<ISentryTransactionContext> ContinueTrace(const FString& sentryTrace, const TArray<FString>& baggageHeaders) override;
3839
};

plugin-dev/Source/Sentry/Private/Android/SentryTransactionAndroid.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include "SentryTransactionAndroid.h"
44
#include "SentrySpanAndroid.h"
55

6+
#include "SentryDefines.h"
7+
68
#include "Infrastructure/SentryConvertorsAndroid.h"
79
#include "Infrastructure/SentryJavaClasses.h"
810

@@ -29,11 +31,23 @@ TSharedPtr<ISentrySpan> SentryTransactionAndroid::StartChild(const FString& oper
2931
return MakeShareable(new SentrySpanAndroid(*span));
3032
}
3133

34+
TSharedPtr<ISentrySpan> SentryTransactionAndroid::StartChildWithTimestamp(const FString& operation, const FString& desctiption, int64 timestamp)
35+
{
36+
UE_LOG(LogSentrySdk, Log, TEXT("Starting child span with explicit timestamp not supported on Android."));
37+
return StartChild(operation, desctiption);
38+
}
39+
3240
void SentryTransactionAndroid::Finish()
3341
{
3442
CallMethod<void>(FinishMethod);
3543
}
3644

45+
void SentryTransactionAndroid::FinishWithTimestamp(int64 timestamp)
46+
{
47+
UE_LOG(LogSentrySdk, Log, TEXT("Finishing transaction with explicit timestamp not supported on Android."));
48+
Finish();
49+
}
50+
3751
bool SentryTransactionAndroid::IsFinished() const
3852
{
3953
return CallMethod<bool>(IsFinishedMethod);;

plugin-dev/Source/Sentry/Private/Android/SentryTransactionAndroid.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ class SentryTransactionAndroid : public ISentryTransaction, public FSentryJavaOb
1414
void SetupClassMethods();
1515

1616
virtual TSharedPtr<ISentrySpan> StartChild(const FString& operation, const FString& desctiption) override;
17+
virtual TSharedPtr<ISentrySpan> StartChildWithTimestamp(const FString& operation, const FString& desctiption, int64 timestamp) override;
1718
virtual void Finish() override;
19+
virtual void FinishWithTimestamp(int64 timestamp) override;
1820
virtual bool IsFinished() const override;
1921
virtual void SetName(const FString& name) override;
2022
virtual void SetTag(const FString& key, const FString& value) override;

plugin-dev/Source/Sentry/Private/Apple/SentrySpanApple.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,29 @@ id<SentrySpan> SentrySpanApple::GetNativeObject()
2525
return SpanApple;
2626
}
2727

28+
TSharedPtr<ISentrySpan> SentrySpanApple::StartChild(const FString& operation, const FString& desctiption)
29+
{
30+
id<SentrySpan> span = [SpanApple startChildWithOperation:operation.GetNSString() description:desctiption.GetNSString()];
31+
return MakeShareable(new SentrySpanApple(span));
32+
}
33+
34+
TSharedPtr<ISentrySpan> SentrySpanApple::StartChildWithTimestamp(const FString& operation, const FString& desctiption, int64 timestamp)
35+
{
36+
UE_LOG(LogSentrySdk, Log, TEXT("Starting child span with explicit timestamp not supported on Mac/iOS."));
37+
return StartChild(operation, desctiption);
38+
}
39+
2840
void SentrySpanApple::Finish()
2941
{
3042
[SpanApple finish];
3143
}
3244

45+
void SentrySpanApple::FinishWithTimestamp(int64 timestamp)
46+
{
47+
UE_LOG(LogSentrySdk, Log, TEXT("Finishing span with explicit timestamp not supported on Mac/iOS."));
48+
Finish();
49+
}
50+
3351
bool SentrySpanApple::IsFinished() const
3452
{
3553
return SpanApple.isFinished;

plugin-dev/Source/Sentry/Private/Apple/SentrySpanApple.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ class SentrySpanApple : public ISentrySpan
1414

1515
id<SentrySpan> GetNativeObject();
1616

17+
virtual TSharedPtr<ISentrySpan> StartChild(const FString& operation, const FString& desctiption) override;
18+
virtual TSharedPtr<ISentrySpan> StartChildWithTimestamp(const FString& operation, const FString& desctiption, int64 timestamp) override;
1719
virtual void Finish() override;
20+
virtual void FinishWithTimestamp(int64 timestamp) override;
1821
virtual bool IsFinished() const override;
1922
virtual void SetTag(const FString& key, const FString& value) override;
2023
virtual void RemoveTag(const FString& key) override;

plugin-dev/Source/Sentry/Private/Apple/SentrySubsystemApple.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,12 @@ TSharedPtr<ISentryTransaction> SentrySubsystemApple::StartTransactionWithContext
296296
return MakeShareable(new SentryTransactionApple(transaction));
297297
}
298298

299+
TSharedPtr<ISentryTransaction> SentrySubsystemApple::StartTransactionWithContextAndTimestamp(TSharedPtr<ISentryTransactionContext> context, int64 timestamp)
300+
{
301+
UE_LOG(LogSentrySdk, Log, TEXT("Setting transaction timestamp explicitly not supported on Mac/iOS."));
302+
return StartTransactionWithContext(context);
303+
}
304+
299305
TSharedPtr<ISentryTransaction> SentrySubsystemApple::StartTransactionWithContextAndOptions(TSharedPtr<ISentryTransactionContext> context, const TMap<FString, FString>& options)
300306
{
301307
TSharedPtr<SentryTransactionContextApple> transactionContextIOS = StaticCastSharedPtr<SentryTransactionContextApple>(context);

0 commit comments

Comments
 (0)