Skip to content
Open
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
12 changes: 12 additions & 0 deletions docs/usage/opentelemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ The following resource detectors are used:
- `GcpDetector` from [@opentelemetry/resource-detector-gcp](https://www.npmjs.com/package/@opentelemetry/resource-detector-gcp) Users hosting on GCP
- `AzureDetector` from [@opentelemetry/resource-detector-azure](https://www.npmjs.com/package/@opentelemetry/resource-detector-azure) Users hosting on Azure

You can disable all cloud detectors by setting the `RENOVATE_USE_CLOUD_METADATA_SERVICES` environment variable to `false`.
Then only the `EnvDetector` will be used.

Additionally you can use `OTEL_NODE_RESOURCE_DETECTORS` environment variable to control which resource detectors are used.
The default values is `all`, which means all of the above detectors are used. Set it to `none` to disable all detectors, or a comma-separated list of the following values to specify which detectors to use:

- `aws`
- `azure`
- `gcp`
- `github`
- `env`

## Supported OTLP data

### Traces
Expand Down
57 changes: 57 additions & 0 deletions lib/instrumentation/detectors.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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 { envDetector } from '@opentelemetry/resources';
import { getResourceDetectors } from './detectors.ts';

describe('instrumentation/detectors', () => {
it.each`
env
${{}}
${{ OTEL_NODE_RESOURCE_DETECTORS: 'all' }}
${{ RENOVATE_USE_CLOUD_METADATA_SERVICES: 'true' }}
`('should return all detectors: %o', () => {
expect(getResourceDetectors({})).toEqual([
awsBeanstalkDetector,
awsEc2Detector,
awsEcsDetector,
awsEksDetector,
awsLambdaDetector,
azureAppServiceDetector,
azureFunctionsDetector,
azureVmDetector,
gcpDetector,
gitHubDetector,
envDetector,
]);
});

it('should disable all detectors', () => {
expect(
getResourceDetectors({ OTEL_NODE_RESOURCE_DETECTORS: 'none' }),
).toEqual([]);
});

it('should disable cloud detectors', () => {
expect(
getResourceDetectors({ RENOVATE_USE_CLOUD_METADATA_SERVICES: 'false' }),
).toEqual([envDetector]);
});

it('should enable selected detectors', () => {
expect(
getResourceDetectors({ OTEL_NODE_RESOURCE_DETECTORS: 'env,github' }),
).toEqual([gitHubDetector, envDetector]);
});
});
55 changes: 55 additions & 0 deletions lib/instrumentation/detectors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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 type { ResourceDetector } from '@opentelemetry/resources';
import { envDetector } from '@opentelemetry/resources';

export function getResourceDetectors(
env: NodeJS.ProcessEnv,
): ResourceDetector[] {
const detectors: Record<string, ResourceDetector | ResourceDetector[]> = {
aws: [
awsBeanstalkDetector,
awsEc2Detector,
awsEcsDetector,
awsEksDetector,
awsLambdaDetector,
],
azure: [azureAppServiceDetector, azureFunctionsDetector, azureVmDetector],
gcp: gcpDetector,
github: gitHubDetector,
env: envDetector,
};

const resourceDetectorsFromEnv = new Set(
env.OTEL_NODE_RESOURCE_DETECTORS?.split(',') ?? [
env.RENOVATE_USE_CLOUD_METADATA_SERVICES?.toLocaleLowerCase() === 'false'
? 'env'
: 'all',
],
);

if (resourceDetectorsFromEnv.has('none')) {
return [];
}

if (resourceDetectorsFromEnv.has('all')) {
return Object.values(detectors).flat();
}

return Object.entries(detectors)
.filter(([name]) => resourceDetectorsFromEnv.has(name))
.map(([_, value]) => value)
.flat();
}
10 changes: 8 additions & 2 deletions lib/instrumentation/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@ describe('instrumentation/index', () => {
beforeEach(() => {
api.trace.disable(); // clear global components
process.env = { ...oldEnv };
delete process.env.OTEL_LOG_LEVEL;
delete process.env.OTEL_EXPORTER_OTLP_ENDPOINT;

// remove any otel env
for (const key in process.env) {
if (key.startsWith('OTEL_')) {
delete process.env[key];
}
}
delete process.env.RENOVATE_TRACING_CONSOLE_EXPORTER;
delete process.env.RENOVATE_USE_CLOUD_METADATA_SERVICES;
});

afterAll(() => {
Expand Down
30 changes: 2 additions & 28 deletions lib/instrumentation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,8 @@ import { registerInstrumentations } from '@opentelemetry/instrumentation';
import { BunyanInstrumentation } from '@opentelemetry/instrumentation-bunyan';
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
import { RedisInstrumentation } from '@opentelemetry/instrumentation-redis';
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 {
Expand All @@ -42,6 +27,7 @@ import {
import { isPromise } from '@sindresorhus/is';
import { pkg } from '../expose.ts';
import { GitOperationSpanProcessor } from '../util/git/span-processor.ts';
import { getResourceDetectors } from './detectors.ts';
import type { RenovateSpanOptions } from './types.ts';
import {
isTraceDebuggingEnabled,
Expand Down Expand Up @@ -92,19 +78,7 @@ export function init(): void {
});

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

const traceProvider = new NodeTracerProvider({
Expand Down
13 changes: 13 additions & 0 deletions lib/instrumentation/reporting.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,19 @@ describe('instrumentation/reporting', () => {
await expect(exportStats(config)).toResolve();
});

it('reports nothing when reportType=null', async () => {
const config: RenovateConfig = {
repository: 'myOrg/myRepo',
reportType: null,
};

await exportStats(config);

expect(logger.logger.debug).not.toHaveBeenCalled();
expect(logger.logger.info).not.toHaveBeenCalled();
expect(logger.logger.warn).not.toHaveBeenCalled();
});

it('should add problems to report', () => {
const config: RenovateConfig = {
repository: 'myOrg/myRepo',
Expand Down