Conversation
…ost.json warnings Closes #78 - Promote _reset_context_vars to public reset_context() so callers can defensively clear invocation context on reused workers. - Add logging_context() context manager that injects on enter and always resets on exit (even when the wrapped block raises), preventing stale context from leaking across invocations. - Update with_context decorator to use the new public reset_context(). - Make host.json conflict detection category-aware: iterate every entry under logging.logLevel (default, Function, Function.<name>, Host.*) and emit one warning per category that is more restrictive than the configured level. Previously only the 'default' key was inspected. - Document logging_context as the recommended Quick Start pattern in README; keep inject_context/reset_context as the lower-level API for custom middleware. - Tests: cover reset_context idempotency, logging_context happy path and exception path, per-category host.json warnings, ContextFilter install idempotency under repeated setup_logging calls, and the WEBSITE_INSTANCE_ID-only Azure environment branch.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #78
Summary
P1 follow-ups from the external review, split into two related concerns: invocation-context lifecycle and category-aware host.json conflict detection.
Context lifecycle
_reset_context_vars()helper to a publicreset_context()API. Callers (custom middleware, test teardown, defensive wrappers) can now explicitly clear invocation context on reused workers.logging_context(context)— a context manager that callsinject_context()on enter and always callsreset_context()on exit, even when the wrapped block raises. This eliminates the most common footgun: staleinvocation_id/cold_startleaking into the next invocation on a warm worker.with_contextdecorator now uses the new publicreset_context()instead of its private duplicate, so there is a single source of truth for the reset semantics.with logging_context(context):and keepsinject_context/reset_contextdocumented as the lower-level primitives for custom integrations.host.json category-aware warnings
warn_host_json_level_conflictpreviously inspected only thedefaultkey underlogging.logLevel. Real Azure Functions apps configure per-category levels (Function,Function.<name>,Host.Results,Host.Aggregator, …) and those silent suppressions were going undetected.logging.logLevel, resolve each level, and emit one warning per category that is more restrictive than the configured Python level.defaultfrom named categories (logLevel for category 'Function' is set to 'Warning' …).logLevelblocks are tolerated (no warning, no crash).Tests
reset_context_clears_all,reset_context_idempotentlogging_context_sets_then_resets,logging_context_resets_when_body_raiseswarns_per_category,no_warning_when_all_permissive,no_warning_when_log_level_block_is_not_a_dictdoes_not_install_duplicate_context_filters(idempotent ContextFilter install)only_website_instance_id_is_false(Azure-env detection edge case)test_public_api_exportsandtest_integration.test_public_api_exportsupdated for the two new exports.Validation
make lint— cleanmake typecheck— clean (24 source files)make test— 142 passed, 3 skipped (e2e), coverage 97.05%make build— sdist + wheel producedCompatibility
inject_contextandwith_contextkeep their existing semantics.reset_context,logging_context. Both are typed and exported via__all__.