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

chore: enforce kwarg logging #7207

Merged
merged 17 commits into from
Feb 29, 2024
Merged

chore: enforce kwarg logging #7207

merged 17 commits into from
Feb 29, 2024

Conversation

wochinge
Copy link
Contributor

@wochinge wochinge commented Feb 26, 2024

Related Issues

Proposed Changes:

  • add a wrapped logger which enforces logging through kwargs

How did you test it?

  • added unit tests

Notes for the reviewer

Checklist

@wochinge wochinge changed the title Chore/enforce extra logging chore: enforce extra logging Feb 26, 2024
test/test_logging.py Outdated Show resolved Hide resolved
Base automatically changed from feat/structured-logging to main February 27, 2024 08:15
@github-actions github-actions bot added the 2.x Related to Haystack v2.0 label Feb 27, 2024
@wochinge wochinge changed the title chore: enforce extra logging chore: enforce kwarg logging Feb 28, 2024
Copy link
Contributor

@masci masci left a comment

Choose a reason for hiding this comment

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

Let's do this, I think the approach has several advantages:

  • it brings in consistency
  • it makes structure logging effective, not just an available feature
  • I like when Haystack is opinionated, and this is a great opportunity to do so

Approving the idea, code review to be done

@@ -296,6 +296,7 @@ select = [
"T10", # flake8-debugger
"W", # pycodestyle
"YTT", # flake8-2020
"I" # isort
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm sorry for this as this causes a big diff but pylint complains about the import order for all logging imports (since the third-party import of logging became a first-party import from haystack) and I couldn't bother fixing them manually. In my opinion this should be enabled by default (and we should also run ruff in the CI!)

Copy link
Contributor

Choose a reason for hiding this comment

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

We tried but turned out we should rethink the whole lint/format workflow, see #5931

@@ -1,9 +1,9 @@
import haystack.logging
Copy link
Contributor Author

Choose a reason for hiding this comment

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

explanation for import order change here: https://github.com/deepset-ai/haystack/pull/7207/files#r1505884720

@@ -40,23 +41,6 @@ def test_skip_logging_configuration(
# Nothing should be captured by capfd since structlog is not configured
assert capfd.readouterr().err == ""

def test_skip_logging_if_structlog_not_installed(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this somehow breaks pytest itself. I tried to fix it but couldn't figure out what happened. Would be nice to test the import error but in my opinion also not super crucial (it's hard to test in the first place)

return wrapper


def _patch_structlog_call_information(logger: logging.Logger) -> None:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wholeheartedly apologize for this 😫

Copy link
Contributor Author

Choose a reason for hiding this comment

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

created an issue for this as well: hynek/structlog#602

@coveralls
Copy link
Collaborator

coveralls commented Feb 28, 2024

Pull Request Test Coverage Report for Build 8096409462

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 242 unchanged lines in 42 files lost coverage.
  • Overall coverage decreased (-0.2%) to 89.901%

Files with Coverage Reduction New Missed Lines %
components/preprocessors/document_cleaner.py 1 98.81%
components/routers/conditional_router.py 1 97.18%
components/websearch/searchapi.py 1 96.3%
components/writers/document_writer.py 1 97.37%
core/type_utils.py 1 97.56%
tracing/opentelemetry.py 1 97.14%
components/converters/azure.py 2 91.53%
components/converters/txt.py 2 90.0%
components/embedders/hugging_face_tei_document_embedder.py 2 95.16%
components/embedders/hugging_face_tei_text_embedder.py 2 92.68%
Totals Coverage Status
Change from base Build 8095219408: -0.2%
Covered Lines: 5279
Relevant Lines: 5872

💛 - Coveralls

@wochinge wochinge requested a review from masci February 28, 2024 16:15
@wochinge wochinge marked this pull request as ready for review February 28, 2024 16:15
@wochinge wochinge requested review from a team as code owners February 28, 2024 16:15
@wochinge wochinge requested review from dfokina and silvanocerza and removed request for a team February 28, 2024 16:15
Copy link
Contributor

@masci masci left a comment

Choose a reason for hiding this comment

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

Left one question but it looks very good to me! Now that I see in action I'm even more convinced this is the right approach, love it!

I might as well miss something but I swear I went through all the changed files 😅

@@ -296,6 +296,7 @@ select = [
"T10", # flake8-debugger
"W", # pycodestyle
"YTT", # flake8-2020
"I" # isort
Copy link
Contributor

Choose a reason for hiding this comment

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

We tried but turned out we should rethink the whole lint/format workflow, see #5931

"Increase the max_tokens parameter to allow for longer completions.",
message.meta["index"],
index=message.meta["index"],
finish_reason=message.meta["finish_reason"],
Copy link
Contributor

Choose a reason for hiding this comment

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

I can't see the {finish_reason} placeholder, is that missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

great catch - this is actually an extra key-value which I found useful to be logged (so it's not interpolated in the message, just attached as key value)

@wochinge wochinge merged commit fe0ac5c into main Feb 29, 2024
23 of 24 checks passed
@wochinge wochinge deleted the chore/enforce-extra-logging branch February 29, 2024 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants