diff --git a/detectors/node/opentelemetry-resource-detector-container/src/detectors/ContainerDetector.ts b/detectors/node/opentelemetry-resource-detector-container/src/detectors/ContainerDetector.ts index 6350b25485..239228e7df 100644 --- a/detectors/node/opentelemetry-resource-detector-container/src/detectors/ContainerDetector.ts +++ b/detectors/node/opentelemetry-resource-detector-container/src/detectors/ContainerDetector.ts @@ -35,7 +35,7 @@ export class ContainerDetector implements DetectorSync { readonly DEFAULT_CGROUP_V2_PATH = '/proc/self/mountinfo'; readonly UTF8_UNICODE = 'utf8'; readonly HOSTNAME = 'hostname'; - readonly MARKING_PREFIX = 'containers'; + readonly MARKING_PREFIX = ['containers', 'overlay-containers']; readonly CRIO = 'crio-'; readonly CRI_CONTAINERD = 'cri-containerd-'; readonly DOCKER = 'docker-'; @@ -105,7 +105,7 @@ export class ContainerDetector implements DetectorSync { const strArray = str?.split('/') ?? []; for (let i = 0; i < strArray.length - 1; i++) { if ( - strArray[i] === this.MARKING_PREFIX && + this.MARKING_PREFIX.includes(strArray[i]) && strArray[i + 1]?.length === this.CONTAINER_ID_LENGTH ) { return strArray[i + 1]; diff --git a/detectors/node/opentelemetry-resource-detector-container/src/detectors/utils.ts b/detectors/node/opentelemetry-resource-detector-container/src/detectors/utils.ts index 96bae1fe80..c43d19e98c 100644 --- a/detectors/node/opentelemetry-resource-detector-container/src/detectors/utils.ts +++ b/detectors/node/opentelemetry-resource-detector-container/src/detectors/utils.ts @@ -18,7 +18,7 @@ export const DEFAULT_CGROUP_V1_PATH = '/proc/self/cgroup'; export const DEFAULT_CGROUP_V2_PATH = '/proc/self/mountinfo'; export const UTF8_UNICODE = 'utf8'; export const HOSTNAME = 'hostname'; -export const MARKING_PREFIX = 'containers'; +export const MARKING_PREFIX = ['containers', 'overlay-containers']; export const CRIO = 'crio-'; export const CRI_CONTAINERD = 'cri-containerd-'; export const DOCKER = 'docker-'; diff --git a/detectors/node/opentelemetry-resource-detector-container/test/ContainerDetector.test.ts b/detectors/node/opentelemetry-resource-detector-container/test/ContainerDetector.test.ts index 51b3c41120..cb6a7e0133 100644 --- a/detectors/node/opentelemetry-resource-detector-container/test/ContainerDetector.test.ts +++ b/detectors/node/opentelemetry-resource-detector-container/test/ContainerDetector.test.ts @@ -32,6 +32,8 @@ describe('ContainerDetector', () => { const correctCgroupV2Data = `containers/tmhdefghijklmnopqrstuvwxyzafgrefghiugkmnopqrstuvwxyzabcdefghijkl/hostname fhkjdshgfhsdfjhdsfkjhfkdshkjhfd/host sahfhfjkhjhfhjdhfjkdhfkjdhfjkhhdsjfhdfhjdhfkj/somethingelse`; + const correctCgroupV2PodmanData = + '4245 4237 0:94 /containers/overlay-containers/4e9dc37d00ebd2daea029d84bb37764ce12d746a6f3a33c5969cee15c4fc4418/userdata/hostname /etc/hostname rw - tmpfs tmpfs rw'; const wrongCgroupV2Data = 'bcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklm/wrongkeyword'; @@ -85,6 +87,22 @@ describe('ContainerDetector', () => { }); }); + it('should return a resource with container ID with a valid container ID present for v2 (Podman)', async () => { + readStub = sinon.stub(ContainerDetector, 'readFileAsync' as any); + + readStub.onFirstCall().resolves(''); + readStub.onSecondCall().resolves(correctCgroupV2PodmanData); + + const resource = containerDetector.detect(); + await resource.waitForAsyncAttributes?.(); + sinon.assert.calledTwice(readStub); + + assert.ok(resource); + assertContainerResource(resource, { + id: '4e9dc37d00ebd2daea029d84bb37764ce12d746a6f3a33c5969cee15c4fc4418', + }); + }); + it('should return a empty resource with failed hostname check for v2', async () => { readStub = sinon.stub(ContainerDetector, 'readFileAsync' as any);