Skip to content

Commit

Permalink
Merge branch 'main' into feat/baggage-support-spring-rest-template
Browse files Browse the repository at this point in the history
  • Loading branch information
adinauer committed Aug 16, 2022
2 parents d6f1f35 + 7dd32c0 commit b262c15
Show file tree
Hide file tree
Showing 67 changed files with 1,691 additions and 408 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@

## Unreleased

### Fixes

- make profiling rate defaults to 101 hz ([#2211](https://github.com/getsentry/sentry-java/pull/2211))
- SentryOptions.setProfilingTracesIntervalMillis has been deprecated
- Added cpu architecture and default environment in profiles envelope ([#2207](https://github.com/getsentry/sentry-java/pull/2207))
- SentryOptions.setProfilingEnabled has been deprecated in favor of setProfilesSampleRate

### Features

- Send source for transactions ([#2180](https://github.com/getsentry/sentry-java/pull/2180))
- Add profilesSampleRate and profileSampler options for Android sdk ([#2184](https://github.com/getsentry/sentry-java/pull/2184))
- Add baggage header to RestTemplate ([#2206](https://github.com/getsentry/sentry-java/pull/2206))

## 6.3.1
Expand All @@ -15,6 +24,7 @@
- `attach-screenshot` set on Manual init. didn't work ([#2186](https://github.com/getsentry/sentry-java/pull/2186))
- Remove extra space from `spring.factories` causing issues in old versions of Spring Boot ([#2181](https://github.com/getsentry/sentry-java/pull/2181))


### Features

- Bump Native SDK to v0.4.18 ([#2154](https://github.com/getsentry/sentry-java/pull/2154))
Expand Down
2 changes: 2 additions & 0 deletions sentry-android-core/api/sentry-android-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public final class io/sentry/android/core/SentryAndroidOptions : io/sentry/Sentr
public fun enableAllAutoBreadcrumbs (Z)V
public fun getAnrTimeoutIntervalMillis ()J
public fun getDebugImagesLoader ()Lio/sentry/android/core/IDebugImagesLoader;
public fun getProfilingTracesHz ()I
public fun getProfilingTracesIntervalMillis ()I
public fun isAnrEnabled ()Z
public fun isAnrReportInDebug ()Z
Expand Down Expand Up @@ -152,6 +153,7 @@ public final class io/sentry/android/core/SentryAndroidOptions : io/sentry/Sentr
public fun setEnableSystemEventBreadcrumbs (Z)V
public fun setEnableUserInteractionBreadcrumbs (Z)V
public fun setEnableUserInteractionTracing (Z)V
public fun setProfilingTracesHz (I)V
public fun setProfilingTracesIntervalMillis (I)V
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import io.sentry.SentryLevel;
import io.sentry.SentryOptions;
import io.sentry.SpanStatus;
import io.sentry.TransactionContext;
import io.sentry.TransactionOptions;
import io.sentry.protocol.TransactionNameSource;
import io.sentry.util.Objects;
import java.io.Closeable;
import java.io.IOException;
Expand Down Expand Up @@ -152,64 +155,46 @@ private void startTracing(final @NotNull Activity activity) {
// as we allow a single transaction running on the bound Scope, we finish the previous ones
stopPreviousTransactions();

// we can only bind to the scope if there's no running transaction
ITransaction transaction;
final String activityName = getActivityName(activity);

final Date appStartTime =
foregroundImportance ? AppStartState.getInstance().getAppStartTime() : null;
final Boolean coldStart = AppStartState.getInstance().isColdStart();

final TransactionOptions transactionOptions = new TransactionOptions();

transactionOptions.setWaitForChildren(true);
transactionOptions.setTransactionFinishedCallback(
(finishingTransaction) -> {
@Nullable Activity unwrappedActivity = weakActivity.get();
if (unwrappedActivity != null) {
activityFramesTracker.setMetrics(
unwrappedActivity, finishingTransaction.getEventId());
} else {
if (options != null) {
options
.getLogger()
.log(
SentryLevel.WARNING,
"Unable to track activity frames as the Activity %s has been destroyed.",
activityName);
}
}
});

if (!(firstActivityCreated || appStartTime == null || coldStart == null)) {
transactionOptions.setStartTimestamp(appStartTime);
}

// we can only bind to the scope if there's no running transaction
ITransaction transaction =
hub.startTransaction(
new TransactionContext(activityName, TransactionNameSource.COMPONENT, UI_LOAD_OP),
transactionOptions);

// in case appStartTime isn't available, we don't create a span for it.
if (firstActivityCreated || appStartTime == null || coldStart == null) {
transaction =
hub.startTransaction(
activityName,
UI_LOAD_OP,
(Date) null,
true,
(finishingTransaction) -> {
@Nullable Activity unwrappedActivity = weakActivity.get();
if (unwrappedActivity != null) {
activityFramesTracker.setMetrics(
unwrappedActivity, finishingTransaction.getEventId());
} else {
if (options != null) {
options
.getLogger()
.log(
SentryLevel.WARNING,
"Unable to track activity frames as the Activity %s has been destroyed.",
activityName);
}
}
});
} else {
// start transaction with app start timestamp
transaction =
hub.startTransaction(
activityName,
UI_LOAD_OP,
appStartTime,
true,
(finishingTransaction) -> {
@Nullable Activity unwrappedActivity = weakActivity.get();
if (unwrappedActivity != null) {
activityFramesTracker.setMetrics(
unwrappedActivity, finishingTransaction.getEventId());
} else {
if (options != null) {
options
.getLogger()
.log(
SentryLevel.WARNING,
"Unable to track activity frames as the Activity %s has been destroyed.",
activityName);
}
}
});
if (!(firstActivityCreated || appStartTime == null || coldStart == null)) {
// start specific span for app start

appStartSpan =
transaction.startChild(
getAppStartOp(coldStart), getAppStartDesc(coldStart), appStartTime);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.sentry.android.core;

import static android.content.Context.ACTIVITY_SERVICE;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;

import android.annotation.SuppressLint;
import android.app.ActivityManager;
Expand Down Expand Up @@ -81,17 +81,17 @@ private void init() {
"Disabling profiling because no profiling traces dir path is defined in options.");
return;
}
long intervalMillis = options.getProfilingTracesIntervalMillis();
if (intervalMillis <= 0) {
final int intervalHz = options.getProfilingTracesHz();
if (intervalHz <= 0) {
options
.getLogger()
.log(
SentryLevel.WARNING,
"Disabling profiling because trace interval is set to %d milliseconds",
intervalMillis);
"Disabling profiling because trace rate is set to %d",
intervalHz);
return;
}
intervalUs = (int) MILLISECONDS.toMicros(intervalMillis);
intervalUs = (int) SECONDS.toMicros(1) / intervalHz;
traceFilesDir = new File(tracesFilesDirPath);
}

Expand Down Expand Up @@ -227,6 +227,7 @@ public synchronized void onTransactionStart(@NotNull ITransaction transaction) {
if (memInfo != null) {
totalMem = Long.toString(memInfo.totalMem);
}
String[] abis = Build.SUPPORTED_ABIS;

// cpu max frequencies are read with a lambda because reading files is involved, so it will be
// done in the background when the trace file is read
Expand All @@ -235,6 +236,7 @@ public synchronized void onTransactionStart(@NotNull ITransaction transaction) {
transaction,
Long.toString(transactionDurationNanos),
buildInfoProvider.getSdkInfoVersion(),
abis != null && abis.length > 0 ? abis[0] : "",
() -> CpuInfoUtils.getInstance().readMaxFrequencies(),
buildInfoProvider.getManufacturer(),
buildInfoProvider.getModel(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ final class ManifestMetadataReader {
static final String TRACES_UI_ENABLE = "io.sentry.traces.user-interaction.enable";

static final String TRACES_PROFILING_ENABLE = "io.sentry.traces.profiling.enable";
static final String PROFILES_SAMPLE_RATE = "io.sentry.traces.profiling.sample-rate";

@ApiStatus.Experimental static final String TRACE_SAMPLING = "io.sentry.traces.trace-sampling";

Expand All @@ -82,6 +83,7 @@ private ManifestMetadataReader() {}
* @param context the application context
* @param options the SentryAndroidOptions
*/
@SuppressWarnings("deprecation")
static void applyMetadata(
final @NotNull Context context, final @NotNull SentryAndroidOptions options) {
Objects.requireNonNull(context, "The application context is required.");
Expand Down Expand Up @@ -245,6 +247,13 @@ static void applyMetadata(
options.setProfilingEnabled(
readBool(metadata, logger, TRACES_PROFILING_ENABLE, options.isProfilingEnabled()));

if (options.getProfilesSampleRate() == null) {
final Double profilesSampleRate = readDouble(metadata, logger, PROFILES_SAMPLE_RATE);
if (profilesSampleRate != -1) {
options.setProfilesSampleRate(profilesSampleRate);
}
}

options.setEnableUserInteractionTracing(
readBool(metadata, logger, TRACES_UI_ENABLE, options.isEnableUserInteractionTracing()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.sentry.SentryOptions;
import io.sentry.SpanStatus;
import io.sentry.protocol.SdkVersion;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;

/** Sentry SDK options for Android */
Expand Down Expand Up @@ -84,8 +85,12 @@ public final class SentryAndroidOptions extends SentryOptions {
*/
private boolean enableActivityLifecycleTracingAutoFinish = true;

/** Interval for profiling traces in milliseconds. Defaults to 100 times per second */
private int profilingTracesIntervalMillis = 1_000 / 100;
/**
* Profiling traces rate. 101 hz means 101 traces in 1 second. Defaults to 101 to avoid possible
* lockstep sampling. More on
* https://stackoverflow.com/questions/45470758/what-is-lockstep-sampling
*/
private int profilingTracesHz = 101;

/** Enables the Auto instrumentation for user interaction tracing. */
private boolean enableUserInteractionTracing = false;
Expand Down Expand Up @@ -235,18 +240,37 @@ public void enableAllAutoBreadcrumbs(boolean enable) {
* Returns the interval for profiling traces in milliseconds.
*
* @return the interval for profiling traces in milliseconds.
* @deprecated has no effect and will be removed in future versions. It now just returns 0.
*/
@Deprecated
@SuppressWarnings("InlineMeSuggester")
public int getProfilingTracesIntervalMillis() {
return profilingTracesIntervalMillis;
return 0;
}

/**
* Sets the interval for profiling traces in milliseconds.
*
* @param profilingTracesIntervalMillis - the interval for profiling traces in milliseconds.
* @deprecated has no effect and will be removed in future versions.
*/
@Deprecated
public void setProfilingTracesIntervalMillis(final int profilingTracesIntervalMillis) {}

/**
* Returns the rate the profiler will sample rates at. 100 hz means 100 traces in 1 second.
*
* @return Rate the profiler will sample rates at.
*/
public void setProfilingTracesIntervalMillis(final int profilingTracesIntervalMillis) {
this.profilingTracesIntervalMillis = profilingTracesIntervalMillis;
@ApiStatus.Internal
public int getProfilingTracesHz() {
return profilingTracesHz;
}

/** Sets the rate the profiler will sample rates at. 100 hz means 100 traces in 1 second. */
@ApiStatus.Internal
public void setProfilingTracesHz(final int profilingTracesHz) {
this.profilingTracesHz = profilingTracesHz;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
import io.sentry.Scope;
import io.sentry.SentryLevel;
import io.sentry.SpanStatus;
import io.sentry.TransactionContext;
import io.sentry.TransactionOptions;
import io.sentry.android.core.SentryAndroidOptions;
import io.sentry.protocol.TransactionNameSource;
import java.lang.ref.WeakReference;
import java.util.Collections;
import java.util.Map;
Expand Down Expand Up @@ -249,8 +252,15 @@ private void startTracing(final @NotNull View target, final @NotNull String even
// we can only bind to the scope if there's no running transaction
final String name = getActivityName(activity) + "." + viewId;
final String op = UI_ACTION + "." + eventType;

final TransactionOptions transactionOptions = new TransactionOptions();
transactionOptions.setWaitForChildren(true);
transactionOptions.setIdleTimeout(options.getIdleTimeout());
transactionOptions.setTrimEnd(true);

final ITransaction transaction =
hub.startTransaction(name, op, true, options.getIdleTimeout(), true);
hub.startTransaction(
new TransactionContext(name, TransactionNameSource.COMPONENT, op), transactionOptions);

hub.configureScope(
scope -> {
Expand Down

0 comments on commit b262c15

Please sign in to comment.