An extension's own usage
Extension reads what one calling extension spent
and how often each of its operations ran and failed (ADR-248).
The extension is the name it passes to with.
Reading the usage of one extension
use Netresearch\NrLlm\Service\Usage\ExtensionUsageReaderInterface;
final readonly class MyUsageReader
{
public function __construct(
private ExtensionUsageReaderInterface $usage,
) {}
public function lastThirtyDays(?int $onlyThisUser): array
{
$to = new \DateTimeImmutable();
// Midnight, so totals and operation counts cover the same days.
$from = $to->modify('-29 days')->setTime(0, 0);
return [
'totals' => $this->usage->totals('my_extension', $from, $to, $onlyThisUser),
'operations' => $this->usage->operations('my_extension', $from, $to, $onlyThisUser),
'coverage' => $this->usage->coverage(),
];
}
}
Copied!
totals() ExtensionwithUsage Totals $estimated(US dollars, the recorded estimate),Cost $requestsand$tokens, from the daily usage aggregate. These are the figures the Analytics module shows per extension. The aggregate counts whole days, so the day$fromfalls on is included entirely. A request is what the usage tracker counts as one, so$requestsneed not equal the callsoperationscounts.() operations() - One
Operationper operation name, most calls first:Usage $operation,$calls,$failedandCalls $last(Unix time). Read from the per-call telemetry.Call At coverage() Telemetry:Coverage $enabled(thetelemetry.setting),enabled $retention(after which the purge command deletes rows) andDays $oldest, the oldest stored call orCall At null. Operation counts for a period that starts before it are incomplete. It is a lower bound: a time while telemetry was switched off leaves a gap after it that the oldest call cannot show.
Pass a backend user uid to totals and operations to narrow
them to that user; coverage always describes the whole installation.
Without a uid the figures cover the whole installation; show them only to
someone allowed to see them. Names are matched as stored: the first 64
characters of the extension and of the operation.