-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate from remoting3 to tracing-java (#100)
* Remove remoting3 dependency and pick up rebranded tracing-java change. * Split tracing-api & tracing implementation dependency * Add tracing sanity check for legacy remoting3 Log error and fallback to remoting3 tracing if the detected remoting3 tracer does not delegate to java-tracing properly. * Use reflection for remoting3 tracing fallback * Extract Tracer interface, java-tracing and reflective implementations * TracingInvocationEventHandler factory
- Loading branch information
Showing
12 changed files
with
442 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
tritium-tracing/src/main/java/com/palantir/tritium/tracing/JavaTracingTracer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* (c) Copyright 2018 Palantir Technologies Inc. All rights reserved. | ||
* | ||
* 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 | ||
* | ||
* http://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 com.palantir.tritium.tracing; | ||
|
||
enum JavaTracingTracer implements Tracer { | ||
INSTANCE; | ||
|
||
@Override | ||
public void startSpan(String operationName) { | ||
com.palantir.tracing.Tracer.startSpan(operationName); | ||
} | ||
|
||
@Override | ||
public void completeSpan() { | ||
com.palantir.tracing.Tracer.fastCompleteSpan(); | ||
} | ||
|
||
} |
89 changes: 89 additions & 0 deletions
89
tritium-tracing/src/main/java/com/palantir/tritium/tracing/ReflectiveTracer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* (c) Copyright 2018 Palantir Technologies Inc. All rights reserved. | ||
* | ||
* 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 | ||
* | ||
* http://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 com.palantir.tritium.tracing; | ||
|
||
import static com.google.common.base.Preconditions.checkArgument; | ||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
import com.google.common.base.Throwables; | ||
import java.lang.reflect.Method; | ||
import java.lang.reflect.Modifier; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
final class ReflectiveTracer implements Tracer { | ||
|
||
private final Method startSpanMethod; | ||
private final Method completeSpanMethod; | ||
|
||
ReflectiveTracer(Method startSpanMethod, Method completeSpanMethod) { | ||
this.startSpanMethod = checkStartMethod(startSpanMethod); | ||
this.completeSpanMethod = checkCompleteMethod(completeSpanMethod); | ||
} | ||
|
||
@Override | ||
public void startSpan(String operationName) { | ||
try { | ||
startSpanMethod.invoke(null, operationName); | ||
} catch (ReflectiveOperationException e) { | ||
throw throwUnchecked(e); | ||
} | ||
} | ||
|
||
@Override | ||
public void completeSpan() { | ||
try { | ||
completeSpanMethod.invoke(null); | ||
} catch (ReflectiveOperationException e) { | ||
throw throwUnchecked(e); | ||
} | ||
} | ||
|
||
private static Method checkStartMethod(Method method) { | ||
checkNotNull(method, "method"); | ||
checkArgument(Modifier.isPublic(method.getModifiers()), "method must be public: %s", method); | ||
checkArgument(Modifier.isStatic(method.getModifiers()), "method must be static: %s", method); | ||
if (method.getParameterCount() != 1 || !String.class.equals(method.getParameterTypes()[0])) { | ||
throw new IllegalArgumentException(String.format("startSpan method should take 1 String argument, was %s", | ||
paramsToClassNames(method))); | ||
} | ||
return method; | ||
} | ||
|
||
private static Method checkCompleteMethod(Method method) { | ||
checkNotNull(method, "method"); | ||
checkArgument(Modifier.isPublic(method.getModifiers()), "method must be public: %s", method); | ||
checkArgument(Modifier.isStatic(method.getModifiers()), "method must be static: %s", method); | ||
checkArgument(method.getParameterCount() == 0, | ||
"completeSpan method should take 0 arguments, was %s", paramsToClassNames(method)); | ||
return method; | ||
} | ||
|
||
private static List<String> paramsToClassNames(Method method) { | ||
return Arrays.stream(method.getParameterTypes()) | ||
.map(Class::getName) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
private static RuntimeException throwUnchecked(ReflectiveOperationException reflectionException) { | ||
Throwable cause = reflectionException.getCause() != null ? reflectionException.getCause() : reflectionException; | ||
Throwables.throwIfUnchecked(cause); | ||
throw new RuntimeException(cause); | ||
} | ||
|
||
} |
Oops, something went wrong.