Repository navigation
feat(landing): Loguru for Python guide - #1576
JeremyFunk wants to merge 4 commits into
Conversation
Maple review🟢 Confidence 8/10 · likely safe to merge Adds a 829-line
Before merge
Findings🟠 Warning · F1 · Link to
|
| </p> | ||
| <Code code={customLevelCode} lang="python" theme={codeTheme} /> | ||
| <p> | ||
| Numbers matter when records leave Loguru. OpenTelemetry maps level numbers to severities, so <code>SUCCESS</code> (25) exports as <code>INFO4</code> and a custom level at 35 as <code>WARN4</code>. The <a href="/guides/python-logging-levels">Python logging levels guide</a> covers how to choose a level for a message. |
There was a problem hiding this comment.
Warning
Link to /guides/python-logging-levels has no page behind it
F1 · Warning · correctness
No python-logging-levels guide exists at this head or on main (apps/landing/src/pages/guides/ holds only api-latency, loguru, uptime-monitoring, what-is-apdex, what-is-apm, and the parallel PR is not merged), so a reader who clicks this link gets a 404 for as long as the other PR lags behind. Land both guides in the same deploy, or drop the sentence's link until the target exists.
Confirm the parallel `python-logging-levels` guide ships in the same deploy, or replace this anchor with plain text or a link to an existing page such as `/docs/explore/logs`.
🤖 Prompt to fix with an AI agent
In `apps/landing/src/pages/guides/loguru.astro:561`: Link to `/guides/python-logging-levels` has no page behind it.
No `python-logging-levels` guide exists at this head or on `main` (`apps/landing/src/pages/guides/` holds only `api-latency`, `loguru`, `uptime-monitoring`, `what-is-apdex`, `what-is-apm`, and the parallel PR is not merged), so a reader who clicks this link gets a 404 for as long as the other PR lags behind. Land both guides in the same deploy, or drop the sentence's link until the target exists.
Suggested fix: Confirm the parallel `python-logging-levels` guide ships in the same deploy, or replace this anchor with plain text or a link to an existing page such as `/docs/explore/logs`.
Verify the problem exists at that location before changing it, and keep the fix to those lines.
There was a problem hiding this comment.
Intentional: /guides/python-logging-levels is being added in a parallel guide PR. If this one merges first the link 404s until that lands; keeping it so the two guides cross-link.
There was a problem hiding this comment.
Devin Review found 1 potential issue.
1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
| logger.add("logs/workers.log", enqueue=True) | ||
|
|
||
| context = multiprocessing.get_context("spawn") | ||
| with context.Pool(4, initializer=set_logger, initargs=(logger,)) as pool: |
There was a problem hiding this comment.
🔴 Spawned workers fail before logging
On Linux with a fork default, enqueue=True creates a fork-context queue that the spawned pool cannot receive. context.Pool raises a SemLock context error before any worker logs.
Learn more
Loguru creates an enqueue=True multiprocessing queue using its configured multiprocessing context. The example creates that sink before selecting a spawn context for multiprocessing.Pool. On Linux installations whose default context is fork, Python refuses to pass the queue's fork-created synchronization primitives to spawn workers. The pool never starts, so the sample does not demonstrate shared worker logging.
Example: On Python 3.10 on Linux, multiprocessing.get_start_method() returns fork. The file sink gets a fork-context queue, but multiprocessing.get_context("spawn").Pool(...) tries to serialize it to a spawned worker and fails with a SemLock context error.
Recommended fix: Create context = multiprocessing.get_context("spawn") before the sink, then pass context=context to logger.add("logs/workers.log", enqueue=True, context=context). Keep the pool on that same context and validate the complete example on a Linux runtime whose default is fork.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Fixed in the latest commit: the sink now gets context=context from the same spawn context as the pool. Reproduced the SemLock failure locally by forcing a fork default, and confirmed the fixed snippet writes all 8 worker lines.
Maple review🟢 Confidence 8/10 · likely safe to merge Adds
Before merge
Still open from earlier reviews
Production impactTelemetry this change adds and removes (1)
What was checked
|
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 57 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Covers install, sinks with rotation/retention/compression, levels, formatting, serialize=True JSON, bind/contextualize, logger.catch, enqueue for async and multiprocessing, the InterceptHandler recipe, and a Loguru sink that forwards records to the OpenTelemetry LoggingHandler so logs keep their trace context.
… OpenTelemetry Six sections with a record-path diagram for the OpenTelemetry bridge, one color per system (Loguru, logging, OpenTelemetry) in badges, the diagram and code, script vs FastAPI/uvicorn tabs for the intercept, and highlighted code via the shared guide highlighter (adds json, python-logging, loguru-output).
4faba4c to
10f51ac
Compare
Maple review🟢 Confidence 8/10 · likely safe to merge Adds a Loguru/Python guide page with three new highlighter languages and lists it in the guides index and
Findings🟠 Warning · F2 · Both guide screenshots point at files that are not in
|
| File | Calls/day | Busiest operations |
|---|---|---|
apps/landing/src/pages/guides/loguru.astro |
105k | maple 105k/day, 91.1% err |
Telemetry this change adds and removes (1)
- ➕ span name
POST /checkout·apps/landing/src/pages/guides/loguru.astro:365
Ingest cost of new log lines
apps/landing/src/pages/guides/loguru.astro:58: If this logs once per call, about 854 MB/month: the file's operations run 105k times a day.apps/landing/src/pages/guides/loguru.astro:59: If this logs once per call, about 854 MB/month: the file's operations run 105k times a day.apps/landing/src/pages/guides/loguru.astro:60: If this logs once per call, about 854 MB/month: the file's operations run 105k times a day.apps/landing/src/pages/guides/loguru.astro:62: If this logs once per call, about 854 MB/month: the file's operations run 105k times a day.apps/landing/src/pages/guides/loguru.astro:63: If this logs once per call, about 854 MB/month: the file's operations run 105k times a day.apps/landing/src/pages/guides/loguru.astro:69: If this logs once per call, about 854 MB/month: the file's operations run 105k times a day.apps/landing/src/pages/guides/loguru.astro:70: If this logs once per call, about 854 MB/month: the file's operations run 105k times a day.apps/landing/src/pages/guides/loguru.astro:71: If this logs once per call, about 854 MB/month: the file's operations run 105k times a day.apps/landing/src/pages/guides/loguru.astro:115: If this logs once per call, about 854 MB/month: the file's operations run 105k times a day.apps/landing/src/pages/guides/loguru.astro:158: If this logs once per call, about 854 MB/month: the file's operations run 105k times a day.
What was checked
tokenizecannot loop: unmatched characters advancei(guide-highlight.ts:37)- Every interpolated value in the new tokenizers goes through
escape(guide-highlight.ts:18) - All 22 TOC slugs match a heading
idin the page
10f51ac · Updated on every push. Reply "won't fix" to dismiss a finding, or mention @maple-review-bot to ask about one.
Maple review🟢 Confidence 8/10 · likely safe to merge The new commit adds the two guide screenshots the figures point at, closing the broken-image finding; nothing else in the file changed. Mergeable except for the Still open from earlier reviews
Fixed since the last review
Production impactProduction traffic of the changed files (last 7 days)
Telemetry this change adds and removes (1)
Ingest cost of new log lines
What was checked
|
Adds
/guides/loguru: Loguru for Python, from the first log line to OpenTelemetry export with trace correlation.What the page covers
pip install loguru,ModuleNotFoundError, the default logger and an annotated default line mapped to its record fields.remove/add,LOGURU_LEVEL, per-module filter), a levels table with the stdlib and OpenTelemetry severity for each level, custom levels, rotation/retention/compression, format strings.serialize=True, a flat JSON function sink,bind()andcontextualize().logger.catch,logger.exception,diagnose(off in production),enqueue=Truewith a spawn-context pool.InterceptHandler, with tabs for a plain script and FastAPI + uvicorn; Loguru vs logging table.LoggingHandler, OTLP), the bridge sink, the rules it relies on (noenqueue=True, filteropentelemetry*records,propagate = False, no reservedextrakeys), a console-exporter check, and the Logs page in Maple.Search intent: people looking up Loguru want to install it and get a working setup quickly. The page leads with that, then covers production setup and OpenTelemetry export.
Code blocks use the shared
guide-highlight.ts, which gains three additive languages:json,python-logging(Loguru / logging / OpenTelemetry identifiers get their own classes) andloguru-output.Maple docs linked
/docs/guides/instrumentation-python/docs/explore/logsVerification
Every snippet was run on Python 3.12.13 with loguru 0.7.3, opentelemetry-sdk 1.45.1, opentelemetry-exporter-otlp-proto-http 1.45.1, opentelemetry-instrumentation-logging 0.66b1, FastAPI 0.154.0, uvicorn 0.54.0:
telemetry.py(last line removed) exporting to a local OTLP receiver: Loguru and stdlib records are each exported once with the span's trace ID; keeping the rootLoggingHandlernext to the intercept exports stdlib records twice.enqueue=Trueon the bridge exports an all-zero trace ID; without theopentelemetryfilter a failing exporter re-queues its own errors; withoutpropagate = FalseLoguru reports a re-entrant logging error; a boundnamekey makesmakeRecordraise.python:3.12-slim): withoutcontext=, the pool fails with the SemLockRuntimeError.uvicorn main:appwith the handler-clearing loop anduvicorn.run(app, log_config=None)route access logs through Loguru.Sources