Skip to content

Commit e48a38d

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 85cbc8d commit e48a38d

File tree

8 files changed

+109
-64
lines changed

8 files changed

+109
-64
lines changed

detectors/node/opentelemetry-resource-detector-azure/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212
* devDependencies
1313
* @opentelemetry/contrib-test-utils bumped from ^0.36.0 to ^0.37.0
1414

15+
### Dependencies
16+
17+
* The following workspace dependencies were updated
18+
* dependencies
19+
* @opentelemetry/semantic-conventions bumped from ^1.0.0 to ^1.22.0
20+
21+
### Enhancement
22+
23+
* refactor: use exported strings for Semantic Resource Attributes, Cloud Platform Values and Cloud Provider Values
24+
1525
## [0.2.3](https://github.com/open-telemetry/opentelemetry-js-contrib/compare/resource-detector-azure-v0.2.2...resource-detector-azure-v0.2.3) (2024-01-04)
1626

1727

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: 17 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,16 @@ 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]:
72+
CLOUDPLATFORMVALUES_AZURE_APP_SERVICE,
6773
};
6874

6975
const azureResourceUri = this.getAzureResourceUri(websiteSiteName);

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

Lines changed: 21 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,34 @@ 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]:
61+
CLOUDPLATFORMVALUES_AZURE_FUNCTIONS,
62+
[SEMRESATTRS_CLOUD_REGION]: process.env[REGION_NAME],
5763
};
5864

5965
if (functionName) {
6066
attributes = {
6167
...attributes,
62-
[SemanticResourceAttributes.FAAS_NAME]: functionName,
68+
[SEMRESATTRS_FAAS_NAME]: functionName,
6369
};
6470
}
6571
if (functionVersion) {
6672
attributes = {
6773
...attributes,
68-
[SemanticResourceAttributes.FAAS_VERSION]: functionVersion,
74+
[SEMRESATTRS_FAAS_VERSION]: functionVersion,
6975
};
7076
}
7177
if (functionInstance) {
7278
attributes = {
7379
...attributes,
74-
[SemanticResourceAttributes.FAAS_INSTANCE]: functionInstance,
80+
[SEMRESATTRS_FAAS_INSTANCE]: functionInstance,
7581
};
7682
}
7783
if (functionMemLimit) {
7884
attributes = {
7985
...attributes,
80-
[SemanticResourceAttributes.FAAS_MAX_MEMORY]: functionMemLimit,
86+
[SEMRESATTRS_FAAS_MAX_MEMORY]: functionMemLimit,
8187
};
8288
}
8389

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 & 16 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

