Skip to content

feat(aci): Context logging #93617

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 17, 2025
Merged

feat(aci): Context logging #93617

merged 6 commits into from
Jun 17, 2025

Conversation

kcons
Copy link
Member

@kcons kcons commented Jun 16, 2025

Add helpers for automatically adjusting logging based on context.

The aim here is to lean firmly toward keeping our scopes safe with root designations and context managers; better no annotations than wrong annotations.

@kcons kcons requested review from a team as code owners June 16, 2025 16:48
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jun 16, 2025
@kcons
Copy link
Member Author

kcons commented Jun 16, 2025

Note: I've applied this widely for demonstration purposes, but I'm happy to revert any of that for initial landing.

Copy link

codecov bot commented Jun 16, 2025

Codecov Report

Attention: Patch coverage is 98.65772% with 2 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...try/workflow_engine/processors/delayed_workflow.py 80.00% 1 Missing ⚠️
src/sentry/workflow_engine/utils/log_context.py 98.21% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           master   #93617    +/-   ##
========================================
  Coverage   88.03%   88.03%            
========================================
  Files       10328    10330     +2     
  Lines      596106   596252   +146     
  Branches    23146    23146            
========================================
+ Hits       524760   524900   +140     
- Misses      70890    70896     +6     
  Partials      456      456            

Copy link
Contributor

@saponifi3d saponifi3d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall this lgtm as a generic logger solution.

i think we might want to introduce a little magic in a follow up PR to simplify the using the logger; either configuring the logger at the beginning of each processor method or have helpers use context vars.

i think we'll also need to think about the logger.debug vs logger.info etc, it's assuming correct use of each log level throughout. we could create a helper method to ensure that info / debug logs are locked down to orgs opt'd in (just for workflow engine).

@@ -247,7 +248,9 @@ def process_workflows(event_data: WorkflowEventData) -> set[Workflow]:
"""
try:
detector = get_detector_by_event(event_data)
log_context.add_extras(detector_id=detector.id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how are you thinking add_extras might work with WorkflowEventContext? would that be included initially?

Comment on lines 607 to 610
if features.has("projects:num-events-issue-debugging", project) or features.has(
"organizations:workflow-engine-process-workflows", project.organization
):
log_context.set_verbose(True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this format for a general purpose logger -- is there a way we can simplify adoption of this inside of workflow engine so we can easily filter down to specific orgs by just setting a flag?

one thought i had around this is that we could initialize the logger with this context data in the processing methods? 🤔

_log_context_state.get().verbose = verbose


def add_extras(**extras: Any) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iirc we had discussed adding a trace_id or something along those lines to track individual evaluations. how are you thinking that would work with .add_extras?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We currently have context_id automatically annotated in all of these when there's a log root. Are there cases not covered by that where we want an ID?

@kcons kcons enabled auto-merge (squash) June 17, 2025 23:03
@kcons kcons merged commit 0bb4528 into master Jun 17, 2025
63 checks passed
@kcons kcons deleted the kcons/loggy branch June 17, 2025 23:22
Copy link

sentry-io bot commented Jun 18, 2025

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ OperationalError: connection to server at "127.0.0.1", port 6432 failed: Connection refused sentry.tasks.post_process.post_process_group View Issue
  • ‼️ ValueError: No open periods found for group sentry.tasks.post_process.post_process_group View Issue

Did you find this useful? React with a 👍 or 👎

andrewshie-sentry pushed a commit that referenced this pull request Jun 19, 2025
Add helpers for automatically adjusting logging based on context.

The aim here is to lean firmly toward keeping our scopes safe with root
designations and context managers; better no annotations than wrong
annotations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants