Skip to content

Commit

Permalink
Fix exception.escaped and timesource for SpanEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
mtoffl01 committed Sep 3, 2024
1 parent 565e43d commit 7655446
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ public Span setStatus(StatusCode statusCode, String description) {
}

/**
* Records information about the Throwable as a span event
* exception.escaped cannot be determined by this function and therefore is not automatically recorded. Record this manually using additionalAttributes
* See: <a href="https://javadoc.io/doc/io.opentelemetry/opentelemetry-api-trace/latest/io/opentelemetry/api/trace/Span.html#recordException(java.lang.Throwable)">...</a>
* Records information about the Throwable as a span event exception.escaped cannot be determined
* by this function and therefore is not automatically recorded. Record this manually using
* additionalAttributes See: <a
* href="https://javadoc.io/doc/io.opentelemetry/opentelemetry-api-trace/latest/io/opentelemetry/api/trace/Span.html#recordException(java.lang.Throwable)">...</a>
*
* @param exception the Throwable to record
* @param additionalAttributes the additional attributes to record
*
*/
@Override
public Span recordException(Throwable exception, Attributes additionalAttributes) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package datadog.opentelemetry.shim.trace;

import datadog.trace.api.time.SystemTimeSource;
import datadog.trace.api.time.TimeSource;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import datadog.trace.bootstrap.instrumentation.api.SpanAttributes;
import edu.umd.cs.findbugs.annotations.NonNull;
import io.opentelemetry.api.common.Attributes;

import java.sql.Time;
import java.util.List;
import java.util.concurrent.TimeUnit;
import datadog.trace.api.time.SystemTimeSource;
import datadog.trace.api.time.TimeSource;

public class SpanEvent {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,37 +257,37 @@ class OpenTelemetry14Test extends AgentTestRunner {
}
}

def "test add event no timestamp"() {
setup:
def builder = tracer.spanBuilder("some-name")
def timeSource = new ControllableTimeSource();
timeSource.set(1000);
SpanEvent.setTimeSource(timeSource);

when:
def result = builder.startSpan()
result.addEvent("evt", null, )
result.end()

then:
def expectedEventTag = """
def "test add event no timestamp"() {
setup:
def builder = tracer.spanBuilder("some-name")
def timeSource = new ControllableTimeSource()
timeSource.set(1000)
SpanEvent.setTimeSource(timeSource)

when:
def result = builder.startSpan()
result.addEvent("evt", null, )
result.end()

then:
def expectedEventTag = """
[
{ "time_unix_nano": ${timeSource.getCurrentTimeNanos()},
"name": "evt"
}
]"""
assertTraces(1) {
trace(1) {
span {
tags {
defaultTags()
"$SPAN_KIND" "$SPAN_KIND_INTERNAL"
tag("events", { JSONAssert.assertEquals(expectedEventTag, it as String, false); return true })
}
}
assertTraces(1) {
trace(1) {
span {
tags {
defaultTags()
"$SPAN_KIND" "$SPAN_KIND_INTERNAL"
tag("events", { JSONAssert.assertEquals(expectedEventTag, it as String, false); return true })
}
}
}
}
}

def "test simple span links"() {
setup:
Expand Down

0 comments on commit 7655446

Please sign in to comment.