Skip to content

Change_log_level #187

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 12 commits into from
Jun 25, 2025
Merged

Change_log_level #187

merged 12 commits into from
Jun 25, 2025

Conversation

GSmithApps
Copy link
Contributor

@GSmithApps GSmithApps commented May 23, 2025

What was changed

Added a hello sample showing how to change the log level for workflow task failures

Why?

Some users have requested a sample on this.

Checklist

  1. Any docs updates needed?
    Updated the top-level readme and the hello readme

  2. How was this tested:
    Ran and confirmed that the log level was changed to error

image

@GSmithApps GSmithApps requested a review from a team as a code owner May 23, 2025 17:46
@GSmithApps GSmithApps force-pushed the changle_log_level branch from 5cfa4c5 to 598c1af Compare May 23, 2025 17:48
return True


logging.getLogger("temporalio.worker._workflow_instance").addFilter(CustomLogFilter())
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
logging.getLogger("temporalio.worker._workflow_instance").addFilter(CustomLogFilter())
logging.getLogger().addFilter(CustomLogFilter())

Can we add this to the root logger instead (untested)? There are no guarantees about how we may refactor internals.

Copy link
Contributor Author

@GSmithApps GSmithApps Jun 17, 2025

Choose a reason for hiding this comment

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

Thank you very much for catching this! I believe it is solved 👍

Copy link
Member

Choose a reason for hiding this comment

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

May be able to add a test for this to confirm continued expected behavior (though I know we haven't always added tests for all samples)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for keeping me honest!

Speaking of that, I vibe coded a test that that checks what we want: it passes with the code as-is, but it fails if I remove the sample's configuration to elevate the logging.

@GSmithApps GSmithApps changed the title Changle_log_level Change_log_level Jun 5, 2025
from temporalio.worker import Worker

# --- Begin logging set‑up ----------------------------------------------------------
_WORKFLOW_TASK_FAILURE_LOG_PREFIX = "Failed activation on workflow"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cretz I'm a little worried about this hardcoding cuz I'm not sure we guarantee this log message won't be modified.

  • If it won't be modified, I think we don’t have anything to worry about
  • if it could be modified, could we do something like expose a constant from the SDK? I recognize it might be a little goofy, but it might be more robust

Copy link
Member

Choose a reason for hiding this comment

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

Yes, this is exactly why we just solved temporalio/sdk-python#864 last week. I'd wait until that is released (soon).

Copy link
Contributor Author

@GSmithApps GSmithApps Jun 20, 2025

Choose a reason for hiding this comment

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

Thanks @cretz! I see the new SDK was released and includes the fix (888). Judging by the files changed in the PR, this string didn’t change, correct? So the benefit of the PR is adding the test to reinforce the fact that this string is public API and won’t change? Meaning, the sample is still good? I know you said nothing blocking

Copy link
Member

Choose a reason for hiding this comment

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

The message string didn't change, but the purpose of the issue is to add another, more stable string for this use case. So we should encourage in this sample to check __temporal_error_identifier attribute instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks — that looked private to me, but upon further inspection, it’s okay to use. Done ✅

Copy link
Member

@cretz cretz left a comment

Choose a reason for hiding this comment

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

LGTM, nothing really blocking, but let's wait for the impending Python SDK release so you can use a more deliberate differentiator on the log record.

from temporalio.worker import Worker

# --- Begin logging set‑up ----------------------------------------------------------
_WORKFLOW_TASK_FAILURE_LOG_PREFIX = "Failed activation on workflow"
Copy link
Member

Choose a reason for hiding this comment

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

Yes, this is exactly why we just solved temporalio/sdk-python#864 last week. I'd wait until that is released (soon).

Comment on lines 58 to 59
id="hello-workflow-id",
task_queue="hello-task-queue",
Copy link
Member

Choose a reason for hiding this comment

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

Would recommend an ID and task queue named specifically for this sample

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Love it - fixed 👍

@GSmithApps
Copy link
Contributor Author

GSmithApps commented Jun 25, 2025

I believe all comments are resolved and this is ready. The tests are failing, but I suspect it’s due to some flakes because they're failing in main too the tests are passing now

@GSmithApps
Copy link
Contributor Author

@cretz ready if you are 👍

Copy link
Member

@cretz cretz left a comment

Choose a reason for hiding this comment

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

I still think this is a bit too specific of a need to go with all the other hello things, but meh

@GSmithApps GSmithApps merged commit 1387fbd into temporalio:main Jun 25, 2025
12 of 35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants