Automatic tag table generation
Without this change we don't even really know how many tags are created and what are their values. With this change we want this information to be automatically rendered.
This commit is contained in:
@@ -47,22 +47,26 @@ class BraveScopedSpan implements ScopedSpan {
|
||||
|
||||
@Override
|
||||
public ScopedSpan name(String name) {
|
||||
return new BraveScopedSpan(this.span.name(name));
|
||||
this.span.name(name);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScopedSpan tag(String key, String value) {
|
||||
return new BraveScopedSpan(this.span.tag(key, value));
|
||||
this.span.tag(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScopedSpan event(String value) {
|
||||
return new BraveScopedSpan(this.span.annotate(value));
|
||||
this.span.annotate(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScopedSpan error(Throwable throwable) {
|
||||
return new BraveScopedSpan(this.span.error(throwable));
|
||||
this.span.error(throwable);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.util.Objects;
|
||||
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.TraceContext;
|
||||
import org.springframework.cloud.sleuth.docs.AssertingSpan;
|
||||
|
||||
/**
|
||||
* Brave implementation of a {@link Span}.
|
||||
@@ -50,22 +51,26 @@ public class BraveSpan implements Span {
|
||||
|
||||
@Override
|
||||
public Span start() {
|
||||
return new BraveSpan(this.delegate.start());
|
||||
this.delegate.start();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Span name(String name) {
|
||||
return new BraveSpan(this.delegate.name(name));
|
||||
this.delegate.name(name);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Span event(String value) {
|
||||
return new BraveSpan(this.delegate.annotate(value));
|
||||
this.delegate.annotate(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Span tag(String key, String value) {
|
||||
return new BraveSpan(this.delegate.tag(key, value));
|
||||
this.delegate.tag(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,7 +78,7 @@ public class BraveSpan implements Span {
|
||||
String message = throwable.getMessage() == null ? throwable.getClass().getSimpleName() : throwable.getMessage();
|
||||
this.delegate.tag("error", message);
|
||||
this.delegate.error(throwable);
|
||||
return new BraveSpan(this.delegate);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -98,7 +103,7 @@ public class BraveSpan implements Span {
|
||||
}
|
||||
|
||||
public static brave.Span toBrave(Span span) {
|
||||
return ((BraveSpan) span).delegate;
|
||||
return ((BraveSpan) AssertingSpan.unwrap(span)).delegate;
|
||||
}
|
||||
|
||||
public static Span fromBrave(brave.Span span) {
|
||||
|
||||
@@ -1,144 +1,145 @@
|
||||
/*
|
||||
* Copyright 2013-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.sleuth.brave.bridge;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import brave.Tracer;
|
||||
import brave.propagation.TraceContextOrSamplingFlags;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.TraceContext;
|
||||
|
||||
/**
|
||||
* Brave implementation of a {@link Span.Builder}.
|
||||
*
|
||||
* @author Marcin Grzejszczak
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class BraveSpanBuilder implements Span.Builder {
|
||||
|
||||
private static final Log log = LogFactory.getLog(BraveSpanBuilder.class);
|
||||
|
||||
brave.Span delegate;
|
||||
|
||||
TraceContextOrSamplingFlags parentContext;
|
||||
|
||||
private final Tracer tracer;
|
||||
|
||||
private long startTimestamp;
|
||||
|
||||
BraveSpanBuilder(Tracer tracer) {
|
||||
this.tracer = tracer;
|
||||
}
|
||||
|
||||
BraveSpanBuilder(Tracer tracer, TraceContextOrSamplingFlags parentContext) {
|
||||
this.tracer = tracer;
|
||||
this.parentContext = parentContext;
|
||||
}
|
||||
|
||||
brave.Span span() {
|
||||
if (this.delegate != null) {
|
||||
return this.delegate;
|
||||
}
|
||||
else if (this.parentContext != null) {
|
||||
this.delegate = this.tracer.nextSpan(this.parentContext);
|
||||
}
|
||||
else {
|
||||
this.delegate = this.tracer.nextSpan();
|
||||
}
|
||||
return this.delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Span.Builder setParent(TraceContext context) {
|
||||
this.parentContext = TraceContextOrSamplingFlags.create(BraveTraceContext.toBrave(context));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Span.Builder setNoParent() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Span.Builder name(String name) {
|
||||
span().name(name);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Span.Builder event(String value) {
|
||||
span().annotate(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Span.Builder tag(String key, String value) {
|
||||
span().tag(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Span.Builder error(Throwable throwable) {
|
||||
span().error(throwable);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Span.Builder kind(Span.Kind kind) {
|
||||
span().kind(kind != null ? brave.Span.Kind.valueOf(kind.toString()) : null);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Span.Builder remoteServiceName(String remoteServiceName) {
|
||||
span().remoteServiceName(remoteServiceName);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Span.Builder remoteUrl(String remoteUrl) {
|
||||
try {
|
||||
URI uri = URI.create(remoteUrl);
|
||||
span().remoteIpAndPort(uri.getHost(), uri.getPort());
|
||||
} catch (Exception e) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Failed to parse url [" + remoteUrl + "]. Will not set the value", e);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Span start() {
|
||||
if (this.startTimestamp > 0) {
|
||||
span().start(this.startTimestamp);
|
||||
}
|
||||
else {
|
||||
span().start();
|
||||
}
|
||||
return BraveSpan.fromBrave(this.delegate);
|
||||
}
|
||||
|
||||
static Span.Builder toBuilder(Tracer tracer, TraceContextOrSamplingFlags context) {
|
||||
return new BraveSpanBuilder(tracer, context);
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Copyright 2013-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.sleuth.brave.bridge;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import brave.Tracer;
|
||||
import brave.propagation.TraceContextOrSamplingFlags;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.TraceContext;
|
||||
|
||||
/**
|
||||
* Brave implementation of a {@link Span.Builder}.
|
||||
*
|
||||
* @author Marcin Grzejszczak
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class BraveSpanBuilder implements Span.Builder {
|
||||
|
||||
private static final Log log = LogFactory.getLog(BraveSpanBuilder.class);
|
||||
|
||||
brave.Span delegate;
|
||||
|
||||
TraceContextOrSamplingFlags parentContext;
|
||||
|
||||
private final Tracer tracer;
|
||||
|
||||
private long startTimestamp;
|
||||
|
||||
BraveSpanBuilder(Tracer tracer) {
|
||||
this.tracer = tracer;
|
||||
}
|
||||
|
||||
BraveSpanBuilder(Tracer tracer, TraceContextOrSamplingFlags parentContext) {
|
||||
this.tracer = tracer;
|
||||
this.parentContext = parentContext;
|
||||
}
|
||||
|
||||
brave.Span span() {
|
||||
if (this.delegate != null) {
|
||||
return this.delegate;
|
||||
}
|
||||
else if (this.parentContext != null) {
|
||||
this.delegate = this.tracer.nextSpan(this.parentContext);
|
||||
}
|
||||
else {
|
||||
this.delegate = this.tracer.nextSpan();
|
||||
}
|
||||
return this.delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Span.Builder setParent(TraceContext context) {
|
||||
this.parentContext = TraceContextOrSamplingFlags.create(BraveTraceContext.toBrave(context));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Span.Builder setNoParent() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Span.Builder name(String name) {
|
||||
span().name(name);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Span.Builder event(String value) {
|
||||
span().annotate(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Span.Builder tag(String key, String value) {
|
||||
span().tag(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Span.Builder error(Throwable throwable) {
|
||||
span().error(throwable);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Span.Builder kind(Span.Kind kind) {
|
||||
span().kind(kind != null ? brave.Span.Kind.valueOf(kind.toString()) : null);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Span.Builder remoteServiceName(String remoteServiceName) {
|
||||
span().remoteServiceName(remoteServiceName);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Span.Builder remoteUrl(String remoteUrl) {
|
||||
try {
|
||||
URI uri = URI.create(remoteUrl);
|
||||
span().remoteIpAndPort(uri.getHost(), uri.getPort());
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Failed to parse url [" + remoteUrl + "]. Will not set the value", e);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Span start() {
|
||||
if (this.startTimestamp > 0) {
|
||||
span().start(this.startTimestamp);
|
||||
}
|
||||
else {
|
||||
span().start();
|
||||
}
|
||||
return BraveSpan.fromBrave(this.delegate);
|
||||
}
|
||||
|
||||
static Span.Builder toBuilder(Tracer tracer, TraceContextOrSamplingFlags context) {
|
||||
return new BraveSpanBuilder(tracer, context);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.cloud.sleuth.brave.bridge;
|
||||
|
||||
import org.springframework.cloud.sleuth.SpanCustomizer;
|
||||
import org.springframework.cloud.sleuth.docs.AssertingSpanCustomizer;
|
||||
|
||||
/**
|
||||
* Brave implementation of a {@link SpanCustomizer}.
|
||||
@@ -48,7 +49,7 @@ public class BraveSpanCustomizer implements SpanCustomizer {
|
||||
}
|
||||
|
||||
static brave.SpanCustomizer toBrave(SpanCustomizer spanCustomizer) {
|
||||
return ((BraveSpanCustomizer) spanCustomizer).spanCustomizer;
|
||||
return ((BraveSpanCustomizer) AssertingSpanCustomizer.unwrap(spanCustomizer)).spanCustomizer;
|
||||
}
|
||||
|
||||
static SpanCustomizer fromBrave(brave.SpanCustomizer spanCustomizer) {
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanCustomizer;
|
||||
import org.springframework.cloud.sleuth.TraceContext;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.docs.AssertingSpan;
|
||||
|
||||
/**
|
||||
* Brave implementation of a {@link Tracer}.
|
||||
@@ -58,7 +59,8 @@ public class BraveTracer implements Tracer {
|
||||
|
||||
@Override
|
||||
public SpanInScope withSpan(Span span) {
|
||||
return new BraveSpanInScope(tracer.withSpanInScope(span == null ? null : ((BraveSpan) span).delegate));
|
||||
return new BraveSpanInScope(
|
||||
tracer.withSpanInScope(span == null ? null : ((BraveSpan) AssertingSpan.unwrap(span)).delegate));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user