• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jjatria / perl-opentelemetry / 6553776671

17 Oct 2023 10:57PM UTC coverage: 73.52% (-18.9%) from 92.443%
6553776671

push

github

jjatria
Add experimental support for testing metrics

2 of 2 new or added lines in 1 file covered. (100.0%)

472 of 642 relevant lines covered (73.52%)

4.18 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

11.11
/lib/OpenTelemetry/Propagator/TraceContext/TraceState.pm
1
use Object::Pad;
13✔
2
# ABSTRACT: Represents the TraceState in a W3C TraceContext
3

4
package OpenTelemetry::Propagator::TraceContext::TraceState;
5

6
our $VERSION = '0.001';
7

8
use Log::Any;
13✔
9
my $logger = Log::Any->get_logger( category => 'OpenTelemetry' );
10

11
class OpenTelemetry::Propagator::TraceContext::TraceState {
12
    use List::Util;
13✔
13

14
    my $MAX_MEMBERS = 32 * 2; # The member list is a flat list of pairs
15
    my $VALID_KEY = qr/
16
        ^
17
        (?:
18
                [ a-z ]     [ a-z 0-9 _ * \/ - ]{0,255} # simple-key
19
            | (?:                                       # multi-tenant-key
20
                [ a-z 0-9 ] [ a-z 0-9 _ * \/ - ]{0,240} #   tenant-id
21
                @
22
                [ a-z ]     [ a-z 0-9 _ * \/ - ]{0,13}  #   system-id
23
              )
24
        )
25
        $
26
    /xx;
27

28
    my $VALID_VALUE = qr/
29
        ^
30
            [ \x{20} \x{21}-\x{2B} \x{2D}-\x{3C} \x{3E}-\x{7E} ]{0,255}
31
            [        \x{21}-\x{2B} \x{2D}-\x{3C} \x{3E}-\x{7E} ]
32
        $
33
    /xx;
34

35
    field @members;
36

37
    # Private methods
38

39
    method $init ( @new ) {
40
        @members = splice @new, 0, $MAX_MEMBERS;
41
        $self
42
    }
43

44
    # Internal setting method: assumes parameters are validated
45
    # Having this in a separate method means we can call it from an
46
    # instance other than $self (eg. the one returned by the call to
47
    # 'delete' in the public 'set' method)
48
    method $set ( $key, $value ) {
49
        unshift @members, $key => $value;
50
        @members = splice @members, 0, $MAX_MEMBERS if @members > $MAX_MEMBERS;
51
        $self;
52
    }
53

54
    # Public interface
55

56
    sub from_string ( $class, $string = undef ) {
×
57
        $logger->debug('Got an undefined value instead of a string when parsing TraceState')
×
58
            unless defined $string;
59

60
        my @members;
×
61
        for ( grep $_, split ',', $string // '' ) {
×
62
            my ( $key, $value ) = split '=', s/^\s+|\s+$//gr, 2;
×
63

64
            next unless $key =~ $VALID_KEY && $value =~ $VALID_VALUE;
×
65
            push @members, $key => $value;
×
66
        }
67

68
        $class->new->$init(@members);
×
69
    }
70

71
    method to_string () {
×
72
        join ',', List::Util::pairmap { join '=', $a, $b } @members
×
73
    }
×
74

75
    # Gets the value
76
    method get ( $key ) {
×
77
        my ( undef, $value ) = List::Util::pairfirst { $a eq $key } @members;
×
78
        $value;
×
79
    }
80

81
    # Sets a new pair, overwriting any existing one with the same key
82
    method set ( $key, $value ) {
×
83
        if ( $key !~ $VALID_KEY ) {
×
84
            $logger->debugf("Invalid TraceState member key: '%s' => '%s'", $key, $value );
×
85
            return $self;
×
86
        }
87
        elsif ( $value !~ $VALID_VALUE ) {
88
            $logger->debugf("Invalid TraceState member value: '%s' => '%s'", $key, $value );
×
89
            return $self;
×
90
        }
91

92
        $self->delete($key)->$set( $key => $value );
×
93
    }
94

95
    # Returns a clone of the TraceState without the deleted key
96
    # or the same object if no change was needed
97
    method delete ( $key ) {
×
98
        ( ref $self )->new->$init(
99
            List::Util::pairgrep { $a ne $key } @members
×
100
        );
×
101
    }
102
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc