Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
36e5dac
[WIP] delegate all tracing calls to `tracing-java`
qinfchen Sep 6, 2018
f321e2c
cleanup
qinfchen Sep 6, 2018
c78a24b
Use published versions of libraries
iamdanfox Sep 6, 2018
edfa0d6
Everything compiles
iamdanfox Sep 6, 2018
6a8471a
Convert#span actually works now
iamdanfox Sep 6, 2018
68d893a
Implement Convert#toRemotingTrace
iamdanfox Sep 6, 2018
420c0e8
All converters propagate nulls
iamdanfox Sep 6, 2018
6ec78ae
Tracer#subscribe returns a remoting span observer
iamdanfox Sep 6, 2018
d4dc7d6
Delete redundant fully-qualified names in TracersTest
iamdanfox Sep 6, 2018
332bbe1
Move longToPaddedHex function out of Tracers
iamdanfox Sep 6, 2018
9e6effd
Delete an asConjure method
iamdanfox Sep 6, 2018
1beda24
@Ignore one TracerTest
iamdanfox Sep 6, 2018
6a02d6f
Thanks checkstyle
iamdanfox Sep 6, 2018
f3724a3
Reduce visibility of Convert class
iamdanfox Sep 6, 2018
9c45298
Fix one Convert method
iamdanfox Sep 6, 2018
13fb17c
Remove mavenLocal()
iamdanfox Sep 6, 2018
0a5b297
Move Utilities to test source set
iamdanfox Sep 6, 2018
8a06a46
Better javadoc and warnings
iamdanfox Sep 6, 2018
bb252e2
Restore CloseableTracerTest
iamdanfox Sep 6, 2018
badb51c
Delete some unused fields and point to their new locations
iamdanfox Sep 6, 2018
b20a71e
rearrange method orders and remove broken javadoc links
qinfchen Sep 6, 2018
1bd0d56
remove Tracers.TRACE_ID_KEY and use java-tracing TRACE_ID_KEY
qinfchen Sep 6, 2018
0ac9f54
thanks checkstyle
qinfchen Sep 6, 2018
e9c0d1e
Revert "remove Tracers.TRACE_ID_KEY and use java-tracing TRACE_ID_KEY"
iamdanfox Sep 7, 2018
adf0f74
Don't make Trace public
iamdanfox Sep 7, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move longToPaddedHex function out of Tracers
  • Loading branch information
