in spectator-ext-sandbox/src/main/java/com/netflix/spectator/sandbox/HttpLogEntry.java [134:178]
private static void log(Logger logger, Marker marker, HttpLogEntry entry) {
Preconditions.checkNotNull(entry.method, "method");
Id dimensions = REGISTRY.createId("tags")
.withTag("mode", marker.getName())
.withTag("status", entry.getStatusTag())
.withTag("statusCode", entry.getStatusCodeTag())
.withTag("method", entry.method);
if (entry.clientName != null) {
dimensions = dimensions.withTag("client", entry.clientName);
}
if (marker == SERVER && entry.path != null) {
dimensions = dimensions.withTag("endpoint", longestPrefixMatch(entry.path, "other"));
}
// Update stats for the final attempt after retries are exhausted
if (!entry.canRetry || entry.attempt >= entry.maxAttempts) {
BucketTimer.get(REGISTRY, COMPLETE.withTags(dimensions.tags()), BUCKETS)
.record(entry.getOverallLatency(), TimeUnit.MILLISECONDS);
}
// Update stats for every actual http request
BucketTimer.get(REGISTRY, ATTEMPT.withTags(dimensions.tags()), BUCKETS)
.record(entry.getLatency(), TimeUnit.MILLISECONDS);
REGISTRY.distributionSummary(REQ_HEADER_SIZE.withTags(dimensions.tags()))
.record(entry.getRequestHeadersLength());
REGISTRY.distributionSummary(REQ_ENTITY_SIZE.withTags(dimensions.tags()))
.record(entry.requestContentLength);
REGISTRY.distributionSummary(RES_HEADER_SIZE.withTags(dimensions.tags()))
.record(entry.getResponseHeadersLength());
REGISTRY.distributionSummary(RES_ENTITY_SIZE.withTags(dimensions.tags()))
.record(entry.responseContentLength);
// Write data out to logger if enabled. For many monitoring use-cases there tend to be
// frequent requests that can be quite noisy so the log level is set to debug. This class is
// mostly intended to generate something like an access log so it presumes users who want the
// information will configure an appender based on the markers to send the data to a
// dedicated file. Others shouldn't have to deal with the spam in the logs, so debug for the
// level seems reasonable.
if (logger.isDebugEnabled(marker)) {
logger.debug(marker, entry.toString());
}
}