Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Tensorflow Serving server request logger h

From Leeroopedia
Knowledge Sources
Domains Model Serving, Request Logging
Last Updated 2026-02-13 00:00 GMT

Overview

ServerRequestLogger logs a sample of requests for all models in the server, managing per-model logging configurations with dynamic update support.

Description

ServerRequestLogger is the server-wide orchestrator for request logging. It manages a mapping from model names to their RequestLogger instances and supports dynamic configuration updates. Multiple models can share a single RequestLogger if they have identical logging configurations, avoiding duplicate log collector instances.

Key features:

  • Dynamic configuration: The Update() method accepts a map from model name to LoggingConfig and reconfigures loggers accordingly. A two-phase update API is also available: CreateUpdateRequest() validates the config and produces an UpdateRequest, which can later be applied infallibly via ApplyUpdateRequest().
  • Multi-sink logging: A model can have multiple logging configs (multiple sinks), and Log() writes to all configured sinks, returning the first error encountered.
  • Streaming support: StartLoggingStream() creates a StreamLogger and registers callbacks from all applicable RequestLogger instances.
  • Config deduplication: Models sharing the same LoggingConfig share a single RequestLogger instance via the config_to_logger_map_.

The class uses FastReadDynamicPtr for the model-to-loggers map, enabling lock-free reads on the hot path while serializing updates via a separate mutex.

Usage

Use ServerRequestLogger at the server level to handle request logging for all hosted models. It is typically created once during server initialization and updated whenever model logging configurations change.

Code Reference

Source Location

  • Repository: Tensorflow_Serving
  • File: tensorflow_serving/core/server_request_logger.h
  • Lines: 1-193

Signature

class ServerRequestLogger {
 public:
  using LoggerCreator = std::function<absl::Status(
      const LoggingConfig& logging_config, std::shared_ptr<RequestLogger>*)>;

  static absl::Status Create(
      LoggerCreator request_logger_creator,
      std::unique_ptr<ServerRequestLogger>* server_request_logger);

  virtual ~ServerRequestLogger() = default;

  virtual absl::StatusOr<UpdateRequest> CreateUpdateRequest(
      const std::map<string, std::vector<LoggingConfig>>& logging_config_map) const;
  virtual void ApplyUpdateRequest(UpdateRequest& req);
  virtual absl::Status Update(
      const std::map<string, std::vector<LoggingConfig>>& logging_config_map);

  virtual absl::Status Log(const google::protobuf::Message& request,
                           const google::protobuf::Message& response,
                           const LogMetadata& log_metadata);

  template <typename Request, typename Response>
  std::unique_ptr<StreamLogger<Request, Response>> StartLoggingStream(
      const LogMetadata& log_metadata,
      CreateStreamLoggerFn<Request, Response> create_stream_logger_fn);
};

Import

#include "tensorflow_serving/core/server_request_logger.h"

I/O Contract

Inputs

Name Type Required Description
request_logger_creator LoggerCreator Yes Factory function to create RequestLogger instances from LoggingConfig
logging_config_map std::map<string, std::vector<LoggingConfig>> Yes (for Update) Mapping from model name to its logging configurations
request const google::protobuf::Message& Yes (for Log) The request protobuf to log
response const google::protobuf::Message& Yes (for Log) The response protobuf to log
log_metadata const LogMetadata& Yes (for Log) Metadata including the model spec

Outputs

Name Type Description
Create() absl::Status OK on success; constructs the ServerRequestLogger
Update() absl::Status OK if config was applied; error if creator is empty but config is non-empty
Log() absl::Status OK if logged to all sinks; first error from any failed sink
StartLoggingStream() std::unique_ptr<StreamLogger<Req, Resp>> A StreamLogger with registered callbacks, or nullptr if not sampled

Usage Examples

Creating and Using ServerRequestLogger

#include "tensorflow_serving/core/server_request_logger.h"

using namespace tensorflow::serving;

auto logger_creator = [](const LoggingConfig& config,
                         std::shared_ptr<RequestLogger>* logger) {
  // Create a RequestLogger subclass based on config
  return absl::OkStatus();
};

std::unique_ptr<ServerRequestLogger> server_logger;
TF_CHECK_OK(ServerRequestLogger::Create(logger_creator, &server_logger));

// Configure logging for models
std::map<string, std::vector<LoggingConfig>> config_map;
config_map["my_model"] = {logging_config};
TF_CHECK_OK(server_logger->Update(config_map));

// Log a request
LogMetadata metadata;
metadata.mutable_model_spec()->set_name("my_model");
TF_CHECK_OK(server_logger->Log(request, response, metadata));

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment