Skip to content

Commit

Permalink
Add a config option to allow overriding Spotlight url (#1659)
Browse files Browse the repository at this point in the history
Co-authored-by: Michi Hoffmann <cleptric@users.noreply.github.com>
  • Loading branch information
adnweedon and cleptric authored Dec 11, 2023
1 parent f0f553a commit 943714e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
5 changes: 5 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ parameters:
count: 1
path: src/Options.php

-
message: "#^Method Sentry\\\\Options\\:\\:getSpotlightUrl\\(\\) should return string but returns mixed\\.$#"
count: 1
path: src/Options.php

-
message: "#^Method Sentry\\\\Options\\:\\:getTags\\(\\) should return array\\<string, string\\> but returns mixed\\.$#"
count: 1
Expand Down
16 changes: 16 additions & 0 deletions src/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,20 @@ public function enableSpotlight(bool $enable): self
return $this;
}

public function getSpotlightUrl(): string
{
return $this->options['spotlight_url'];
}

public function setSpotlightUrl(string $url): self
{
$options = array_merge($this->options, ['spotlight_url' => $url]);

$this->options = $this->resolver->resolve($options);

return $this;
}

/**
* Gets the release tag to be passed with every event sent to Sentry.
*/
Expand Down Expand Up @@ -999,6 +1013,7 @@ private function configureOptions(OptionsResolver $resolver): void
'environment' => $_SERVER['SENTRY_ENVIRONMENT'] ?? null,
'logger' => null,
'spotlight' => false,
'spotlight_url' => 'http://localhost:8969',
'release' => $_SERVER['SENTRY_RELEASE'] ?? null,
'dsn' => $_SERVER['SENTRY_DSN'] ?? null,
'server_name' => gethostname(),
Expand Down Expand Up @@ -1047,6 +1062,7 @@ private function configureOptions(OptionsResolver $resolver): void
$resolver->setAllowedTypes('in_app_include', 'string[]');
$resolver->setAllowedTypes('logger', ['null', LoggerInterface::class]);
$resolver->setAllowedTypes('spotlight', 'bool');
$resolver->setAllowedTypes('spotlight_url', 'string');
$resolver->setAllowedTypes('release', ['null', 'string']);
$resolver->setAllowedTypes('dsn', ['null', 'string', 'bool', Dsn::class]);
$resolver->setAllowedTypes('server_name', 'string');
Expand Down
2 changes: 1 addition & 1 deletion src/Transport/HttpTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private function sendRequestToSpotlight(Event $event): void
try {
$spotLightResponse = SpotlightClient::sendRequest(
$request,
'http://localhost:8969/stream'
$this->options->getSpotlightUrl() . '/stream'
);

if ($spotLightResponse->hasError()) {
Expand Down
7 changes: 7 additions & 0 deletions tests/OptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,13 @@ static function (): void {},
'EnableSpotlight',
];

yield [
'spotlight_url',
'http://google.com',
'getSpotlightUrl',
'setSpotlightUrl',
];

yield [
'release',
'dev',
Expand Down

0 comments on commit 943714e

Please sign in to comment.