Skip to content

Instantly share code, notes, and snippets.

@ahebrank
Created May 20, 2024 15:44
Show Gist options
  • Save ahebrank/0cf3c8dc0e21e307331f190527b56f51 to your computer and use it in GitHub Desktop.
Save ahebrank/0cf3c8dc0e21e307331f190527b56f51 to your computer and use it in GitHub Desktop.
diff --git a/src/Client.php b/src/Client.php
index bfcee62..a441486 100644
--- a/src/Client.php
+++ b/src/Client.php
@@ -172,6 +172,10 @@ public function captureEvent(Event $event, ?EventHint $hint = null, ?Scope $scop
return null;
}
+ if ($this->options->getFastcgiFinishRequest() && function_exists('fastcgi_finish_request')) {
+ fastcgi_finish_request();
+ }
+
try {
/** @var Response $response */
$response = $this->transport->send($event)->wait();
diff --git a/src/Options.php b/src/Options.php
index c784162..c23065e 100644
--- a/src/Options.php
+++ b/src/Options.php
@@ -878,6 +878,29 @@ public function setTracesSampler(?callable $sampler): void
$this->options = $this->resolver->resolve($options);
}
+ /**
+ * Returns whether to use fastcgi_finish_request() to flush the client response.
+ */
+ public function getFastcgiFinishRequest(): bool
+ {
+ return $this->options['fastcgi_finish_request'];
+ }
+
+ /**
+ * Sets a callback that will be invoked when we take the sampling decision for Transactions.
+ * Return a number between 0 and 1 to define the sample rate for the provided SamplingContext.
+ *
+ * @param ?callable $sampler The sampler
+ *
+ * @psalm-param null|callable(\Sentry\Tracing\SamplingContext): float $sampler
+ */
+ public function setFastcgiFinishRequest(bool $fastcgiFinishRequest): void
+ {
+ $options = array_merge($this->options, ['fastcgi_finish_request' => $fastcgiFinishRequest]);
+
+ $this->options = $this->resolver->resolve($options);
+ }
+
/**
* Configures the options of the client.
*
@@ -931,6 +954,7 @@ private function configureOptions(OptionsResolver $resolver): void
'capture_silenced_errors' => false,
'max_request_body_size' => 'medium',
'class_serializers' => [],
+ 'fastcgi_finish_request' => false,
]);
$resolver->setAllowedTypes('send_attempts', 'int');
@@ -969,6 +993,7 @@ private function configureOptions(OptionsResolver $resolver): void
$resolver->setAllowedTypes('capture_silenced_errors', 'bool');
$resolver->setAllowedTypes('max_request_body_size', 'string');
$resolver->setAllowedTypes('class_serializers', 'array');
+ $resolver->setAllowedTypes('fastcgi_finish_request', 'bool');
$resolver->setAllowedValues('max_request_body_size', ['none', 'never', 'small', 'medium', 'always']);
$resolver->setAllowedValues('dsn', \Closure::fromCallable([$this, 'validateDsnOption']));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment