Skip to content
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

feat(logging)!: add client & worker option to pass a custom logger #1171

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nikoksr
Copy link

@nikoksr nikoksr commented Jan 9, 2025

Description

We're actively using and building on Hatchet and enjoy it a lot. Not being able to plug our logger into the system is an issue for us though. This PR aims to provide a solution that seamlessly fits into the existing Hatchet SDK.

Adds WithLogger() option to the client and worker. The option replaces the WithLogLevel() option as its possible to supply a logger with the desired log-level and pass it to WithLogger().

Note: Since the removal of WithLogLevel technically is a breaking change, I'd be fine with rolling this part back despite the functional redundancy.

Note: PR is incomplete on purpose; wanted to validate the contribution before completing it.

Relates to #1170

Examples

Setting a custom logger:

logger := zerolog.New(os.Stdout)

// Client
hatchet, err := client.New(
    client.WithLogger(&logger),
    // other options ...
)

// Worker
worker, err := worker.NewWorker(
    worker.WithLogger(&logger),
    // other options ...
)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Documentation change (pure documentation change)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (non-breaking changes to code which doesn't change any behaviour)
  • CI (any automation pipeline changes)
  • Chore (changes which are not directly related to any business logic)
  • Test changes (add, refactor, improve or change a test)
  • This change requires a documentation update

What's Changed

  • Add client.WithLogger option
  • Remove client.WithLogLevel option
  • Add worker.WithLogger option
  • Remove worker.WithLogLevel option

Extra

Thank you for building Hatchet, really enjoy working with it and I'd love to contribute more in the future. Cheers to you guys :)

Adds WithLogger() option to the client and worker. The option replaces
the WithLogLevel() option as its possible to supply a logger with the
desired log-level and pass it to WithLogger().
Copy link

vercel bot commented Jan 9, 2025

@nikoksr is attempting to deploy a commit to the Hatchet Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

@abelanger5 abelanger5 left a comment

Choose a reason for hiding this comment

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

Hey @nikoksr, thank you for this PR!

I just wanted to confirm: is the intention for this PR to provide a custom logger for Hatchet internal messages, or to provide a custom logger to automatically send application logs to Hatchet (which are displayed in the Hatchet UI)?

If it's the former, I believe we can work on this in conjunction with #1170, as these are targeting separate concerns. Otherwise we'll need to find a way to consolidate the PRs.

worker.WithMaxRuns(200),
)

w, err := worker.NewWorker(worker.WithClient(c), worker.WithMaxRuns(200))
Copy link
Contributor

Choose a reason for hiding this comment

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

Would definitely pass in a zerolog logger configured to log at a warn level -- otherwise this test becomes very noisy.

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