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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# vNext

* Feat: Support logging via JUL (#1211)
* Fix: Fix returning Sentry trace header from Span (#1217)

# 4.0.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import io.sentry.SpanContext
import io.sentry.SpanStatus
import kotlin.test.Test
import org.assertj.core.api.Assertions.assertThat
import org.hamcrest.core.IsNull
import org.springframework.http.HttpMethod
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
Expand All @@ -24,7 +23,7 @@ class SentrySpanRestTemplateCustomizerTest {
val hub = mock<IHub>()
val restTemplate = RestTemplate()
var mockServer = MockRestServiceServer.createServer(restTemplate)
val transaction = SentryTransaction("aTransaction", SpanContext(), hub)
val transaction = SentryTransaction("aTransaction", SpanContext(true), hub)
internal val customizer = SentrySpanRestTemplateCustomizer(hub)

fun getSut(isTransactionActive: Boolean, status: HttpStatus = HttpStatus.OK): RestTemplate {
Expand All @@ -37,7 +36,12 @@ class SentrySpanRestTemplateCustomizerTest {

mockServer.expect(MockRestRequestMatchers.requestTo("/test/123"))
.andExpect(MockRestRequestMatchers.method(HttpMethod.GET))
.andExpect(MockRestRequestMatchers.header("sentry-trace", IsNull.notNullValue()))
.andExpect {
// must have trace id from the parent transaction and must not contain spanId from the parent transaction
assertThat(it.headers["sentry-trace"]!!.first()).startsWith(transaction.spanContext.traceId.toString())
.endsWith("-1")
.doesNotContain(transaction.spanContext.spanId.toString())
}
.andRespond(MockRestResponseCreators.withStatus(status).body("OK").contentType(MediaType.APPLICATION_JSON))
} else {
mockServer.expect(MockRestRequestMatchers.requestTo("/test/123"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public SentrySpanClientHttpRequestInterceptor(final @NotNull IHub hub) {
span.setDescription(
request.getMethodValue() + " " + ensureLeadingSlash(urlTemplate.get().poll()));

final SentryTraceHeader sentryTraceHeader = activeSpan.toSentryTrace();
final SentryTraceHeader sentryTraceHeader = span.toSentryTrace();
request.getHeaders().add(sentryTraceHeader.getName(), sentryTraceHeader.getValue());
try {
final ClientHttpResponse response = execution.execute(request, body);
Expand Down
2 changes: 2 additions & 0 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -937,8 +937,10 @@ public class io/sentry/SpanContext : java/lang/Cloneable {
public fun getOperation ()Ljava/lang/String;
public fun getParentSpanId ()Lio/sentry/SpanId;
public fun getSampled ()Ljava/lang/Boolean;
public fun getSpanId ()Lio/sentry/SpanId;
public fun getStatus ()Lio/sentry/SpanStatus;
public fun getTags ()Ljava/util/Map;
public fun getTraceId ()Lio/sentry/protocol/SentryId;
public fun setDescription (Ljava/lang/String;)V
public fun setOperation (Ljava/lang/String;)V
public fun setStatus (Lio/sentry/SpanStatus;)V
Expand Down
2 changes: 1 addition & 1 deletion sentry/src/main/java/io/sentry/Span.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public final class Span extends SpanContext implements ISpan {

@Override
public @NotNull SentryTraceHeader toSentryTrace() {
return transaction.toSentryTrace();
return new SentryTraceHeader(getTraceId(), getSpanId(), getSampled());
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions sentry/src/main/java/io/sentry/SpanContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ public void setStatus(final @Nullable SpanStatus status) {
}

@NotNull
SentryId getTraceId() {
public SentryId getTraceId() {
return traceId;
}

@NotNull
SpanId getSpanId() {
public SpanId getSpanId() {
return spanId;
}

Expand Down
14 changes: 14 additions & 0 deletions sentry/src/test/java/io/sentry/SpanTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ class SpanTest {
assertEquals("description", child.description)
}

@Test
fun `converts to Sentry trace header`() {
val traceId = SentryId()
val parentSpanId = SpanId()
val hub = mock<IHub>()
val span = Span(traceId, parentSpanId, SentryTransaction(TransactionContext("name", true), hub), hub)
val sentryTrace = span.toSentryTrace()
assertEquals(traceId, sentryTrace.traceId)
assertEquals(span.spanId, sentryTrace.spanId)
assertNotNull(sentryTrace.isSampled) {
assertTrue(it)
}
}

@Test
fun `starting a child with details adds span to transaction`() {
val transaction = SentryTransaction("name")
Expand Down