-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft: feat: add trace handling #114
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -37,6 +37,11 @@ trait DefaultBuilderTrait | |||||
/** @var ProcessorInterface<mixed>|null */ | ||||||
private ProcessorInterface|null $processor; | ||||||
|
||||||
/** | ||||||
* @var \Closure(): string | ||||||
*/ | ||||||
private \Closure $traceGenerator; | ||||||
|
||||||
public function setLogger(LoggerInterface|null $logger): void | ||||||
{ | ||||||
$this->logger = $logger; | ||||||
|
@@ -210,17 +215,39 @@ private function convertToMultipartItems(string $key, array|string|\Stringable|i | |||||
|
||||||
public function generate(): GotenbergFileResult | ||||||
{ | ||||||
$this->logger?->debug('Processing file using {sensiolabs_gotenberg.builder} builder.', [ | ||||||
$this->traceGenerator ??= $this::defaultTraceGenerator(...); | ||||||
$trace = ($this->traceGenerator)(); | ||||||
$headers = ['Gotenberg-Trace' => $trace]; | ||||||
|
||||||
$this->logger?->debug('Processing file with trace "{sensiolabs_gotenberg.trace}" using {sensiolabs_gotenberg.builder} builder.', [ | ||||||
'sensiolabs_gotenberg.trace' => $trace, | ||||||
'sensiolabs_gotenberg.builder' => $this::class, | ||||||
]); | ||||||
|
||||||
$processor = $this->processor ?? new NullProcessor(); | ||||||
|
||||||
return new GotenbergFileResult( | ||||||
$this->client->call($this->getEndpoint(), $this->getMultipartFormData()), | ||||||
$this->client->call($this->getEndpoint(), $this->getMultipartFormData(), $headers), | ||||||
$processor($this->fileName), | ||||||
$this->headerDisposition, | ||||||
$this->fileName, | ||||||
); | ||||||
} | ||||||
|
||||||
/** | ||||||
* Sets the callable that will generate the trace ID for each operation. | ||||||
* | ||||||
* @param \Closure(): string $traceGenerator | ||||||
*/ | ||||||
public function traceGenerator(\Closure $traceGenerator): static | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
If set, use the \Closure, if not, use a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. + There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see the value. There will be a trace no matter what. Either explicitly set from our component or automaticcaly create by gotenberg. But for webhooks we do need this feature. Withotu trace, webhook won't be possible. Trace act as a token per request. Also I think |
||||||
{ | ||||||
$this->traceGenerator = $traceGenerator; | ||||||
|
||||||
return $this; | ||||||
} | ||||||
|
||||||
protected static function defaultTraceGenerator(): string | ||||||
{ | ||||||
return bin2hex(random_bytes(16)).microtime(true); | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trace should be optional to allow keeping default behavior (generated UUID).
We can make the trace nullable and call it only if set. If so, we should add an "unset" method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder. Wouldn't it be better to always set this ourselves ?