@@ -46,35 +54,35 @@ describe('AzureAppServiceDetector', () => {
4654
assert.ok(resource);
4755
const attributes = resource.attributes;
4856
assert.strictEqual(
49-
attributes[SemanticResourceAttributes.SERVICE_NAME],
57+
attributes[SEMRESATTRS_SERVICE_NAME],
5058
'test-site'
5159
);
5260
assert.strictEqual(
53-
attributes[SemanticResourceAttributes.CLOUD_PROVIDER],
61+
attributes[SEMRESATTRS_CLOUD_PROVIDER],
5462
'azure'
5563
);
5664
assert.strictEqual(
57-
attributes[SemanticResourceAttributes.CLOUD_PLATFORM],
65+
attributes[SEMRESATTRS_CLOUD_PLATFORM],
5866
'azure_app_service'
5967
);
6068
assert.strictEqual(
6169
attributes['cloud.resource_id'],
6270
`/subscriptions/${process.env.WEBSITE_OWNER_NAME}/resourceGroups/${process.env.WEBSITE_RESOURCE_GROUP}/providers/Microsoft.Web/sites/${process.env.WEBSITE_SITE_NAME}`
6371
);
6472
assert.strictEqual(
65-
attributes[SemanticResourceAttributes.CLOUD_REGION],
73+
attributes[SEMRESATTRS_CLOUD_REGION],
6674
'test-region'
6775
);
6876
assert.strictEqual(
69-
attributes[SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT],
77+
attributes[SEMRESATTRS_DEPLOYMENT_ENVIRONMENT],
7078
'test-slot'
7179
);
7280
assert.strictEqual(
73-
attributes[SemanticResourceAttributes.HOST_ID],
81+
attributes[SEMRESATTRS_HOST_ID],
7482
'test-hostname'
7583
);
7684
assert.strictEqual(
77-
attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID],
85+
attributes[SEMRESATTRS_SERVICE_INSTANCE_ID],
7886
'test-instance-id'
7987
);
8088
assert.strictEqual(
@@ -98,19 +106,19 @@ describe('AzureAppServiceDetector', () => {
98106
assert.ok(resource);
99107
const attributes = resource.attributes;
100108
assert.strictEqual(
101-
attributes[SemanticResourceAttributes.CLOUD_REGION],
109+
attributes[SEMRESATTRS_CLOUD_REGION],
102110
'test-region'
103111
);
104112
assert.strictEqual(
105-
attributes[SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT],
113+
attributes[SEMRESATTRS_DEPLOYMENT_ENVIRONMENT],
106114
'test-slot'
107115
);
108116
assert.strictEqual(
109-
attributes[SemanticResourceAttributes.HOST_ID],
117+
attributes[SEMRESATTRS_HOST_ID],
110118
'test-hostname'
111119
);
112120
assert.strictEqual(
113-
attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID],
121+
attributes[SEMRESATTRS_SERVICE_INSTANCE_ID],
114122
'test-instance-id'
115123
);
116124
assert.strictEqual(
@@ -135,19 +143,19 @@ describe('AzureAppServiceDetector', () => {
135143
assert.ok(resource);
136144
const attributes = resource.attributes;
137145
assert.strictEqual(
138-
attributes[SemanticResourceAttributes.CLOUD_REGION],
146+
attributes[SEMRESATTRS_CLOUD_REGION],
139147
'test-region'
140148
);
141149
assert.strictEqual(
142-
attributes[SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT],
150+
attributes[SEMRESATTRS_DEPLOYMENT_ENVIRONMENT],
143151
'test-slot'
144152
);
145153
assert.strictEqual(
146-
attributes[SemanticResourceAttributes.HOST_ID],
154+
attributes[SEMRESATTRS_HOST_ID],
147155
'test-hostname'
148156
);
149157
assert.strictEqual(
150-
attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID],
158+
attributes[SEMRESATTRS_SERVICE_INSTANCE_ID],
151159
'test-instance-id'
152160
);
153161
assert.strictEqual(

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

Lines changed: 18 additions & 9 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

@@ -44,37 +53,37 @@ describe('AzureFunctionsDetector', () => {
4453
assert.ok(resource);
4554
const attributes = resource.attributes;
4655
assert.strictEqual(
47-
attributes[SemanticResourceAttributes.FAAS_NAME],
56+
attributes[SEMRESATTRS_FAAS_NAME],
4857
'test-function'
4958
);
5059
assert.strictEqual(
51-
attributes[SemanticResourceAttributes.CLOUD_PROVIDER],
60+
attributes[SEMRESATTRS_CLOUD_PROVIDER],
5261
'azure'
5362
);
5463
assert.strictEqual(
55-
attributes[SemanticResourceAttributes.CLOUD_PLATFORM],
64+
attributes[SEMRESATTRS_CLOUD_PLATFORM],
5665
'azure_functions'
5766
);
5867
assert.strictEqual(
59-
attributes[SemanticResourceAttributes.CLOUD_REGION],
68+
attributes[SEMRESATTRS_CLOUD_REGION],
6069
'test-region'
6170
);
6271
assert.strictEqual(
63-
attributes[SemanticResourceAttributes.FAAS_INSTANCE],
72+
attributes[SEMRESATTRS_FAAS_INSTANCE],
6473
'test-instance-id'
6574
);
6675
assert.strictEqual(
67-
attributes[SemanticResourceAttributes.FAAS_MAX_MEMORY],
76+
attributes[SEMRESATTRS_FAAS_MAX_MEMORY],
6877
'1000'
6978
);
7079
assert.strictEqual(
71-
attributes[SemanticResourceAttributes.FAAS_VERSION],
80+
attributes[SEMRESATTRS_FAAS_VERSION],
7281
'~4'
7382
);
7483

7584
// Should not detect app service values
7685
assert.strictEqual(
77-
attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID],
86+
attributes[SEMRESATTRS_SERVICE_INSTANCE_ID],
7887
undefined
7988
);
8089

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)