Skip to content

PostgreSQLHandler logs wrong server_type/server_id for multi-service machines #643

@lwhite1

Description

@lwhite1

Problem

PostgreSQLHandler.emit() derives server_type and server_id at log-time from the OS environment:

# log_manager.py:348-349
"server_type": config.get_server_name_from_env(),   # USERPROFILE → "presentation" / "acquisition" / "control"
"server_id": platform.uname().node,                 # hostname → "stm" / "acq" / "ctr"

This breaks when a machine runs more than one service. The new ACQ service on the STM machine logs as presentation|stm — identical to the presentation service — making it impossible to distinguish which service produced a log_application row.

The correct identity is already known at startup:

  • server_acq.py:37enable_crash_handler(f"ACQ_{acq_index}")
  • server_acq.py:41config.load_config_by_service_name("ACQ", acq_index=acq_index)
  • server_stm.py:40enable_crash_handler("STM")
  • gui.py:647enable_crash_handler("CTR")

But PostgreSQLHandler never receives this information.

Impact

Cannot analyze mbient connect/reset timing by service when RF/LF are managed by the new acquisition service on the STM machine. All five mbients appear to come from only two server identities (acquisition|acq and presentation|stm) even though there are now three services.

Proposed fix

Store the service identity in a module-level variable in log_manager.py (like SESSION_ID and SUBJECT_ID), set it once at startup, and use it in emit():

  1. Add a module-level SERVICE_NAME: str = "" to log_manager.py.
  2. Have make_db_logger() accept an optional service_name parameter and store it in SERVICE_NAME.
  3. In PostgreSQLHandler.emit(), replace:
    "server_type": config.get_server_name_from_env(),
    "server_id": platform.uname().node,
    with:
    "server_type": _role_from_service_name(SERVICE_NAME),  # "acquisition", "presentation", "control"
    "server_id": SERVICE_NAME,                              # "ACQ_0", "ACQ_1", "STM", "CTR"
  4. Update the three entry points to pass the service name through:
    • server_acq.pymake_db_logger(service_name=f"ACQ_{acq_index}")
    • server_stm.pymake_db_logger(service_name="STM")
    • gui.pymake_db_logger(service_name="CTR")

This keeps server_type as a coarse role for filtering and makes server_id the specific service instance. No schema changes needed — just different values written to the existing columns.

Files

  • neurobooth_os/log_manager.pyPostgreSQLHandler.emit() (line 348-349), make_db_logger() (line 115)
  • neurobooth_os/server_acq.pymain() (line 42)
  • neurobooth_os/server_stm.pymain() (line 45)
  • neurobooth_os/gui.pysetup_log() / main() (line 652)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions