Skip to content

Commit ce729a8

Browse files
jamietannasecustor
andauthored
chore(telemetry): add span attribute for splits (#38633)
As part of a step towards better OpenTelemetry instrumentation as part of #38609, we can start by introducing a known span attribute for the repository "split" we're currently processing. This requires a slight refactor of the `SpanOptions`, to use our custom type, which enforces the `RenovateSplit` type when using the span name. This adds it into each of the splits we currently instrument. Co-authored-by: secustor <[email protected]>
1 parent e34af57 commit ce729a8

File tree

3 files changed

+48
-17
lines changed

3 files changed

+48
-17
lines changed

lib/instrumentation/index.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
import { ClientRequest } from 'node:http';
2-
import type {
3-
Context,
4-
Span,
5-
SpanOptions,
6-
Tracer,
7-
TracerProvider,
8-
} from '@opentelemetry/api';
2+
import type { Context, Span, Tracer, TracerProvider } from '@opentelemetry/api';
93
import * as api from '@opentelemetry/api';
104
import { ProxyTracerProvider, SpanStatusCode } from '@opentelemetry/api';
115
import { AsyncLocalStorageContextManager } from '@opentelemetry/context-async-hooks';
@@ -47,6 +41,7 @@ import {
4741
} from '@opentelemetry/semantic-conventions';
4842
import { pkg } from '../expose.cjs';
4943
import { getEnv } from '../util/env';
44+
import type { RenovateSpanOptions } from './types';
5045
import {
5146
isTraceDebuggingEnabled,
5247
isTraceSendingEnabled,
@@ -170,18 +165,18 @@ export function instrument<F extends () => ReturnType<F>>(
170165
export function instrument<F extends () => ReturnType<F>>(
171166
name: string,
172167
fn: F,
173-
options: SpanOptions,
168+
options: RenovateSpanOptions,
174169
): ReturnType<F>;
175170
export function instrument<F extends () => ReturnType<F>>(
176171
name: string,
177172
fn: F,
178-
options: SpanOptions,
173+
options: RenovateSpanOptions,
179174
context: Context,
180175
): ReturnType<F>;
181176
export function instrument<F extends () => ReturnType<F>>(
182177
name: string,
183178
fn: F,
184-
options: SpanOptions = {},
179+
options: RenovateSpanOptions = {},
185180
context: Context = api.context.active(),
186181
): ReturnType<F> {
187182
return getTracer().startActiveSpan(name, options, context, (span: Span) => {

lib/instrumentation/types.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
import type { Attributes, SpanKind } from '@opentelemetry/api';
1+
import type { Attributes, SpanKind, SpanOptions } from '@opentelemetry/api';
2+
import type { RenovateSplit } from '../config/types';
23
import type { BunyanRecord } from '../logger/types';
34
import type { PackageFile } from '../modules/manager/types';
45
import type { BranchCache } from '../util/cache/repository/types';
56

7+
export type RenovateSpanOptions = {
8+
attributes?: RenovateSpanAttributes;
9+
} & SpanOptions;
10+
11+
export type RenovateSpanAttributes = {
12+
[ATTR_RENOVATE_SPLIT]?: RenovateSplit;
13+
} & Attributes;
14+
615
/**
716
* The instrumentation decorator parameters.
817
*/
@@ -54,3 +63,5 @@ export interface DependencyStatus {
5463
outdated: number;
5564
total: number;
5665
}
66+
67+
export const ATTR_RENOVATE_SPLIT = 'renovate.split';

lib/workers/repository/index.ts

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
import { pkg } from '../../expose.cjs';
1111
import { instrument } from '../../instrumentation';
1212
import { addExtractionStats } from '../../instrumentation/reporting';
13+
import { ATTR_RENOVATE_SPLIT } from '../../instrumentation/types';
1314
import { logger, setMeta } from '../../logger';
1415
import { resetRepositoryLogLevelRemaps } from '../../logger/remap';
1516
import { removeDanglingContainers } from '../../util/exec/docker';
@@ -95,6 +96,11 @@ export async function renovateRepository(
9596

9697
return { config, localDir, errorRes };
9798
},
99+
{
100+
attributes: {
101+
[ATTR_RENOVATE_SPLIT]: 'init',
102+
},
103+
},
98104
);
99105

100106
try {
@@ -107,8 +113,15 @@ export async function renovateRepository(
107113
config.repoIsOnboarded! ||
108114
!OnboardingState.onboardingCacheValid ||
109115
OnboardingState.prUpdateRequested;
110-
const extractResult = await instrument('extract', () =>
111-
performExtract ? extractDependencies(config) : emptyExtract(config),
116+
const extractResult = await instrument(
117+
'extract',
118+
() =>
119+
performExtract ? extractDependencies(config) : emptyExtract(config),
120+
{
121+
attributes: {
122+
[ATTR_RENOVATE_SPLIT]: 'extract',
123+
},
124+
},
112125
);
113126
addExtractionStats(config, extractResult);
114127

@@ -122,12 +135,24 @@ export async function renovateRepository(
122135
GlobalConfig.get('dryRun') !== 'lookup' &&
123136
GlobalConfig.get('dryRun') !== 'extract'
124137
) {
125-
await instrument('onboarding', () =>
126-
ensureOnboardingPr(config, packageFiles, branches),
138+
await instrument(
139+
'onboarding',
140+
() => ensureOnboardingPr(config, packageFiles, branches),
141+
{
142+
attributes: {
143+
[ATTR_RENOVATE_SPLIT]: 'onboarding',
144+
},
145+
},
127146
);
128147
addSplit('onboarding');
129-
const res = await instrument('update', () =>
130-
updateRepo(config, branches),
148+
const res = await instrument(
149+
'update',
150+
() => updateRepo(config, branches),
151+
{
152+
attributes: {
153+
[ATTR_RENOVATE_SPLIT]: 'update',
154+
},
155+
},
131156
);
132157
setMeta({ repository: config.repository });
133158
addSplit('update');

0 commit comments

Comments
 (0)