ForgeOps-Tracker

 view release on metacpan or  search on metacpan

lib/ForgeOps/Tracker/Configuration.pm  view on Meta::CPAN

        # (https://www.w3.org/TR/trace-context/) for the outgoing request, so the service being
        # called can continue this request's trace instead of starting its own. On by default, and
        # independent of track_tracing: the header also carries the trace id that links an error
        # here to an error there, which is useful with or without spans.
        propagate_traces => 1,
        # Which hosts get that header: undef (the default) means every host. Otherwise an arrayref
        # where each entry is either a host string, matching that host and its subdomains on a dot
        # boundary, ignoring case and a leading dot ("example.com" matches "api.example.com" but
        # not "badexample.com"), or a qr// regular expression matched against the host. Useful for
        # third-party APIs that reject unknown headers, or that shouldn't learn this app's trace
        # ids at all.
        trace_propagation_targets => undef,
        # Sends one startup snapshot per process after init() (the Perl version; see
        # ForgeOps::Tracker::Changes), which ForgeOps diffs against the previous boot's to record
        # what changed between deploys. On by default, like every other automatic behavior here.
        detect_changes => 1,
        # Whether that snapshot also lists the names of this process's environment variables, so an
        # added or removed variable shows up as a change. Off by default: names only, never values,
        # but even names can say more about an app than some teams want to share. Host-specific
        # names (HOSTNAME, PATH, PORT, and so on; see ForgeOps::Tracker::Changes) are always left
        # out.
        track_env_var_names => 0,
    }, $class;
}

# https://<api_key>@host[:port]/path: captures scheme, an optional userinfo (the api_key,
# percent-decoded), and everything from the host onward.
my $DSN_RE = qr{^(https?)://(?:([^:@/]*)@)?([^/]+)(/.*)?$};

sub _parsed_dsn {
    my ($self) = @_;
    return undef unless $self->{dsn};
    return undef unless $self->{dsn} =~ $DSN_RE;

    my ($scheme, $userinfo, $host, $path) = ($1, $2, $3, $4 // '');
    my $api_key = defined($userinfo) && length($userinfo) ? _uri_unescape($userinfo) : undef;
    return {
        scheme        => $scheme,
        api_key       => $api_key,
        ingestion_uri => "$scheme://$host$path",
    };
}

sub api_key {
    my ($self) = @_;
    my $parsed = $self->_parsed_dsn;
    return undef unless $parsed && defined $parsed->{api_key} && length $parsed->{api_key};
    return $parsed->{api_key};
}

# The ingestion URL with credentials stripped out (they travel as the Authorization header
# instead, never embedded in the request URI).
sub ingestion_uri {
    my ($self) = @_;
    my $parsed = $self->_parsed_dsn;
    return undef unless $parsed;
    return $parsed->{ingestion_uri};
}

# Same derivation as ingestion_uri, with the trailing "/events" swapped for
# "/performance_samples": one DSN, two more endpoints alongside deliver's own, matching the Ruby
# gem's own Configuration#performance_samples_uri.
sub performance_samples_uri {
    my ($self) = @_;
    my $uri = $self->ingestion_uri;
    return undef unless defined $uri;

    (my $swapped = $uri) =~ s{/events\z}{/performance_samples};
    return $swapped;
}

# Same derivation again, swapping the trailing "/events" for "/custom_metrics" and
# "/infrastructure_metrics".
sub custom_metrics_uri {
    my ($self) = @_;
    my $uri = $self->ingestion_uri;
    return undef unless defined $uri;

    (my $swapped = $uri) =~ s{/events\z}{/custom_metrics};
    return $swapped;
}

sub infrastructure_metrics_uri {
    my ($self) = @_;
    my $uri = $self->ingestion_uri;
    return undef unless defined $uri;

    (my $swapped = $uri) =~ s{/events\z}{/infrastructure_metrics};
    return $swapped;
}

# Same derivation again, swapping the trailing "/events" for "/spans".
sub changes_uri {
    my ($self) = @_;
    my $uri = $self->ingestion_uri;
    return undef unless defined $uri;

    (my $swapped = $uri) =~ s{/events\z}{/changes};
    return $swapped;
}

sub change_snapshots_uri {
    my ($self) = @_;
    my $uri = $self->ingestion_uri;
    return undef unless defined $uri;

    (my $swapped = $uri) =~ s{/events\z}{/change_snapshots};
    return $swapped;
}

sub spans_uri {
    my ($self) = @_;
    my $uri = $self->ingestion_uri;
    return undef unless defined $uri;

    (my $swapped = $uri) =~ s{/events\z}{/spans};
    return $swapped;
}

# Whether an outgoing request to $host should carry a traceparent header; see propagate_traces and
# trace_propagation_targets above. Case-insensitive, since hostnames are.



( run in 1.274 second using v1.01-cache-2.11-cpan-16aabcbfbcb )