Merge pull request #646 from trask/dd-merge

This commit is contained in:
Tyler Benson 2020-07-23 13:58:46 -07:00 committed by GitHub
commit 145c6752c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 77 additions and 5 deletions

View File

@ -89,6 +89,10 @@ public class GlobalIgnoresMatcher<T extends TypeDescription>
}
return true;
}
// clojure
if (name.startsWith("clojure.") || name.contains("$fn__")) {
return true;
}
if (name.startsWith("io.opentelemetry.auto.")) {
// FIXME: We should remove this once

View File

@ -19,6 +19,7 @@ package io.opentelemetry.auto.test
import io.opentelemetry.auto.bootstrap.AgentClassLoader
import io.opentelemetry.auto.tooling.ClassLoaderMatcher
import io.opentelemetry.auto.tooling.ExporterClassLoader
import io.opentelemetry.auto.tooling.log.LogContextScopeListener
import io.opentelemetry.auto.util.test.AgentSpecification
class ClassLoaderMatcherTest extends AgentSpecification {
@ -60,4 +61,9 @@ class ClassLoaderMatcherTest extends AgentSpecification {
expect:
ExporterClassLoader.name == "io.opentelemetry.auto.tooling.ExporterClassLoader"
}
def "helper class names are hardcoded in Log Instrumentations"() {
expect:
LogContextScopeListener.name == "io.opentelemetry.auto.tooling.log.LogContextScopeListener"
}
}

View File

@ -31,6 +31,10 @@ public class TextMapExtractAdapter implements HttpTextFormat.Getter<Headers> {
if (header == null) {
return null;
}
return new String(header.value(), StandardCharsets.UTF_8);
byte[] value = header.value();
if (value == null) {
return null;
}
return new String(value, StandardCharsets.UTF_8);
}
}

View File

@ -31,6 +31,10 @@ public class TextMapExtractAdapter implements HttpTextFormat.Getter<Headers> {
if (header == null) {
return null;
}
return new String(header.value(), StandardCharsets.UTF_8);
byte[] value = header.value();
if (value == null) {
return null;
}
return new String(value, StandardCharsets.UTF_8);
}
}

View File

@ -22,7 +22,6 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
import io.opentelemetry.auto.config.Config;
import io.opentelemetry.auto.tooling.Instrumenter;
import io.opentelemetry.auto.tooling.log.LogContextScopeListener;
import java.lang.reflect.Method;
import java.util.Map;
import net.bytebuddy.asm.Advice;
@ -55,7 +54,7 @@ public class Log4jMDCInstrumentation extends Instrumenter.Default {
@Override
public String[] helperClassNames() {
return new String[] {LogContextScopeListener.class.getName()};
return new String[] {"io.opentelemetry.auto.tooling.log.LogContextScopeListener"};
}
public static class MDCContextAdvice {

View File

@ -38,4 +38,15 @@ class Log4jMDCTest extends LogContextInjectionTestBase {
def get(String key) {
return MDC.get(key)
}
@Override
def remove(String key) {
MDC.context
return MDC.remove(key)
}
@Override
def clear() {
return MDC.clear()
}
}

View File

@ -31,4 +31,14 @@ class Log4jThreadContextTest extends LogContextInjectionTestBase {
def get(String key) {
return ThreadContext.get(key)
}
@Override
def remove(String key) {
return ThreadContext.remove(key)
}
@Override
def clear() {
return ThreadContext.clearAll()
}
}

View File

@ -70,7 +70,7 @@ public class MDCInjectionInstrumentation extends Instrumenter.Default {
@Override
public String[] helperClassNames() {
return new String[] {LogContextScopeListener.class.getName()};
return new String[] {"io.opentelemetry.auto.tooling.log.LogContextScopeListener"};
}
public static class MDCAdvice {

View File

@ -12,4 +12,14 @@ class Slf4jMDCTest extends LogContextInjectionTestBase {
def get(String key) {
return MDC.get(key)
}
@Override
def remove(String key) {
return MDC.remove(key)
}
@Override
def clear() {
return MDC.clear()
}
}

View File

@ -44,6 +44,13 @@ abstract class LogContextInjectionTestBase extends AgentTestRunner {
*/
abstract get(String key)
/**
* Remove from the framework-specific context the value at the given key
*/
abstract remove(String key)
abstract clear()
static {
ConfigUtils.updateConfig {
System.setProperty("ota.logs.injection", "true")
@ -139,4 +146,21 @@ abstract class LogContextInjectionTestBase extends AgentTestRunner {
mainSpan?.end()
mainScope?.close()
}
def "modify thread context after clear of context map at the beginning of new thread"() {
def t1A
final Thread thread1 = new Thread() {
@Override
void run() {
clear()
put("a", "a thread1")
t1A = get("a")
}
}
thread1.start()
thread1.join()
expect:
t1A == "a thread1"
}
}