Skip to content

Commit

Permalink
feat(auto-instrumentation-node): add azure detector (#2101)
Browse files Browse the repository at this point in the history
The Azure detectors were not being added to the list of possible detectors. All other cloud providers
were possible values, so this commit adds the missing detectors for Azure.

Signed-off-by: maryliag <marylia.gutierrez@grafana.com>
Co-authored-by: Amir Blum <amirgiraffe@gmail.com>
  • Loading branch information
maryliag and blumamir committed Apr 29, 2024
1 parent 86d143a commit af2f3f1
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions metapackages/auto-instrumentations-node/README.md
Expand Up @@ -65,6 +65,7 @@ By default, all SDK resource detectors are used, but you can use the environment
- `container`
- `alibaba`
- `aws`
- `azure`
- `gcp`
- `all` - enable all resource detectors
- `none` - disable resource detection
Expand Down
1 change: 1 addition & 0 deletions metapackages/auto-instrumentations-node/package.json
Expand Up @@ -89,6 +89,7 @@
"@opentelemetry/instrumentation-winston": "^0.37.0",
"@opentelemetry/resource-detector-alibaba-cloud": "^0.28.9",
"@opentelemetry/resource-detector-aws": "^1.4.2",
"@opentelemetry/resource-detector-azure": "^0.2.6",
"@opentelemetry/resource-detector-container": "^0.3.9",
"@opentelemetry/resource-detector-gcp": "^0.29.9",
"@opentelemetry/resources": "^1.12.0",
Expand Down
12 changes: 11 additions & 1 deletion metapackages/auto-instrumentations-node/src/utils.ts
Expand Up @@ -73,6 +73,11 @@ import {
osDetectorSync,
processDetectorSync,
} from '@opentelemetry/resources';
import {
azureAppServiceDetector,
azureFunctionsDetector,
azureVmDetector,
} from '@opentelemetry/resource-detector-azure';

const RESOURCE_DETECTOR_CONTAINER = 'container';
const RESOURCE_DETECTOR_ENVIRONMENT = 'env';
Expand All @@ -81,6 +86,7 @@ const RESOURCE_DETECTOR_OS = 'os';
const RESOURCE_DETECTOR_PROCESS = 'process';
const RESOURCE_DETECTOR_ALIBABA = 'alibaba';
const RESOURCE_DETECTOR_AWS = 'aws';
const RESOURCE_DETECTOR_AZURE = 'azure';
const RESOURCE_DETECTOR_GCP = 'gcp';

const InstrumentationMap = {
Expand Down Expand Up @@ -196,7 +202,7 @@ function getEnabledInstrumentationsFromEnv() {
export function getResourceDetectorsFromEnv(): Array<Detector | DetectorSync> {
const resourceDetectors = new Map<
string,
Detector | DetectorSync | Detector[]
Detector | DetectorSync | Detector[] | DetectorSync[]
>([
[RESOURCE_DETECTOR_CONTAINER, containerDetector],
[RESOURCE_DETECTOR_ENVIRONMENT, envDetectorSync],
Expand All @@ -215,6 +221,10 @@ export function getResourceDetectorsFromEnv(): Array<Detector | DetectorSync> {
awsLambdaDetector,
],
],
[
RESOURCE_DETECTOR_AZURE,
[azureAppServiceDetector, azureFunctionsDetector, azureVmDetector],
],
]);

const resourceDetectorsFromEnv =
Expand Down
4 changes: 2 additions & 2 deletions metapackages/auto-instrumentations-node/test/utils.test.ts
Expand Up @@ -114,13 +114,13 @@ describe('utils', () => {

describe('getResourceDetectorsFromEnv', () => {
it('should return all resource detectors by default', () => {
assert.equal(getResourceDetectorsFromEnv().length, 12);
assert.equal(getResourceDetectorsFromEnv().length, 15);
});

it('should return all resource detectors when OTEL_NODE_RESOURCE_DETECTORS contains "all"', () => {
process.env.OTEL_NODE_RESOURCE_DETECTORS = 'all';

assert.equal(getResourceDetectorsFromEnv().length, 12);
assert.equal(getResourceDetectorsFromEnv().length, 15);

delete process.env.OTEL_NODE_RESOURCE_DETECTORS;
});
Expand Down
2 changes: 2 additions & 0 deletions package-lock.json

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

0 comments on commit af2f3f1

Please sign in to comment.