mirror of
https://github.com/renovatebot/renovate.git
synced 2026-11-06 04:11:28 +00:00
b5cd0317cf
Now we have instrumented our Git operations with tracing, we can make sure that users who are not using OpenTelemetry still get insights into their Git operation usage using a debug log output. Following how other insights are produced, we can introduce a new type in `lib/util/stats` for `GitOperationStats`, which will track the overall execution for each operation type, and output them in the same style as we use for other timing reports. At the end of a Renovate run, we'll then make sure that this is logged into a debug log for further investigation. To create the report, we can make sure that we introduce a new OpenTelemetry `SpanProcessor`, which will run when we end our Run, and store any Git operations in `GitOperationStats`. This adapts code from GPT-4.1 and code from [0]. Co-authored-by: gpt-4.1 <jamie.tanna+github-copilot@mend.io> [0]: https://github.com/yurisouza/monitoria-sdk/blob/ca9d751fa7c3a785a04f87b8966bb782b4617021/src/adapters/nestjs/span-duration-tracker.ts#L18-L27
42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import type { Context } from '@opentelemetry/api';
|
|
import type {
|
|
ReadableSpan,
|
|
Span,
|
|
SpanProcessor,
|
|
} from '@opentelemetry/sdk-trace-base';
|
|
import { ATTR_VCS_GIT_OPERATION_TYPE } from '../../instrumentation/types';
|
|
import { GitOperationStats } from '../stats';
|
|
import type { GitOperationType } from './types';
|
|
|
|
export class GitOperationSpanProcessor implements SpanProcessor {
|
|
async forceFlush(): Promise<void> {
|
|
// no implementation
|
|
}
|
|
onStart(span: Span, parentContext: Context): void {
|
|
// no implementation
|
|
}
|
|
onEnd(span: ReadableSpan): void {
|
|
if (!span.ended) {
|
|
return;
|
|
}
|
|
|
|
if (!span.attributes[ATTR_VCS_GIT_OPERATION_TYPE]) {
|
|
return;
|
|
}
|
|
|
|
const start = span.startTime; // [seconds, nanos]
|
|
const end = span.endTime; // [seconds, nanos]
|
|
const startNs = start[0] * 1e9 + start[1];
|
|
const endNs = end[0] * 1e9 + end[1];
|
|
const ns = endNs - startNs;
|
|
|
|
GitOperationStats.write(
|
|
span.attributes[ATTR_VCS_GIT_OPERATION_TYPE] as GitOperationType,
|
|
ns / 1_000_000,
|
|
);
|
|
}
|
|
async shutdown(): Promise<void> {
|
|
// no implementation
|
|
}
|
|
}
|