Skip to content

Commit ed5f897

Browse files
committed
Merge branch 'main' into feat/timber-sentry-logs
# Conflicts: # CHANGELOG.md # sentry-android-core/src/main/java/io/sentry/android/core/SentryLogcatAdapter.java # sentry-android-core/src/test/java/io/sentry/android/core/SentryLogcatAdapterTest.kt
2 parents 86007fb + bc15877 commit ed5f897

File tree

9 files changed

+87
-25
lines changed

9 files changed

+87
-25
lines changed

CHANGELOG.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,17 @@
88
- Enable the Logs feature in your `SentryOptions` or with the `io.sentry.logs.enabled` manifest option and the SDK will automatically send Timber logs to Sentry, if the TimberIntegration is enabled.
99
- The SDK will automatically detect Timber and use it to send logs to Sentry.
1010
- Send logcat through Sentry Logs ([#4487](https://github.com/getsentry/sentry-java/pull/4487))
11-
- Enable the Logs feature in your `SentryOptions` or with the `io.sentry.logs.enabled` manifest option and the SDK will automatically send logcat logs to Sentry, if the Sentry Android Gradle plugin is applied.
12-
- To set the logcat level check the [Logcat integration documentation](https://docs.sentry.io/platforms/android/integrations/logcat/#configure).
11+
- Enable the Logs feature in your `SentryOptions` or with the `io.sentry.logs.enabled` manifest option and the SDK will automatically send logcat logs to Sentry, if the Sentry Android Gradle plugin is applied.
12+
- To set the logcat level check the [Logcat integration documentation](https://docs.sentry.io/platforms/android/integrations/logcat/#configure).
13+
14+
## 8.16.1-alpha.2
15+
16+
### Fixes
17+
1318
- Optimize scope when maxBreadcrumb is 0 ([#4504](https://github.com/getsentry/sentry-java/pull/4504))
1419
- Fix javadoc on TransportResult ([#4528](https://github.com/getsentry/sentry-java/pull/4528))
20+
- Session Replay: Fix `IllegalArgumentException` when `Bitmap` is initialized with non-positive values ([#4536](https://github.com/getsentry/sentry-java/pull/4536))
21+
- Set thread information on transaction from OpenTelemetry attributes ([#4478](https://github.com/getsentry/sentry-java/pull/4478))
1522

1623
### Internal
1724

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled
1111
android.useAndroidX=true
1212

1313
# Release information
14-
versionName=8.16.0
14+
versionName=8.16.1-alpha.2
1515

1616
# Override the SDK name on native crashes on Android
1717
sentryAndroidSdkName=sentry.native.android

sentry-android-core/src/main/java/io/sentry/android/core/SentryLogcatAdapter.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import io.sentry.Sentry;
77
import io.sentry.SentryLevel;
88
import io.sentry.SentryLogLevel;
9-
import java.io.PrintWriter;
10-
import java.io.StringWriter;
119
import org.jetbrains.annotations.ApiStatus;
1210
import org.jetbrains.annotations.NotNull;
1311
import org.jetbrains.annotations.Nullable;
@@ -57,15 +55,11 @@ private static void addAsLog(
5755
if (!scopes.getOptions().getLogs().isEnabled()) {
5856
return;
5957
}
60-
if (tr == null) {
58+
final @Nullable String trMessage = tr != null ? tr.getMessage() : null;
59+
if (tr == null || trMessage == null) {
6160
scopes.logger().log(level, msg);
6261
} else {
63-
StringWriter sw = new StringWriter(256);
64-
PrintWriter pw = new PrintWriter(sw, false);
65-
tr.printStackTrace(pw);
66-
pw.flush();
67-
scopes.logger().log(level, msg != null ? (msg + "\n" + sw.toString()) : sw.toString());
68-
pw.close();
62+
scopes.logger().log(level, msg != null ? (msg + "\n" + trMessage) : trMessage);
6963
}
7064
}
7165

sentry-android-core/src/test/java/io/sentry/android/core/SentryLogcatAdapterTest.kt

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class SentryLogcatAdapterTest {
113113
fixture.breadcrumbs.first().assert(tag, "$commonMsg error exception", SentryLevel.ERROR)
114114
fixture.logs
115115
.first()
116-
.assert("$commonMsg error exception\n${throwable.stackTraceToString()}", SentryLogLevel.ERROR)
116+
.assert("$commonMsg error exception\n${throwable.message}", SentryLogLevel.ERROR)
117117
}
118118

119119
@Test
@@ -123,10 +123,7 @@ class SentryLogcatAdapterTest {
123123
fixture.breadcrumbs.first().assert(tag, "$commonMsg verbose exception", SentryLevel.DEBUG)
124124
fixture.logs
125125
.first()
126-
.assert(
127-
"$commonMsg verbose exception\n${throwable.stackTraceToString()}",
128-
SentryLogLevel.TRACE,
129-
)
126+
.assert("$commonMsg verbose exception\n${throwable.message}", SentryLogLevel.TRACE)
130127
}
131128

132129
@Test
@@ -136,7 +133,7 @@ class SentryLogcatAdapterTest {
136133
fixture.breadcrumbs.first().assert(tag, "$commonMsg info exception", SentryLevel.INFO)
137134
fixture.logs
138135
.first()
139-
.assert("$commonMsg info exception\n${throwable.stackTraceToString()}", SentryLogLevel.INFO)
136+
.assert("$commonMsg info exception\n${throwable.message}", SentryLogLevel.INFO)
140137
}
141138

142139
@Test
@@ -146,7 +143,7 @@ class SentryLogcatAdapterTest {
146143
fixture.breadcrumbs.first().assert(tag, "$commonMsg debug exception", SentryLevel.DEBUG)
147144
fixture.logs
148145
.first()
149-
.assert("$commonMsg debug exception\n${throwable.stackTraceToString()}", SentryLogLevel.DEBUG)
146+
.assert("$commonMsg debug exception\n${throwable.message}", SentryLogLevel.DEBUG)
150147
}
151148

152149
@Test
@@ -156,10 +153,7 @@ class SentryLogcatAdapterTest {
156153
fixture.breadcrumbs.first().assert(tag, "$commonMsg warning exception", SentryLevel.WARNING)
157154
fixture.logs
158155
.first()
159-
.assert(
160-
"$commonMsg warning exception\n${throwable.stackTraceToString()}",
161-
SentryLogLevel.WARN,
162-
)
156+
.assert("$commonMsg warning exception\n${throwable.message}", SentryLogLevel.WARN)
163157
}
164158

165159
@Test
@@ -169,7 +163,7 @@ class SentryLogcatAdapterTest {
169163
fixture.breadcrumbs.first().assert(tag, "$commonMsg wtf exception", SentryLevel.ERROR)
170164
fixture.logs
171165
.first()
172-
.assert("$commonMsg wtf exception\n${throwable.stackTraceToString()}", SentryLogLevel.FATAL)
166+
.assert("$commonMsg wtf exception\n${throwable.message}", SentryLogLevel.FATAL)
173167
}
174168

175169
@Test

sentry-android-replay/src/main/java/io/sentry/android/replay/util/Views.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,4 +245,4 @@ internal fun View?.removeOnPreDrawListenerSafe(listener: ViewTreeObserver.OnPreD
245245
}
246246
}
247247

248-
internal fun View.hasSize(): Boolean = width != 0 && height != 0
248+
internal fun View.hasSize(): Boolean = width > 0 && height > 0
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package io.sentry.android.replay.util
2+
3+
import android.view.View
4+
import androidx.test.core.app.ApplicationProvider
5+
import androidx.test.ext.junit.runners.AndroidJUnit4
6+
import kotlin.test.Test
7+
import kotlin.test.assertFalse
8+
import kotlin.test.assertTrue
9+
import org.junit.runner.RunWith
10+
11+
@RunWith(AndroidJUnit4::class)
12+
class ViewsTest {
13+
@Test
14+
fun `hasSize returns true for positive values`() {
15+
val view = View(ApplicationProvider.getApplicationContext())
16+
view.right = 100
17+
view.bottom = 100
18+
assertTrue(view.hasSize())
19+
}
20+
21+
@Test
22+
fun `hasSize returns false for null values`() {
23+
val view = View(ApplicationProvider.getApplicationContext())
24+
view.right = 0
25+
view.bottom = 0
26+
assertFalse(view.hasSize())
27+
}
28+
29+
@Test
30+
fun `hasSize returns false for negative values`() {
31+
val view = View(ApplicationProvider.getApplicationContext())
32+
view.right = -1
33+
view.bottom = -1
34+
assertFalse(view.hasSize())
35+
}
36+
}

sentry-opentelemetry/sentry-opentelemetry-core/api/sentry-opentelemetry-core.api

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ public final class io/sentry/opentelemetry/OtelSpanInfo {
5050
public fun getTransactionNameSource ()Lio/sentry/protocol/TransactionNameSource;
5151
}
5252

53+
public final class io/sentry/opentelemetry/OtelSpanUtils {
54+
public fun <init> ()V
55+
public static fun maybeTransferOtelAttribute (Lio/opentelemetry/sdk/trace/data/SpanData;Lio/sentry/ISpan;Lio/opentelemetry/api/common/AttributeKey;)V
56+
}
57+
5358
public final class io/sentry/opentelemetry/OtelSpanWrapper : io/sentry/opentelemetry/IOtelSpanWrapper {
5459
public fun <init> (Lio/opentelemetry/sdk/trace/ReadWriteSpan;Lio/sentry/IScopes;Lio/sentry/SentryDate;Lio/sentry/TracesSamplingDecision;Lio/sentry/opentelemetry/IOtelSpanWrapper;Lio/sentry/SpanId;Lio/sentry/Baggage;)V
5560
public fun finish ()V
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package io.sentry.opentelemetry;
2+
3+
import io.opentelemetry.api.common.AttributeKey;
4+
import io.opentelemetry.api.common.Attributes;
5+
import io.opentelemetry.sdk.trace.data.SpanData;
6+
import io.sentry.ISpan;
7+
import org.jetbrains.annotations.NotNull;
8+
import org.jetbrains.annotations.Nullable;
9+
10+
public final class OtelSpanUtils {
11+
public static <T> void maybeTransferOtelAttribute(
12+
final @NotNull SpanData otelSpan,
13+
final @NotNull ISpan sentrySpan,
14+
final @NotNull AttributeKey<T> key) {
15+
final @NotNull Attributes attributes = otelSpan.getAttributes();
16+
final @Nullable T value = attributes.get(key);
17+
if (value != null) {
18+
sentrySpan.setData(key.getKey(), value);
19+
}
20+
}
21+
}

sentry-opentelemetry/sentry-opentelemetry-core/src/main/java/io/sentry/opentelemetry/SentrySpanExporter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static io.sentry.TransactionContext.DEFAULT_TRANSACTION_NAME;
44
import static io.sentry.opentelemetry.InternalSemanticAttributes.IS_REMOTE_PARENT;
55
import static io.sentry.opentelemetry.OtelInternalSpanDetectionUtil.isSentryRequest;
6+
import static io.sentry.opentelemetry.OtelSpanUtils.maybeTransferOtelAttribute;
67

78
import io.opentelemetry.api.common.Attributes;
89
import io.opentelemetry.api.trace.StatusCode;
@@ -12,6 +13,7 @@
1213
import io.opentelemetry.sdk.trace.export.SpanExporter;
1314
import io.opentelemetry.semconv.HttpAttributes;
1415
import io.opentelemetry.semconv.incubating.ProcessIncubatingAttributes;
16+
import io.opentelemetry.semconv.incubating.ThreadIncubatingAttributes;
1517
import io.sentry.Baggage;
1618
import io.sentry.DateUtils;
1719
import io.sentry.DefaultSpanFactory;
@@ -340,6 +342,9 @@ private void transferSpanDetails(
340342
setOtelSpanKind(span, sentryTransaction);
341343
transferSpanDetails(sentrySpanMaybe, sentryTransaction);
342344

345+
maybeTransferOtelAttribute(span, sentryTransaction, ThreadIncubatingAttributes.THREAD_ID);
346+
maybeTransferOtelAttribute(span, sentryTransaction, ThreadIncubatingAttributes.THREAD_NAME);
347+
343348
scopesToUse.configureScope(
344349
ScopeType.CURRENT,
345350
scope -> attributesExtractor.extract(span, scope, scopesToUse.getOptions()));

0 commit comments

Comments
 (0)