Skip to content

Commit 052aede

Browse files
committed
resource-detector-aws
- chore(resource-detector-aws)!: merge Sync and async resources - removed `awsBeanstalkDetectorSync` -> use `awsBeanstalkDetector` - removed `awsEc2DetectorSync` -> use `awsEc2Detector` - removed `awsEcsDetectorSync` -> use `awsEcsDetector` - removed `awsEksDetectorSync` -> use `awsEksDetector` - removed `awsLambdaDetectorSync` -> use `awsLambdaDetector` - no longer exporting the detector classes: `AwsBeanstalkDetector`, `AwsEcsDetector`, `AwsEksDetector`, `AwsLambdaDetector`,
1 parent 4777b71 commit 052aede

25 files changed

+1092
-2231
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"author": "OpenTelemetry Authors",
2828
"license": "Apache-2.0",
2929
"engines": {
30-
"node": ">=14"
30+
"node": "^18.19.0 || >=20.6.0"
3131
},
3232
"files": [
3333
"build/src/**/*.js",
@@ -44,7 +44,7 @@
4444
"@opentelemetry/api": "^1.0.0",
4545
"@opentelemetry/contrib-test-utils": "^0.45.1",
4646
"@opentelemetry/instrumentation-fs": "^0.19.1",
47-
"@opentelemetry/instrumentation-http": "^0.57.2",
47+
"@opentelemetry/instrumentation-http": "^0.200.0-dev.0",
4848
"@types/mocha": "10.0.10",
4949
"@types/node": "18.18.14",
5050
"@types/sinon": "17.0.4",
@@ -58,8 +58,8 @@
5858
"@opentelemetry/api": "^1.0.0"
5959
},
6060
"dependencies": {
61-
"@opentelemetry/core": "^1.0.0",
62-
"@opentelemetry/resources": "^1.10.0",
61+
"@opentelemetry/core": "^2.0.0-dev.0",
62+
"@opentelemetry/resources": "^2.0.0-dev.0",
6363
"@opentelemetry/semantic-conventions": "^1.27.0"
6464
},
6565
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/detectors/node/opentelemetry-resource-detector-aws#readme",

detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsBeanstalkDetector.ts

Lines changed: 78 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,28 @@
1414
* limitations under the License.
1515
*/
1616

17+
import { context } from '@opentelemetry/api';
18+
import { suppressTracing } from '@opentelemetry/core';
19+
1720
import {
18-
Detector,
19-
IResource,
20-
ResourceDetectionConfig,
21+
ResourceDetector,
22+
DetectedResource,
23+
DetectedResourceAttributes,
2124
} from '@opentelemetry/resources';
22-
23-
import { awsBeanstalkDetectorSync } from './AwsBeanstalkDetectorSync';
25+
import {
26+
ATTR_SERVICE_NAME,
27+
ATTR_SERVICE_VERSION,
28+
} from '@opentelemetry/semantic-conventions';
29+
import {
30+
ATTR_CLOUD_PROVIDER,
31+
ATTR_CLOUD_PLATFORM,
32+
ATTR_SERVICE_NAMESPACE,
33+
ATTR_SERVICE_INSTANCE_ID,
34+
CLOUD_PROVIDER_VALUE_AWS,
35+
CLOUD_PLATFORM_VALUE_AWS_ELASTIC_BEANSTALK,
36+
} from '../semconv';
37+
import * as fs from 'fs';
38+
import * as util from 'util';
2439

2540
/**
2641
* The AwsBeanstalkDetector can be used to detect if a process is running in AWS Elastic
@@ -29,13 +44,66 @@ import { awsBeanstalkDetectorSync } from './AwsBeanstalkDetectorSync';
2944
*
3045
* See https://docs.amazonaws.cn/en_us/xray/latest/devguide/xray-guide.pdf
3146
* for more details about detecting information of Elastic Beanstalk plugins
32-
*
33-
* @deprecated Use {@link AwsBeanstalkDetectorSync} class instead.
3447
*/
3548

36-
export class AwsBeanstalkDetector implements Detector {
37-
detect(config?: ResourceDetectionConfig): Promise<IResource> {
38-
return Promise.resolve(awsBeanstalkDetectorSync.detect(config));
49+
const DEFAULT_BEANSTALK_CONF_PATH =
50+
'/var/elasticbeanstalk/xray/environment.conf';
51+
const WIN_OS_BEANSTALK_CONF_PATH =
52+
'C:\\Program Files\\Amazon\\XRay\\environment.conf';
53+
54+
export class AwsBeanstalkDetector implements ResourceDetector {
55+
BEANSTALK_CONF_PATH: string;
56+
private static readFileAsync = util.promisify(fs.readFile);
57+
private static fileAccessAsync = util.promisify(fs.access);
58+
59+
constructor() {
60+
if (process.platform === 'win32') {
61+
this.BEANSTALK_CONF_PATH = WIN_OS_BEANSTALK_CONF_PATH;
62+
} else {
63+
this.BEANSTALK_CONF_PATH = DEFAULT_BEANSTALK_CONF_PATH;
64+
}
65+
}
66+
67+
detect(): DetectedResource {
68+
const attributes = context.with(suppressTracing(context.active()), () =>
69+
this._getAttributes()
70+
);
71+
return { attributes };
72+
}
73+
74+
/**
75+
* Async resource attributes for AWS Beanstalk configuration read from file.
76+
*/
77+
_getAttributes(): DetectedResourceAttributes {
78+
const parsedDataP = AwsBeanstalkDetector.fileAccessAsync(
79+
this.BEANSTALK_CONF_PATH,
80+
fs.constants.R_OK
81+
)
82+
.then(() =>
83+
AwsBeanstalkDetector.readFileAsync(this.BEANSTALK_CONF_PATH, 'utf8')
84+
)
85+
.then(rawData => {
86+
return JSON.parse(rawData);
87+
});
88+
89+
return {
90+
[ATTR_CLOUD_PROVIDER]: parsedDataP.then(() => CLOUD_PROVIDER_VALUE_AWS),
91+
[ATTR_CLOUD_PLATFORM]: parsedDataP.then(
92+
() => CLOUD_PLATFORM_VALUE_AWS_ELASTIC_BEANSTALK
93+
),
94+
[ATTR_SERVICE_NAME]: parsedDataP.then(
95+
() => CLOUD_PLATFORM_VALUE_AWS_ELASTIC_BEANSTALK
96+
),
97+
[ATTR_SERVICE_NAMESPACE]: parsedDataP.then(
98+
parsedData => parsedData.environment_name
99+
),
100+
[ATTR_SERVICE_VERSION]: parsedDataP.then(
101+
parsedData => parsedData.version_label
102+
),
103+
[ATTR_SERVICE_INSTANCE_ID]: parsedDataP.then(
104+
parsedData => parsedData.deployment_id
105+
),
106+
};
39107
}
40108
}
41109

detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsBeanstalkDetectorSync.ts

Lines changed: 0 additions & 114 deletions
This file was deleted.

0 commit comments

Comments
 (0)