|
1 | 1 | /**
|
2 |
| - * Copyright 2022 the original author or authors. |
| 2 | + * Copyright 2023 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
16 | 16 | package io.micrometer.tracing.handler;
|
17 | 17 |
|
18 | 18 | import io.micrometer.observation.Observation;
|
| 19 | +import io.micrometer.observation.Observation.Event; |
19 | 20 | import io.micrometer.tracing.CurrentTraceContext;
|
20 | 21 | import io.micrometer.tracing.Span;
|
21 | 22 | import io.micrometer.tracing.Tracer;
|
|
25 | 26 | import org.mockito.InOrder;
|
26 | 27 |
|
27 | 28 | import java.util.Collections;
|
| 29 | +import java.util.concurrent.TimeUnit; |
28 | 30 |
|
29 | 31 | import static org.assertj.core.api.Assertions.assertThat;
|
30 | 32 | import static org.assertj.core.api.BDDAssertions.thenNoException;
|
@@ -95,4 +97,34 @@ void spanShouldNotBeOverriddenWhenResettingScope() {
|
95 | 97 | assertThat(tracingContext.getSpan()).isSameAs(span);
|
96 | 98 | }
|
97 | 99 |
|
| 100 | + @Test |
| 101 | + void eventTimestamp() { |
| 102 | + Span span = mock(Span.class); |
| 103 | + Observation.Context context = new Observation.Context(); |
| 104 | + TracingObservationHandler.TracingContext tracingContext = new TracingObservationHandler.TracingContext(); |
| 105 | + tracingContext.setSpan(span); |
| 106 | + context.put(TracingObservationHandler.TracingContext.class, tracingContext); |
| 107 | + TracingObservationHandler<Observation.Context> handler = () -> tracer; |
| 108 | + |
| 109 | + Event defaultEvent = () -> "default-event"; |
| 110 | + handler.onEvent(defaultEvent, context); |
| 111 | + BDDMockito.then(span).should().event("default-event"); |
| 112 | + |
| 113 | + BDDMockito.reset(span); |
| 114 | + |
| 115 | + Event eventWithWallTime = new Event() { |
| 116 | + @Override |
| 117 | + public String getName() { |
| 118 | + return "walltime-event"; |
| 119 | + } |
| 120 | + |
| 121 | + @Override |
| 122 | + public long getWallTime() { |
| 123 | + return 100; |
| 124 | + } |
| 125 | + }; |
| 126 | + handler.onEvent(eventWithWallTime, context); |
| 127 | + BDDMockito.then(span).should().event("walltime-event", 100, TimeUnit.MILLISECONDS); |
| 128 | + } |
| 129 | + |
98 | 130 | }
|
0 commit comments