@Test public void testAddTraceTokenProperties() { registerTraceToken(TESTING_TRACE_TOKEN); try (TraceTokenScope ignored = addTraceTokenProperties("key-f", "value-f", "key-a", "value-a")) { assertEquals(getCurrentRequestToken(), "{id=testing-id, key-d=value-d, key-f=value-f, key-a=value-a}"); assertEquals(getCurrentTraceToken(), ImmutableMap.of("id", "testing-id", "key-d", "value-d", "key-f", "value-f", "key-a", "value-a")); assertEquals(getCurrentTraceToken().keySet(), ImmutableList.of("id", "key-d", "key-f", "key-a")); assertEquals(currentThread().getName(), "testing thread name {id=testing-id, key-d=value-d, key-f=value-f, key-a=value-a}"); } assertEquals(getCurrentRequestToken(), "{id=testing-id, key-d=value-d}"); assertEquals(getCurrentTraceToken(), TESTING_TRACE_TOKEN); assertEquals(currentThread().getName(), "testing thread name {id=testing-id, key-d=value-d}"); }
public static TraceTokenScope addTraceTokenProperties(String... properties) { TokenState tokenState = token.get(); if (tokenState == null) { return new TraceTokenScope(null); } Map<String, String> map = new LinkedHashMap<>(tokenState.getToken()); checkArgument((properties.length % 2) == 0, "odd number of elements in properties"); for (int i = 0; i < properties.length; i += 2) { requireNonNull(properties[i], "property key is null"); requireNonNull(properties[i+1], "property value is null"); map.put(properties[i], properties[i+1]); } return registerTraceToken(new TraceToken(map)); }
TraceTokenManager { public static TraceTokenScope addTraceTokenProperties(String... properties) { TokenState tokenState = token.get(); if (tokenState == null) { return new TraceTokenScope(null); } Map<String, String> map = new LinkedHashMap<>(tokenState.getToken()); checkArgument((properties.length % 2) == 0, "odd number of elements in properties"); for (int i = 0; i < properties.length; i += 2) { requireNonNull(properties[i], "property key is null"); requireNonNull(properties[i+1], "property value is null"); map.put(properties[i], properties[i+1]); } return registerTraceToken(new TraceToken(map)); } }
TraceTokenManager { public static TraceTokenScope addTraceTokenProperties(String... properties) { TokenState tokenState = token.get(); if (tokenState == null) { return new TraceTokenScope(null); } Map<String, String> map = new LinkedHashMap<>(tokenState.getToken()); checkArgument((properties.length % 2) == 0, "odd number of elements in properties"); for (int i = 0; i < properties.length; i += 2) { requireNonNull(properties[i], "property key is null"); requireNonNull(properties[i+1], "property value is null"); map.put(properties[i], properties[i+1]); } return registerTraceToken(new TraceToken(map)); } private  TraceTokenManager(); }
TraceTokenManager { public static TraceTokenScope addTraceTokenProperties(String... properties) { TokenState tokenState = token.get(); if (tokenState == null) { return new TraceTokenScope(null); } Map<String, String> map = new LinkedHashMap<>(tokenState.getToken()); checkArgument((properties.length % 2) == 0, "odd number of elements in properties"); for (int i = 0; i < properties.length; i += 2) { requireNonNull(properties[i], "property key is null"); requireNonNull(properties[i+1], "property value is null"); map.put(properties[i], properties[i+1]); } return registerTraceToken(new TraceToken(map)); } private  TraceTokenManager(); static TraceTokenScope registerRequestToken(@Nullable String tokenId); static TraceTokenScope registerTraceToken(@Nullable TraceToken token); @Deprecated @Nullable static String getCurrentRequestToken(); @Nullable static TraceToken getCurrentTraceToken(); static String createAndRegisterNewRequestToken(String... properties); static void clearRequestToken(); static TraceTokenScope addTraceTokenProperties(String... properties); }
TraceTokenManager { public static TraceTokenScope addTraceTokenProperties(String... properties) { TokenState tokenState = token.get(); if (tokenState == null) { return new TraceTokenScope(null); } Map<String, String> map = new LinkedHashMap<>(tokenState.getToken()); checkArgument((properties.length % 2) == 0, "odd number of elements in properties"); for (int i = 0; i < properties.length; i += 2) { requireNonNull(properties[i], "property key is null"); requireNonNull(properties[i+1], "property value is null"); map.put(properties[i], properties[i+1]); } return registerTraceToken(new TraceToken(map)); } private  TraceTokenManager(); static TraceTokenScope registerRequestToken(@Nullable String tokenId); static TraceTokenScope registerTraceToken(@Nullable TraceToken token); @Deprecated @Nullable static String getCurrentRequestToken(); @Nullable static TraceToken getCurrentTraceToken(); static String createAndRegisterNewRequestToken(String... properties); static void clearRequestToken(); static TraceTokenScope addTraceTokenProperties(String... properties);  }