Skip to content

Commit

Permalink
Merge branch 'main' into feat/compose-tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
markushi committed Feb 9, 2023
2 parents 78c7345 + fe30606 commit b8689b2
Show file tree
Hide file tree
Showing 56 changed files with 675 additions and 299 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/integration-tests-benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ jobs:
- name: Run All Tests in SauceLab
uses: saucelabs/saucectl-run-action@889cc2382b05b47e4a78bd35516603acc6c15fad # pin@v2
if: github.event_name != 'pull_request' && env.SAUCE_USERNAME != null
env:
GITHUB_TOKEN: ${{ github.token }}
with:
sauce-username: ${{ secrets.SAUCE_USERNAME }}
sauce-access-key: ${{ secrets.SAUCE_ACCESS_KEY }}
Expand All @@ -50,6 +52,8 @@ jobs:
- name: Run one test in SauceLab
uses: saucelabs/saucectl-run-action@889cc2382b05b47e4a78bd35516603acc6c15fad # pin@v2
if: github.event_name == 'pull_request' && env.SAUCE_USERNAME != null
env:
GITHUB_TOKEN: ${{ github.token }}
with:
sauce-username: ${{ secrets.SAUCE_USERNAME }}
sauce-access-key: ${{ secrets.SAUCE_ACCESS_KEY }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/integration-tests-ui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ jobs:

- name: Run Tests in SauceLab
uses: saucelabs/saucectl-run-action@889cc2382b05b47e4a78bd35516603acc6c15fad # pin@v2
env:
GITHUB_TOKEN: ${{ github.token }}
with:
sauce-username: ${{ secrets.SAUCE_USERNAME }}
sauce-access-key: ${{ secrets.SAUCE_ACCESS_KEY }}
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@

### Features

- Add `main` flag to threads and `in_foreground` flag for app contexts ([#2516](https://github.com/getsentry/sentry-java/pull/2516))
- Add capabilities to track Jetpack Compose composition/rendering time ([#2507](https://github.com/getsentry/sentry-java/pull/2507))

### Fixes

- Ignore Shutdown in progress when closing ShutdownHookIntegration ([#2521](https://github.com/getsentry/sentry-java/pull/2521))
- Fix app start span end-time is wrong if SDK init is deferred ([#2519](https://github.com/getsentry/sentry-java/pull/2519))

## 6.13.1

### Fixes

- Fix transaction performance collector oom ([#2505](https://github.com/getsentry/sentry-java/pull/2505))
- Remove authority from URLs sent to Sentry ([#2366](https://github.com/getsentry/sentry-java/pull/2366))
- Fix `sentry-bom` containing incorrect artifacts ([#2504](https://github.com/getsentry/sentry-java/pull/2504))

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ android.useAndroidX=true
android.defaults.buildfeatures.buildconfig=true

# Release information
versionName=6.13.0
versionName=6.13.1

# Override the SDK name on native crashes on Android
sentryAndroidSdkName=sentry.native.android
Expand Down
5 changes: 3 additions & 2 deletions sentry-android-core/api/sentry-android-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public final class io/sentry/android/core/ActivityLifecycleIntegration : android

public final class io/sentry/android/core/AndroidCpuCollector : io/sentry/ICollector {
public fun <init> (Lio/sentry/ILogger;Lio/sentry/android/core/BuildInfoProvider;)V
public fun collect (Ljava/lang/Iterable;)V
public fun collect (Lio/sentry/PerformanceCollectionData;)V
public fun setup ()V
}

Expand All @@ -45,7 +45,7 @@ public final class io/sentry/android/core/AndroidLogger : io/sentry/ILogger {

public class io/sentry/android/core/AndroidMemoryCollector : io/sentry/ICollector {
public fun <init> ()V
public fun collect (Ljava/lang/Iterable;)V
public fun collect (Lio/sentry/PerformanceCollectionData;)V
public fun setup ()V
}

Expand All @@ -71,6 +71,7 @@ public final class io/sentry/android/core/AppLifecycleIntegration : io/sentry/In
}

public final class io/sentry/android/core/AppStartState {
public fun getAppStartEndTime ()Lio/sentry/SentryDate;
public fun getAppStartInterval ()Ljava/lang/Long;
public fun getAppStartMillis ()Ljava/lang/Long;
public fun getAppStartTime ()Lio/sentry/SentryDate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ public final class ActivityLifecycleIntegration
private boolean isAllActivityCallbacksAvailable;

private boolean firstActivityCreated = false;
private boolean firstActivityResumed = false;
private boolean foregroundImportance = false;
private final boolean foregroundImportance;

private @Nullable ISpan appStartSpan;
private final @NotNull WeakHashMap<Activity, ISpan> ttidSpanMap = new WeakHashMap<>();
Expand Down Expand Up @@ -210,6 +209,11 @@ private void startTracing(final @NotNull Activity activity) {
getAppStartDesc(coldStart),
appStartTime,
Instrumenter.SENTRY);

// in case there's already an end time (e.g. due to deferred SDK init)
// we can finish the app-start span
finishAppStartSpan();

// The first activity ttidSpan should start at the same time as the app start time
ttidSpanMap.put(
activity,
Expand Down Expand Up @@ -328,28 +332,17 @@ public synchronized void onActivityStarted(final @NotNull Activity activity) {
@SuppressLint("NewApi")
@Override
public synchronized void onActivityResumed(final @NotNull Activity activity) {
if (!firstActivityResumed) {

// we only finish the app start if the process is of foregroundImportance
if (foregroundImportance) {
// sets App start as finished when the very first activity calls onResume
AppStartState.getInstance().setAppStartEnd();
} else {
if (options != null) {
options
.getLogger()
.log(
SentryLevel.DEBUG,
"App Start won't be reported because Process wasn't of foregroundImportance.");
}
}

// finishes app start span
if (performanceEnabled && appStartSpan != null) {
appStartSpan.finish();
}
firstActivityResumed = true;
// app start span
@Nullable final SentryDate appStartStartTime = AppStartState.getInstance().getAppStartTime();
@Nullable final SentryDate appStartEndTime = AppStartState.getInstance().getAppStartEndTime();
// in case the SentryPerformanceProvider is disabled it does not set the app start times,
// and we need to set the end time manually here,
// the start time gets set manually in SentryAndroid.init()
if (appStartStartTime != null && appStartEndTime == null) {
AppStartState.getInstance().setAppStartEnd();
}
finishAppStartSpan();

final ISpan ttidSpan = ttidSpanMap.get(activity);
final View rootView = activity.findViewById(android.R.id.content);
Expand Down Expand Up @@ -507,4 +500,17 @@ private void setColdStart(final @Nullable Bundle savedInstanceState) {
return APP_START_WARM;
}
}

private void finishAppStartSpan() {
final @Nullable SentryDate appStartEndTime = AppStartState.getInstance().getAppStartEndTime();
if (appStartSpan != null
&& !appStartSpan.isFinished()
&& performanceEnabled
&& appStartEndTime != null) {

final SpanStatus status =
appStartSpan.getStatus() != null ? appStartSpan.getStatus() : SpanStatus.OK;
appStartSpan.finish(status, appStartEndTime);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ public void setup() {

@SuppressLint("NewApi")
@Override
public void collect(
@NotNull final Iterable<PerformanceCollectionData> performanceCollectionData) {
public void collect(final @NotNull PerformanceCollectionData performanceCollectionData) {
if (buildInfoProvider.getSdkInfoVersion() < Build.VERSION_CODES.LOLLIPOP || !isEnabled) {
return;
}
Expand All @@ -86,9 +85,7 @@ public void collect(
new CpuCollectionData(
System.currentTimeMillis(), (cpuUsagePercentage / (double) numCores) * 100.0);

for (PerformanceCollectionData data : performanceCollectionData) {
data.addCpuData(cpuData);
}
performanceCollectionData.addCpuData(cpuData);
}

/** Read the /proc/self/stat file and parses the result. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ public class AndroidMemoryCollector implements ICollector {
public void setup() {}

@Override
public void collect(@NotNull Iterable<PerformanceCollectionData> performanceCollectionData) {
public void collect(final @NotNull PerformanceCollectionData performanceCollectionData) {
long now = System.currentTimeMillis();
long usedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
long usedNativeMemory = Debug.getNativeHeapSize() - Debug.getNativeHeapFreeSize();
MemoryCollectionData memoryData = new MemoryCollectionData(now, usedMemory, usedNativeMemory);
for (PerformanceCollectionData data : performanceCollectionData) {
data.addMemoryData(memoryData);
}
performanceCollectionData.addMemoryData(memoryData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.content.pm.PackageInfo;
import android.content.res.AssetManager;
import android.os.Build;
import io.sentry.DefaultTransactionPerformanceCollector;
import io.sentry.ILogger;
import io.sentry.SendFireAndForgetEnvelopeSender;
import io.sentry.SendFireAndForgetOutboxSender;
Expand Down Expand Up @@ -168,6 +169,7 @@ static void initializeIntegrationsAndProcessors(
options.addCollector(new AndroidMemoryCollector());
options.addCollector(new AndroidCpuCollector(options.getLogger(), buildInfoProvider));
}
options.setTransactionPerformanceCollector(new DefaultTransactionPerformanceCollector(options));
}

private static void installDefaultIntegrations(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public void onFrameMetricCollected(
@Override
public @Nullable synchronized ProfilingTraceData onTransactionFinish(
final @NotNull ITransaction transaction,
final @Nullable PerformanceCollectionData performanceCollectionData) {
final @Nullable List<PerformanceCollectionData> performanceCollectionData) {
try {
return options
.getExecutorService()
Expand All @@ -269,7 +269,7 @@ public void onFrameMetricCollected(
private @Nullable ProfilingTraceData onTransactionFinish(
final @NotNull ITransaction transaction,
final boolean isTimeout,
final @Nullable PerformanceCollectionData performanceCollectionData) {
final @Nullable List<PerformanceCollectionData> performanceCollectionData) {

// onTransactionStart() is only available since Lollipop
// and SystemClock.elapsedRealtimeNanos() since Jelly Bean
Expand Down Expand Up @@ -416,28 +416,32 @@ public void onFrameMetricCollected(
}

private void putPerformanceCollectionDataInMeasurements(
final @Nullable PerformanceCollectionData performanceCollectionData) {
final @Nullable List<PerformanceCollectionData> performanceCollectionData) {
if (performanceCollectionData != null) {
final @NotNull ArrayDeque<ProfileMeasurementValue> memoryUsageMeasurements =
new ArrayDeque<>();
new ArrayDeque<>(performanceCollectionData.size());
final @NotNull ArrayDeque<ProfileMeasurementValue> nativeMemoryUsageMeasurements =
new ArrayDeque<>();
final @NotNull ArrayDeque<ProfileMeasurementValue> cpuUsageMeasurements = new ArrayDeque<>();
for (CpuCollectionData cpuData : performanceCollectionData.getCpuData()) {
cpuUsageMeasurements.add(
new ProfileMeasurementValue(
TimeUnit.MILLISECONDS.toNanos(cpuData.getTimestampMillis()) - transactionStartNanos,
cpuData.getCpuUsagePercentage()));
}
for (MemoryCollectionData memoryData : performanceCollectionData.getMemoryData()) {
if (memoryData.getUsedHeapMemory() > -1) {
new ArrayDeque<>(performanceCollectionData.size());
final @NotNull ArrayDeque<ProfileMeasurementValue> cpuUsageMeasurements =
new ArrayDeque<>(performanceCollectionData.size());
for (PerformanceCollectionData performanceData : performanceCollectionData) {
CpuCollectionData cpuData = performanceData.getCpuData();
MemoryCollectionData memoryData = performanceData.getMemoryData();
if (cpuData != null) {
cpuUsageMeasurements.add(
new ProfileMeasurementValue(
TimeUnit.MILLISECONDS.toNanos(cpuData.getTimestampMillis())
- transactionStartNanos,
cpuData.getCpuUsagePercentage()));
}
if (memoryData != null && memoryData.getUsedHeapMemory() > -1) {
memoryUsageMeasurements.add(
new ProfileMeasurementValue(
TimeUnit.MILLISECONDS.toNanos(memoryData.getTimestampMillis())
- transactionStartNanos,
memoryData.getUsedHeapMemory()));
}
if (memoryData.getUsedNativeMemory() > -1) {
if (memoryData != null && memoryData.getUsedNativeMemory() > -1) {
nativeMemoryUsageMeasurements.add(
new ProfileMeasurementValue(
TimeUnit.MILLISECONDS.toNanos(memoryData.getTimestampMillis())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.sentry.android.core;

import android.os.SystemClock;
import io.sentry.DateUtils;
import io.sentry.SentryDate;
import io.sentry.SentryLongDate;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -84,6 +86,20 @@ public SentryDate getAppStartTime() {
return appStartTime;
}

@Nullable
public SentryDate getAppStartEndTime() {
@Nullable final SentryDate start = getAppStartTime();
if (start != null) {
@Nullable final Long durationMillis = getAppStartInterval();
if (durationMillis != null) {
final long startNanos = start.nanoTimestamp();
final long endNanos = startNanos + DateUtils.millisToNanos(durationMillis);
return new SentryLongDate(endNanos);
}
}
return null;
}

@Nullable
public Long getAppStartMillis() {
return appStartMillis;
Expand Down
Loading

0 comments on commit b8689b2

Please sign in to comment.