mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-02 03:25:56 +01:00
Implemented default LoggingExporter for trace api
This commit is contained in:
@@ -24,7 +24,6 @@
|
||||
|
||||
package sonia.scm.trace;
|
||||
|
||||
import java.time.Clock;
|
||||
import java.time.Instant;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -37,7 +36,6 @@ import java.util.Map;
|
||||
*/
|
||||
public final class Span implements AutoCloseable {
|
||||
|
||||
private final Clock clock;
|
||||
private final Tracer tracer;
|
||||
private final String kind;
|
||||
private final Map<String,String> labels = new LinkedHashMap<>();
|
||||
@@ -45,14 +43,9 @@ public final class Span implements AutoCloseable {
|
||||
private boolean failed;
|
||||
|
||||
Span(Tracer tracer, String kind) {
|
||||
this(tracer, kind, Clock.systemUTC());
|
||||
}
|
||||
|
||||
Span(Tracer tracer, String kind, Clock clock) {
|
||||
this.clock = clock;
|
||||
this.tracer = tracer;
|
||||
this.kind = kind;
|
||||
this.opened = clock.instant();
|
||||
this.opened = Instant.now();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -142,7 +135,7 @@ public final class Span implements AutoCloseable {
|
||||
*/
|
||||
@Override
|
||||
public void close() {
|
||||
tracer.export(new SpanContext(kind, Collections.unmodifiableMap(labels), opened, clock.instant(), failed));
|
||||
tracer.export(new SpanContext(kind, Collections.unmodifiableMap(labels), opened, Instant.now(), failed));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,8 +24,6 @@
|
||||
|
||||
package sonia.scm.trace;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Value;
|
||||
|
||||
import java.time.Duration;
|
||||
@@ -33,12 +31,12 @@ import java.time.Instant;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The {@link SpanContext} represents a finsished span which could be processed by an {@link Exporter}.
|
||||
* The {@link SpanContext} represents a finished span which could be processed by an {@link Exporter}.
|
||||
*
|
||||
* @since 2.9.0
|
||||
*/
|
||||
@Value
|
||||
@AllArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
public final class SpanContext {
|
||||
public class SpanContext {
|
||||
|
||||
String kind;
|
||||
Map<String,String> labels;
|
||||
|
||||
@@ -34,7 +34,6 @@ import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
class TracerTest {
|
||||
|
||||
private Tracer tracer;
|
||||
@@ -63,8 +62,6 @@ class TracerTest {
|
||||
try (Span span = tracer.span("sample")) {
|
||||
span.label("l1", "one");
|
||||
Thread.sleep(1L);
|
||||
} catch (Exception ex) {
|
||||
span.
|
||||
}
|
||||
|
||||
SpanContext span = exporter.spans.get(0);
|
||||
|
||||
Reference in New Issue
Block a user