Skip to content

Commit de28045

Browse files
committed
chore(resource-detector-azure): use exported strings for attributes
Use exported strings for Semantic Resource Attributes, Cloud Platform Values and Cloud Provider Values. Signed-off-by: maryliag <[email protected]>
1 parent d5f079b commit de28045

File tree

7 files changed

+97
-106
lines changed

7 files changed

+97
-106
lines changed

detectors/node/opentelemetry-resource-detector-azure/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
},
4949
"dependencies": {
5050
"@opentelemetry/resources": "^1.10.1",
51-
"@opentelemetry/semantic-conventions": "^1.0.0"
51+
"@opentelemetry/semantic-conventions": "^1.22.0"
5252
},
5353
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/detectors/node/opentelemetry-resource-detector-azure#readme"
5454
}

detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureAppServiceDetector.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,22 @@ import {
2929
FUNCTIONS_VERSION,
3030
} from '../types';
3131
import {
32-
CloudProviderValues,
33-
CloudPlatformValues,
34-
SemanticResourceAttributes,
32+
SEMRESATTRS_CLOUD_REGION,
33+
SEMRESATTRS_DEPLOYMENT_ENVIRONMENT,
34+
SEMRESATTRS_HOST_ID,
35+
SEMRESATTRS_SERVICE_INSTANCE_ID,
36+
SEMRESATTRS_SERVICE_NAME,
37+
SEMRESATTRS_CLOUD_PROVIDER,
38+
SEMRESATTRS_CLOUD_PLATFORM,
39+
CLOUDPROVIDERVALUES_AZURE,
40+
CLOUDPLATFORMVALUES_AZURE_APP_SERVICE,
3541
} from '@opentelemetry/semantic-conventions';
3642

3743
const APP_SERVICE_ATTRIBUTE_ENV_VARS = {
38-
[SemanticResourceAttributes.CLOUD_REGION]: REGION_NAME,
39-
[SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT]: WEBSITE_SLOT_NAME,
40-
[SemanticResourceAttributes.HOST_ID]: WEBSITE_HOSTNAME,
41-
[SemanticResourceAttributes.SERVICE_INSTANCE_ID]: WEBSITE_INSTANCE_ID,
44+
[SEMRESATTRS_CLOUD_REGION]: REGION_NAME,
45+
[SEMRESATTRS_DEPLOYMENT_ENVIRONMENT]: WEBSITE_SLOT_NAME,
46+
[SEMRESATTRS_HOST_ID]: WEBSITE_HOSTNAME,
47+
[SEMRESATTRS_SERVICE_INSTANCE_ID]: WEBSITE_INSTANCE_ID,
4248
[AZURE_APP_SERVICE_STAMP_RESOURCE_ATTRIBUTE]: WEBSITE_HOME_STAMPNAME,
4349
};
4450

