Logging improvements and other misc
from reviewing a customer’s logs.
This commit is contained in:
parent
ae9d4619a4
commit
a3875aff2c
|
@ -68,6 +68,7 @@ public class AgentInstaller {
|
||||||
.or(nameStartsWith("org.groovy."))
|
.or(nameStartsWith("org.groovy."))
|
||||||
.or(nameStartsWith("com.p6spy."))
|
.or(nameStartsWith("com.p6spy."))
|
||||||
.or(nameStartsWith("org.slf4j."))
|
.or(nameStartsWith("org.slf4j."))
|
||||||
|
.or(nameStartsWith("com.newrelic."))
|
||||||
.or(nameContains("javassist"))
|
.or(nameContains("javassist"))
|
||||||
.or(nameContains(".asm."))
|
.or(nameContains(".asm."))
|
||||||
.or(nameMatches("com\\.mchange\\.v2\\.c3p0\\..*Proxy"));
|
.or(nameMatches("com\\.mchange\\.v2\\.c3p0\\..*Proxy"));
|
||||||
|
|
|
@ -39,6 +39,9 @@ public class Servlet2Advice {
|
||||||
GlobalTracer.get()
|
GlobalTracer.get()
|
||||||
.buildSpan("servlet.request")
|
.buildSpan("servlet.request")
|
||||||
.asChildOf(extractedContext)
|
.asChildOf(extractedContext)
|
||||||
|
.withTag(Tags.COMPONENT.getKey(), "java-web-servlet")
|
||||||
|
.withTag(Tags.HTTP_METHOD.getKey(), httpServletRequest.getMethod())
|
||||||
|
.withTag(Tags.HTTP_URL.getKey(), httpServletRequest.getRequestURL().toString())
|
||||||
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER)
|
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER)
|
||||||
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.WEB_SERVLET)
|
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.WEB_SERVLET)
|
||||||
.withTag("servlet.context", httpServletRequest.getContextPath())
|
.withTag("servlet.context", httpServletRequest.getContextPath())
|
||||||
|
@ -48,12 +51,8 @@ public class Servlet2Advice {
|
||||||
((TraceScope) scope).setAsyncPropagation(true);
|
((TraceScope) scope).setAsyncPropagation(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Span span = scope.span();
|
|
||||||
Tags.COMPONENT.set(span, "java-web-servlet");
|
|
||||||
Tags.HTTP_METHOD.set(span, httpServletRequest.getMethod());
|
|
||||||
Tags.HTTP_URL.set(span, httpServletRequest.getRequestURL().toString());
|
|
||||||
if (httpServletRequest.getUserPrincipal() != null) {
|
if (httpServletRequest.getUserPrincipal() != null) {
|
||||||
span.setTag("user.principal", httpServletRequest.getUserPrincipal().getName());
|
scope.span().setTag("user.principal", httpServletRequest.getUserPrincipal().getName());
|
||||||
}
|
}
|
||||||
return scope;
|
return scope;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,9 @@ public class Servlet3Advice {
|
||||||
GlobalTracer.get()
|
GlobalTracer.get()
|
||||||
.buildSpan("servlet.request")
|
.buildSpan("servlet.request")
|
||||||
.asChildOf(extractedContext)
|
.asChildOf(extractedContext)
|
||||||
|
.withTag(Tags.COMPONENT.getKey(), "java-web-servlet")
|
||||||
|
.withTag(Tags.HTTP_METHOD.getKey(), httpServletRequest.getMethod())
|
||||||
|
.withTag(Tags.HTTP_URL.getKey(), httpServletRequest.getRequestURL().toString())
|
||||||
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER)
|
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER)
|
||||||
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.WEB_SERVLET)
|
.withTag(DDTags.SPAN_TYPE, DDSpanTypes.WEB_SERVLET)
|
||||||
.withTag("servlet.context", httpServletRequest.getContextPath())
|
.withTag("servlet.context", httpServletRequest.getContextPath())
|
||||||
|
@ -48,12 +51,8 @@ public class Servlet3Advice {
|
||||||
((TraceScope) scope).setAsyncPropagation(true);
|
((TraceScope) scope).setAsyncPropagation(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Span span = scope.span();
|
|
||||||
Tags.COMPONENT.set(span, "java-web-servlet");
|
|
||||||
Tags.HTTP_METHOD.set(span, httpServletRequest.getMethod());
|
|
||||||
Tags.HTTP_URL.set(span, httpServletRequest.getRequestURL().toString());
|
|
||||||
if (httpServletRequest.getUserPrincipal() != null) {
|
if (httpServletRequest.getUserPrincipal() != null) {
|
||||||
span.setTag("user.principal", httpServletRequest.getUserPrincipal().getName());
|
scope.span().setTag("user.principal", httpServletRequest.getUserPrincipal().getName());
|
||||||
}
|
}
|
||||||
return scope;
|
return scope;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,8 +30,27 @@ class SpringBootBasedTest extends AgentTestRunner {
|
||||||
restTemplate.getForObject("http://localhost:$port/", String) == "Hello World"
|
restTemplate.getForObject("http://localhost:$port/", String) == "Hello World"
|
||||||
|
|
||||||
and:
|
and:
|
||||||
TEST_WRITER.waitForTraces(1)
|
assertTraces(TEST_WRITER, 1) {
|
||||||
TEST_WRITER.size() == 1
|
trace(0, 2) {
|
||||||
|
span(0) {
|
||||||
|
operationName "servlet.request"
|
||||||
|
resourceName "GET /"
|
||||||
|
spanType DDSpanTypes.WEB_SERVLET
|
||||||
|
parent()
|
||||||
|
errored false
|
||||||
|
tags {
|
||||||
|
"http.url" "http://localhost:$port/"
|
||||||
|
"http.method" "GET"
|
||||||
|
"span.kind" "server"
|
||||||
|
"span.type" "web"
|
||||||
|
"component" "java-web-servlet"
|
||||||
|
"http.status_code" 200
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
controllerSpan(it, 1, "TestController.greeting")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def "generates spans"() {
|
def "generates spans"() {
|
||||||
|
|
|
@ -87,6 +87,7 @@ public class DDSpan implements Span, MutableSpan {
|
||||||
private void finishAndAddToTrace(final long durationNano) {
|
private void finishAndAddToTrace(final long durationNano) {
|
||||||
// ensure a min duration of 1
|
// ensure a min duration of 1
|
||||||
if (this.durationNano.compareAndSet(0, Math.max(1, durationNano))) {
|
if (this.durationNano.compareAndSet(0, Math.max(1, durationNano))) {
|
||||||
|
log.debug("Finished: {}", this);
|
||||||
context.getTrace().addSpan(this);
|
context.getTrace().addSpan(this);
|
||||||
} else {
|
} else {
|
||||||
log.debug("{} - already finished!", this);
|
log.debug("{} - already finished!", this);
|
||||||
|
@ -149,7 +150,7 @@ public class DDSpan implements Span, MutableSpan {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final DDSpan setTag(final String tag, final String value) {
|
public final DDSpan setTag(final String tag, final String value) {
|
||||||
this.context().setTag(tag, (Object) value);
|
context().setTag(tag, (Object) value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,7 +159,7 @@ public class DDSpan implements Span, MutableSpan {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final DDSpan setTag(final String tag, final boolean value) {
|
public final DDSpan setTag(final String tag, final boolean value) {
|
||||||
this.context().setTag(tag, (Object) value);
|
context().setTag(tag, (Object) value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,7 +168,7 @@ public class DDSpan implements Span, MutableSpan {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final DDSpan setTag(final String tag, final Number value) {
|
public final DDSpan setTag(final String tag, final Number value) {
|
||||||
this.context().setTag(tag, (Object) value);
|
context().setTag(tag, (Object) value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +177,7 @@ public class DDSpan implements Span, MutableSpan {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final DDSpanContext context() {
|
public final DDSpanContext context() {
|
||||||
return this.context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -184,7 +185,7 @@ public class DDSpan implements Span, MutableSpan {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final String getBaggageItem(final String key) {
|
public final String getBaggageItem(final String key) {
|
||||||
return this.context.getBaggageItem(key);
|
return context.getBaggageItem(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -192,7 +193,7 @@ public class DDSpan implements Span, MutableSpan {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final DDSpan setBaggageItem(final String key, final String value) {
|
public final DDSpan setBaggageItem(final String key, final String value) {
|
||||||
this.context.setBaggageItem(key, value);
|
context.setBaggageItem(key, value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,7 +202,7 @@ public class DDSpan implements Span, MutableSpan {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final DDSpan setOperationName(final String operationName) {
|
public final DDSpan setOperationName(final String operationName) {
|
||||||
this.context().setOperationName(operationName);
|
context().setOperationName(operationName);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,13 +248,13 @@ public class DDSpan implements Span, MutableSpan {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final DDSpan setServiceName(final String serviceName) {
|
public final DDSpan setServiceName(final String serviceName) {
|
||||||
this.context().setServiceName(serviceName);
|
context().setServiceName(serviceName);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final DDSpan setResourceName(final String resourceName) {
|
public final DDSpan setResourceName(final String resourceName) {
|
||||||
this.context().setResourceName(resourceName);
|
context().setResourceName(resourceName);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,13 +265,13 @@ public class DDSpan implements Span, MutableSpan {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final DDSpan setSamplingPriority(final int newPriority) {
|
public final DDSpan setSamplingPriority(final int newPriority) {
|
||||||
this.context().setSamplingPriority(newPriority);
|
context().setSamplingPriority(newPriority);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final DDSpan setSpanType(final String type) {
|
public final DDSpan setSpanType(final String type) {
|
||||||
this.context().setSpanType(type);
|
context().setSpanType(type);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -371,7 +372,7 @@ public class DDSpan implements Span, MutableSpan {
|
||||||
@Override
|
@Override
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public Map<String, Object> getTags() {
|
public Map<String, Object> getTags() {
|
||||||
return this.context().getTags();
|
return context().getTags();
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonGetter
|
@JsonGetter
|
||||||
|
@ -405,12 +406,13 @@ public class DDSpan implements Span, MutableSpan {
|
||||||
this(null);
|
this(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UInt64IDStringSerializer(Class<String> stringClass) {
|
public UInt64IDStringSerializer(final Class<String> stringClass) {
|
||||||
super(stringClass);
|
super(stringClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serialize(String value, JsonGenerator gen, SerializerProvider provider)
|
public void serialize(
|
||||||
|
final String value, final JsonGenerator gen, final SerializerProvider provider)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
gen.writeNumber(value);
|
gen.writeNumber(value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -325,7 +325,7 @@ public class DDSpanContext implements io.opentracing.SpanContext {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final StringBuilder s =
|
final StringBuilder s =
|
||||||
new StringBuilder()
|
new StringBuilder()
|
||||||
.append("Span [ t_id=")
|
.append("DDSpan [ t_id=")
|
||||||
.append(traceId)
|
.append(traceId)
|
||||||
.append(", s_id=")
|
.append(", s_id=")
|
||||||
.append(spanId)
|
.append(spanId)
|
||||||
|
|
|
@ -48,7 +48,7 @@ public class ContinuableScope implements Scope, TraceScope {
|
||||||
this.continuation = continuation;
|
this.continuation = continuation;
|
||||||
this.spanUnderScope = spanUnderScope;
|
this.spanUnderScope = spanUnderScope;
|
||||||
this.finishOnClose = finishOnClose;
|
this.finishOnClose = finishOnClose;
|
||||||
this.toRestore = scopeManager.tlsScope.get();
|
toRestore = scopeManager.tlsScope.get();
|
||||||
scopeManager.tlsScope.set(this);
|
scopeManager.tlsScope.set(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,6 +96,11 @@ public class ContinuableScope implements Scope, TraceScope {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return super.toString() + "->" + spanUnderScope;
|
||||||
|
}
|
||||||
|
|
||||||
public class Continuation implements Closeable, TraceScope.Continuation {
|
public class Continuation implements Closeable, TraceScope.Continuation {
|
||||||
public WeakReference<Continuation> ref;
|
public WeakReference<Continuation> ref;
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ class DDSpanContextTest extends Specification {
|
||||||
context.serviceName == "fakeService"
|
context.serviceName == "fakeService"
|
||||||
context.resourceName == "fakeResource"
|
context.resourceName == "fakeResource"
|
||||||
context.spanType == "fakeType"
|
context.spanType == "fakeType"
|
||||||
context.toString() == "Span [ t_id=1, s_id=1, p_id=0] trace=fakeService/fakeOperation/fakeResource metrics={} *errored* tags={${extra}span.type=${context.getSpanType()}, thread.id=${Thread.currentThread().id}, thread.name=${Thread.currentThread().name}}"
|
context.toString() == "DDSpan [ t_id=1, s_id=1, p_id=0] trace=fakeService/fakeOperation/fakeResource metrics={} *errored* tags={${extra}span.type=${context.getSpanType()}, thread.id=${Thread.currentThread().id}, thread.name=${Thread.currentThread().name}}"
|
||||||
|
|
||||||
where:
|
where:
|
||||||
name | extra | tags
|
name | extra | tags
|
||||||
|
@ -35,7 +35,7 @@ class DDSpanContextTest extends Specification {
|
||||||
def thread = Thread.currentThread()
|
def thread = Thread.currentThread()
|
||||||
|
|
||||||
def expectedTags = [(DDTags.THREAD_NAME): thread.name, (DDTags.THREAD_ID): thread.id, (DDTags.SPAN_TYPE): context.getSpanType()]
|
def expectedTags = [(DDTags.THREAD_NAME): thread.name, (DDTags.THREAD_ID): thread.id, (DDTags.SPAN_TYPE): context.getSpanType()]
|
||||||
def expectedTrace = "Span [ t_id=1, s_id=1, p_id=0] trace=$details metrics={} tags={span.type=${context.getSpanType()}, thread.id=$thread.id, thread.name=$thread.name}"
|
def expectedTrace = "DDSpan [ t_id=1, s_id=1, p_id=0] trace=$details metrics={} tags={span.type=${context.getSpanType()}, thread.id=$thread.id, thread.name=$thread.name}"
|
||||||
|
|
||||||
expect:
|
expect:
|
||||||
context.getTags() == expectedTags
|
context.getTags() == expectedTags
|
||||||
|
@ -62,7 +62,7 @@ class DDSpanContextTest extends Specification {
|
||||||
(DDTags.THREAD_NAME): thread.name,
|
(DDTags.THREAD_NAME): thread.name,
|
||||||
(DDTags.THREAD_ID) : thread.id
|
(DDTags.THREAD_ID) : thread.id
|
||||||
]
|
]
|
||||||
context.toString() == "Span [ t_id=1, s_id=1, p_id=0] trace=fakeService/fakeOperation/fakeResource metrics={} tags={span.type=${context.getSpanType()}, $name=$value, thread.id=$thread.id, thread.name=$thread.name}"
|
context.toString() == "DDSpan [ t_id=1, s_id=1, p_id=0] trace=fakeService/fakeOperation/fakeResource metrics={} tags={span.type=${context.getSpanType()}, $name=$value, thread.id=$thread.id, thread.name=$thread.name}"
|
||||||
|
|
||||||
where:
|
where:
|
||||||
name | value
|
name | value
|
||||||
|
|
Loading…
Reference in New Issue