Skip to content

Fix PHP Monolog LogsHandler constructor in logs docs - #19640

Open
Hashim1999164 wants to merge 2 commits into
getsentry:masterfrom
Hashim1999164:fix/php-logs-monolog-handler-ctor
Open

Hashim1999164 wants to merge 2 commits into
getsentry:masterfrom
Hashim1999164:fix/php-logs-monolog-handler-ctor

Conversation

@Hashim1999164

@Hashim1999164 Hashim1999164 commented Sep 25, 2026 •

Copy link
Copy Markdown

DESCRIBE YOUR PR

Fixes #19177

The PHP logs setup snippet still constructed LogsHandler with a Hub argument. In sentry/sentry 4.x that constructor only takes a log level (and bubble), so the sample failed as written. Updated it to match the working 4.x call.

IS YOUR CHANGE URGENT?

  • Urgent deadline (GA date, etc.): YYYY-MM-DD
  • Other deadline: YYYY-MM-DD
  • No deadline: Not urgent, can wait up to 1 week+

PRE-MERGE CHECKLIST

  • Checked Vercel preview for correctness, including links
  • PR was reviewed and approved by any necessary SMEs (subject matter experts)
  • PR was reviewed and approved by a member of the Sentry docs team

LEGAL BOILERPLATE

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

Test plan

LogsHandler in sentry/sentry 4.x only takes a level (and bubble). The
logs setup snippet still passed a Hub, so the sample could not run.
@vercel

vercel Bot commented Sep 25, 2026

Copy link
Copy Markdown

@Hashim1999164 is attempting to deploy a commit to the Sentry Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added the Priority: Needs Triage The PR description is missing valid priority information label Sep 25, 2026
@codeowner-assignment
codeowner-assignment Bot requested a review from a team September 25, 2026 23:11
@github-actions github-actions Bot added Priority: Normal Docs review has no urgent deadline and removed Priority: Needs Triage The PR description is missing valid priority information labels Sep 26, 2026
@coolguyzone
coolguyzone requested a review from cleptric October 1, 2026 20:05
@cleptric
cleptric requested review from Litarnus and removed request for cleptric October 5, 2026 20:52
]);

$log = new Logger('app');
$log->pushHandler(new \Sentry\Monolog\LogsHandler(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

good catch, LogsHandler is (logLevel, bubble). updated the sample to pass true for bubble. Monolog\Level::Info is still valid there too (constructor takes LogLevel|Monolog\Level|int).

LogsHandler takes (logLevel, bubble). Keep the level and set bubble true so the sample matches the constructor.
@Hashim1999164
Hashim1999164 force-pushed the fix/php-logs-monolog-handler-ctor branch from 0a08b13 to da3cf18 Compare October 6, 2026 19:02
@Hashim1999164

Copy link
Copy Markdown
Author

good catch, LogsHandler is (logLevel, bubble). updated the sample to pass true for bubble.

hub: \Sentry\SentrySdk::getCurrentHub(),
level: Level::Info,
));
$log->pushHandler(new \Sentry\Monolog\LogsHandler(Level::Info, true));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: The documentation example uses Monolog\Level::Info for the \Sentry\Monolog\LogsHandler constructor, but it likely expects a Sentry\Logs\LogLevel instance.
Severity: MEDIUM

Suggested Fix

In the code example, replace the usage of Monolog\Level::Info with Sentry\Logs\LogLevel::info(). Also, ensure the corresponding use statement is updated from use Monolog\Level; to use Sentry\Logs\LogLevel; to match the correct class.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: platform-includes/logs/setup/php.mdx#L25

Potential issue: The documentation example in `platform-includes/logs/setup/php.mdx`
instantiates `\Sentry\Monolog\LogsHandler` using `Monolog\Level::Info`, which is a
`Monolog\Level` enum case. However, other comprehensive documentation for this
integration uses `Sentry\Logs\LogLevel::info()`, which is a method call returning a
`Sentry\Logs\LogLevel` object. If the `LogsHandler` constructor is type-hinted for
`Sentry\Logs\LogLevel`, passing the `Monolog\Level` enum will cause a `PHP TypeError` at
runtime, making the example code non-functional.

Did we get this right? 👍 / 👎 to inform future reviews.

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

Priority: Normal Docs review has no urgent deadline

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Monolog Log Handler is using old constructor parameters

3 participants