Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/Sentry/Hub.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ sub reset ($self) {

sub bind_client ($self, $client) {
$self->client($client);
$client->setup_integrations();
$client->setup_integrations() if $client;
}

sub get_current_scope ($package) {
Expand Down Expand Up @@ -66,7 +66,7 @@ sub get_scope ($self) {
}

sub _invoke_client ($self, $method, @args) {
my $client = $self->client;
my $client = $self->client or return;
my $scope = $self->get_current_scope;

if ($client->can($method)) {
Expand Down Expand Up @@ -124,7 +124,7 @@ sub run ($self, $cb) {
}

sub sample ($self, $transaction, $sampling_context) {
my $client = $self->client;
my $client = $self->client or return;
my $options = ($client && $client->get_options) // {};

# nothing to do if there's no client or if tracing is disabled
Expand Down
2 changes: 1 addition & 1 deletion lib/Sentry/SDK.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ sub _call_on_hub ($method, @args) {

sub _init_and_bind ($options) {
my $hub = Sentry::Hub->get_current_hub();
my $client = Sentry::Client->new(_options => $options);
my $client = $options->{dsn} ? Sentry::Client->new(_options => $options) : undef;
$hub->bind_client($client);
}

Expand Down
11 changes: 10 additions & 1 deletion t/sdk.t
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use Sentry::Hub;
use Sentry::Logger 'logger';
use Sentry::SDK;
use Sentry::Severity;
use Test::Exception;
use Test::Snapshot;
use Test::Spec;
use UUID::Tiny 'is_UUID_string';
Expand Down Expand Up @@ -66,6 +67,14 @@ describe 'Sentry::SDK' => sub {

is_deeply_snapshot($hub->client->get_options, 'client options (env)');
};

it 'disables SDK if DSN is empty' => sub {
Sentry::SDK->init({ dsn => '' });

is($hub->client, undef, 'client is undefined');

lives_ok { Sentry::SDK->capture_message('foo') };
};
};

describe 'message sending' => sub {
Expand Down Expand Up @@ -139,7 +148,7 @@ describe 'Sentry::SDK' => sub {
};

it 'start_transaction()' => sub {
Sentry::SDK->init({ traces_sample_rate => 1, });
Sentry::SDK->init({ dsn => 'abc', traces_sample_rate => 1, });

my $tx
= Sentry::SDK->start_transaction(
Expand Down