[OPIK-5191] [BE] feat: add user identity to ClickHouse log_comment#5778
[OPIK-5191] [BE] feat: add user identity to ClickHouse log_comment#5778
Conversation
…r query attribution Extend the existing log_comment SETTINGS format from `query_name:workspace_id:details` to `query_name:workspace_id:user_name:details` so slow query investigations can identify which user triggered each query. The userName is already available in scope at every call site (first parameter of the makeMonoContextAware lambda) — this change simply passes it through to the log_comment string. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
📋 PR Linter Failed❌ Missing Section. The description is missing the ❌ Missing Section. The description is missing the ❌ Missing Section. The description is missing the ❌ Missing Section. The description is missing the ❌ Missing Section. The description is missing the |
2 similar comments
📋 PR Linter Failed❌ Missing Section. The description is missing the ❌ Missing Section. The description is missing the ❌ Missing Section. The description is missing the ❌ Missing Section. The description is missing the ❌ Missing Section. The description is missing the |
📋 PR Linter Failed❌ Missing Section. The description is missing the ❌ Missing Section. The description is missing the ❌ Missing Section. The description is missing the ❌ Missing Section. The description is missing the ❌ Missing Section. The description is missing the |
| public static ST getSTWithLogComment(String query, String queryName, String workspaceId, String userName, | ||
| Object details) { | ||
| var logComment = getLogComment(queryName, workspaceId, userName, details); | ||
| return TemplateUtils.newST(query) | ||
| .add("log_comment", logComment); | ||
| } | ||
|
|
||
| public static String getLogComment(String queryName, String workspaceId, Object details) { | ||
| public static String getLogComment(String queryName, String workspaceId, String userName, Object details) { | ||
| return TemplateUtils.newST(LOG_COMMENT) | ||
| .add("query_name", queryName != null ? queryName.replace("'", "''") : null) | ||
| .add("workspace_id", workspaceId != null ? workspaceId.replace("'", "''") : null) | ||
| .add("user_name", userName != null ? userName.replace("'", "''") : null) |
There was a problem hiding this comment.
getLogComment logs RequestContext.USER_NAME into ClickHouse (which can include emails/PII) and violates .agents/skills/opik-backend/SKILL.md; should we restrict log_comment to a non-PII identifier like workspace_id/opaque user ID or mask the user string?
Finding type: AI Coding Guidelines | Severity: 🔴 High
Want Baz to fix this for you? Activate Fixer
Other fix methods
Prompt for AI Agents:
Before applying, verify this suggestion against the current code. In
apps/opik-backend/src/main/java/com/comet/opik/infrastructure/DatabaseUtils.java around
lines 174 to 185, the getLogComment method currently adds user_name directly into
log_comment which can contain PII (emails/display names). Change getLogComment to NOT
log raw user_name: either remove the .add("user_name", ...) entry entirely or replace it
with a sanitized non-PII value (for example: look up an opaque user id from
RequestContext or compute a short deterministic hash of the user_name and render it as
"user_hash:<first8chars>" or mask emails by replacing the local-part with '***'). Make
the change in getLogComment and update getSTWithLogComment signature/usage if needed to
accept the sanitized value; preserve the existing single-quote escaping behavior for the
final rendered string. Add a short unit test ensuring that log_comment never contains an
'@' or full email and that workspace_id continues to be logged as before.
andrescrz
left a comment
There was a problem hiding this comment.
LGTM, just a future suggestion.
|
|
||
| public static ST getSTWithLogComment(String query, String queryName, String workspaceId, Object details) { | ||
| var logComment = getLogComment(queryName, workspaceId, details); | ||
| public static ST getSTWithLogComment(String query, String queryName, String workspaceId, String userName, |
There was a problem hiding this comment.
Nit: at some point we will need to create a Java record (with a builder) for the whole payload containing the query_name, workspace_id etc. fields for the log comment, instead of so many params.
Details
Extends the existing ClickHouse
log_commentSETTINGS format fromquery_name:workspace_id:detailstoquery_name:workspace_id:user_name:detailsso slow query investigations can identify which user triggered each query.userNameparameter toDatabaseUtils.getSTWithLogComment()andgetLogComment()userNamewas already in scope at every site (first param ofmakeMonoContextAwarelambda)Change checklist
Issues
AI-WATERMARK
AI-WATERMARK: yes
Testing
mvn compilepasses with zero errorslog_commentorDatabaseUtils— consistent with prior log_comment changes (OPIK-5050, OPIK-4380) which also had no testsDocumentation
No documentation changes needed — internal observability improvement only.