Pierre-Lannoy / wp-decalog

Capture and log events, metrics and traces on your site. Make WordPress observable - finally!
https://perfops.one/
GNU General Public License v3.0
64 stars 8 forks source link

Adds ability to add logger using wp-config #41

Closed JanThiel closed 1 year ago

JanThiel commented 1 year ago

Hey @Pierre-Lannoy,

happy new year! 🎆

We voted to go the easy way to be honest for now.

Instead of refactoring the different ways the logger config is read we simply added a way to define loggers in wp-config.php. This will also solve all our edge case issues. When the settings would be reset, they would now simply fall back to the wp-config ones which contain what we need. It simplifies setup of decalog as well as you now can setup all loggers using tools like ansible or such by configuring / deploying the wp-config accordingly.

This PR will add the ability to add an array of Logger Configs to wp-config. Here is an example how to add a Datadog Event logger. But it will naturally work for any supported logger. The uuid can be set to any value. It will be used to check whether the logger is there or has to be added.

define('DECALOG_DEFAULT_LOGGERS', array(
  '383b90f4-3e4f-4909-b01e-e8c4ed84db81' => array (
    'name' => 'Datadog Events',
    'handler' => 'DatadogHandler',
    'running' => true,
    'level' => '250',
    'privacy' => array (
      'obfuscation' => false,
      'pseudonymization' => false,
    ),
    'processors' => array (
      0 => 'WordpressProcessor',
      1 => 'WWWProcessor',
      2 => 'IntrospectionProcessor',
      3 => 'BacktraceProcessor',
    ),
    'configuration' => array (
      'host' => 'https://http-intake.logs.datadoghq.eu/v1/input',
      'token' => '<TOKEN>',
      'buffer' => true,
    ),
  )
));

It's actually simply what you currently store in the logger settings anyway. I considered to derive and construct the logger settings in code but finally couldn't find any reasonable reason to do so.

This might break when you do a breaking change in the logger config. But why would you do that? ;-)

Best Regards,

Jan

oscarmparedes commented 1 year ago

Im very interested in this feature, so that we can automate the setup. Any ideas when this would be merged?

Pierre-Lannoy commented 1 year ago

Hello @oscarmparedes ! This feature will be merged for next release - I have to review it with Jan. But, regarding setup automation, all is already "doable" via wp-cli. Do you find something which can not be done with it?

oscarmparedes commented 1 year ago

makes sense, I still need to test the wp-cli more, I understand you can configure loggers with it, but wp-config feature is more gitops friendly. This plugin is amazing.

Pierre-Lannoy commented 1 year ago

Hello @JanThiel ! Thank you so much for this PR. I've tested it on my test servers from 2 weeks now and all seems ok. Just a quick question, do you use it in production as is? (i.e. with wp-config defined loggers)

Pierre-Lannoy commented 1 year ago

Oh, and yes, for the record: there's no reason I break in the future the way loggers are defined ;)

JanThiel commented 1 year ago

We have this code up and running on our staging servers since I opened the PR. So that's as closest as code can get to PROD within our deployments without being on PROD.

Pierre-Lannoy commented 1 year ago

Than you so much for this PR, @JanThiel !