-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.ts
38 lines (33 loc) · 1023 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import {
Detector,
Resource,
ResourceDetectionConfig,
} from '@opentelemetry/resources';
import { cLogger } from './utils/logger';
import { detectorFactory } from './detectors/factory';
class LMResourceDetector implements Detector {
private context;
constructor(context?: {}) {
this.context = context;
}
async detect(_config?: ResourceDetectionConfig): Promise<Resource> {
cLogger.info('detecting resources');
const detectors = this.context
? detectorFactory.getDetectors(this.context)
: detectorFactory.getDetectors();
for (let i = 0; i < detectors.length; i++) {
const resource = await detectors[i].detect();
if (
Object.keys(resource).length > 0 &&
Object.keys(resource.attributes).length > 0
) {
cLogger.debug('detected resource: ', resource);
return resource;
}
}
cLogger.info('no resources detected');
return Resource.empty();
}
}
export const lmResourceDetector = new LMResourceDetector();
export const LmResourceDetectorWithContext = LMResourceDetector;