Publishing Metrics

OnceĀ initialized, the DecaLog SDK is ready to publish metrics.
This publishing is a two step process: you must first register the metrics you want to publish, then update their values.

Registering metrics

To register a metric, you must know to which profile to attach this metric – “production” or “development” – and of what type is this metric (please, read the WordPress monitoring section).
You can then register it with create methods:

<?php $metrics = \DecaLog\Engine::metricsLogger( 'my-plugin-slug' ); $metrics->createProdGauge( 'my_first_metric', 0, 'Free something ratio - [percent]' ); $metrics->createDevCounter( 'my_second_metric', 'Size of something - [byte]' );
Code language: HTML, XML (xml)

Updating metrics

Now, somewhere else in your code, you can update the previously registered metrics:

<?php $metrics = ; \DecaLog\Engine::metricsLogger( 'my-plugin-slug' )->setProdGauge( 'my_first_metric', 28 ); \DecaLog\Engine::metricsLogger( 'my-plugin-slug' )->incDevCounter( 'my_second_metric' );
Code language: HTML, XML (xml)

Best practice and limitations

It is a best practice to perform long-running operations in the WordPress shutdown hook. So, it is obviously a good place to compute some metrics as they are inclined to be resource intensive and this should be considered as a best practice too.
Keep in mind, however, that anything that happens after the DECALOG_MAX_SHUTDOWN_PRIORITY will be dropped by DecaLog.

<?php // 'my_first_metric' will be updated: add_action( 'shutdown', function() { \DecaLog\Engine::metricsLogger( 'my-plugin-slug' )->setProdGauge( 'my_first_metric', 28 ); }, DECALOG_MAX_SHUTDOWN_PRIORITY, 0 ); // 'my_first_metric' will never be updated: add_action( 'shutdown', function() { \DecaLog\Engine::metricsLogger( 'my-plugin-slug' )->setProdGauge( 'my_first_metric', 28 ); }, DECALOG_MAX_SHUTDOWN_PRIORITY + 1, 0 );
Code language: HTML, XML (xml)