Skip to content

Commit

Permalink
Merge branch 'main' into fix/processor-transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto authored Apr 24, 2021
2 parents 7771ba4 + 6c8aae1 commit 3e9d3bd
Show file tree
Hide file tree
Showing 21 changed files with 214 additions and 67 deletions.
28 changes: 0 additions & 28 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,31 +66,3 @@ jobs:
uses: codecov/codecov-action@v1
with:
name: sentry-java

release:
## Only run on a release branch
if: github.event_name == 'push' && contains(github.ref, 'refs/heads/release')
needs: [build]
name: Release
runs-on: ubuntu-latest
steps:
- name: Download packages
uses: actions/download-artifact@v2
with:
name: artifacts
path: ./*/build/distributions/*.zip

- uses: actions/setup-node@v1

- name: Install Zeus
run: |
yarn global add @zeus-ci/cli
echo "::add-path::$(yarn global bin)"
- name: Upload to Zeus
env:
ZEUS_API_TOKEN: ${{ secrets.ZEUS_TOKEN }}
ZEUS_HOOK_BASE: ${{ secrets.ZEUS_HOOK_BASE }}
run: |
zeus job update -b $GITHUB_RUN_ID -j $GITHUB_RUN_NUMBER -r $GITHUB_SHA
zeus upload -b $GITHUB_RUN_ID -j $GITHUB_RUN_NUMBER -t "application/zip+maven" *.zip
zeus job update --status=passed -b $GITHUB_RUN_ID -j $GITHUB_RUN_NUMBER -r $GITHUB_SHA
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
* Fix: set correct transaction status for unhandled exceptions in SentryTracingFilter (#1406)
* Fix: handle network errors in SentrySpanClientHttpRequestInterceptor (#1407)
* Fix: set scope on transaction (#1409)
* Fix: set status and associate events with transactions (#1426)
* Fix: Do not set free memory and is low memory fields when it's a NDK hard crash (#1399)
* Fix: Apply user from the scope to transaction (#1424)
* Fix: Pass maxBreadcrumbs config. to sentry-native (#1425)
* Fix: Run event processors and enrich transactions with contexts (#1430)
* Bump: sentry-native to 0.4.9 (#1431)

# 4.4.0-alpha.2

Expand Down
2 changes: 1 addition & 1 deletion sentry-android-ndk/sentry-native
Submodule sentry-native updated 63 files
+5 −0 .github/workflows/ci.yml
+36 −0 CHANGELOG.md
+16 −6 CMakeLists.txt
+4 −3 README.md
+8 −15 examples/example.c
+1 −1 external/breakpad
+1 −1 external/crashpad
+1 −0 fuzzing-examples/macos-event.json
+1 −0 fuzzing-examples/macos-session.json
+95 −11 include/sentry.h
+11 −2 src/backends/sentry_backend_crashpad.cpp
+6 −23 src/backends/sentry_backend_inproc.c
+220 −185 src/modulefinder/sentry_modulefinder_linux.c
+31 −12 src/modulefinder/sentry_modulefinder_linux.h
+1 −1 src/path/sentry_path_unix.c
+12 −14 src/sentry_backend.h
+4 −0 src/sentry_boot.h
+9 −3 src/sentry_core.c
+0 −5 src/sentry_core.h
+1 −1 src/sentry_database.c
+22 −9 src/sentry_envelope.c
+38 −57 src/sentry_json.c
+6 −3 src/sentry_json.h
+7 −8 src/sentry_scope.c
+2 −1 src/sentry_scope.h
+1 −0 src/sentry_sync.c
+18 −0 src/sentry_sync.h
+26 −7 src/sentry_utils.c
+23 −0 src/sentry_utils.h
+120 −20 src/sentry_value.c
+8 −0 src/sentry_value.h
+6 −2 src/transports/sentry_transport_curl.c
+13 −8 src/unwinder/sentry_unwinder_libbacktrace.c
+9 −1 tests/__init__.py
+3 −4 tests/assertions.py
+4 −1 tests/cmake.py
+1 −0 tests/fuzzing-failures/id-000000,sig-06,src-000560,op-havoc,rep-2
+ tests/fuzzing-failures/id-000000,sig-11,src-000033+000005,op-splice,rep-16
+ tests/fuzzing-failures/id-000000,sig-11,src-000320,op-havoc,rep-2
+ tests/fuzzing-failures/id-000000,sig-11,src-000494+000073,op-splice,rep-8
+ tests/fuzzing-failures/id-000001,sig-11,src-000052+000222,op-splice,rep-32
+1 −0 tests/fuzzing-failures/id-000001,sig-11,src-000215+000415,op-splice,rep-16
+1 −0 tests/fuzzing-failures/id-000002,sig-11,src-000339+000110,op-splice,rep-16
+ tests/fuzzing-failures/id-000002,sig-11,src-000447+000419,op-splice,rep-32
+ tests/fuzzing-failures/id-000003,sig-11,src-000399+000468,op-splice,rep-32
+ tests/fuzzing-failures/id-000004,sig-11,src-000440+000369,op-splice,rep-2
+3 −2 tests/test_integration_http.py
+2 −0 tests/unit/.gitattributes
+22 −0 tests/unit/CMakeLists.txt
+77 −0 tests/unit/fuzz.c
+1 −1 tests/unit/test_attachments.c
+2 −2 tests/unit/test_basic.c
+5 −5 tests/unit/test_consent.c
+1 −1 tests/unit/test_envelopes.c
+66 −0 tests/unit/test_fuzzfailures.c
+2 −2 tests/unit/test_logger.c
+59 −29 tests/unit/test_modulefinder.c
+3 −1 tests/unit/test_mpack.c
+2 −2 tests/unit/test_session.c
+4 −4 tests/unit/test_uninit.c
+49 −1 tests/unit/test_value.c
+3 −0 tests/unit/tests.inc
+29 −0 tests/valgrind.txt
2 changes: 1 addition & 1 deletion sentry-android-ndk/src/main/jni/sentry.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,5 +398,5 @@ Java_io_sentry_android_ndk_NativeModuleListLoader_nativeLoadModuleList(JNIEnv *e

JNIEXPORT void JNICALL
Java_io_sentry_android_ndk_SentryNdk_shutdown(JNIEnv *env, jclass cls) {
sentry_shutdown();
sentry_close();
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:theme="@style/AppTheme"
android:allowNativeHeapPointerTagging="false"
android:extractNativeLibs="true"
tools:ignore="GoogleAppIndexingWarning, UnusedAttribute">

<activity android:name=".MainActivity">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.jakewharton.nopen.annotation.Open;
import io.sentry.IHub;
import io.sentry.ITransaction;
import io.sentry.SpanStatus;
import io.sentry.util.Objects;
import java.lang.reflect.Method;
import org.aopalliance.intercept.MethodInterceptor;
Expand Down Expand Up @@ -59,7 +60,13 @@ public Object invoke(final @NotNull MethodInvocation invocation) throws Throwabl
hub.pushScope();
final ITransaction transaction = hub.startTransaction(name, operation, true);
try {
return invocation.proceed();
final Object result = invocation.proceed();
transaction.setStatus(SpanStatus.OK);
return result;
} catch (Exception e) {
transaction.setStatus(SpanStatus.INTERNAL_ERROR);
transaction.setThrowable(e);
throw e;
} finally {
transaction.finish();
hub.popScope();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ import com.nhaarman.mockitokotlin2.reset
import com.nhaarman.mockitokotlin2.verify
import com.nhaarman.mockitokotlin2.verifyZeroInteractions
import com.nhaarman.mockitokotlin2.whenever
import io.sentry.IHub
import io.sentry.ITransportFactory
import io.sentry.Sentry
import io.sentry.SentryOptions
import io.sentry.SpanStatus
import io.sentry.spring.tracing.SentryTracingConfiguration
import io.sentry.spring.tracing.SentryTransaction
import io.sentry.test.checkEvent
import io.sentry.test.checkTransaction
import io.sentry.transport.ITransport
import java.lang.RuntimeException
import java.lang.Exception
import java.time.Duration
import org.assertj.core.api.Assertions.assertThat
import org.awaitility.kotlin.await
Expand All @@ -25,6 +31,7 @@ import org.springframework.boot.test.web.client.TestRestTemplate
import org.springframework.boot.web.server.LocalServerPort
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Import
import org.springframework.http.HttpEntity
import org.springframework.http.HttpHeaders
import org.springframework.http.HttpMethod
Expand All @@ -37,6 +44,7 @@ import org.springframework.security.core.userdetails.UserDetailsService
import org.springframework.security.crypto.factory.PasswordEncoderFactories
import org.springframework.security.crypto.password.PasswordEncoder
import org.springframework.security.provisioning.InMemoryUserDetailsManager
import org.springframework.stereotype.Service
import org.springframework.test.context.junit4.SpringRunner
import org.springframework.web.bind.annotation.ControllerAdvice
import org.springframework.web.bind.annotation.ExceptionHandler
Expand All @@ -53,6 +61,12 @@ class SentrySpringIntegrationTest {
@Autowired
lateinit var transport: ITransport

@Autowired
lateinit var someService: SomeService

@Autowired
lateinit var hub: IHub

@LocalServerPort
lateinit var port: Integer

Expand Down Expand Up @@ -137,10 +151,51 @@ class SentrySpringIntegrationTest {
verifyZeroInteractions(transport)
}
}

@Test
fun `calling a method annotated with @SentryTransaction creates transaction`() {
someService.aMethod()
await.untilAsserted {
verify(transport).send(checkTransaction {
assertThat(it.status).isEqualTo(SpanStatus.OK)
}, anyOrNull())
}
}

@Test
fun `calling a method annotated with @SentryTransaction throwing exception associates Sentry event with transaction`() {
try {
someService.aMethodThrowing()
} catch (e: Exception) {
hub.captureException(e)
}
await.untilAsserted {
verify(transport).send(checkEvent {
assertThat(it.contexts.trace).isNotNull
assertThat(it.contexts.trace!!.operation).isEqualTo("bean")
}, anyOrNull())
}
}

@Test
fun `calling a method annotated with @SentryTransaction, where an inner span is created within transaction, throwing exception associates Sentry event with inner span`() {
try {
someService.aMethodWithInnerSpanThrowing()
} catch (e: Exception) {
hub.captureException(e)
}
await.untilAsserted {
verify(transport).send(checkEvent {
assertThat(it.contexts.trace).isNotNull
assertThat(it.contexts.trace!!.operation).isEqualTo("child-op")
}, anyOrNull())
}
}
}

@SpringBootApplication
@EnableSentry(dsn = "http://key@localhost/proj", sendDefaultPii = true)
@Import(SentryTracingConfiguration::class)
open class App {

private val transport = mock<ITransport>()
Expand All @@ -157,6 +212,37 @@ open class App {

@Bean
open fun sentrySpringRequestListener() = SentrySpringRequestListener()

@Bean
open fun tracesSamplerCallback() = SentryOptions.TracesSamplerCallback {
1.0
}
}

@Service
open class SomeService {

@SentryTransaction(operation = "bean")
open fun aMethod() { Thread.sleep(100) }

@SentryTransaction(operation = "bean")
open fun aMethodThrowing() {
throw RuntimeException("oops")
}

@SentryTransaction(operation = "bean")
open fun aMethodWithInnerSpanThrowing() {
val span = Sentry.getSpan()!!.startChild("child-op")
try {
throw RuntimeException("oops")
} catch (e: Exception) {
span.status = SpanStatus.INTERNAL_ERROR
span.throwable = e
throw e
} finally {
span.finish()
}
}
}

@RestController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import io.sentry.IHub
import io.sentry.Scope
import io.sentry.ScopeCallback
import io.sentry.SentryOptions
import io.sentry.SpanStatus
import io.sentry.TransactionContext
import kotlin.test.BeforeTest
import kotlin.test.Test
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.assertThrows
import org.junit.runner.RunWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Bean
Expand Down Expand Up @@ -53,6 +55,15 @@ class SentryTransactionAdviceTest {
verify(hub).captureTransaction(check {
assertThat(it.transaction).isEqualTo("customName")
assertThat(it.contexts.trace!!.operation).isEqualTo("bean")
assertThat(it.status).isEqualTo(SpanStatus.OK)
})
}

@Test
fun `when method annotated with @SentryTransaction throws exception, sets error status on transaction`() {
assertThrows<RuntimeException> { sampleService.methodThrowingException() }
verify(hub).captureTransaction(check {
assertThat(it.status).isEqualTo(SpanStatus.INTERNAL_ERROR)
})
}

Expand Down Expand Up @@ -133,6 +144,9 @@ class SentryTransactionAdviceTest {

@SentryTransaction(operation = "op")
open fun methodWithoutTransactionNameSet() = Unit

@SentryTransaction(operation = "op")
open fun methodThrowingException(): Nothing = throw RuntimeException()
}

@SentryTransaction(operation = "op")
Expand Down
1 change: 1 addition & 0 deletions sentry-test-support/api/sentry-test-support.api
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
public final class io/sentry/test/AssertionsKt {
public static final fun checkEvent (Lkotlin/jvm/functions/Function1;)Lio/sentry/SentryEnvelope;
public static final fun checkTransaction (Lkotlin/jvm/functions/Function1;)Lio/sentry/SentryEnvelope;
}

public final class io/sentry/test/ReflectionKt {
Expand Down
27 changes: 23 additions & 4 deletions sentry-test-support/src/main/kotlin/io/sentry/test/assertions.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
package io.sentry.test

import com.nhaarman.mockitokotlin2.check
import io.sentry.GsonSerializer
import io.sentry.SentryEnvelope
import io.sentry.SentryEvent
import io.sentry.SentryOptions
import io.sentry.protocol.SentryTransaction
import java.lang.AssertionError

/**
* Verifies is [SentryEnvelope] contains first event matching a predicate.
*/
inline fun checkEvent(noinline predicate: (SentryEvent) -> Unit): SentryEnvelope {
fun checkEvent(predicate: (SentryEvent) -> Unit): SentryEnvelope {
val options = SentryOptions().apply {
setSerializer(GsonSerializer(SentryOptions()))
}
return check {
val event: SentryEvent? = it.items.first().getEvent(options.serializer)
if (event != null) {
predicate(event)
} else {
throw AssertionError("event is null")
}
}
}

fun checkTransaction(predicate: (SentryTransaction) -> Unit): SentryEnvelope {
val options = SentryOptions().apply {
setSerializer(GsonSerializer(SentryOptions()))
}
return check {
val event = it.items.first().getEvent(options.serializer)!!
predicate(event)
val transaction = it.items.first().getTransaction(options.serializer)
if (transaction != null) {
predicate(transaction)
} else {
throw AssertionError("transaction is null")
}
}
}
14 changes: 10 additions & 4 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public final class io/sentry/Hub : io/sentry/IHub {
public fun setExtra (Ljava/lang/String;Ljava/lang/String;)V
public fun setFingerprint (Ljava/util/List;)V
public fun setLevel (Lio/sentry/SentryLevel;)V
public fun setSpanContext (Ljava/lang/Throwable;Lio/sentry/ISpan;)V
public fun setSpanContext (Ljava/lang/Throwable;Lio/sentry/ISpan;Ljava/lang/String;)V
public fun setTag (Ljava/lang/String;Ljava/lang/String;)V
public fun setTransaction (Ljava/lang/String;)V
public fun setUser (Lio/sentry/protocol/User;)V
Expand Down Expand Up @@ -166,7 +166,7 @@ public final class io/sentry/HubAdapter : io/sentry/IHub {
public fun setExtra (Ljava/lang/String;Ljava/lang/String;)V
public fun setFingerprint (Ljava/util/List;)V
public fun setLevel (Lio/sentry/SentryLevel;)V
public fun setSpanContext (Ljava/lang/Throwable;Lio/sentry/ISpan;)V
public fun setSpanContext (Ljava/lang/Throwable;Lio/sentry/ISpan;Ljava/lang/String;)V
public fun setTag (Ljava/lang/String;Ljava/lang/String;)V
public fun setTransaction (Ljava/lang/String;)V
public fun setUser (Lio/sentry/protocol/User;)V
Expand Down Expand Up @@ -219,7 +219,7 @@ public abstract interface class io/sentry/IHub {
public abstract fun setExtra (Ljava/lang/String;Ljava/lang/String;)V
public abstract fun setFingerprint (Ljava/util/List;)V
public abstract fun setLevel (Lio/sentry/SentryLevel;)V
public abstract fun setSpanContext (Ljava/lang/Throwable;Lio/sentry/ISpan;)V
public abstract fun setSpanContext (Ljava/lang/Throwable;Lio/sentry/ISpan;Ljava/lang/String;)V
public abstract fun setTag (Ljava/lang/String;Ljava/lang/String;)V
public abstract fun setTransaction (Ljava/lang/String;)V
public abstract fun setUser (Lio/sentry/protocol/User;)V
Expand Down Expand Up @@ -369,7 +369,7 @@ public final class io/sentry/NoOpHub : io/sentry/IHub {
public fun setExtra (Ljava/lang/String;Ljava/lang/String;)V
public fun setFingerprint (Ljava/util/List;)V
public fun setLevel (Lio/sentry/SentryLevel;)V
public fun setSpanContext (Ljava/lang/Throwable;Lio/sentry/ISpan;)V
public fun setSpanContext (Ljava/lang/Throwable;Lio/sentry/ISpan;Ljava/lang/String;)V
public fun setTag (Ljava/lang/String;Ljava/lang/String;)V
public fun setTransaction (Ljava/lang/String;)V
public fun setUser (Lio/sentry/protocol/User;)V
Expand Down Expand Up @@ -1872,6 +1872,12 @@ public final class io/sentry/util/Objects {
public static fun requireNonNull (Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;
}

public final class io/sentry/util/Pair {
public fun <init> (Ljava/lang/Object;Ljava/lang/Object;)V
public fun getFirst ()Ljava/lang/Object;
public fun getSecond ()Ljava/lang/Object;
}

public final class io/sentry/util/StringUtils {
public static fun capitalize (Ljava/lang/String;)Ljava/lang/String;
public static fun getStringAfterDot (Ljava/lang/String;)Ljava/lang/String;
Expand Down
Loading

0 comments on commit 3e9d3bd

Please sign in to comment.