@@ -54,16 +60,15 @@ class AzureAppServiceDetector implements DetectorSync {
5460
if (websiteSiteName && !isAzureFunction) {
5561
attributes = {
5662
...attributes,
57-
[SemanticResourceAttributes.SERVICE_NAME]: websiteSiteName,
63+
[SEMRESATTRS_SERVICE_NAME]: websiteSiteName,
5864
};
5965
attributes = {
6066
...attributes,
61-
[SemanticResourceAttributes.CLOUD_PROVIDER]: CloudProviderValues.AZURE,
67+
[SEMRESATTRS_CLOUD_PROVIDER]: CLOUDPROVIDERVALUES_AZURE,
6268
};
6369
attributes = {
6470
...attributes,
65-
[SemanticResourceAttributes.CLOUD_PLATFORM]:
66-
CloudPlatformValues.AZURE_APP_SERVICE,
71+
[SEMRESATTRS_CLOUD_PLATFORM]: CLOUDPLATFORMVALUES_AZURE_APP_SERVICE,
6772
};
6873

6974
const azureResourceUri = this.getAzureResourceUri(websiteSiteName);

detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureFunctionsDetector.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,15 @@
1717
import { DetectorSync, IResource, Resource } from '@opentelemetry/resources';
1818

1919
import {
20-
CloudProviderValues,
21-
CloudPlatformValues,
22-
SemanticResourceAttributes,
20+
SEMRESATTRS_FAAS_NAME,
21+
SEMRESATTRS_FAAS_VERSION,
22+
SEMRESATTRS_FAAS_MAX_MEMORY,
23+
SEMRESATTRS_FAAS_INSTANCE,
24+
SEMRESATTRS_CLOUD_PROVIDER,
25+
SEMRESATTRS_CLOUD_PLATFORM,
26+
SEMRESATTRS_CLOUD_REGION,
27+
CLOUDPROVIDERVALUES_AZURE,
28+
CLOUDPLATFORMVALUES_AZURE_FUNCTIONS,
2329
} from '@opentelemetry/semantic-conventions';
2430
import {
2531
WEBSITE_SITE_NAME,
@@ -30,10 +36,10 @@ import {
3036
} from '../types';
3137

3238
const AZURE_FUNCTIONS_ATTRIBUTE_ENV_VARS = {
33-
[SemanticResourceAttributes.FAAS_NAME]: WEBSITE_SITE_NAME,
34-
[SemanticResourceAttributes.FAAS_VERSION]: FUNCTIONS_VERSION,
35-
[SemanticResourceAttributes.FAAS_INSTANCE]: WEBSITE_INSTANCE_ID,
36-
[SemanticResourceAttributes.FAAS_MAX_MEMORY]: FUNCTIONS_MEM_LIMIT,
39+
[SEMRESATTRS_FAAS_NAME]: WEBSITE_SITE_NAME,
40+
[SEMRESATTRS_FAAS_VERSION]: FUNCTIONS_VERSION,
41+
[SEMRESATTRS_FAAS_INSTANCE]: WEBSITE_INSTANCE_ID,
42+
[SEMRESATTRS_FAAS_MAX_MEMORY]: FUNCTIONS_MEM_LIMIT,
3743
};
3844

3945
/**
@@ -50,34 +56,33 @@ class AzureFunctionsDetector implements DetectorSync {
5056
const functionMemLimit = process.env[FUNCTIONS_MEM_LIMIT];
5157

5258
attributes = {
53-
[SemanticResourceAttributes.CLOUD_PROVIDER]: CloudProviderValues.AZURE,
54-
[SemanticResourceAttributes.CLOUD_PLATFORM]:
55-
CloudPlatformValues.AZURE_FUNCTIONS,
56-
[SemanticResourceAttributes.CLOUD_REGION]: process.env[REGION_NAME],
59+
[SEMRESATTRS_CLOUD_PROVIDER]: CLOUDPROVIDERVALUES_AZURE,
60+
[SEMRESATTRS_CLOUD_PLATFORM]: CLOUDPLATFORMVALUES_AZURE_FUNCTIONS,
61+
[SEMRESATTRS_CLOUD_REGION]: process.env[REGION_NAME],
5762
};
5863

5964
if (functionName) {
6065
attributes = {
6166
...attributes,
62-
[SemanticResourceAttributes.FAAS_NAME]: functionName,
67+
[SEMRESATTRS_FAAS_NAME]: functionName,
6368
};
6469
}
6570
if (functionVersion) {
6671
attributes = {
6772
...attributes,
68-
[SemanticResourceAttributes.FAAS_VERSION]: functionVersion,
73+
[SEMRESATTRS_FAAS_VERSION]: functionVersion,
6974
};
7075
}
7176
if (functionInstance) {
7277
attributes = {
7378
...attributes,
74-
[SemanticResourceAttributes.FAAS_INSTANCE]: functionInstance,
79+
[SEMRESATTRS_FAAS_INSTANCE]: functionInstance,
7580
};
7681
}
7782
if (functionMemLimit) {
7883
attributes = {
7984
...attributes,
80-
[SemanticResourceAttributes.FAAS_MAX_MEMORY]: functionMemLimit,
85+
[SEMRESATTRS_FAAS_MAX_MEMORY]: functionMemLimit,
8186
};
8287
}
8388

detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureVmDetector.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,15 @@ import {
2222
ResourceAttributes,
2323
} from '@opentelemetry/resources';
2424
import {
25-
CloudPlatformValues,
26-
CloudProviderValues,
27-
SemanticResourceAttributes,
25+
CLOUDPLATFORMVALUES_AZURE_VM,
26+
CLOUDPROVIDERVALUES_AZURE,
27+
SEMRESATTRS_CLOUD_PLATFORM,
28+
SEMRESATTRS_CLOUD_PROVIDER,
29+
SEMRESATTRS_CLOUD_REGION,
30+
SEMRESATTRS_HOST_ID,
31+
SEMRESATTRS_HOST_NAME,
32+
SEMRESATTRS_HOST_TYPE,
33+
SEMRESATTRS_OS_VERSION,
2834
} from '@opentelemetry/semantic-conventions';
2935
import {
3036
CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE,
@@ -90,14 +96,14 @@ class AzureVmResourceDetector implements DetectorSync {
9096
const attributes = {
9197
[AZURE_VM_SCALE_SET_NAME_ATTRIBUTE]: metadata['vmScaleSetName'],
9298
[AZURE_VM_SKU_ATTRIBUTE]: metadata['sku'],
93-
[SemanticResourceAttributes.CLOUD_PLATFORM]: CloudPlatformValues.AZURE_VM,
94-
[SemanticResourceAttributes.CLOUD_PROVIDER]: CloudProviderValues.AZURE,
95-
[SemanticResourceAttributes.CLOUD_REGION]: metadata['location'],
99+
[SEMRESATTRS_CLOUD_PLATFORM]: CLOUDPLATFORMVALUES_AZURE_VM,
100+
[SEMRESATTRS_CLOUD_PROVIDER]: CLOUDPROVIDERVALUES_AZURE,
101+
[SEMRESATTRS_CLOUD_REGION]: metadata['location'],
96102
[CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE]: metadata['resourceId'],
97-
[SemanticResourceAttributes.HOST_ID]: metadata['vmId'],
98-
[SemanticResourceAttributes.HOST_NAME]: metadata['name'],
99-
[SemanticResourceAttributes.HOST_TYPE]: metadata['vmSize'],
100-
[SemanticResourceAttributes.OS_VERSION]: metadata['version'],
103+
[SEMRESATTRS_HOST_ID]: metadata['vmId'],
104+
[SEMRESATTRS_HOST_NAME]: metadata['name'],
105+
[SEMRESATTRS_HOST_TYPE]: metadata['vmSize'],
106+
[SEMRESATTRS_OS_VERSION]: metadata['version'],
101107
};
102108
return attributes;
103109
}

detectors/node/opentelemetry-resource-detector-azure/test/detectors/AzureAppServiceDetector.test.ts

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@
1616

1717
import * as assert from 'assert';
1818
import { azureAppServiceDetector } from '../../src/detectors/AzureAppServiceDetector';
19-
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
19+
import {
20+
SEMRESATTRS_CLOUD_PLATFORM,
21+
SEMRESATTRS_CLOUD_PROVIDER,
22+
SEMRESATTRS_CLOUD_REGION,
23+
SEMRESATTRS_DEPLOYMENT_ENVIRONMENT,
24+
SEMRESATTRS_HOST_ID,
25+
SEMRESATTRS_SERVICE_INSTANCE_ID,
26+
SEMRESATTRS_SERVICE_NAME,
27+
} from '@opentelemetry/semantic-conventions';
2028
import { azureFunctionsDetector } from '../../src';
2129
import { detectResourcesSync } from '@opentelemetry/resources';
2230

@@ -45,36 +53,24 @@ describe('AzureAppServiceDetector', () => {
4553
});
4654
assert.ok(resource);
4755
const attributes = resource.attributes;
56+
assert.strictEqual(attributes[SEMRESATTRS_SERVICE_NAME], 'test-site');
57+
assert.strictEqual(attributes[SEMRESATTRS_CLOUD_PROVIDER], 'azure');
4858
assert.strictEqual(
49-
attributes[SemanticResourceAttributes.SERVICE_NAME],
50-
'test-site'
51-
);
52-
assert.strictEqual(
53-
attributes[SemanticResourceAttributes.CLOUD_PROVIDER],
54-
'azure'
55-
);
56-
assert.strictEqual(
57-
attributes[SemanticResourceAttributes.CLOUD_PLATFORM],
59+
attributes[SEMRESATTRS_CLOUD_PLATFORM],
5860
'azure_app_service'
5961
);
6062
assert.strictEqual(
6163
attributes['cloud.resource_id'],
6264
`/subscriptions/${process.env.WEBSITE_OWNER_NAME}/resourceGroups/${process.env.WEBSITE_RESOURCE_GROUP}/providers/Microsoft.Web/sites/${process.env.WEBSITE_SITE_NAME}`
6365
);
66+
assert.strictEqual(attributes[SEMRESATTRS_CLOUD_REGION], 'test-region');
6467
assert.strictEqual(
65-
attributes[SemanticResourceAttributes.CLOUD_REGION],
66-
'test-region'
67-
);
68-
assert.strictEqual(
69-
attributes[SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT],
68+
attributes[SEMRESATTRS_DEPLOYMENT_ENVIRONMENT],
7069
'test-slot'
7170
);
71+
assert.strictEqual(attributes[SEMRESATTRS_HOST_ID], 'test-hostname');
7272
assert.strictEqual(
73-
attributes[SemanticResourceAttributes.HOST_ID],
74-
'test-hostname'
75-
);
76-
assert.strictEqual(
77-
attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID],
73+
attributes[SEMRESATTRS_SERVICE_INSTANCE_ID],
7874
'test-instance-id'
7975
);
8076
assert.strictEqual(
@@ -97,20 +93,14 @@ describe('AzureAppServiceDetector', () => {
9793
});
9894
assert.ok(resource);
9995
const attributes = resource.attributes;
96+
assert.strictEqual(attributes[SEMRESATTRS_CLOUD_REGION], 'test-region');
10097
assert.strictEqual(
101-
attributes[SemanticResourceAttributes.CLOUD_REGION],
102-
'test-region'
103-
);
104-
assert.strictEqual(
105-
attributes[SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT],
98+
attributes[SEMRESATTRS_DEPLOYMENT_ENVIRONMENT],
10699
'test-slot'
107100
);
101+
assert.strictEqual(attributes[SEMRESATTRS_HOST_ID], 'test-hostname');
108102
assert.strictEqual(
109-
attributes[SemanticResourceAttributes.HOST_ID],
110-
'test-hostname'
111-
);
112-
assert.strictEqual(
113-
attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID],
103+
attributes[SEMRESATTRS_SERVICE_INSTANCE_ID],
114104
'test-instance-id'
115105
);
116106
assert.strictEqual(
@@ -134,20 +124,14 @@ describe('AzureAppServiceDetector', () => {
134124
});
135125
assert.ok(resource);
136126
const attributes = resource.attributes;
127+
assert.strictEqual(attributes[SEMRESATTRS_CLOUD_REGION], 'test-region');
137128
assert.strictEqual(
138-
attributes[SemanticResourceAttributes.CLOUD_REGION],
139-
'test-region'
140-
);
141-
assert.strictEqual(
142-
attributes[SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT],
129+
attributes[SEMRESATTRS_DEPLOYMENT_ENVIRONMENT],
143130
'test-slot'
144131
);
132+
assert.strictEqual(attributes[SEMRESATTRS_HOST_ID], 'test-hostname');
145133
assert.strictEqual(
146-
attributes[SemanticResourceAttributes.HOST_ID],
147-
'test-hostname'
148-
);
149-
assert.strictEqual(
150-
attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID],
134+
attributes[SEMRESATTRS_SERVICE_INSTANCE_ID],
151135
'test-instance-id'
152136
);
153137
assert.strictEqual(

detectors/node/opentelemetry-resource-detector-azure/test/detectors/AzureFunctionsDetector.test.ts

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,16 @@
1717
import * as assert from 'assert';
1818
import { azureFunctionsDetector } from '../../src/detectors/AzureFunctionsDetector';
1919
import { azureAppServiceDetector } from '../../src/detectors/AzureAppServiceDetector';
20-
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
20+
import {
21+
SEMRESATTRS_CLOUD_PLATFORM,
22+
SEMRESATTRS_CLOUD_PROVIDER,
23+
SEMRESATTRS_CLOUD_REGION,
24+
SEMRESATTRS_FAAS_INSTANCE,
25+
SEMRESATTRS_FAAS_MAX_MEMORY,
26+
SEMRESATTRS_FAAS_NAME,
27+
SEMRESATTRS_FAAS_VERSION,
28+
SEMRESATTRS_SERVICE_INSTANCE_ID,
29+
} from '@opentelemetry/semantic-conventions';
2130
import { detectResourcesSync } from '@opentelemetry/resources';
2231
import { AZURE_APP_SERVICE_STAMP_RESOURCE_ATTRIBUTE } from '../../src/types';
2332

@@ -43,40 +52,22 @@ describe('AzureFunctionsDetector', () => {
4352
});
4453
assert.ok(resource);
4554
const attributes = resource.attributes;
55+
assert.strictEqual(attributes[SEMRESATTRS_FAAS_NAME], 'test-function');
56+
assert.strictEqual(attributes[SEMRESATTRS_CLOUD_PROVIDER], 'azure');
4657
assert.strictEqual(
47-
attributes[SemanticResourceAttributes.FAAS_NAME],
48-
'test-function'
49-
);
50-
assert.strictEqual(
51-
attributes[SemanticResourceAttributes.CLOUD_PROVIDER],
52-
'azure'
53-
);
54-
assert.strictEqual(
55-
attributes[SemanticResourceAttributes.CLOUD_PLATFORM],
58+
attributes[SEMRESATTRS_CLOUD_PLATFORM],
5659
'azure_functions'
5760
);
61+
assert.strictEqual(attributes[SEMRESATTRS_CLOUD_REGION], 'test-region');
5862
assert.strictEqual(
59-
attributes[SemanticResourceAttributes.CLOUD_REGION],
60-
'test-region'
61-
);
62-
assert.strictEqual(
63-
attributes[SemanticResourceAttributes.FAAS_INSTANCE],
63+
attributes[SEMRESATTRS_FAAS_INSTANCE],
6464
'test-instance-id'
6565
);
66-
assert.strictEqual(
67-
attributes[SemanticResourceAttributes.FAAS_MAX_MEMORY],
68-
'1000'
69-
);
70-
assert.strictEqual(
71-
attributes[SemanticResourceAttributes.FAAS_VERSION],
72-
'~4'
73-
);
66+
assert.strictEqual(attributes[SEMRESATTRS_FAAS_MAX_MEMORY], '1000');
67+
assert.strictEqual(attributes[SEMRESATTRS_FAAS_VERSION], '~4');
7468

7569
// Should not detect app service values
76-
assert.strictEqual(
77-
attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID],
78-
undefined
79-
);
70+
assert.strictEqual(attributes[SEMRESATTRS_SERVICE_INSTANCE_ID], undefined);
8071

8172
assert.strictEqual(
8273
attributes[AZURE_APP_SERVICE_STAMP_RESOURCE_ATTRIBUTE],

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)