Dancer2-Plugin-OpenTelemetry

 view release on metacpan or  search on metacpan

t/basic.t  view on Meta::CPAN

        'OK';
    };

    get '/error' => sub { die 'oops' };
}

my $test = Plack::Test->create( Local::App->to_app );

subtest 'Static URL' => sub {
    is $test->request( GET '/static/url?query=parameter' ), object {
        call decoded_content => 'OK';
    }, 'Request OK';

    is $span->{otel}, {
        attributes => {
            'client.address'           => '127.0.0.1',
            'client.port'              => DNE,
            'http.request.method'      => 'GET',
            'http.route'               => '/static/url',
            'network.protocol.version' => '1.1',
            'server.address'           => 'localhost',

t/basic.t  view on Meta::CPAN

    }, 'Span created as expected';

    span_calls [
        set_attribute => [ 'http.response.status_code', 200 ],
        end           => [],
    ], 'Expected calls on span';
};

subtest 'Forward' => sub {
    is $test->request( GET '/forward' ), object {
        call decoded_content => 'OK';
    }, 'Request OK';

    is $span->{otel}, {
        attributes => {
            'client.address'           => '127.0.0.1',
            'client.port'              => DNE,
            'http.request.method'      => 'GET',
            'http.route'               => '/forward',
            'network.protocol.version' => '1.1',
            'server.address'           => 'localhost',

t/basic.t  view on Meta::CPAN

    }, 'Span created as expected';

    span_calls [
        set_attribute => [ 'http.response.status_code', 200 ],
        end           => [],
    ], 'Expected calls on span';
};

subtest 'Pass' => sub {
    is $test->request( GET '/url/with/pass' ), object {
        call decoded_content => 'OK';
    }, 'Request OK';

    is $span->{otel}, {
        attributes => {
            'client.address'           => '127.0.0.1',
            'client.port'              => DNE,
            'http.request.method'      => 'GET',
            'http.route'               => '/url/with/pass',
            'network.protocol.version' => '1.1',
            'server.address'           => 'localhost',

t/basic.t  view on Meta::CPAN

        set_attribute => [ 'http.response.status_code', 200 ],
        end           => [],
    ], 'Expected calls on span';
};

subtest 'Async' => sub {
    require Test2::Require::Module;
    Test2::Require::Module->import('IO::Async');

    is $test->request( GET '/async', user_agent => 'Test' ), object {
        call decoded_content => 'OK';
    }, 'Request OK';

    is $span->{otel}, {
        attributes => {
            'client.address'           => '127.0.0.1',
            'client.port'              => DNE,
            'http.request.method'      => 'GET',
            'http.route'               => '/async',
            'network.protocol.version' => '1.1',
            'server.address'           => 'localhost',

t/basic.t  view on Meta::CPAN

    }, 'Span created as expected';

    span_calls [
        set_attribute => [ 'http.response.status_code', 200 ],
        end           => [],
    ], 'Expected calls on span';
};

subtest 'With placeholder' => sub {
    is $test->request( GET '/url/with/value' ), object {
        call decoded_content => 'OK';
    }, 'Request OK';

    is $span->{otel}, {
        attributes => {
            'client.address'           => '127.0.0.1',
            'client.port'              => DNE,
            'http.request.method'      => 'GET',
            'http.route'               => '/url/with/:placeholder',
            'network.protocol.version' => '1.1',
            'server.address'           => 'localhost',

t/basic.t  view on Meta::CPAN


    span_calls [
        set_attribute => [ 'http.response.status_code', 200 ],
        end           => [],
    ], 'Expected calls on span';
};

subtest 'Response code' => sub {
    is $test->request( GET '/status/400' ), object {
        call code            => 400;
        call decoded_content => 'OK';
    }, 'Request OK';

    is $span->{otel}, {
        attributes => {
            'client.address'           => '127.0.0.1',
            'client.port'              => DNE,
            'http.request.method'      => 'GET',
            'http.route'               => '/status/:code',
            'network.protocol.version' => '1.1',
            'server.address'           => 'localhost',



( run in 0.400 second using v1.01-cache-2.11-cpan-a9ef4e587e4 )