Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
696ba61
todo
vaind Aug 17, 2023
4f85144
feat: expose cocoa profiling via method channels
vaind Aug 18, 2023
de6f244
feat: prepare profiler interfaces and hub integration
vaind Aug 22, 2023
7c73348
fix CI
vaind Aug 23, 2023
42af467
integrate dart & cocoa profiling
vaind Aug 24, 2023
162c2ba
fix API breakage
vaind Aug 26, 2023
31a92e5
fix tests
vaind Aug 28, 2023
b12978e
dart format
vaind Aug 28, 2023
3582adf
ci: fix pana
vaind Aug 29, 2023
1d74bac
update tests
vaind Aug 29, 2023
8d23d3f
analysis issues
vaind Aug 29, 2023
c9be10c
update to the latest cocoa SDK API
vaind Sep 5, 2023
32c6e5d
linter issue
vaind Sep 7, 2023
0ae79d4
fix import
vaind Sep 12, 2023
df9fb5b
refactor: SentryNative integration
vaind Sep 12, 2023
0fb649c
update cocoa native binding to use ffi startProfiler()
vaind Sep 12, 2023
dccb853
tmp: findPrimeNumber in example
vaind Sep 12, 2023
6119812
fix: make FFI dependency conditional (web/vm)
vaind Sep 18, 2023
5218efa
exclude generated binding code from code coverage
vaind Sep 18, 2023
4c8f2bf
test: profiler integration test
vaind Sep 18, 2023
e0bb3ab
workaround for the integration test issue
vaind Sep 18, 2023
8a4fed7
chore: formatting
vaind Sep 19, 2023
2d29cb6
Merge branch 'main' into feat/profiling
vaind Sep 19, 2023
4748a00
Merge branch 'main' into feat/profiling
vaind Sep 20, 2023
39d1187
chore: remove obsolete code
vaind Sep 25, 2023
50994d4
Update flutter/example/lib/main.dart
vaind Oct 3, 2023
6e599fb
renames
vaind Oct 3, 2023
e7582d7
Breadcrumbs for file I/O operations (#1649)
denrase Sep 25, 2023
36b052e
ci: don't run CI on markdown updates (#1651)
vaind Sep 25, 2023
813b947
fixup mock names after renames
vaind Oct 3, 2023
ce59509
Merge branch 'main' into feat/profiling
stefanosiano Oct 4, 2023
e13e7de
more renames (Sentry prefix)
vaind Oct 4, 2023
8e6bd13
chore: update changelog
vaind Oct 4, 2023
227b701
Merge branch 'main' into feat/profiling
vaind Oct 26, 2023
defdfa6
don't inline findPrimeNumber profiler-test function
vaind Oct 27, 2023
4074f01
fixup changelog
vaind Oct 27, 2023
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
Prev Previous commit
Next Next commit
refactor: SentryNative integration
  • Loading branch information
vaind committed Sep 18, 2023
commit df9fb5b7b03466721119cdd57d5f5af1df8caa93
135 changes: 74 additions & 61 deletions flutter/lib/src/native/sentry_native.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,17 @@ import 'dart:async';
import 'package:meta/meta.dart';

import '../../sentry_flutter.dart';
import 'sentry_native_channel.dart';
import 'sentry_native_binding.dart';

/// [SentryNative] holds state that it fetches from to the native SDKs. Always
/// use the shared instance with [SentryNative()].
/// [SentryNative] holds state that it fetches from to the native SDKs.
/// It forwards to platform-specific implementations of [SentryNativeBinding].
/// Any errors are logged and ignored.
@internal
class SentryNative {
SentryNative._();
final SentryOptions _options;
final SentryNativeBinding _binding;

static final SentryNative _instance = SentryNative._();

SentryNativeChannel? _nativeChannel;

factory SentryNative() {
return _instance;
}

SentryNativeChannel? get nativeChannel => _instance._nativeChannel;

/// Provide [nativeChannel] for native communication.
set nativeChannel(SentryNativeChannel? nativeChannel) {
_instance._nativeChannel = nativeChannel;
}
SentryNative(this._options, this._binding);

// AppStart

Expand All @@ -41,75 +30,99 @@ class SentryNative {
/// Fetch [NativeAppStart] from native channels. Can only be called once.
Future<NativeAppStart?> fetchNativeAppStart() async {
_didFetchAppStart = true;
return await _nativeChannel?.fetchNativeAppStart();
return _invoke("fetchNativeAppStart", _binding.fetchNativeAppStart);
}

// NativeFrames

Future<void> beginNativeFramesCollection() async {
await _nativeChannel?.beginNativeFrames();
}
Future<void> beginNativeFramesCollection() =>
_invoke("beginNativeFrames", _binding.beginNativeFrames);

Future<NativeFrames?> endNativeFramesCollection(SentryId traceId) async {
return await _nativeChannel?.endNativeFrames(traceId);
}
Future<NativeFrames?> endNativeFramesCollection(SentryId traceId) =>
_invoke("endNativeFrames", () => _binding.endNativeFrames(traceId));

// Scope

Future<void> setContexts(String key, dynamic value) async {
return await _nativeChannel?.setContexts(key, value);
}
Future<void> setContexts(String key, dynamic value) =>
_invoke("setContexts", () => _binding.setContexts(key, value));

Future<void> removeContexts(String key) async {
return await _nativeChannel?.removeContexts(key);
}
Future<void> removeContexts(String key) =>
_invoke("removeContexts", () => _binding.removeContexts(key));

Future<void> setUser(SentryUser? sentryUser) async {
return await _nativeChannel?.setUser(sentryUser);
}
Future<void> setUser(SentryUser? sentryUser) =>
_invoke("setUser", () => _binding.setUser(sentryUser));

Future<void> addBreadcrumb(Breadcrumb breadcrumb) async {
return await _nativeChannel?.addBreadcrumb(breadcrumb);
}
Future<void> addBreadcrumb(Breadcrumb breadcrumb) =>
_invoke("addBreadcrumb", () => _binding.addBreadcrumb(breadcrumb));

Future<void> clearBreadcrumbs() async {
return await _nativeChannel?.clearBreadcrumbs();
}
Future<void> clearBreadcrumbs() =>
_invoke("clearBreadcrumbs", _binding.clearBreadcrumbs);

Future<void> setExtra(String key, dynamic value) async {
return await _nativeChannel?.setExtra(key, value);
}
Future<void> setExtra(String key, dynamic value) =>
_invoke("setExtra", () => _binding.setExtra(key, value));

Future<void> removeExtra(String key) async {
return await _nativeChannel?.removeExtra(key);
}
Future<void> removeExtra(String key) =>
_invoke("removeExtra", () => _binding.removeExtra(key));

Future<void> setTag(String key, String value) async {
return await _nativeChannel?.setTag(key, value);
}
Future<void> setTag(String key, String value) =>
_invoke("setTag", () => _binding.setTag(key, value));

Future<void> removeTag(String key) async {
return await _nativeChannel?.removeTag(key);
}
Future<void> removeTag(String key) =>
_invoke("removeTag", () => _binding.removeTag(key));

Future<int?> startProfiler(SentryId traceId) async {
return _nativeChannel?.startProfiler(traceId);
}
int? startProfiler(SentryId traceId) =>
_invokeSync("startProfiler", () => _binding.startProfiler(traceId));

Future<void> discardProfiler(SentryId traceId) async {
return _nativeChannel?.discardProfiler(traceId);
}
Future<void> discardProfiler(SentryId traceId) =>
_invoke("discardProfiler", () => _binding.discardProfiler(traceId));

Future<Map<String, dynamic>?> collectProfile(
SentryId traceId, int startTimeNs, int endTimeNs) async {
return _nativeChannel?.collectProfile(traceId, startTimeNs, endTimeNs);
}
SentryId traceId, int startTimeNs, int endTimeNs) =>
_invoke("collectProfile",
() => _binding.collectProfile(traceId, startTimeNs, endTimeNs));

/// Reset state
void reset() {
appStartEnd = null;
_didFetchAppStart = false;
}

// Helpers
Future<T?> _invoke<T>(
String nativeMethodName, Future<T?> Function() fn) async {
try {
return await fn();
} catch (error, stackTrace) {
_logError(nativeMethodName, error, stackTrace);
// ignore: invalid_use_of_internal_member
if (_options.devMode) {
rethrow;
}
return null;
}
}

T? _invokeSync<T>(String nativeMethodName, T? Function() fn) {
try {
return fn();
} catch (error, stackTrace) {
_logError(nativeMethodName, error, stackTrace);
// ignore: invalid_use_of_internal_member
if (_options.devMode) {
rethrow;
}
return null;
}
}

void _logError(String nativeMethodName, Object error, StackTrace stackTrace) {
_options.logger(
SentryLevel.error,
'Native call `$nativeMethodName` failed',
exception: error,
stackTrace: stackTrace,
);
}
}

class NativeAppStart {
Expand Down
43 changes: 43 additions & 0 deletions flutter/lib/src/native/sentry_native_binding.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import 'dart:async';

import 'package:meta/meta.dart';

import '../../sentry_flutter.dart';
import 'sentry_native.dart';

/// Provide typed methods to access native layer.
@internal
abstract class SentryNativeBinding {
// TODO Move other native calls here.

Future<NativeAppStart?> fetchNativeAppStart();

Future<void> beginNativeFrames();

Future<NativeFrames?> endNativeFrames(SentryId id);

Future<void> setUser(SentryUser? user);

Future<void> addBreadcrumb(Breadcrumb breadcrumb);

Future<void> clearBreadcrumbs();

Future<void> setContexts(String key, dynamic value);

Future<void> removeContexts(String key);

Future<void> setExtra(String key, dynamic value);

Future<void> removeExtra(String key);

Future<void> setTag(String key, String value);

Future<void> removeTag(String key);

int? startProfiler(SentryId traceId);

Future<void> discardProfiler(SentryId traceId);

Future<Map<String, dynamic>?> collectProfile(
SentryId traceId, int startTimeNs, int endTimeNs);
}
Loading