CGI-Application-Plugin-OpenTracing
view release on metacpan or search on metacpan
lib/CGI/Application/Plugin/OpenTracing.pm view on Meta::CPAN
################################################################################
#
# NOTE: please take a minute to understand the structure of this module
#
# CGI::Application::Plugin has an interesting design on itself
#
# within this code base there are three sections:
# - import
# - callbacks, as defined by CGI::Application
# - plugin related methods, that deal with the plugin internals
# - tracing specific routines
# - cgi related routines, that just work on the CGI::Application only
#
################################################################################
sub import {
my $package = shift;
lib/CGI/Application/Plugin/OpenTracing.pod view on Meta::CPAN
By default, the parameter values are joined with the contents of
C<$CGI::Application::Plugin::TAG_JOIN_CHAR>, which is a comma by default.
Without any customization, the example above would yield the following tags:
'http.query.id' => '1,2,3',
'http.query.view' => 'compact',
Simple join is often not enough and there are parameters which should
be skipped or obscured. The plugin allows to specify the formatting
with the following callbacks:
=over 4
=item opentracing_process_tags_query_params
Used to match and format URL query parameters (C<http.query.*> tags).
=item opentracing_process_tags_form_fields
Used to match and format form data fields (C<http.form.*> tags).
=item opentracing_process_tags
Used to match both query parameters and form data, when the specific
callbacks fail to match (see L<Fallbacks and matching order>).
=back
Their expected return values all follow the same format of key-value pairs
with an optional odd element at the end. For example:
sub opentracing_process_tags_query_params {
id => sub { "[@_]" },
location => 'REDACTED',
access_token => undef,
t/00_use_ok.t view on Meta::CPAN
use Test::Most;
use strict;
use warnings;
use Ref::Util qw/is_coderef/;
# we could check that we actually add the callbacks ? that is what `use` is
# suposed to do, we opught to test that here!!
#
my $callbacks = [];
sub add_callback { push @$callbacks, +{ name=> $_[1], coderef => $_[2] } };
BEGIN {
use_ok('CGI::Application::Plugin::OpenTracing');
cmp_deeply( $callbacks =>
[
{
name => 'init',
coderef => code( \&is_coderef ),
},
{
name => 'prerun',
coderef => code( \&is_coderef ),
},
{
t/00_use_ok.t view on Meta::CPAN
},
{
name => 'teardown',
coderef => code( \&is_coderef ),
},
{
name => 'error',
coderef => code( \&is_coderef ),
},
],
"Installed expected callbacks, and these are coderefs!"
);
};
done_testing;
( run in 0.283 second using v1.01-cache-2.11-cpan-9b1e4054eb1 )