mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-25 06:51:11 +00:00
f635ae29c4
* feat: timing statistics for getReleases Adds collection and reporting of timing statistics for `datasource.getReleases()` calls. Each call records the datasource, registryUrl, packageName, and duration. The intent is to visibility into where renovate is retrieving release information and how long that might take. The report consists of a nested data-structure that provides increasing detail as we descend datasource, registryUrl, and packageName. The full report is logged at trace level `getReleases statistics with packages`. A summary report including only datasources and registryUrls is logged at debug level `getReleases statistics summary`. * add GetReleasesSpanProcessor - Re-instrument getReleases calls using open telemetry. - Adds GetReleasesSpanProcessor, which can adapt `getReleases` spans to GetReleasesStats. * fixup instrumentation tests * pr feedback * pr feedback: naming * pr feedback: comments
57 lines
1.4 KiB
TypeScript
57 lines
1.4 KiB
TypeScript
import type { Context } from '@opentelemetry/api';
|
|
import type {
|
|
ReadableSpan,
|
|
Span,
|
|
SpanProcessor,
|
|
} from '@opentelemetry/sdk-trace-base';
|
|
import { ATTR_CODE_FUNCTION_NAME } from '@opentelemetry/semantic-conventions';
|
|
import {
|
|
ATTR_RENOVATE_DATASOURCE,
|
|
ATTR_RENOVATE_PACKAGE_NAME,
|
|
ATTR_RENOVATE_REGISTRY_URL,
|
|
} from '../../instrumentation/types.ts';
|
|
import { GetDatasourceReleasesStats } from '../../util/stats.ts';
|
|
|
|
export class GetDatasourceReleasesSpanProcessor implements SpanProcessor {
|
|
forceFlush(): Promise<void> {
|
|
return Promise.resolve();
|
|
}
|
|
|
|
onStart(_span: Span, _parentContext: Context): void {
|
|
// no implementation
|
|
}
|
|
|
|
onEnd(span: ReadableSpan): void {
|
|
if (!span.ended) {
|
|
return;
|
|
}
|
|
|
|
if (span.attributes[ATTR_CODE_FUNCTION_NAME] !== 'getReleases') {
|
|
return;
|
|
}
|
|
|
|
const datasource = span.attributes[ATTR_RENOVATE_DATASOURCE] as string;
|
|
const registryUrl = (span.attributes[ATTR_RENOVATE_REGISTRY_URL] ??
|
|
'') as string;
|
|
const packageName = span.attributes[ATTR_RENOVATE_PACKAGE_NAME] as string;
|
|
|
|
if (!datasource || !packageName) {
|
|
return;
|
|
}
|
|
|
|
// duration[0] is seconds, duration[1] is nanoseconds.
|
|
const durationMs = span.duration[0] * 1000 + span.duration[1] / 1_000_000;
|
|
|
|
GetDatasourceReleasesStats.write(
|
|
datasource,
|
|
registryUrl,
|
|
packageName,
|
|
durationMs,
|
|
);
|
|
}
|
|
|
|
shutdown(): Promise<void> {
|
|
return Promise.resolve();
|
|
}
|
|
}
|