iamdanfox committed Sep 6, 2018
commit 332bbe156cbfc9854ed2a10e6a4df51fe4a74b43
28 changes: 0 additions & 28 deletions tracing/src/main/java/com/palantir/remoting3/tracing/Tracers.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
public final class Tracers {
/** The key under which trace ids are inserted into SLF4J {@link org.slf4j.MDC MDCs}. */
public static final String TRACE_ID_KEY = "traceId";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should delete public static final fields like this, because if some consumer is depending on com.palantir.remoting3.tracingTracers.TRACE_ID_KEY then they'd suddenly break?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't seem like anyone is using it, https://github.com/search?p=2&q=Tracers.TRACE_ID_KEY&type=Code
i also did a quick search on the key internally and no internal consumer is using it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't think we should remove things like this when there isn't a clear motivation - what if there was a user that didn't appear in your search? Did you check OSS consumers too (e.g. atlasdb?)

private static final char[] HEX_DIGITS =
{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

private Tracers() {}

Expand All @@ -34,32 +32,6 @@ public static String randomId() {
return com.palantir.tracing.Tracers.randomId();
}

/**
* Convert a long to a big-endian hex string. Hand-coded implementation is more efficient than
* Strings.pad(Long.toHexString) because that code has to deal with mixed length longs, and then mixed length
* amounts of padding - we want to minimise the overhead of tracing.
*/
static String longToPaddedHex(long number) {
char[] data = new char[16];
data[0] = HEX_DIGITS[(int) ((number >> 60) & 0xF)];
data[1] = HEX_DIGITS[(int) ((number >> 56) & 0xF)];
data[2] = HEX_DIGITS[(int) ((number >> 52) & 0xF)];
data[3] = HEX_DIGITS[(int) ((number >> 48) & 0xF)];
data[4] = HEX_DIGITS[(int) ((number >> 44) & 0xF)];
data[5] = HEX_DIGITS[(int) ((number >> 40) & 0xF)];
data[6] = HEX_DIGITS[(int) ((number >> 36) & 0xF)];
data[7] = HEX_DIGITS[(int) ((number >> 32) & 0xF)];
data[8] = HEX_DIGITS[(int) ((number >> 28) & 0xF)];
data[9] = HEX_DIGITS[(int) ((number >> 24) & 0xF)];
data[10] = HEX_DIGITS[(int) ((number >> 20) & 0xF)];
data[11] = HEX_DIGITS[(int) ((number >> 16) & 0xF)];
data[12] = HEX_DIGITS[(int) ((number >> 12) & 0xF)];
data[13] = HEX_DIGITS[(int) ((number >> 8) & 0xF)];
data[14] = HEX_DIGITS[(int) ((number >> 4) & 0xF)];
data[15] = HEX_DIGITS[(int) ((number >> 0) & 0xF)];
return new String(data);
}

/**
* Wraps the provided executor service such that any submitted {@link Callable} (or {@link Runnable}) is {@link
* #wrap wrapped} in order to be trace-aware.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* (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.remoting3.tracing;

public final class Utilities {
private static final char[] HEX_DIGITS =
{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

private Utilities() {}

/**
* Convert a long to a big-endian hex string. Hand-coded implementation is more efficient than
* Strings.pad(Long.toHexString) because that code has to deal with mixed length longs, and then mixed length
* amounts of padding - we want to minimise the overhead of tracing.
*/
static String longToPaddedHex(long number) {
char[] data = new char[16];
data[0] = HEX_DIGITS[(int) ((number >> 60) & 0xF)];
data[1] = HEX_DIGITS[(int) ((number >> 56) & 0xF)];
data[2] = HEX_DIGITS[(int) ((number >> 52) & 0xF)];
data[3] = HEX_DIGITS[(int) ((number >> 48) & 0xF)];
data[4] = HEX_DIGITS[(int) ((number >> 44) & 0xF)];
data[5] = HEX_DIGITS[(int) ((number >> 40) & 0xF)];
data[6] = HEX_DIGITS[(int) ((number >> 36) & 0xF)];
data[7] = HEX_DIGITS[(int) ((number >> 32) & 0xF)];
data[8] = HEX_DIGITS[(int) ((number >> 28) & 0xF)];
data[9] = HEX_DIGITS[(int) ((number >> 24) & 0xF)];
data[10] = HEX_DIGITS[(int) ((number >> 20) & 0xF)];
data[11] = HEX_DIGITS[(int) ((number >> 16) & 0xF)];
data[12] = HEX_DIGITS[(int) ((number >> 12) & 0xF)];
data[13] = HEX_DIGITS[(int) ((number >> 8) & 0xF)];
data[14] = HEX_DIGITS[(int) ((number >> 4) & 0xF)];
data[15] = HEX_DIGITS[(int) ((number >> 0) & 0xF)];
return new String(data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,10 @@ public void testWrapRunnableWithAlternateTraceId_traceStateRestoredWhenThrows()
@Test
public void testTraceIdGeneration() throws Exception {
assertThat(Tracers.randomId()).hasSize(16); // fails with p=1/16 if generated string is not padded
assertThat(Tracers.longToPaddedHex(0)).isEqualTo("0000000000000000");
assertThat(Tracers.longToPaddedHex(42)).isEqualTo("000000000000002a");
assertThat(Tracers.longToPaddedHex(-42)).isEqualTo("ffffffffffffffd6");
assertThat(Tracers.longToPaddedHex(123456789L)).isEqualTo("00000000075bcd15");
assertThat(Utilities.longToPaddedHex(0)).isEqualTo("0000000000000000");
assertThat(Utilities.longToPaddedHex(42)).isEqualTo("000000000000002a");
assertThat(Utilities.longToPaddedHex(-42)).isEqualTo("ffffffffffffffd6");
assertThat(Utilities.longToPaddedHex(123456789L)).isEqualTo("00000000075bcd15");
}

private static Callable<Void> newTraceExpectingCallable() {
Expand Down