Skip to content

Conversation

HypeMC
Copy link
Member

@HypeMC HypeMC commented Aug 9, 2024

Adds support for getsentry/sentry-php#1199.

monolog:
  handlers:
    sentry:
      type: sentry
      hub_id: Sentry\State\HubInterface
      level: !php/const Monolog\Logger::ERROR
    sentry_breadcrumb:
      type: sentry_breadcrumb
      sentry_handler: sentry
      level: !php/const Monolog\Logger::INFO

# or if you don't have Sentry bundle installed

monolog:
  handlers:
    sentry:
      type: sentry
      dsn: "https://[email protected]/1"
      level: !php/const Monolog\Logger::ERROR
    sentry_breadcrumb:
      type: sentry_breadcrumb
      sentry_handler: sentry
      level: !php/const Monolog\Logger::INFO

Initially, I considered using the existing handler option instead of introducing the new sentry_handler option. However, I decided against it because the PSR logger doesn't get auto-enabled when the handler option is used:

if (null === $handler['process_psr_3_messages']['enabled']) {
$handler['process_psr_3_messages']['enabled'] = !isset($handler['handler']) && !$handler['members'];
}

@HypeMC HypeMC force-pushed the add-sentry-breadcrumbhandler-support branch from 7d533ee to 10c35d5 Compare August 11, 2024 20:27
@HypeMC HypeMC force-pushed the add-sentry-breadcrumbhandler-support branch 5 times, most recently from ce023ed to 133cd1c Compare August 30, 2025 21:46
Comment on lines 758 to 777
$hub = new Definition(
$hubId = \sprintf('monolog.handler.%s.hub', $name);
$hub = $container->setDefinition($hubId, new Definition(
'Sentry\\State\\Hub',
[new Reference($clientId)]
);
$container->setDefinition(\sprintf('monolog.handler.%s.hub', $name), $hub);
));

// can't set the hub to the current hub, getting into a recursion otherwise...
// $hub->addMethodCall('setCurrent', array($hub));
}

$definition->setArguments([
$hub,
new Reference($hubId),
Copy link
Member Author

Choose a reason for hiding this comment

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

Taken from #514, should be merged first.

@HypeMC HypeMC force-pushed the add-sentry-breadcrumbhandler-support branch from 133cd1c to c469777 Compare September 5, 2025 22:37
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