Skip to content

Commit

Permalink
Merge branch 'release/8.0.0' into denrase/android-native-contexts
Browse files Browse the repository at this point in the history
# Conflicts:
#	flutter/android/src/main/kotlin/io/sentry/flutter/SentryFlutterPlugin.kt
  • Loading branch information
denrase committed Aug 29, 2023
2 parents 82c4cda + 852a85e commit 891870f
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 92 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @marandaneto @krystofwoldrich @stefanosiano
* @krystofwoldrich @stefanosiano @buenaflor
2 changes: 1 addition & 1 deletion .github/workflows/flutter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ jobs:
steps:
- uses: actions/checkout@v3
# https://github.com/CocoaPods/CocoaPods/issues/5275#issuecomment-315461879
- run: pod lib lint ios/sentry_flutter.podspec --configuration=Debug --skip-import-validation --allow-warnings
- run: pod lib lint ios/sentry_flutter.podspec --configuration=Debug --skip-import-validation --allow-warnings --verbose

swift-lint:
runs-on: ubuntu-latest
Expand Down
80 changes: 41 additions & 39 deletions .github/workflows/flutter_integration_test.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
name: flutter integration tests
on:
push:
branches:
- main
- release/**
pull_request:
paths-ignore:
- 'file/**'
# Currently broken, enable after fixing
workflow_dispatch
# push:
# branches:
# - main
# - release/**
# pull_request:
# paths-ignore:
# - 'file/**'

jobs:
cancel-previous-workflow:
Expand All @@ -16,35 +18,35 @@ jobs:
uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 # [email protected]
with:
access_token: ${{ github.token }}

test-android:
runs-on: macos-latest
timeout-minutes: 30
defaults:
run:
working-directory: ./flutter/example
run:
working-directory: ./flutter/example
strategy:
fail-fast: false
matrix:
sdk: ['stable', 'beta']
fail-fast: false
matrix:
sdk: ["stable", "beta"]
steps:
- name: checkout
uses: actions/checkout@v3
- name: checkout
uses: actions/checkout@v3

- uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '11'
- uses: actions/setup-java@v3
with:
distribution: "adopt"
java-version: "11"

- uses: subosito/flutter-action@48cafc24713cca54bbe03cdc3a423187d413aafa # [email protected]
with:
channel: ${{ matrix.sdk }}
- uses: subosito/flutter-action@48cafc24713cca54bbe03cdc3a423187d413aafa # [email protected]
with:
channel: ${{ matrix.sdk }}

- name: flutter upgrade
run: flutter upgrade
- name: flutter upgrade
run: flutter upgrade

- name: flutter pub get
run: flutter pub get
- name: flutter pub get
run: flutter pub get

- name: Gradle cache
uses: gradle/gradle-build-action@v2
Expand All @@ -58,18 +60,18 @@ jobs:
~/.android/adb*
key: avd-21
- name: create AVD and generate snapshot for caching
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@d94c3fbe4fe6a29e4a5ba47c12fb47677c73656b #[email protected]
with:
working-directory: ./flutter/example
api-level: 21
force-avd-creation: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: false
arch: x86_64
profile: Nexus 6
script: echo "Generated AVD snapshot for caching."
- name: create AVD and generate snapshot for caching
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@d94c3fbe4fe6a29e4a5ba47c12fb47677c73656b #[email protected]
with:
working-directory: ./flutter/example
api-level: 21
force-avd-creation: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: false
arch: x86_64
profile: Nexus 6
script: echo 'Generated AVD snapshot for caching.'

- name: launch android emulator & run android integration test
uses: reactivecircus/android-emulator-runner@d94c3fbe4fe6a29e4a5ba47c12fb47677c73656b #[email protected]
Expand All @@ -93,7 +95,7 @@ jobs:
fail-fast: false
matrix:
# 'beta' is flaky because of https://github.com/flutter/flutter/issues/124340
sdk: ['stable']
sdk: ["stable"]
steps:
- name: checkout
uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/web-example-ghpages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
workingDir: flutter/example
customArgs: --source-maps
webRenderer: canvaskit
baseHref: "/sentry-dart/"

- name: Upload source maps
run: |
Expand Down
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,24 @@
- Refrain from overwriting the span status for unfinished spans ([#1577](https://github.com/getsentry/sentry-dart/pull/1577))
- Older self-hosted sentry instances will drop transactions containing unfinished spans.
- This change was introduced in [relay/#1690](https://github.com/getsentry/relay/pull/1690) and released with [22.12.0](https://github.com/getsentry/relay/releases/tag/22.12.0)

## Unreleased

### Fixes

- Fixing memory leak issue in SentryFlutterPlugin (Android Plugin) ([#1588](https://github.com/getsentry/sentry-dart/pull/1588))

### Dependencies

- Bump Android SDK from v6.25.2 to v6.28.0 ([#1586](https://github.com/getsentry/sentry-dart/pull/1586))
- [changelog](https://github.com/getsentry/sentry-java/blob/main/CHANGELOG.md#6280)
- [diff](https://github.com/getsentry/sentry-java/compare/6.25.2...6.28.0)
- Bump Cocoa SDK from v8.9.1 to v8.10.0 ([#1584](https://github.com/getsentry/sentry-dart/pull/1584), [#1606](https://github.com/getsentry/sentry-dart/pull/1606))
- [changelog](https://github.com/getsentry/sentry-cocoa/blob/main/CHANGELOG.md#8100)
- [diff](https://github.com/getsentry/sentry-cocoa/compare/8.9.1...8.10.0)

## 7.9.0

### Features

- Send trace origin ([#1534](https://github.com/getsentry/sentry-dart/pull/1534))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import io.flutter.plugin.common.MethodChannel.Result
import io.flutter.plugin.common.StandardMessageCodec
import io.sentry.Breadcrumb
import io.sentry.DateUtils
import io.sentry.Hint
import io.sentry.HubAdapter
import io.sentry.Scope
import io.sentry.Sentry
import io.sentry.SentryEvent
import io.sentry.SentryLevel
import io.sentry.SentryOptions
import io.sentry.android.core.ActivityFramesTracker
import io.sentry.android.core.AppStartState
import io.sentry.android.core.BuildConfig.VERSION_NAME
Expand All @@ -42,10 +43,6 @@ class SentryFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
private var framesTracker: ActivityFramesTracker? = null
private var autoPerformanceTracingEnabled = false

private val flutterSdk = "sentry.dart.flutter"
private val androidSdk = "sentry.java.android.flutter"
private val nativeSdk = "sentry.native.android.flutter"

override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
context = flutterPluginBinding.applicationContext
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "sentry_flutter")
Expand Down Expand Up @@ -118,9 +115,15 @@ class SentryFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
args.getIfNotNull<String>("environment") { options.environment = it }
args.getIfNotNull<String>("release") { options.release = it }
args.getIfNotNull<String>("dist") { options.dist = it }
args.getIfNotNull<Boolean>("enableAutoSessionTracking") { options.isEnableAutoSessionTracking = it }
args.getIfNotNull<Long>("autoSessionTrackingIntervalMillis") { options.sessionTrackingIntervalMillis = it }
args.getIfNotNull<Long>("anrTimeoutIntervalMillis") { options.anrTimeoutIntervalMillis = it }
args.getIfNotNull<Boolean>("enableAutoSessionTracking") {
options.isEnableAutoSessionTracking = it
}
args.getIfNotNull<Long>("autoSessionTrackingIntervalMillis") {
options.sessionTrackingIntervalMillis = it
}
args.getIfNotNull<Long>("anrTimeoutIntervalMillis") {
options.anrTimeoutIntervalMillis = it
}
args.getIfNotNull<Boolean>("attachThreads") { options.isAttachThreads = it }
args.getIfNotNull<Boolean>("attachStacktrace") { options.isAttachStacktrace = it }
args.getIfNotNull<Boolean>("enableAutoNativeBreadcrumbs") {
Expand Down Expand Up @@ -174,12 +177,7 @@ class SentryFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
options.sdkVersion = sdkVersion
options.sentryClientName = "$androidSdk/$VERSION_NAME"
options.nativeSdkName = nativeSdk

options.setBeforeSend { event, _ ->
setEventOriginTag(event)
addPackages(event, options.sdkVersion)
event
}
options.beforeSend = BeforeSendCallbackImpl(options.sdkVersion)

args.getIfNotNull<Int>("connectionTimeoutMillis") { options.connectionTimeoutMillis = it }
args.getIfNotNull<Int>("readTimeoutMillis") { options.readTimeoutMillis = it }
Expand Down Expand Up @@ -398,30 +396,50 @@ class SentryFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
result.success("")
}

private fun setEventOriginTag(event: SentryEvent) {
event.sdk?.let {
when (it.name) {
flutterSdk -> setEventEnvironmentTag(event, "flutter", "dart")
androidSdk -> setEventEnvironmentTag(event, environment = "java")
nativeSdk -> setEventEnvironmentTag(event, environment = "native")
else -> return
}
private class BeforeSendCallbackImpl(
private val sdkVersion: SdkVersion?
) : SentryOptions.BeforeSendCallback {
override fun execute(event: SentryEvent, hint: Hint): SentryEvent {
setEventOriginTag(event)
addPackages(event, sdkVersion)
return event
}
}

private fun setEventEnvironmentTag(event: SentryEvent, origin: String = "android", environment: String) {
event.setTag("event.origin", origin)
event.setTag("event.environment", environment)
}

private fun addPackages(event: SentryEvent, sdk: SdkVersion?) {
event.sdk?.let {
if (it.name == flutterSdk) {
sdk?.packageSet?.forEach { sentryPackage ->
it.addPackage(sentryPackage.name, sentryPackage.version)
companion object {

private const val flutterSdk = "sentry.dart.flutter"
private const val androidSdk = "sentry.java.android.flutter"
private const val nativeSdk = "sentry.native.android.flutter"
private fun setEventOriginTag(event: SentryEvent) {
event.sdk?.let {
when (it.name) {
flutterSdk -> setEventEnvironmentTag(event, "flutter", "dart")
androidSdk -> setEventEnvironmentTag(event, environment = "java")
nativeSdk -> setEventEnvironmentTag(event, environment = "native")
else -> return
}
sdk?.integrationSet?.forEach { integration ->
it.addIntegration(integration)
}
}

private fun setEventEnvironmentTag(
event: SentryEvent,
origin: String = "android",
environment: String
) {
event.setTag("event.origin", origin)
event.setTag("event.environment", environment)
}

private fun addPackages(event: SentryEvent, sdk: SdkVersion?) {
event.sdk?.let {
if (it.name == flutterSdk) {
sdk?.packageSet?.forEach { sentryPackage ->
it.addPackage(sentryPackage.name, sentryPackage.version)
}
sdk?.integrationSet?.forEach { integration ->
it.addIntegration(integration)
}
}
}
}
Expand Down
12 changes: 10 additions & 2 deletions flutter/example/integration_test/integration_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: avoid_print

import 'dart:async';
import 'dart:convert';

Expand Down Expand Up @@ -160,6 +162,7 @@ void main() {
final uri = Uri.parse(
'https://sentry.io/api/0/projects/$org/$slug/events/$id/',
);
expect(authToken, isNotEmpty);

final event = await fixture.poll(uri, authToken);
expect(event, isNotNull);
Expand Down Expand Up @@ -206,26 +209,31 @@ class Fixture {

const maxRetries = 10;
const initialDelay = Duration(seconds: 2);
const factor = 2;
const delayIncrease = Duration(seconds: 2);

var retries = 0;
var delay = initialDelay;

while (retries < maxRetries) {
try {
print("Trying to fetch $url [try $retries/$maxRetries]");
final response = await client.get(
url,
headers: <String, String>{'Authorization': 'Bearer $authToken'},
);
print("Response status code: ${response.statusCode}");
if (response.statusCode == 200) {
return jsonDecode(utf8.decode(response.bodyBytes));
} else if (response.statusCode == 401) {
print("Cannot fetch $url - invalid auth token.");
break;
}
} catch (e) {
// Do nothing
} finally {
retries++;
await Future.delayed(delay);
delay *= factor;
delay += delayIncrease;
}
}
return null;
Expand Down
13 changes: 1 addition & 12 deletions flutter/example/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
wanted_project_target = '11.0'

# Uncomment this line to define a global platform for your project
platform :ios, wanted_project_target
platform :ios, '11.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down Expand Up @@ -37,15 +35,6 @@ target 'Runner' do
end

post_install do |installer|
# remove after https://github.com/flutter/flutter/issues/124340 getting into all channels
installer.generated_projects.each do |project|
project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = wanted_project_target
end
end
end

installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
Expand Down
5 changes: 5 additions & 0 deletions flutter/ios/Classes/SentryFlutterPluginApple.swift
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ public class SentryFlutterPluginApple: NSObject, FlutterPlugin {
}

private func fetchNativeAppStart(result: @escaping FlutterResult) {
#if os(iOS) || os(tvOS)
guard let appStartMeasurement = PrivateSentrySDKOnly.appStartMeasurement else {
print("warning: appStartMeasurement is null")
result(nil)
Expand All @@ -481,6 +482,10 @@ public class SentryFlutterPluginApple: NSObject, FlutterPlugin {
]

result(item)
#else
print("note: appStartMeasurement not available on this platform")
result(nil)
#endif
}

private var totalFrames: UInt = 0
Expand Down
4 changes: 2 additions & 2 deletions flutter/ios/sentry_flutter.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ Pod::Spec.new do |s|
Sentry SDK for Flutter with support to native through sentry-cocoa.
DESC
s.homepage = 'https://sentry.io'
s.license = { :file => '../LICENSE' }
s.license = { :type => 'MIT', :file => '../LICENSE' }
s.authors = "Sentry"
s.source = { :git => "https://github.com/getsentry/sentry-dart.git",
:tag => s.version.to_s }
s.source_files = 'Classes/**/*'
s.public_header_files = 'Classes/**/*.h'
s.dependency 'Sentry/HybridSDK', '8.9.1'
s.dependency 'Sentry/HybridSDK', '8.10.0'
s.ios.dependency 'Flutter'
s.osx.dependency 'FlutterMacOS'
s.ios.deployment_target = '11.0'
Expand Down

0 comments on commit 891870f

Please sign in to comment.