|
25 | 25 | import io.opentelemetry.context.Context;
|
26 | 26 | import io.opentelemetry.context.ContextKey;
|
27 | 27 | import io.opentelemetry.context.propagation.TextMapGetter;
|
| 28 | +import io.opentelemetry.instrumentation.api.internal.InstrumenterUtil; |
28 | 29 | import io.opentelemetry.instrumentation.api.internal.SchemaUrlProvider;
|
29 | 30 | import io.opentelemetry.instrumentation.api.internal.SpanKey;
|
30 | 31 | import io.opentelemetry.instrumentation.api.internal.SpanKeyProvider;
|
31 | 32 | import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
|
32 | 33 | import io.opentelemetry.sdk.testing.junit5.OpenTelemetryExtension;
|
33 | 34 | import io.opentelemetry.sdk.trace.data.LinkData;
|
34 | 35 | import io.opentelemetry.sdk.trace.data.StatusData;
|
| 36 | +import java.time.Instant; |
35 | 37 | import java.util.Collections;
|
36 | 38 | import java.util.HashMap;
|
37 | 39 | import java.util.Map;
|
38 | 40 | import java.util.concurrent.atomic.AtomicReference;
|
39 | 41 | import java.util.stream.Collectors;
|
40 | 42 | import java.util.stream.Stream;
|
41 | 43 | import javax.annotation.Nullable;
|
| 44 | +import org.assertj.core.api.Assertions; |
42 | 45 | import org.junit.jupiter.api.Test;
|
43 | 46 | import org.junit.jupiter.api.extension.ExtendWith;
|
44 | 47 | import org.junit.jupiter.api.extension.RegisterExtension;
|
@@ -581,6 +584,45 @@ void instrumentationVersion_default() {
|
581 | 584 | span -> span.hasName("span").hasInstrumentationScopeInfo(expectedLibraryInfo)));
|
582 | 585 | }
|
583 | 586 |
|
| 587 | + @Test |
| 588 | + void instrumenterGetNanosWithNullArgument() { |
| 589 | + AtomicReference<Long> endTime = new AtomicReference<>(); |
| 590 | + OperationListener operationListener = |
| 591 | + new OperationListener() { |
| 592 | + @Override |
| 593 | + public Context onStart(Context context, Attributes startAttributes, long startNanos) { |
| 594 | + return context; |
| 595 | + } |
| 596 | + |
| 597 | + @Override |
| 598 | + public void onEnd(Context context, Attributes endAttributes, long endNanos) { |
| 599 | + endTime.set(endNanos); |
| 600 | + } |
| 601 | + }; |
| 602 | + |
| 603 | + InstrumenterBuilder<Map<String, String>, Map<String, String>> builder = |
| 604 | + Instrumenter.builder( |
| 605 | + otelTesting.getOpenTelemetry(), "test-instrumentation", name -> "span"); |
| 606 | + builder.addOperationListener(operationListener); |
| 607 | + InstrumenterUtil.propagateOperationListenersToOnEnd(builder); |
| 608 | + |
| 609 | + Instant startTime = Instant.now(); |
| 610 | + Instrumenter<Map<String, String>, Map<String, String>> instrumenter = |
| 611 | + builder.buildInstrumenter(); |
| 612 | + InstrumenterUtil.startAndEnd( |
| 613 | + instrumenter, Context.root(), emptyMap(), emptyMap(), null, startTime, null); |
| 614 | + |
| 615 | + otelTesting |
| 616 | + .assertTraces() |
| 617 | + .hasTracesSatisfyingExactly( |
| 618 | + trace -> |
| 619 | + trace.hasSpansSatisfyingExactly(span -> span.hasName("span").startsAt(startTime))); |
| 620 | + System.out.printf( |
| 621 | + "Epoche second of start: %d and end: %d\n", |
| 622 | + startTime.getEpochSecond(), endTime.get() / 1_000_000_000); |
| 623 | + Assertions.assertThat(endTime.get() / 1_000_000_000 == startTime.getEpochSecond()).isTrue(); |
| 624 | + } |
| 625 | + |
584 | 626 | @Test
|
585 | 627 | void instrumentationVersion_custom() {
|
586 | 628 | Instrumenter<Map<String, String>, Map<String, String>> instrumenter =
|
|
0 commit comments