Skip to content

feat(landing): Loguru for Python guide - #1576

Open
JeremyFunk wants to merge 4 commits into
mainfrom
feat/guide-loguru
Open

JeremyFunk wants to merge 4 commits into
mainfrom
feat/guide-loguru

Conversation

@JeremyFunk

@JeremyFunk JeremyFunk commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

Adds /guides/loguru: Loguru for Python, from the first log line to OpenTelemetry export with trace correlation.

What the page covers

  • What Loguru is: definition, pip install loguru, ModuleNotFoundError, the default logger and an annotated default line mapped to its record fields.
  • Levels, sinks and files: setting the level (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.
  • JSON logs and context: serialize=True, a flat JSON function sink, bind() and contextualize().
  • Exceptions and processes: logger.catch, logger.exception, diagnose (off in production), enqueue=True with a spawn-context pool.
  • Loguru and the logging module: an InterceptHandler, with tabs for a plain script and FastAPI + uvicorn; Loguru vs logging table.
  • Send Loguru logs to OpenTelemetry: a diagram of a record's path (Loguru, the stdlib intercept, the bridge sink, LoggingHandler, OTLP), the bridge sink, the rules it relies on (no enqueue=True, filter opentelemetry* records, propagate = False, no reserved extra keys), 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) and loguru-output.

Maple docs linked

  • /docs/guides/instrumentation-python
  • /docs/explore/logs

Verification

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:

  • Output blocks are real output from those runs.
  • The bridge was tested against the Python guide's 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 root LoggingHandler next to the intercept exports stdlib records twice.
  • Tested caveats: enqueue=True on the bridge exports an all-zero trace ID; without the opentelemetry filter a failing exporter re-queues its own errors; without propagate = False Loguru reports a re-entrant logging error; a bound name key makes makeRecord raise.
  • The spawn-context caveat was reproduced on Linux (python:3.12-slim): without context=, the pool fails with the SemLock RuntimeError.
  • uvicorn: both uvicorn main:app with the handler-clearing loop and uvicorn.run(app, log_config=None) route access logs through Loguru.

Sources

@maple-review-bot

maple-review-bot Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Maple review

🟢 Confidence 8/10 · likely safe to merge
Held at 8 because a warning is open.
1 warning −1 · tests not needed · risk low

Adds a 829-line /guides/loguru landing guide (sinks, JSON, intercept, an OpenTelemetry bridge sink) plus its entries in the guides index and llms.txt. It is safe to merge once the python-logging-levels guide it links to exists.

  • New apps/landing/src/pages/guides/loguru.astro guide page with FAQ, JSON-LD and per-page styles
  • coreGuides in guides/index.astro gains the Loguru entry (15 min read)
  • llms.txt.ts lists the new guide under ## Guides

Before merge

  • Manual · Confirm the parallel python-logging-levels guide merges in the same deploy as this page

Findings

🟠 Warning · F1 · Link to /guides/python-logging-levels has no page behind it

correctness · apps/landing/src/pages/guides/loguru.astro:561

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 this finding with an AI agent
Findings from an automated review of commit e5e90b63f022f349f946dd773fce71e9f76fe6a9. Verify each one against the current code before changing anything, fix only those that still apply, and keep each fix to the lines it names.

---

F1 · Warning · correctness · 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`.

Production impact

Telemetry this change adds and removes (1)
  • ➕ span name POST /checkout · apps/landing/src/pages/guides/loguru.astro:344
What was checked
  • Maple UI claims (trace: link, Log Attributes, trace-ID search) match `content/docs/explore/logs.md:46,66,71
  • "delete its last line" instruction matches `content/docs/guides/instrumentation-python.md:77
  • logger.remove()/configure(extra=)/{extra[request_id]} snippets and the InterceptHandler match upstream loguru behaviour

e5e90b6 · Updated on every push. Reply "won't fix" to dismiss a finding, or mention @maple-review-bot to ask about one.

@maple-review-bot maple-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 inline note from Maple's review. The score and summary are in the review comment above.

</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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

Comment on lines +248 to +251
logger.add("logs/workers.log", enqueue=True)

context = multiprocessing.get_context("spawn")
with context.Pool(4, initializer=set_logger, initargs=(logger,)) as pool:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔴 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.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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-bot

maple-review-bot Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Maple review

🟢 Confidence 8/10 · likely safe to merge
Held at 8 because a warning is open.
1 warning −1 · tests not needed · risk low

Adds /guides/loguru, a Loguru how-to ending in a Loguru-to-OpenTelemetry bridge sink, plus links from the guides index and llms.txt. Content only and safe to merge once the cross-linked levels guide exists.

  • New loguru.astro guide: sinks, JSON, context, the InterceptHandler recipe and an OTel bridge sink
  • index.astro and llms.txt.ts link the new guide

Before merge

  • Manual · Land the parallel /guides/python-logging-levels guide first, or drop the link at apps/landing/src/pages/guides/loguru.astro:562

Still open from earlier reviews

Production impact

Telemetry this change adds and removes (1)
  • ➕ span name POST /checkout · apps/landing/src/pages/guides/loguru.astro:345
What was checked
  • /docs/guides/instrumentation-python and /docs/explore/logs both resolve (apps/landing/src/lib/docs-languages.ts:52, apps/web/src/lib/docs.ts:13)
  • context= kwarg and logger.complete() match the pinned loguru 0.7.3 API the page declares
  • The enqueue fix at lines 247-255 builds queue and pool from the same spawn context

4faba4c · Updated on every push. Reply "won't fix" to dismiss a finding, or mention @maple-review-bot to ask about one.

@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5de0aa11-46f5-46d5-8dee-42d9a03dd15b
📥 Commits

Reviewing files that changed from the base of the PR and between e71f8b9 and 9716c0d.

📒 Files selected for processing: 6
  • apps/landing/public/screenshots/guides/loguru-01-logs.webp
  • apps/landing/public/screenshots/guides/loguru-02-log-detail.webp
  • apps/landing/src/lib/guide-highlight.ts
  • apps/landing/src/pages/guides/index.astro
  • apps/landing/src/pages/guides/loguru.astro
  • apps/landing/src/pages/llms.txt.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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).
@maple-review-bot

maple-review-bot Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Maple review

🟢 Confidence 8/10 · likely safe to merge
Content-only change; a rejected warning is the missing screenshot assets and the python-logging-levels link still has no page.
2 warnings −2 · tests not needed · risk low

Adds a Loguru/Python guide page with three new highlighter languages and lists it in the guides index and llms.txt. Safe to merge once the two referenced screenshot files exist.

  • guide-highlight.ts gains json, python-logging and loguru-output tokenizers
  • New /guides/loguru page linked from the guides index and llms.txt

Findings

🟠 Warning · F2 · Both guide screenshots point at files that are not in public/

correctness · apps/landing/src/pages/guides/loguru.astro:881-886

/screenshots/guides/loguru-01-logs.webp (line 881) and /screenshots/guides/loguru-02-log-detail.webp (line 886) are not in the repository — apps/landing/public/screenshots/guides/ holds only the three prometheus-metrics-* images — so both figures render as broken images on the live guide. Add the two webp files, or the steps carry no picture.

🤖 Prompt to fix this finding with an AI agent
Findings from an automated review of commit 10f51ac42cc4230e7a7b6d99d1d4b25cad06806b. Verify each one against the current code before changing anything, fix only those that still apply, and keep each fix to the lines it names.

---

F2 · Warning · correctness · apps/landing/src/pages/guides/loguru.astro:881-886
Both guide screenshots point at files that are not in `public/`
`/screenshots/guides/loguru-01-logs.webp` (line 881) and `/screenshots/guides/loguru-02-log-detail.webp` (line 886) are not in the repository — `apps/landing/public/screenshots/guides/` holds only the three `prometheus-metrics-*` images — so both figures render as broken images on the live guide. Add the two webp files, or the steps carry no picture.

Still open from earlier reviews

Production impact

Production traffic of the changed files (last 7 days)
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
  • tokenize cannot loop: unmatched characters advance i (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 id in 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-bot maple-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 inline note from Maple's review. The score and summary are in the review comment above.

Comment thread apps/landing/src/pages/guides/loguru.astro Outdated
@maple-review-bot

maple-review-bot Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Maple review

🟢 Confidence 8/10 · likely safe to merge
Held at 8 because a warning is open.
1 warning −1 · tests not needed · risk low

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 /guides/python-logging-levels link, which still 404s until the sibling guide lands.

Still open from earlier reviews

Fixed since the last review

  • ✅ F2 · Both guide screenshots point at files that are not in public/

Production impact

Production traffic of the changed files (last 7 days)
File Calls/day Busiest operations
apps/landing/src/pages/guides/loguru.astro 98k maple 98k/day, 90.4% 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 798 MB/month: the file's operations run 98k times a day.
  • apps/landing/src/pages/guides/loguru.astro:59: If this logs once per call, about 798 MB/month: the file's operations run 98k times a day.
  • apps/landing/src/pages/guides/loguru.astro:60: If this logs once per call, about 798 MB/month: the file's operations run 98k times a day.
  • apps/landing/src/pages/guides/loguru.astro:62: If this logs once per call, about 798 MB/month: the file's operations run 98k times a day.
  • apps/landing/src/pages/guides/loguru.astro:63: If this logs once per call, about 798 MB/month: the file's operations run 98k times a day.
  • apps/landing/src/pages/guides/loguru.astro:69: If this logs once per call, about 798 MB/month: the file's operations run 98k times a day.
  • apps/landing/src/pages/guides/loguru.astro:70: If this logs once per call, about 798 MB/month: the file's operations run 98k times a day.
  • apps/landing/src/pages/guides/loguru.astro:71: If this logs once per call, about 798 MB/month: the file's operations run 98k times a day.
  • apps/landing/src/pages/guides/loguru.astro:115: If this logs once per call, about 798 MB/month: the file's operations run 98k times a day.
  • apps/landing/src/pages/guides/loguru.astro:158: If this logs once per call, about 798 MB/month: the file's operations run 98k times a day.
What was checked
  • Both screenshot paths at loguru.astro:881 and :886 now exist in apps/landing/public/screenshots/guides/ (git ls-tree: 71 KB and 27 KB webp blobs)
  • /guides/python-logging-levels (line 618) still has no page: src/pages/guides/ holds no such file at this head

9716c0d · Updated on every push. Reply "won't fix" to dismiss a finding, or mention @maple-review-bot to ask about one.

This branch has not been deployed

No deployments
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.

1 participant