/** * Sets the current span in scope until the returned object is closed. It is a programming error * to drop or never close the result. Using try-with-resources is preferred for this reason. * * @param currentSpan span to place into scope or null to clear the scope */ public abstract Scope newScope(@Nullable TraceContext currentSpan);
/** * The parent's {@link #spanId} or null if this the root span in a trace. * * @see #parentIdAsLong() */ @Nullable public final Long parentId() { return parentId != 0 ? parentId : null; }
/** * The entire URL, including the scheme, host and query parameters if available or null if * unreadable. * * <p>Conventionally associated with the key "http.url" */ @Nullable public abstract String url(Req request);
/** * The HTTP status code or null if unreadable. * * <p>Conventionally associated with the key "http.status_code" * * @see #statusCodeAsInt(Object) */ @Nullable public abstract Integer statusCode(Resp response);
/** * Returns an overriding sampling decision for a new trace. Return null ignore the request and use * the {@link brave.sampler.Sampler trace ID sampler}. */ @Nullable public abstract <Req> Boolean trySample(HttpAdapter<Req, ?> adapter, Req request);
/** * The HTTP method, or verb, such as "GET" or "POST" or null if unreadable. * * <p>Conventionally associated with the key "http.method" */ @Nullable public abstract String method(Req request);
/** * Returns the same value, an updated one, or null to drop the annotation. * * @see brave.Span#annotate(long, String) */ @Nullable String update(long timestamp, String value); }
/** Allows you to create flags from a boolean value without allocating a builder instance */ public static SamplingFlags build(@Nullable Boolean sampled) { if (sampled != null) return sampled ? SAMPLED : NOT_SAMPLED; return EMPTY; }
public static TraceContextOrSamplingFlags create(@Nullable Boolean sampled, boolean debug) { if (debug) return DEBUG; if (sampled == null) return EMPTY; return sampled ? SAMPLED : NOT_SAMPLED; }
/** * Returns the same value, an updated one, or null to drop the tag. * * @see brave.Span#tag(String, String) */ @Nullable String update(String key, String value); }
/** * When null {@link brave.Tracing.Builder#localServiceName(String) default} will be used for * zipkin. */ @Nullable public String localServiceName() { return localServiceName; }
/** * The text representation of the primary IPv4 or IPv6 address associated with the remote side of * this connection. Ex. 192.168.99.100 null if unknown. * * @see brave.Span#remoteIpAndPort(String, int) */ @Nullable public String remoteIp() { return remoteIp; }
/** * Finishes the client span after assigning it tags according to the response or error. * * <p>This is typically called once the response headers are received, and after the span is * {@link brave.Tracer.SpanInScope#close() no longer in scope}. * * @see HttpClientParser#response(HttpAdapter, Object, Throwable, SpanCustomizer) */ public void handleReceive(@Nullable Resp response, @Nullable Throwable error, Span span) { handleFinish(response, error, span); } }
/** Returns true if the key/value was removed from the pair-indexed list at index {@code i} */ static boolean updateOrRemove(ArrayList list, int i, Object value, @Nullable Object newValue) { if (newValue == null) { list.remove(i); list.remove(i); return true; } else if (!value.equals(newValue)) { list.set(i + 1, newValue); } return false; }
/** Returns the last value associated with the key or null */ @Nullable public String tag(String key) { if (key == null) throw new NullPointerException("key == null"); if (key.isEmpty()) throw new IllegalArgumentException("key is empty"); String result = null; for (int i = 0, length = tags.size(); i < length; i += 2) { if (key.equals(tags.get(i))) result = tags.get(i + 1); } return result; }
@Nullable public static String ipOrNull(@Nullable String ip) { if (ip == null || ip.isEmpty()) return null; if ("::1".equals(ip) || "127.0.0.1".equals(ip)) return ip; // special-case localhost IpFamily format = detectFamily(ip); if (format == IpFamily.IPv4Embedded) { ip = ip.substring(ip.lastIndexOf(':') + 1); } else if (format == IpFamily.Unknown) { ip = null; } return ip; }
/** @see TraceContext#sampled() */ public Builder sampled(@Nullable Boolean sampled) { if (sampled == null) { flags &= ~(FLAG_SAMPLED_SET | FLAG_SAMPLED); return this; } return sampled(sampled.booleanValue()); }
/** * The absolute http path, without any query parameters or null if unreadable. Ex. * "/objects/abcd-ff" * * <p>Conventionally associated with the key "http.path" * @see #route(Object) */ @Nullable public String path(Req request) { String url = url(request); if (url == null) return null; return URI.create(url).getPath(); // TODO benchmark }