Files
renovate/lib/util/cache/repository/index.ts
Zack Kanter 264f813cab feat(instrumentation): instrument cache lifecycle with OTEL (#41922)
* fix(cache): instrument repository cache load and save

Wrap repository cache `load()` and `save()` calls with the existing
`instrument()` helper to create OpenTelemetry spans for cache lifecycle
operations. This gives operators visibility into repository cache
performance, especially useful with S3 backends.

Refs #41760

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(cache): instrument package cache init and destroy

Wrap package cache `init()` and `destroy()` with `instrument()` to
create OpenTelemetry spans, matching the repository cache instrumentation
from the previous commit. Covers redis, sqlite, and file backends.

Refs #41760

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* docs: document cache lifecycle tracing in OpenTelemetry guide

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Move destroy() outside init instrument span

Avoids nesting the package-cache.destroy span inside
package-cache.init, making them sibling spans instead.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Use 'verb NounClass' span naming convention

Rename instrument span names from dot-notation (e.g.
'package-cache.init') to 'verb NounClass' pattern (e.g.
'init PackageCache') per reviewer feedback.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-20 05:54:43 +00:00

34 lines
975 B
TypeScript

import { GlobalConfig } from '../../../config/global.ts';
import { instrument } from '../../../instrumentation/index.ts';
import { logger } from '../../../logger/index.ts';
import { RepoCacheNull } from './impl/null.ts';
import type { RepoCache, RepoCacheData } from './types.ts';
// This will be overwritten with initRepoCache()
// Used primarily as a placeholder and for testing
let repoCache: RepoCache = new RepoCacheNull();
export function resetCache(): void {
setCache(new RepoCacheNull());
}
export function setCache(cache: RepoCache): void {
repoCache = cache;
}
export function getCache(): RepoCacheData {
return repoCache.getData();
}
export async function saveCache(): Promise<void> {
if (GlobalConfig.get('dryRun')) {
logger.info(`DRY-RUN: Would save repository cache.`);
} else {
await instrument('save RepoCache', () => repoCache.save());
}
}
export function isCacheModified(): boolean | undefined {
return repoCache.isModified();
}