AWS-XRay

 view release on metacpan or  search on metacpan

lib/AWS/XRay/Buffer.pm  view on Meta::CPAN

package AWS::XRay::Buffer;

use 5.012000;
use strict;
use warnings;

sub new {
    my $class = shift;
    my ($sock, $auto_flush) = @_;
    bless {
        buf        => [],
        sock       => $sock,
        auto_flush => $auto_flush,
    }, $class;
}

sub flush {
    my $self = shift;
    my $sock = $self->{sock};
    for my $buf (@{ $self->{buf} }) {

lib/AWS/XRay/Segment.pm  view on Meta::CPAN

use JSON::XS    ();
use Time::HiRes ();

my $header = qq|{"format":"json","version":1}\n|;
my $json   = JSON::XS->new->utf8;

sub new {
    my $class = shift;
    my $src   = shift;

    return bless {}, "${class}::NoTrace" if !$AWS::XRay::ENABLED;

    my $segment = {
        id         => AWS::XRay::new_id(),
        start_time => Time::HiRes::time(),
        trace_id   => $AWS::XRay::TRACE_ID,
        %$src,
    };
    if (my $parent_id = $AWS::XRay::SEGMENT_ID) {
        # This is a sub segment.
        $segment->{parent_id} = $parent_id;
        $segment->{type}      = "subsegment";
        $segment->{namespace} = "remote";
    }
    bless $segment, $class;
}

# alias for backward compatibility
*send = \&close;

sub close {
    my $self = shift;
    $self->{end_time} //= Time::HiRes::time();
    my $sock = AWS::XRay::sock() or return;
    $sock->print($header, $json->encode({%$self}));

lib/AWS/XRay/Segment.pm  view on Meta::CPAN

    if (defined $AWS::XRay::SAMPLED) {
        $h .= ";Sampled=$AWS::XRay::SAMPLED";
    }
    return $h;
}

package AWS::XRay::Segment::NoTrace;

sub new {
    my $class = shift;
    bless {}, $class;
}

sub close {
    # do not anything
}

sub trace_header {
    "";
}



( run in 0.337 second using v1.01-cache-2.11-cpan-de7293f3b23 )