Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/usage/opentelemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ You can also set the following environment variables:
- `OTEL_SERVICE_NAMESPACE`: to control the service namespace that will be emitted in traces, defaults to `renovatebot.com`
- `OTEL_SERVICE_VERSION`: to control the service version that will be emitted in traces, defaults to using the release version of Renovate

The following resource detectors are used:

- `EnvDetector` from @opentelemetry/resources to allow users to add the custom attributes
- `GithubDetector` from [@opentelemetry/resource-detector-github](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/detectors/node/opentelemetry-resource-detector-github) for the Github Action
- `AWSDetector` from [@opentelemetry/resource-detector-aws](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/detectors/node/opentelemetry-resource-detector-aws) Users hosting on AWS
- `GcpDetector` from [@opentelemetry/resource-detector-gcp](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/detectors/node/opentelemetry-resource-detector-gcp) Users hosting on GCP
- `AzureDetector` from [@opentelemetry/resource-detector-azure](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/detectors/node/opentelemetry-resource-detector-azure) Users hosting on Azure

## Debugging

To help you debug, you can print the telemetry to the console.
Expand Down
56 changes: 46 additions & 10 deletions lib/instrumentation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,25 @@ import type { Instrumentation } from '@opentelemetry/instrumentation';
import { registerInstrumentations } from '@opentelemetry/instrumentation';
import { BunyanInstrumentation } from '@opentelemetry/instrumentation-bunyan';
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
import { resourceFromAttributes } from '@opentelemetry/resources';
import {
awsBeanstalkDetector,
awsEc2Detector,
awsEcsDetector,
awsEksDetector,
awsLambdaDetector,
} from '@opentelemetry/resource-detector-aws';
import {
azureAppServiceDetector,
azureFunctionsDetector,
azureVmDetector,
} from '@opentelemetry/resource-detector-azure';
import { gcpDetector } from '@opentelemetry/resource-detector-gcp';
import { gitHubDetector } from '@opentelemetry/resource-detector-github';
import {
detectResources,
envDetector,
resourceFromAttributes,
} from '@opentelemetry/resources';
import {
BatchSpanProcessor,
ConsoleSpanExporter,
Expand Down Expand Up @@ -55,16 +73,34 @@ export function init(): void {
spanProcessors.push(new BatchSpanProcessor(exporter));
}

const baseResource = resourceFromAttributes({
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/README.md#semantic-attributes-with-sdk-provided-default-value
[ATTR_SERVICE_NAME]: process.env.OTEL_SERVICE_NAME ?? 'renovate',
// https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv
// https://github.com/open-telemetry/opentelemetry-js/blob/e9d3c71918635d490b6a9ac9f8259265b38394d0/semantic-conventions/src/experimental_attributes.ts#L7688
['service.namespace']:
process.env.OTEL_SERVICE_NAMESPACE ?? 'renovatebot.com',
[ATTR_SERVICE_VERSION]: process.env.OTEL_SERVICE_VERSION ?? pkg.version,
});

const detectedResource = detectResources({
detectors: [
awsBeanstalkDetector,
awsEc2Detector,
awsEcsDetector,
awsEksDetector,
awsLambdaDetector,
azureAppServiceDetector,
azureFunctionsDetector,
azureVmDetector,
gcpDetector,
gitHubDetector,
envDetector,
],
});

const traceProvider = new NodeTracerProvider({
resource: resourceFromAttributes({
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/README.md#semantic-attributes-with-sdk-provided-default-value
[ATTR_SERVICE_NAME]: process.env.OTEL_SERVICE_NAME ?? 'renovate',
// https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv
// https://github.com/open-telemetry/opentelemetry-js/blob/e9d3c71918635d490b6a9ac9f8259265b38394d0/semantic-conventions/src/experimental_attributes.ts#L7688
['service.namespace']:
process.env.OTEL_SERVICE_NAMESPACE ?? 'renovatebot.com',
[ATTR_SERVICE_VERSION]: process.env.OTEL_SERVICE_VERSION ?? pkg.version,
}),
resource: baseResource.merge(detectedResource),
spanProcessors,
});

Expand Down
26 changes: 24 additions & 2 deletions lib/workers/repository/update/pr/body/config-description.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,31 @@ describe('workers/repository/update/pr/body/config-description', () => {
it('renders UTC as the default timezone', () => {
const res = getPrConfigDescription({
...config,
schedule: ['* 1 * * * *'],
schedule: ['* 1 * * *'],
});
expect(res).toContain(`"* 1 * * * *" (UTC)`);
expect(res).toContain(
'Between 01:00 AM and 01:59 AM ( * 1 * * * ) (UTC)',
);
});

it('summarizes cron schedules', () => {
const res = getPrConfigDescription({
...config,
schedule: ['* 1 * * *', '* * 2 * 1'],
});
expect(res).toContain(
'Between 01:00 AM and 01:59 AM ( * 1 * * * ), On day 2 of the month, and on Monday ( * * 2 * 1 ) (UTC)',
);
});

it('displays later schedules', () => {
const res = getPrConfigDescription({
...config,
schedule: ['before 6am on Monday', 'after 3pm on Tuesday'],
});
expect(res).toContain(
'"before 6am on Monday,after 3pm on Tuesday" (UTC)',
);
});

it('renders undefined schedule', () => {
Expand Down
31 changes: 30 additions & 1 deletion lib/workers/repository/update/pr/body/config-description.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { CronPattern } from 'croner';
import cronstrue from 'cronstrue';
import { emojify } from '../../../../../util/emoji';
import { capitalize } from '../../../../../util/string';
import type { BranchConfig } from '../../../../types';

export function getPrConfigDescription(config: BranchConfig): string {
Expand Down Expand Up @@ -51,7 +54,8 @@ function scheduleToString(
): string {
let scheduleString = '';
if (schedule && schedule[0] !== 'at any time') {
scheduleString += `"${String(schedule)}"`;
scheduleString =
getReadableCronSchedule(schedule) ?? `"${String(schedule)}"`;
if (timezone) {
scheduleString += ` in timezone ${timezone}`;
} else {
Expand All @@ -62,3 +66,28 @@ function scheduleToString(
}
return scheduleString;
}

/**
* Return human-readable cron schedule summary if the schedule is a valid cron
* else return null
*/
function getReadableCronSchedule(scheduleText: string[]): string | null {
// assuming if one schedule is cron the others in the array will be cron too
try {
new CronPattern(scheduleText[0]); // validate cron
return scheduleText
.map(
(cron) =>
capitalize(
cronstrue
.toString(cron, {
throwExceptionOnParseError: false,
})
.replace('Every minute, ', ''),
) + ` ( ${cron} )`,
)
.join(', ');
} catch {
return null;
}
}
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@
"@opentelemetry/instrumentation": "0.200.0",
"@opentelemetry/instrumentation-bunyan": "0.46.0",
"@opentelemetry/instrumentation-http": "0.200.0",
"@opentelemetry/resource-detector-aws": "2.0.0",
"@opentelemetry/resource-detector-azure": "0.7.0",
"@opentelemetry/resource-detector-gcp": "0.34.0",
"@opentelemetry/resource-detector-github": "0.31.0",
"@opentelemetry/resources": "2.0.0",
"@opentelemetry/sdk-trace-base": "2.0.0",
"@opentelemetry/sdk-trace-node": "2.0.0",
Expand Down Expand Up @@ -203,7 +207,7 @@
"find-packages": "10.0.4",
"find-up": "5.0.0",
"fs-extra": "11.3.0",
"git-url-parse": "16.0.1",
"git-url-parse": "16.1.0",
"github-url-from-git": "1.5.0",
"glob": "11.0.1",
"global-agent": "3.0.0",
Expand Down Expand Up @@ -285,7 +289,6 @@
"@types/diff": "7.0.2",
"@types/eslint-config-prettier": "6.11.3",
"@types/fs-extra": "11.0.4",
"@types/git-url-parse": "16.0.0",
"@types/github-url-from-git": "1.5.3",
"@types/global-agent": "3.0.0",
"@types/ini": "4.1.1",
Expand Down
96 changes: 71 additions & 25 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading