Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public PersonController(PersonService personService, Tracer tracer) {
Person person(@PathVariable Long id) {
Span span = tracer.spanBuilder("spanCreatedThroughOtelApi").startSpan();
try (final @NotNull Scope spanScope = span.makeCurrent()) {
Sentry.logger().warn("warn Sentry logging");
Sentry.logger().error("error Sentry logging");
Sentry.logger().info("hello %s %s", "there", "world!");
ISpan currentSpan = Sentry.getSpan();
ISpan sentrySpan = currentSpan.startChild("spanCreatedThroughSentryApi");
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ sentry.graphql.ignored-error-types=SOME_ERROR,ANOTHER_ERROR
sentry.enable-backpressure-handling=true
sentry.enable-spotlight=true
sentry.enablePrettySerializationOutput=false
sentry.experimental.logs.enabled=true
in-app-includes="io.sentry.samples"

# Uncomment and set to true to enable aot compatibility
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ class PersonSystemTest {
testHelper.doesTransactionContainSpanWithOp(transaction, "spanCreatedThroughOtelApi") &&
testHelper.doesTransactionContainSpanWithOp(transaction, "spanCreatedThroughSentryApi")
}

Thread.sleep(10000)

testHelper.ensureLogsReceived { logs, envelopeHeader ->
testHelper.doesContainLogWithBody(logs, "warn Sentry logging") &&
testHelper.doesContainLogWithBody(logs, "error Sentry logging") &&
testHelper.doesContainLogWithBody(logs, "hello there world!")
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public PersonController(PersonService personService, Tracer tracer) {
Person person(@PathVariable Long id) {
Span span = tracer.spanBuilder("spanCreatedThroughOtelApi").startSpan();
try (final @NotNull Scope spanScope = span.makeCurrent()) {
Sentry.logger().warn("warn Sentry logging");
Sentry.logger().error("error Sentry logging");
Sentry.logger().info("hello %s %s", "there", "world!");
ISpan currentSpan = Sentry.getSpan();
ISpan sentrySpan = currentSpan.startChild("spanCreatedThroughSentryApi");
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ sentry.graphql.ignored-error-types=SOME_ERROR,ANOTHER_ERROR
sentry.enable-backpressure-handling=true
sentry.enable-spotlight=true
sentry.enablePrettySerializationOutput=false
sentry.experimental.logs.enabled=true
in-app-includes="io.sentry.samples"

# Uncomment and set to true to enable aot compatibility
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ class PersonSystemTest {
testHelper.doesTransactionContainSpanWithOp(transaction, "spanCreatedThroughOtelApi") &&
testHelper.doesTransactionContainSpanWithOp(transaction, "spanCreatedThroughSentryApi")
}

Thread.sleep(10000)

testHelper.ensureLogsReceived { logs, envelopeHeader ->
testHelper.doesContainLogWithBody(logs, "warn Sentry logging") &&
testHelper.doesContainLogWithBody(logs, "error Sentry logging") &&
testHelper.doesContainLogWithBody(logs, "hello there world!")
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ Person person(@PathVariable Long id) {
ISpan currentSpan = Sentry.getSpan();
ISpan sentrySpan = currentSpan.startChild("spanCreatedThroughSentryApi");
try {
Sentry.logger().warn("warn Sentry logging");
Sentry.logger().error("error Sentry logging");
Sentry.logger().info("hello %s %s", "there", "world!");
LOGGER.error("Trying person with id={}", id, new RuntimeException("error while loading"));
throw new IllegalArgumentException("Something went wrong [id=" + id + "]");
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ class PersonSystemTest {
testHelper.ensureTransactionReceived { transaction, envelopeHeader ->
testHelper.doesTransactionHaveOp(transaction, "http.server")
}

Thread.sleep(10000)

testHelper.ensureLogsReceived { logs, envelopeHeader ->
testHelper.doesContainLogWithBody(logs, "warn Sentry logging") &&
testHelper.doesContainLogWithBody(logs, "error Sentry logging") &&
testHelper.doesContainLogWithBody(logs, "hello there world!")
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public PersonController(PersonService personService, Tracer tracer) {
Person person(@PathVariable Long id) {
Span span = tracer.spanBuilder("spanCreatedThroughOtelApi").startSpan();
try (final @NotNull Scope spanScope = span.makeCurrent()) {
Sentry.logger().warn("warn Sentry logging");
Sentry.logger().error("error Sentry logging");
Sentry.logger().info("hello %s %s", "there", "world!");
ISpan currentSpan = Sentry.getSpan();
ISpan sentrySpan = currentSpan.startChild("spanCreatedThroughSentryApi");
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ sentry.debug=true
sentry.graphql.ignored-error-types=SOME_ERROR,ANOTHER_ERROR
sentry.enable-backpressure-handling=true
sentry.enable-spotlight=true
sentry.experimental.logs.enabled=true
in-app-includes="io.sentry.samples"

# Database configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ class PersonSystemTest {
testHelper.doesTransactionContainSpanWithOp(transaction, "spanCreatedThroughOtelApi") &&
testHelper.doesTransactionContainSpanWithOp(transaction, "spanCreatedThroughSentryApi")
}

Thread.sleep(10000)

testHelper.ensureLogsReceived { logs, envelopeHeader ->
testHelper.doesContainLogWithBody(logs, "warn Sentry logging") &&
testHelper.doesContainLogWithBody(logs, "error Sentry logging") &&
testHelper.doesContainLogWithBody(logs, "hello there world!")
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public PersonController(PersonService personService, Tracer tracer) {
Person person(@PathVariable Long id) {
Span span = tracer.spanBuilder("spanCreatedThroughOtelApi").startSpan();
try (final @NotNull Scope spanScope = span.makeCurrent()) {
Sentry.logger().warn("warn Sentry logging");
Sentry.logger().error("error Sentry logging");
Sentry.logger().info("hello %s %s", "there", "world!");
ISpan currentSpan = Sentry.getSpan();
ISpan sentrySpan = currentSpan.startChild("spanCreatedThroughSentryApi");
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ sentry.debug=true
sentry.graphql.ignored-error-types=SOME_ERROR,ANOTHER_ERROR
sentry.enable-backpressure-handling=true
sentry.enable-spotlight=true
sentry.experimental.logs.enabled=true
in-app-includes="io.sentry.samples"

# Database configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ class PersonSystemTest {
testHelper.doesTransactionContainSpanWithOp(transaction, "spanCreatedThroughOtelApi") &&
testHelper.doesTransactionContainSpanWithOp(transaction, "spanCreatedThroughSentryApi")
}

Thread.sleep(10000)

testHelper.ensureLogsReceived { logs, envelopeHeader ->
testHelper.doesContainLogWithBody(logs, "warn Sentry logging") &&
testHelper.doesContainLogWithBody(logs, "error Sentry logging") &&
testHelper.doesContainLogWithBody(logs, "hello there world!")
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.sentry.samples.spring.boot.jakarta;

import io.sentry.Sentry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -22,6 +23,9 @@ public PersonController(PersonService personService) {

@GetMapping("{id}")
Person person(@PathVariable Long id) {
Sentry.logger().warn("warn Sentry logging");
Sentry.logger().error("error Sentry logging");
Sentry.logger().info("hello %s %s", "there", "world!");
LOGGER.info("Loading person with id={}", id);
throw new IllegalArgumentException("Something went wrong [id=" + id + "]");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ sentry.logging.minimum-breadcrumb-level=debug
sentry.reactive.thread-local-accessor-enabled=true
sentry.traces-sample-rate=1.0
sentry.enable-backpressure-handling=true
sentry.experimental.logs.enabled=true
sentry.enable-spotlight=true
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ class PersonSystemTest {
testHelper.ensureTransactionReceived { transaction, envelopeHeader ->
testHelper.doesTransactionHaveOp(transaction, "http.server")
}

Thread.sleep(10000)

testHelper.ensureLogsReceived { logs, envelopeHeader ->
testHelper.doesContainLogWithBody(logs, "warn Sentry logging") &&
testHelper.doesContainLogWithBody(logs, "error Sentry logging") &&
testHelper.doesContainLogWithBody(logs, "hello there world!")
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.sentry.samples.spring.boot;

import io.sentry.Sentry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -22,6 +23,9 @@ public PersonController(PersonService personService) {

@GetMapping("{id}")
Person person(@PathVariable Long id) {
Sentry.logger().warn("warn Sentry logging");
Sentry.logger().error("error Sentry logging");
Sentry.logger().info("hello %s %s", "there", "world!");
LOGGER.info("Loading person with id={}", id);
throw new IllegalArgumentException("Something went wrong [id=" + id + "]");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ spring.graphql.graphiql.enabled=true
spring.graphql.websocket.path=/graphql
spring.graphql.schema.printer.enabled=true
sentry.enable-backpressure-handling=true
sentry.experimental.logs.enabled=true
sentry.enable-spotlight=true
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ class PersonSystemTest {
testHelper.ensureTransactionReceived { transaction, envelopeHeader ->
testHelper.doesTransactionHaveOp(transaction, "http.server")
}

Thread.sleep(10000)

testHelper.ensureLogsReceived { logs, envelopeHeader ->
testHelper.doesContainLogWithBody(logs, "warn Sentry logging") &&
testHelper.doesContainLogWithBody(logs, "error Sentry logging") &&
testHelper.doesContainLogWithBody(logs, "hello there world!")
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.sentry.samples.spring.boot;

import io.sentry.Sentry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -21,6 +22,9 @@ public PersonController(PersonService personService) {

@GetMapping("{id}")
Person person(@PathVariable Long id) {
Sentry.logger().warn("warn Sentry logging");
Sentry.logger().error("error Sentry logging");
Sentry.logger().info("hello %s %s", "there", "world!");
LOGGER.info("Loading person with id={}", id);
throw new IllegalArgumentException("Something went wrong [id=" + id + "]");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ sentry.debug=true
sentry.graphql.ignored-error-types=SOME_ERROR,ANOTHER_ERROR
sentry.enable-backpressure-handling=true
sentry.enable-spotlight=true
sentry.experimental.logs.enabled=true
in-app-includes="io.sentry.samples"

# Database configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ class PersonSystemTest {
testHelper.ensureTransactionReceived { transaction, envelopeHeader ->
testHelper.doesTransactionHaveOp(transaction, "http.server")
}

Thread.sleep(10000)

testHelper.ensureLogsReceived { logs, envelopeHeader ->
testHelper.doesContainLogWithBody(logs, "warn Sentry logging") &&
testHelper.doesContainLogWithBody(logs, "error Sentry logging") &&
testHelper.doesContainLogWithBody(logs, "hello there world!")
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.sentry.samples.spring.jakarta.web;

import io.sentry.Sentry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -22,6 +23,9 @@ public PersonController(PersonService personService) {

@GetMapping("{id}")
Person person(@PathVariable Long id) {
Sentry.logger().warn("warn Sentry logging");
Sentry.logger().error("error Sentry logging");
Sentry.logger().info("hello %s %s", "there", "world!");
LOGGER.info("Loading person with id={}", id);
if (id > 10L) {
throw new IllegalArgumentException("Something went wrong [id=" + id + "]");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.sentry.samples.spring.web;

import io.sentry.Sentry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -22,6 +23,9 @@ public PersonController(PersonService personService) {

@GetMapping("{id}")
Person person(@PathVariable Long id) {
Sentry.logger().warn("warn Sentry logging");
Sentry.logger().error("error Sentry logging");
Sentry.logger().info("hello %s %s", "there", "world!");
LOGGER.info("Loading person with id={}", id);
if (id > 10L) {
throw new IllegalArgumentException("Something went wrong [id=" + id + "]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ public final class io/sentry/systemtest/util/SentryMockServerClient : io/sentry/

public final class io/sentry/systemtest/util/TestHelper {
public fun <init> (Ljava/lang/String;)V
public final fun doesContainLogWithBody (Lio/sentry/SentryLogEvents;Ljava/lang/String;)Z
public final fun doesTransactionContainSpanWithDescription (Lio/sentry/protocol/SentryTransaction;Ljava/lang/String;)Z
public final fun doesTransactionContainSpanWithOp (Lio/sentry/protocol/SentryTransaction;Ljava/lang/String;)Z
public final fun doesTransactionHaveOp (Lio/sentry/protocol/SentryTransaction;Ljava/lang/String;)Z
Expand All @@ -559,6 +560,7 @@ public final class io/sentry/systemtest/util/TestHelper {
public final fun ensureEnvelopeReceived (Lkotlin/jvm/functions/Function1;)V
public final fun ensureErrorCount (Lcom/apollographql/apollo3/api/ApolloResponse;I)V
public final fun ensureErrorReceived (Lkotlin/jvm/functions/Function1;)V
public final fun ensureLogsReceived (Lkotlin/jvm/functions/Function2;)V
public final fun ensureNoEnvelopeReceived (Lkotlin/jvm/functions/Function1;)V
public final fun ensureNoErrors (Lcom/apollographql/apollo3/api/ApolloResponse;)V
public final fun ensureNoTransactionReceived (Lkotlin/jvm/functions/Function2;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import io.sentry.JsonSerializer
import io.sentry.SentryEnvelopeHeader
import io.sentry.SentryEvent
import io.sentry.SentryItemType
import io.sentry.SentryLogEvents
import io.sentry.SentryOptions
import io.sentry.protocol.SentrySpan
import io.sentry.protocol.SentryTransaction
Expand Down Expand Up @@ -83,6 +84,46 @@ class TestHelper(backendUrl: String) {
}
}

fun ensureLogsReceived(callback: ((SentryLogEvents, SentryEnvelopeHeader) -> Boolean)) {
ensureEnvelopeReceived { envelopeString ->
checkIfLogsMatch(envelopeString, callback)
}
}

private fun checkIfLogsMatch(envelopeString: String, callback: ((SentryLogEvents, SentryEnvelopeHeader) -> Boolean)): Boolean {
val deserializeEnvelope =
jsonSerializer.deserializeEnvelope(envelopeString.byteInputStream())
if (deserializeEnvelope == null) {
return false
}

val envelopeHeader = deserializeEnvelope.header

val logsItem =
deserializeEnvelope.items.firstOrNull { it.header.type == SentryItemType.Log }
if (logsItem == null) {
return false
}

val logs = logsItem.getLogs(jsonSerializer)
if (logs == null) {
return false
}

return callback(logs, envelopeHeader)
}

fun doesContainLogWithBody(logs: SentryLogEvents, body: String): Boolean {
val logItem = logs.items.firstOrNull { logItem -> logItem.body == body }
if (logItem == null) {
println("Unable to find log item with body $body in logs:")
logObject(logs)
return false
}

return true
}

private fun checkIfTransactionMatches(envelopeString: String, callback: ((SentryTransaction, SentryEnvelopeHeader) -> Boolean)): Boolean {
val deserializeEnvelope =
jsonSerializer.deserializeEnvelope(envelopeString.byteInputStream())
Expand Down
1 change: 1 addition & 0 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -2833,6 +2833,7 @@ public final class io/sentry/SentryEnvelopeItem {
public fun getData ()[B
public fun getEvent (Lio/sentry/ISerializer;)Lio/sentry/SentryEvent;
public fun getHeader ()Lio/sentry/SentryEnvelopeItemHeader;
public fun getLogs (Lio/sentry/ISerializer;)Lio/sentry/SentryLogEvents;
public fun getTransaction (Lio/sentry/ISerializer;)Lio/sentry/protocol/SentryTransaction;
}

Expand Down
5 changes: 3 additions & 2 deletions sentry/src/main/java/io/sentry/ExternalOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ public final class ExternalOptions {
options.setCaptureOpenTelemetryEvents(
propertiesProvider.getBooleanProperty("capture-open-telemetry-events"));

options.setEnableLogs(propertiesProvider.getBooleanProperty("logs.enabled"));
options.setLogsSampleRate(propertiesProvider.getDoubleProperty("logs.sample-rate"));
options.setEnableLogs(propertiesProvider.getBooleanProperty("experimental.logs.enabled"));
options.setLogsSampleRate(
propertiesProvider.getDoubleProperty("experimental.logs.sample-rate"));

for (final String ignoredExceptionType :
propertiesProvider.getList("ignored-exceptions-for-type")) {
Expand Down
Loading
Loading