Skip to content

Commit

Permalink
Merge pull request #2052 from bugsnag/release/v6.6.1
Browse files Browse the repository at this point in the history
Release v6.6.1
  • Loading branch information
YYChen01988 authored Jul 3, 2024
2 parents 6974b07 + 14e492a commit d1d2eee
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 7 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 6.6.1 (2024-07-03)

### Bug fixes

* Allow ReactNative applications to set the `correlation` property on Events
[#2050](https://github.com/bugsnag/bugsnag-android/pull/2050)
* Avoid possible crashes in apps the use custom proguard rules that don't include protection for `Enum.values()`
[#2049](https://github.com/bugsnag/bugsnag-android/pull/2049)

## 6.6.0 (2024-06-19)

### Enhancements
Expand Down
6 changes: 6 additions & 0 deletions bugsnag-android-core/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@
-keep class com.bugsnag.android.BreadcrumbState { *; }
-keep class com.bugsnag.android.BreadcrumbType { *; }
-keep class com.bugsnag.android.Severity { *; }
-keepclassmembers enum com.bugsnag.android.Telemetry {
public static com.bugsnag.android.Telemetry[] values();
}
-keepclassmembers enum com.bugsnag.android.ErrorType {
public static com.bugsnag.android.Telemetry[] values();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import java.io.IOException
*/
class Notifier @JvmOverloads constructor(
var name: String = "Android Bugsnag Notifier",
var version: String = "6.6.0",
var version: String = "6.6.1",
var url: String = "https://bugsnag.com"
) : JsonStream.Streamable {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.bugsnag.android

import java.util.UUID

internal class EventDeserializer(
private val client: Client,
private val projectPackages: Collection<String>
Expand Down Expand Up @@ -86,17 +88,61 @@ internal class EventDeserializer(
metadata.forEach {
event.addMetadata(it.key, it.value as Map<String, Any>)
}

val correlation = map["correlation"] as? Map<String, Any?>
correlation?.let {
deserializeCorrelation(it, event)
}

return event
}

private fun deserializeCorrelation(
correlation: Map<String, Any?>,
event: Event
) {
val traceId = (correlation["traceId"] as? String)
?.takeIf { it.length == TRACE_ID_LENGTH }
?.let {
val mostSigBits = it.substring(0, HEX_LONG_LENGTH).hexToLong()
val leastSigBits = it.substring(HEX_LONG_LENGTH).hexToLong()

if (mostSigBits != null && leastSigBits != null) {
UUID(mostSigBits, leastSigBits)
} else {
null
}
}
val spanId = (correlation["spanId"] as? String)
?.takeIf { it.length == HEX_LONG_LENGTH }
?.hexToLong()

if (traceId != null && spanId != null) {
event.setTraceCorrelation(traceId, spanId)
}
}

private fun getOriginalUnhandled(
map: Map<String, Any>,
unhandled: Boolean
): Boolean {
val unhandledOverridden = map.getOrElse("unhandledOverridden", { false }) as Boolean
val unhandledOverridden = (map.getOrElse("unhandledOverridden") { false }) as Boolean
return when {
unhandledOverridden -> !unhandled
else -> unhandled
}
}

@Suppress("MagicNumber")
private fun String.hexToLong(): Long? {
if (length != HEX_LONG_LENGTH || this[0] == '-' || this[3] == '-') return null
val firstByte = this.substring(0, 2).toLongOrNull(HEX_LONG_LENGTH) ?: return null
val remaining = this.substring(2).toLongOrNull(HEX_LONG_LENGTH) ?: return null
return (firstByte shl 56) or remaining
}

companion object {
private const val TRACE_ID_LENGTH = 32
private const val HEX_LONG_LENGTH = 16
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.mockito.Mock
import org.mockito.Mockito.`when`
import org.mockito.junit.MockitoJUnitRunner
import java.util.Date
import java.util.UUID

@RunWith(MockitoJUnitRunner::class)
class EventDeserializerTest {
Expand Down Expand Up @@ -39,6 +40,10 @@ class EventDeserializerTest {
map["app"] = mapOf(Pair("id", "app-id"))
map["device"] =
mapOf(Pair("id", "device-id"), Pair("runtimeVersions", mutableMapOf<String, Any>()))
map["correlation"] = mapOf(
"traceId" to "b39e53513eec3c68b5e5c34dc43611e0",
"spanId" to "51d886b3a693a406"
)

`when`(client.config).thenReturn(TestData.generateConfig())
`when`(client.getLogger()).thenReturn(object : Logger {})
Expand Down Expand Up @@ -91,6 +96,13 @@ class EventDeserializerTest {
assertEquals("device-id", event.device.id)
assertEquals("123", event.getMetadata("custom", "id"))
assertEquals(TestData.generateConfig().apiKey, event.apiKey)

assertEquals(
UUID(-5503870086187041688L, -5339647044406079008L),
TestHooks.getCorrelatedTraceId(event)
)

assertEquals(5897611818193626118L, TestHooks.getCorrelatedSpanId(event))
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
package com.bugsnag.android;

import androidx.annotation.Nullable;

import java.util.UUID;

class TestHooks {
static boolean getUnhandledOverridden(Event event) {
return event.getImpl().getUnhandledOverridden();
}

@Nullable
static UUID getCorrelatedTraceId(Event event) {
TraceCorrelation traceCorrelation = event.getImpl().getTraceCorrelation();
return traceCorrelation != null ? traceCorrelation.getTraceId() : null;
}

@Nullable
static Long getCorrelatedSpanId(Event event) {
TraceCorrelation traceCorrelation = event.getImpl().getTraceCorrelation();
return traceCorrelation != null ? traceCorrelation.getSpanId() : null;
}

static MetadataState generateMetadataState() {
return new MetadataState();
}
Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/Dockerfile.android-publisher
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ WORKDIR /app
# Copy gradle files
COPY gradlew gradle.properties /app/
COPY gradle/ /app/gradle/
COPY build.gradle settings.gradle /app/
COPY build.gradle settings.gradle.kts /app/
COPY buildSrc/ buildSrc/

# Copy sdk source files
Expand Down
4 changes: 2 additions & 2 deletions examples/sdk-app-example/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ android {
}

dependencies {
implementation "com.bugsnag:bugsnag-android:6.6.0"
implementation "com.bugsnag:bugsnag-plugin-android-okhttp:6.6.0"
implementation "com.bugsnag:bugsnag-android:6.6.1"
implementation "com.bugsnag:bugsnag-plugin-android-okhttp:6.6.1"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "androidx.appcompat:appcompat:1.6.1"
implementation "com.google.android.material:material:1.11.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ internal class OomScenario(
context: Context,
eventMetadata: String
) : Scenario(config, context, eventMetadata) {

private val queue = LinkedList<Array<String>>()

init {
config.enabledErrorTypes.anrs = false
}

override fun startScenario() {
super.startScenario()
while (true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public UnhandledJavaLoadedConfigScenario(@NonNull Configuration config,
@NonNull Context context,
@Nullable String eventMetadata) {
super(config, context, eventMetadata);
config.getEnabledErrorTypes().setAnrs(false);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ org.gradle.jvmargs=-Xmx4096m
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
org.gradle.parallel=true
VERSION_NAME=6.6.0
VERSION_NAME=6.6.1
GROUP=com.bugsnag
POM_SCM_URL=https://github.com/bugsnag/bugsnag-android
POM_SCM_CONNECTION=scm:[email protected]:bugsnag/bugsnag-android.git
Expand Down

0 comments on commit d1d2eee

Please sign in to comment.