/** * @return The current thread's trace token, or null if no token. */ @Nullable public static TraceToken getCurrentTraceToken() { TokenState tokenState = token.get(); if (tokenState == null) { return null; } return tokenState.getToken(); }
/** * @return The current thread's trace token in string form, or null if no token. * @deprecated Use {@link #getCurrentTraceToken()}. */ @Deprecated @Nullable public static String getCurrentRequestToken() { TokenState tokenState = token.get(); if (tokenState == null) { return null; } return tokenState.getToken().toString(); }
/** * Add properties to the current thread's trace token. If there is * currently no trace token, does nothing. * * @param properties Properties to add or replace. * @return a {@link TraceTokenScope} which may be used to restore the thread's * previous set of properties. */ 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)); }
return new TraceTokenScope(oldTokenState.getToken());
@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof TraceTokenManager.TokenState) { TraceTokenManager.TokenState that = (TraceTokenManager.TokenState) o; return (this.token.equals(that.getToken())) && (this.oldThreadName.equals(that.getOldThreadName())); } return false; }