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

Add API allowing to start/finish transactions and spans with explicit timings #715

Merged
merged 5 commits into from
Dec 22, 2024
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
8 changes: 3 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Features

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

### Dependencies
Expand All @@ -14,12 +15,9 @@
- Bump Java SDK (Android) from v7.18.1 to v7.19.0 ([#709](https://github.com/getsentry/sentry-unreal/pull/709))
- [changelog](https://github.com/getsentry/sentry-java/blob/main/CHANGELOG.md#7190)
- [diff](https://github.com/getsentry/sentry-java/compare/7.18.1...7.19.0)
- Bump Cocoa SDK (iOS and Mac) from v8.41.0 to v8.42.0 ([#716](https://github.com/getsentry/sentry-unreal/pull/716))
- [changelog](https://github.com/getsentry/sentry-cocoa/blob/main/CHANGELOG.md#8420)
- [diff](https://github.com/getsentry/sentry-cocoa/compare/8.41.0...8.42.0)
- Bump Cocoa SDK (iOS and Mac) from v8.42.0 to v8.42.1 ([#719](https://github.com/getsentry/sentry-unreal/pull/719))
- 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))
- [changelog](https://github.com/getsentry/sentry-cocoa/blob/main/CHANGELOG.md#8421)
- [diff](https://github.com/getsentry/sentry-cocoa/compare/8.42.0...8.42.1)
- [diff](https://github.com/getsentry/sentry-cocoa/compare/8.41.0...8.42.1)

## 0.21.1

Expand Down
21 changes: 21 additions & 0 deletions plugin-dev/Source/Sentry/Private/Android/SentrySpanAndroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "SentrySpanAndroid.h"

#include "SentryDefines.h"

#include "Infrastructure/SentryConvertorsAndroid.h"
#include "Infrastructure/SentryJavaClasses.h"

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

void SentrySpanAndroid::SetupClassMethods()
{
StartChildMethod = GetMethod("startChild", "(Ljava/lang/String;Ljava/lang/String;)Lio/sentry/ISpan;");
FinishMethod = GetMethod("finish", "()V");
IsFinishedMethod = GetMethod("isFinished", "()Z");
SetTagMethod = GetMethod("setTag", "(Ljava/lang/String;Ljava/lang/String;)V");
SetDataMethod = GetMethod("setData", "(Ljava/lang/String;Ljava/lang/Object;)V");
ToSentryTraceMethod = GetMethod("toSentryTrace", "()Lio/sentry/SentryTraceHeader;");
}

TSharedPtr<ISentrySpan> SentrySpanAndroid::StartChild(const FString& operation, const FString& desctiption)
{
auto span = CallObjectMethod<jobject>(StartChildMethod, *GetJString(operation), *GetJString(desctiption));
return MakeShareable(new SentrySpanAndroid(*span));
}

TSharedPtr<ISentrySpan> SentrySpanAndroid::StartChildWithTimestamp(const FString& operation, const FString& desctiption, int64 timestamp)
{
UE_LOG(LogSentrySdk, Log, TEXT("Starting child span with explicit timestamp not supported on Android."));
return StartChild(operation, desctiption);
}

void SentrySpanAndroid::Finish()
{
CallMethod<void>(FinishMethod);
}

void SentrySpanAndroid::FinishWithTimestamp(int64 timestamp)
{
UE_LOG(LogSentrySdk, Log, TEXT("Finishing span with explicit timestamp not supported on Android."));
Finish();
}

bool SentrySpanAndroid::IsFinished() const
{
return CallMethod<bool>(IsFinishedMethod);;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ class SentrySpanAndroid : public ISentrySpan, public FSentryJavaObjectWrapper

void SetupClassMethods();

virtual TSharedPtr<ISentrySpan> StartChild(const FString& operation, const FString& desctiption) override;
virtual TSharedPtr<ISentrySpan> StartChildWithTimestamp(const FString& operation, const FString& desctiption, int64 timestamp) override;
virtual void Finish() override;
virtual void FinishWithTimestamp(int64 timestamp) override;
virtual bool IsFinished() const override;
virtual void SetTag(const FString& key, const FString& value) override;
virtual void RemoveTag(const FString& key) override;
Expand All @@ -22,6 +25,7 @@ class SentrySpanAndroid : public ISentrySpan, public FSentryJavaObjectWrapper
virtual void GetTrace(FString& name, FString& value) override;

private:
FSentryJavaMethod StartChildMethod;
FSentryJavaMethod FinishMethod;
FSentryJavaMethod IsFinishedMethod;
FSentryJavaMethod SetTagMethod;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,12 @@ TSharedPtr<ISentryTransaction> SentrySubsystemAndroid::StartTransactionWithConte
return MakeShareable(new SentryTransactionAndroid(*transaction));
}

TSharedPtr<ISentryTransaction> SentrySubsystemAndroid::StartTransactionWithContextAndTimestamp(TSharedPtr<ISentryTransactionContext> context, int64 timestamp)
{
UE_LOG(LogSentrySdk, Log, TEXT("Setting transaction timestamp explicitly not supported on Android."));
return StartTransactionWithContext(context);
}

TSharedPtr<ISentryTransaction> SentrySubsystemAndroid::StartTransactionWithContextAndOptions(TSharedPtr<ISentryTransactionContext> context, const TMap<FString, FString>& options)
{
TSharedPtr<SentryTransactionContextAndroid> transactionContextAndroid = StaticCastSharedPtr<SentryTransactionContextAndroid>(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class SentrySubsystemAndroid : public ISentrySubsystem
virtual void EndSession() override;
virtual TSharedPtr<ISentryTransaction> StartTransaction(const FString& name, const FString& operation) override;
virtual TSharedPtr<ISentryTransaction> StartTransactionWithContext(TSharedPtr<ISentryTransactionContext> context) override;
virtual TSharedPtr<ISentryTransaction> StartTransactionWithContextAndTimestamp(TSharedPtr<ISentryTransactionContext> context, int64 timestamp) override;
virtual TSharedPtr<ISentryTransaction> StartTransactionWithContextAndOptions(TSharedPtr<ISentryTransactionContext> context, const TMap<FString, FString>& options) override;
virtual TSharedPtr<ISentryTransactionContext> ContinueTrace(const FString& sentryTrace, const TArray<FString>& baggageHeaders) override;
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "SentryTransactionAndroid.h"
#include "SentrySpanAndroid.h"

#include "SentryDefines.h"

#include "Infrastructure/SentryConvertorsAndroid.h"
#include "Infrastructure/SentryJavaClasses.h"

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

TSharedPtr<ISentrySpan> SentryTransactionAndroid::StartChildWithTimestamp(const FString& operation, const FString& desctiption, int64 timestamp)
{
UE_LOG(LogSentrySdk, Log, TEXT("Starting child span with explicit timestamp not supported on Android."));
return StartChild(operation, desctiption);
}

void SentryTransactionAndroid::Finish()
{
CallMethod<void>(FinishMethod);
}

void SentryTransactionAndroid::FinishWithTimestamp(int64 timestamp)
{
UE_LOG(LogSentrySdk, Log, TEXT("Finishing transaction with explicit timestamp not supported on Android."));
Finish();
}

bool SentryTransactionAndroid::IsFinished() const
{
return CallMethod<bool>(IsFinishedMethod);;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ class SentryTransactionAndroid : public ISentryTransaction, public FSentryJavaOb
void SetupClassMethods();

virtual TSharedPtr<ISentrySpan> StartChild(const FString& operation, const FString& desctiption) override;
virtual TSharedPtr<ISentrySpan> StartChildWithTimestamp(const FString& operation, const FString& desctiption, int64 timestamp) override;
virtual void Finish() override;
virtual void FinishWithTimestamp(int64 timestamp) override;
virtual bool IsFinished() const override;
virtual void SetName(const FString& name) override;
virtual void SetTag(const FString& key, const FString& value) override;
Expand Down
18 changes: 18 additions & 0 deletions plugin-dev/Source/Sentry/Private/Apple/SentrySpanApple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,29 @@ id<SentrySpan> SentrySpanApple::GetNativeObject()
return SpanApple;
}

TSharedPtr<ISentrySpan> SentrySpanApple::StartChild(const FString& operation, const FString& desctiption)
{
id<SentrySpan> span = [SpanApple startChildWithOperation:operation.GetNSString() description:desctiption.GetNSString()];
return MakeShareable(new SentrySpanApple(span));
}

TSharedPtr<ISentrySpan> SentrySpanApple::StartChildWithTimestamp(const FString& operation, const FString& desctiption, int64 timestamp)
{
UE_LOG(LogSentrySdk, Log, TEXT("Starting child span with explicit timestamp not supported on Mac/iOS."));
return StartChild(operation, desctiption);
}

void SentrySpanApple::Finish()
{
[SpanApple finish];
}

void SentrySpanApple::FinishWithTimestamp(int64 timestamp)
{
UE_LOG(LogSentrySdk, Log, TEXT("Finishing span with explicit timestamp not supported on Mac/iOS."));
Finish();
}

bool SentrySpanApple::IsFinished() const
{
return SpanApple.isFinished;
Expand Down
3 changes: 3 additions & 0 deletions plugin-dev/Source/Sentry/Private/Apple/SentrySpanApple.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ class SentrySpanApple : public ISentrySpan

id<SentrySpan> GetNativeObject();

virtual TSharedPtr<ISentrySpan> StartChild(const FString& operation, const FString& desctiption) override;
virtual TSharedPtr<ISentrySpan> StartChildWithTimestamp(const FString& operation, const FString& desctiption, int64 timestamp) override;
virtual void Finish() override;
virtual void FinishWithTimestamp(int64 timestamp) override;
virtual bool IsFinished() const override;
virtual void SetTag(const FString& key, const FString& value) override;
virtual void RemoveTag(const FString& key) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,12 @@ TSharedPtr<ISentryTransaction> SentrySubsystemApple::StartTransactionWithContext
return MakeShareable(new SentryTransactionApple(transaction));
}

TSharedPtr<ISentryTransaction> SentrySubsystemApple::StartTransactionWithContextAndTimestamp(TSharedPtr<ISentryTransactionContext> context, int64 timestamp)
{
UE_LOG(LogSentrySdk, Log, TEXT("Setting transaction timestamp explicitly not supported on Mac/iOS."));
return StartTransactionWithContext(context);
}

TSharedPtr<ISentryTransaction> SentrySubsystemApple::StartTransactionWithContextAndOptions(TSharedPtr<ISentryTransactionContext> context, const TMap<FString, FString>& options)
{
TSharedPtr<SentryTransactionContextApple> transactionContextIOS = StaticCastSharedPtr<SentryTransactionContextApple>(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class SentrySubsystemApple : public ISentrySubsystem
virtual void EndSession() override;
virtual TSharedPtr<ISentryTransaction> StartTransaction(const FString& name, const FString& operation) override;
virtual TSharedPtr<ISentryTransaction> StartTransactionWithContext(TSharedPtr<ISentryTransactionContext> context) override;
virtual TSharedPtr<ISentryTransaction> StartTransactionWithContextAndTimestamp(TSharedPtr<ISentryTransactionContext> context, int64 timestamp) override;
virtual TSharedPtr<ISentryTransaction> StartTransactionWithContextAndOptions(TSharedPtr<ISentryTransactionContext> context, const TMap<FString, FString>& options) override;
virtual TSharedPtr<ISentryTransactionContext> ContinueTrace(const FString& sentryTrace, const TArray<FString>& baggageHeaders) override;
};
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,23 @@ TSharedPtr<ISentrySpan> SentryTransactionApple::StartChild(const FString& operat
return MakeShareable(new SentrySpanApple(span));
}

TSharedPtr<ISentrySpan> SentryTransactionApple::StartChildWithTimestamp(const FString& operation, const FString& desctiption, int64 timestamp)
{
UE_LOG(LogSentrySdk, Log, TEXT("Starting child span with explicit timestamp not supported on Mac/iOS."));
return StartChild(operation, desctiption);
}

void SentryTransactionApple::Finish()
{
[TransactionApple finish];
}

void SentryTransactionApple::FinishWithTimestamp(int64 timestamp)
{
UE_LOG(LogSentrySdk, Log, TEXT("Finishing transaction with explicit timestamp not supported on Mac/iOS."));
Finish();
}

bool SentryTransactionApple::IsFinished() const
{
return TransactionApple.isFinished;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ class SentryTransactionApple : public ISentryTransaction
id<SentrySpan> GetNativeObject();

virtual TSharedPtr<ISentrySpan> StartChild(const FString& operation, const FString& desctiption) override;
virtual TSharedPtr<ISentrySpan> StartChildWithTimestamp(const FString& operation, const FString& desctiption, int64 timestamp) override;
virtual void Finish() override;
virtual void FinishWithTimestamp(int64 timestamp) override;
virtual bool IsFinished() const override;
virtual void SetName(const FString& name) override;
virtual void SetTag(const FString& key, const FString& value) override;
Expand Down
19 changes: 19 additions & 0 deletions plugin-dev/Source/Sentry/Private/Desktop/SentrySpanDesktop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,32 @@ sentry_span_t* SentrySpanDesktop::GetNativeObject()
return SpanDesktop;
}

TSharedPtr<ISentrySpan> SentrySpanDesktop::StartChild(const FString& operation, const FString& desctiption)
{
sentry_span_t* nativeSpan = sentry_span_start_child(SpanDesktop, TCHAR_TO_ANSI(*operation), TCHAR_TO_ANSI(*desctiption));
return MakeShareable(new SentrySpanDesktop(nativeSpan));
}

TSharedPtr<ISentrySpan> SentrySpanDesktop::StartChildWithTimestamp(const FString& operation, const FString& desctiption, int64 timestamp)
{
sentry_span_t* nativeSpan = sentry_span_start_child_ts(SpanDesktop, TCHAR_TO_ANSI(*operation), TCHAR_TO_ANSI(*desctiption), timestamp);
return MakeShareable(new SentrySpanDesktop(nativeSpan));
}

void SentrySpanDesktop::Finish()
{
sentry_span_finish(SpanDesktop);

isFinished = true;
}

void SentrySpanDesktop::FinishWithTimestamp(int64 timestamp)
{
sentry_span_finish_ts(SpanDesktop, timestamp);

isFinished = true;
}

bool SentrySpanDesktop::IsFinished() const
{
return isFinished;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ class SentrySpanDesktop : public ISentrySpan

sentry_span_t* GetNativeObject();

virtual TSharedPtr<ISentrySpan> StartChild(const FString& operation, const FString& desctiption) override;
virtual TSharedPtr<ISentrySpan> StartChildWithTimestamp(const FString& operation, const FString& desctiption, int64 timestamp) override;
virtual void Finish() override;
virtual void FinishWithTimestamp(int64 timestamp) override;
virtual bool IsFinished() const override;
virtual void SetTag(const FString& key, const FString& value) override;
virtual void RemoveTag(const FString& key) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,15 @@ TSharedPtr<ISentryTransaction> SentrySubsystemDesktop::StartTransactionWithConte
return MakeShareable(new SentryTransactionDesktop(nativeTransaction));
}

TSharedPtr<ISentryTransaction> SentrySubsystemDesktop::StartTransactionWithContextAndTimestamp(TSharedPtr<ISentryTransactionContext> context, int64 timestamp)
{
TSharedPtr<SentryTransactionContextDesktop> transactionContextDesktop = StaticCastSharedPtr<SentryTransactionContextDesktop>(context);

sentry_transaction_t* nativeTransaction = sentry_transaction_start_ts(transactionContextDesktop->GetNativeObject(), sentry_value_new_null(), timestamp);

return MakeShareable(new SentryTransactionDesktop(nativeTransaction));
}

TSharedPtr<ISentryTransaction> SentrySubsystemDesktop::StartTransactionWithContextAndOptions(TSharedPtr<ISentryTransactionContext> context, const TMap<FString, FString>& options)
{
UE_LOG(LogSentrySdk, Log, TEXT("Transaction options currently not supported on desktop."));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class SentrySubsystemDesktop : public ISentrySubsystem
virtual void EndSession() override;
virtual TSharedPtr<ISentryTransaction> StartTransaction(const FString& name, const FString& operation) override;
virtual TSharedPtr<ISentryTransaction> StartTransactionWithContext(TSharedPtr<ISentryTransactionContext> context) override;
virtual TSharedPtr<ISentryTransaction> StartTransactionWithContextAndTimestamp(TSharedPtr<ISentryTransactionContext> context, int64 timestamp) override;
virtual TSharedPtr<ISentryTransaction> StartTransactionWithContextAndOptions(TSharedPtr<ISentryTransactionContext> context, const TMap<FString, FString>& options) override;
virtual TSharedPtr<ISentryTransactionContext> ContinueTrace(const FString& sentryTrace, const TArray<FString>& baggageHeaders) override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,26 @@ TSharedPtr<ISentrySpan> SentryTransactionDesktop::StartChild(const FString& oper
return MakeShareable(new SentrySpanDesktop(nativeSpan));
}

TSharedPtr<ISentrySpan> SentryTransactionDesktop::StartChildWithTimestamp(const FString& operation, const FString& desctiption, int64 timestamp)
{
sentry_span_t* nativeSpan = sentry_transaction_start_child_ts(TransactionDesktop, TCHAR_TO_ANSI(*operation), TCHAR_TO_ANSI(*desctiption), timestamp);
return MakeShareable(new SentrySpanDesktop(nativeSpan));
}

void SentryTransactionDesktop::Finish()
{
sentry_transaction_finish(TransactionDesktop);

isFinished = true;
}

void SentryTransactionDesktop::FinishWithTimestamp(int64 timestamp)
{
sentry_transaction_finish_ts(TransactionDesktop, timestamp);

isFinished = true;
}

bool SentryTransactionDesktop::IsFinished() const
{
return isFinished;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class SentryTransactionDesktop : public ISentryTransaction
sentry_transaction_t* GetNativeObject();

virtual TSharedPtr<ISentrySpan> StartChild(const FString& operation, const FString& desctiption) override;
virtual TSharedPtr<ISentrySpan> StartChildWithTimestamp(const FString& operation, const FString& desctiption, int64 timestamp) override;
virtual void Finish() override;
virtual void FinishWithTimestamp(int64 timestamp) override;
virtual bool IsFinished() const override;
virtual void SetName(const FString& name) override;
virtual void SetTag(const FString& key, const FString& value) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ class ISentrySpan
public:
virtual ~ISentrySpan() = default;

virtual TSharedPtr<ISentrySpan> StartChild(const FString& operation, const FString& desctiption) = 0;
virtual TSharedPtr<ISentrySpan> StartChildWithTimestamp(const FString& operation, const FString& desctiption, int64 timestamp) = 0;
virtual void Finish() = 0;
virtual void FinishWithTimestamp(int64 timestamp) = 0;
virtual bool IsFinished() const = 0;
virtual void SetTag(const FString& key, const FString& value) = 0;
virtual void RemoveTag(const FString& key) = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class ISentrySubsystem
virtual void EndSession() = 0;
virtual TSharedPtr<ISentryTransaction> StartTransaction(const FString& name, const FString& operation) = 0;
virtual TSharedPtr<ISentryTransaction> StartTransactionWithContext(TSharedPtr<ISentryTransactionContext> context) = 0;
virtual TSharedPtr<ISentryTransaction> StartTransactionWithContextAndTimestamp(TSharedPtr<ISentryTransactionContext> context, int64 timestamp) = 0;
virtual TSharedPtr<ISentryTransaction> StartTransactionWithContextAndOptions(TSharedPtr<ISentryTransactionContext> context, const TMap<FString, FString>& options) = 0;
virtual TSharedPtr<ISentryTransactionContext> ContinueTrace(const FString& sentryTrace, const TArray<FString>& baggageHeaders) = 0;
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class ISentryTransaction
virtual ~ISentryTransaction() = default;

virtual TSharedPtr<ISentrySpan> StartChild(const FString& operation, const FString& desctiption) = 0;
virtual TSharedPtr<ISentrySpan> StartChildWithTimestamp(const FString& operation, const FString& desctiption, int64 timestamp) = 0;
virtual void Finish() = 0;
virtual void FinishWithTimestamp(int64 timestamp) = 0;
virtual bool IsFinished() const = 0;
virtual void SetName(const FString& name) = 0;
virtual void SetTag(const FString& key, const FString& value) = 0;
Expand Down
Loading
Loading