Adding OpenTelemetry and provide traces - #4598
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
@FredPraca I am not able to push changes to enable the CICD missing extension. Would you mind ticking the box or modify the php-test and php-dist yaml files :) |
The Allow edits by maintainers is checked so I don't know why you're unable to change it. The main problem is that opentelemetry extensions is not a standard one. The process is described here but I don't know if I can do something like this Github actions. |
|
I'm also trying to include a package providing metrics about PHP runtime, especially RAM but I face a problem with initialization order. |
f9637f6 to
47907fc
Compare
| } | ||
| $trace = app(TraceService::class); | ||
|
|
||
| return $trace->traceMethod('photo.load_file_metadata', function () use ($state, $next) { |
There was a problem hiding this comment.
I think here it might be cleaner to rename
handle(InitDTO $state, \Closure $next): InitDTO
into
_handle(InitDTO $state, \Closure $next): InitDTO
and then have
public function handle(InitDTO $state, \Closure $next): InitDTO
{
$trace = app(TraceService::class);
return $trace->traceMethod('photo.load_file_metadata',
fn () => $this->_handle($state, $next));
}There was a problem hiding this comment.
or indeed, rename into execute() instead of _handle :)
There was a problem hiding this comment.
In fact, I started with it for telemetry tests and switched to Standalone pipes which were more promising in terms of trace and memory investigations.
If the part on Standalone pipes was considered well done by the main maintainer of Lychee, I was considering using the same pattern as for standalone pipes :)
We could also generalize this "pattern" to other types of pipes.
The drawback is that it will generate a lot of traces 😄
| return $trace->traceMethod($this->getSpanName(), function () use ($state, $next) { | ||
| return $this->execute($state, $next); | ||
| }); |
There was a problem hiding this comment.
| return $trace->traceMethod($this->getSpanName(), function () use ($state, $next) { | |
| return $this->execute($state, $next); | |
| }); | |
| return $trace->traceMethod($this->getSpanName(), fn () => $this->execute($state, $next)); |
You can use the arrow functions instead to avoid the use (...)
There was a problem hiding this comment.
Ahaha, I am not really a PHP dev as you may have seen :)
| // Skip if the caller explicitly provided a title at upload time (FR-041-06). | ||
| // User-supplied titles take precedence and must not be overwritten by renamer rules. | ||
| if ($state->title !== null) { | ||
| Log::info('Photo has a title, we don\'t rename it, skipping'); |
There was a problem hiding this comment.
I don't think this is necessary :)
There was a problem hiding this comment.
Maybe at debug level or even trace ?
There was a problem hiding this comment.
Ahaha, there is no trace :)
Notice maybe ?
|
|
||
| // Skip if not enabled. | ||
| if (!$state->shall_rename_photo_title) { | ||
| Log::info('renaming not necessary, skipping'); |
| public function handle(StandaloneDTO $state, \Closure $next): StandaloneDTO | ||
| protected function execute(StandaloneDTO $state, \Closure $next): StandaloneDTO | ||
| { | ||
| Log::info('Computing original checksum'); |
There was a problem hiding this comment.
Instead of info maybe we want to keep those at debug level?
There was a problem hiding this comment.
As it is standard flow, yes, debug is enough
| { | ||
| $meta = $request->meta(); | ||
| $file = new UploadedFile($request->uploaded_file_chunk()); | ||
| // Reset max memory usage before measuring |
There was a problem hiding this comment.
Should this be in a middleware instead?
There was a problem hiding this comment.
I'll read it as I'm not aware of all Laravel possibilities and especially with the middleware and so on stuff.
Besides this, I was not super happy with this way of tracing memory usage.
So we might maybe leave the trace without performing these memory features and keep tracing telemetry for what it is, following calls durations.
Your way of profiling might be a better way that we may merge with telemetry afterwards.
What do you think ?
| $final->delete(); | ||
| $processable_file->close(); | ||
| // End of work-around | ||
| return $this->trace->traceMethod('photo.process', function () use ($verify, |
There was a problem hiding this comment.
It is important to note that here you are measuring either of two cases:
if the processing is done sync, you will have the full processing memory, but if it is dispatch to a queue you won't see the computation anymore.
There was a problem hiding this comment.
Yes, I figured it out and maybe we will use traces to provide time consumption instead of memory consumption.
That's the reason why I would like to import the php metrics module and experiment around it.
Codecov Report❌ Patch coverage is 🚀 New features to boost your workflow:
|
This PR provides OpenTelemetry functionalities to Lychee.
It allows to send logs, metrics and traces to any OpenTelemetry collector.
It has been tested with Loki, Tempo and Mimir for logs, traces and metrics respectively.
The best way to test it is to use Grafana Alloy as a collector and then dispatch to other tools such as the ones mentioned before.
It requires to install the opentelemetry extension as described here.
The following environment variables may be set:
Please note that exporters may be set to console or otlp. When using otlp, you may provide the OTEL_EXPORTER_OTLP_ENDPOINT variable to point to an OTLP collector. Here http://localhost:4318/ corresponds to a local setup for Tempo.
Moreover, OTEL_PHP_DISABLED_INSTRUMENTATIONS allows to disable some instrumentation. Here, I disabled pdo to avoid having all SQL operations in my traces. Currently, only laravel, guzzle and pdo are configured.