Skip to content

Commit

Permalink
fix: address deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
myrotvorets-team committed Aug 24, 2024
1 parent 6a87c1d commit 7ac2b14
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 97 deletions.
4 changes: 2 additions & 2 deletions lib/detectors/dockerdetector.mts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
type ResourceAttributes,
type ResourceDetectionConfig,
} from '@opentelemetry/resources';
import { SEMRESATTRS_CONTAINER_ID } from '@opentelemetry/semantic-conventions';
import { ATTR_CONTAINER_ID } from '@opentelemetry/semantic-conventions/incubating';
import { getContainerIDFormCGroup, getContainerIDFormCGroup2 } from './utils.mjs';

export class DockerDetector implements DetectorSync {
Expand All @@ -18,7 +18,7 @@ export class DockerDetector implements DetectorSync {
const cid = await DockerDetector.getContainerID();
if (cid) {
return {
[SEMRESATTRS_CONTAINER_ID]: cid,
[ATTR_CONTAINER_ID]: cid,
};
}

Expand Down
26 changes: 13 additions & 13 deletions lib/detectors/k8sdetector.mts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import {
type ResourceDetectionConfig,
} from '@opentelemetry/resources';
import {
SEMRESATTRS_CONTAINER_ID,
SEMRESATTRS_HOST_ID,
SEMRESATTRS_HOST_NAME,
SEMRESATTRS_K8S_DEPLOYMENT_NAME,
SEMRESATTRS_K8S_NAMESPACE_NAME,
SEMRESATTRS_K8S_POD_NAME,
} from '@opentelemetry/semantic-conventions';
ATTR_CONTAINER_ID,
ATTR_HOST_ID,
ATTR_HOST_NAME,
ATTR_K8S_DEPLOYMENT_NAME,
ATTR_K8S_NAMESPACE_NAME,
ATTR_K8S_POD_NAME,
} from '@opentelemetry/semantic-conventions/incubating';
import { getContainerIDFormCGroup } from './utils.mjs';

export class K8sDetector implements DetectorSync {
Expand All @@ -25,9 +25,9 @@ export class K8sDetector implements DetectorSync {
}

const attrs = {
[SEMRESATTRS_HOST_NAME]: process.env['HOSTNAME']!,
[SEMRESATTRS_K8S_POD_NAME]: matches[1],
[SEMRESATTRS_K8S_DEPLOYMENT_NAME]: matches[2],
[ATTR_HOST_NAME]: process.env['HOSTNAME']!,
[ATTR_K8S_POD_NAME]: matches[1],
[ATTR_K8S_DEPLOYMENT_NAME]: matches[2],
};

return new Resource(attrs, K8sDetector.getAsyncAttributes());
Expand All @@ -41,9 +41,9 @@ export class K8sDetector implements DetectorSync {
]);

const attrs = {
[SEMRESATTRS_HOST_ID]: uid,
[SEMRESATTRS_K8S_NAMESPACE_NAME]: ns,
[SEMRESATTRS_CONTAINER_ID]: cid,
[ATTR_HOST_ID]: uid,
[ATTR_K8S_NAMESPACE_NAME]: ns,
[ATTR_CONTAINER_ID]: cid,
};

return K8sDetector.cleanUpAttributes(attrs);
Expand Down
92 changes: 46 additions & 46 deletions lib/detectors/osdetector.mts
Original file line number Diff line number Diff line change
@@ -1,72 +1,72 @@
import { arch, hostname, type } from 'node:os';
import { type DetectorSync, type IResource, Resource, type ResourceDetectionConfig } from '@opentelemetry/resources';
import {
HOSTARCHVALUES_AMD64,
HOSTARCHVALUES_ARM32,
HOSTARCHVALUES_ARM64,
HOSTARCHVALUES_PPC32,
HOSTARCHVALUES_PPC64,
HOSTARCHVALUES_X86,
OSTYPEVALUES_AIX,
OSTYPEVALUES_DARWIN,
OSTYPEVALUES_DRAGONFLYBSD,
OSTYPEVALUES_FREEBSD,
OSTYPEVALUES_HPUX,
OSTYPEVALUES_LINUX,
OSTYPEVALUES_NETBSD,
OSTYPEVALUES_OPENBSD,
OSTYPEVALUES_SOLARIS,
OSTYPEVALUES_WINDOWS,
OSTYPEVALUES_Z_OS,
SEMRESATTRS_HOST_ARCH,
SEMRESATTRS_HOST_NAME,
SEMRESATTRS_OS_TYPE,
} from '@opentelemetry/semantic-conventions';
ATTR_HOST_ARCH,
ATTR_HOST_NAME,
ATTR_OS_TYPE,
HOST_ARCH_VALUE_AMD64,
HOST_ARCH_VALUE_ARM32,
HOST_ARCH_VALUE_ARM64,
HOST_ARCH_VALUE_PPC32,
HOST_ARCH_VALUE_PPC64,
HOST_ARCH_VALUE_X86,
OS_TYPE_VALUE_AIX,
OS_TYPE_VALUE_DARWIN,
OS_TYPE_VALUE_DRAGONFLYBSD,
OS_TYPE_VALUE_FREEBSD,
OS_TYPE_VALUE_HPUX,
OS_TYPE_VALUE_LINUX,
OS_TYPE_VALUE_NETBSD,
OS_TYPE_VALUE_OPENBSD,
OS_TYPE_VALUE_SOLARIS,
OS_TYPE_VALUE_WINDOWS,
OS_TYPE_VALUE_Z_OS,
} from '@opentelemetry/semantic-conventions/incubating';

export class OSDetector implements DetectorSync {
// eslint-disable-next-line class-methods-use-this
public detect(_config: ResourceDetectionConfig): IResource {
const attrs = {
[SEMRESATTRS_HOST_NAME]: hostname(),
[SEMRESATTRS_HOST_ARCH]: OSDetector.mapArchitecture(arch()),
[SEMRESATTRS_OS_TYPE]: OSDetector.mapOSType(type()),
[ATTR_HOST_NAME]: hostname(),
[ATTR_HOST_ARCH]: OSDetector.mapArchitecture(arch()),
[ATTR_OS_TYPE]: OSDetector.mapOSType(type()),
};

return new Resource(attrs);
}

private static mapArchitecture(architecture: string): string {
const lut: Record<string, string> = {
arm: HOSTARCHVALUES_ARM32,
arm64: HOSTARCHVALUES_ARM64,
ia32: HOSTARCHVALUES_X86,
ppc: HOSTARCHVALUES_PPC32,
ppc64: HOSTARCHVALUES_PPC64,
x32: HOSTARCHVALUES_X86,
x64: HOSTARCHVALUES_AMD64,
arm: HOST_ARCH_VALUE_ARM32,
arm64: HOST_ARCH_VALUE_ARM64,
ia32: HOST_ARCH_VALUE_X86,
ppc: HOST_ARCH_VALUE_PPC32,
ppc64: HOST_ARCH_VALUE_PPC64,
x32: HOST_ARCH_VALUE_X86,
x64: HOST_ARCH_VALUE_AMD64,
};

return lut[architecture] ?? architecture;
}

private static mapOSType(os: string): string {
const lut: Record<string, string> = {
AIX: OSTYPEVALUES_AIX,
Darwin: OSTYPEVALUES_DARWIN,
DragonFly: OSTYPEVALUES_DRAGONFLYBSD,
FreeBSD: OSTYPEVALUES_FREEBSD,
'HP-UX': OSTYPEVALUES_HPUX,
Linux: OSTYPEVALUES_LINUX,
NetBSD: OSTYPEVALUES_NETBSD,
OpenBSD: OSTYPEVALUES_OPENBSD,
SunOS: OSTYPEVALUES_SOLARIS,
Windows_NT: OSTYPEVALUES_WINDOWS,
'OS/390': OSTYPEVALUES_Z_OS,
AIX: OS_TYPE_VALUE_AIX,
Darwin: OS_TYPE_VALUE_DARWIN,
DragonFly: OS_TYPE_VALUE_DRAGONFLYBSD,
FreeBSD: OS_TYPE_VALUE_FREEBSD,
'HP-UX': OS_TYPE_VALUE_HPUX,
Linux: OS_TYPE_VALUE_LINUX,
NetBSD: OS_TYPE_VALUE_NETBSD,
OpenBSD: OS_TYPE_VALUE_OPENBSD,
SunOS: OS_TYPE_VALUE_SOLARIS,
Windows_NT: OS_TYPE_VALUE_WINDOWS,
'OS/390': OS_TYPE_VALUE_Z_OS,

'CYGWIN_NT-5.1': OSTYPEVALUES_WINDOWS,
'CYGWIN_NT-6.1': OSTYPEVALUES_WINDOWS,
'CYGWIN_NT-6.1-WOW64': OSTYPEVALUES_WINDOWS,
'CYGWIN_NT-10.0': OSTYPEVALUES_WINDOWS,
'CYGWIN_NT-5.1': OS_TYPE_VALUE_WINDOWS,
'CYGWIN_NT-6.1': OS_TYPE_VALUE_WINDOWS,
'CYGWIN_NT-6.1-WOW64': OS_TYPE_VALUE_WINDOWS,
'CYGWIN_NT-10.0': OS_TYPE_VALUE_WINDOWS,
};

return lut[os] ?? os.replace(/[^a-z0-9]/giu, '').toUpperCase();
Expand Down
6 changes: 3 additions & 3 deletions lib/detectors/packagejsondetector.mts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
type ResourceAttributes,
type ResourceDetectionConfig,
} from '@opentelemetry/resources';
import { SEMRESATTRS_SERVICE_NAME, SEMRESATTRS_SERVICE_VERSION } from '@opentelemetry/semantic-conventions';
import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION } from '@opentelemetry/semantic-conventions';

export class PackageJsonDetector implements DetectorSync {
// eslint-disable-next-line class-methods-use-this
Expand All @@ -21,8 +21,8 @@ export class PackageJsonDetector implements DetectorSync {
const raw = await readFile(file, { encoding: 'utf-8' });
const json = JSON.parse(raw) as Record<string, unknown>;
return {
[SEMRESATTRS_SERVICE_NAME]: `${json['name']}`,
[SEMRESATTRS_SERVICE_VERSION]: `${json['version']}`,
[ATTR_SERVICE_NAME]: `${json['name']}`,
[ATTR_SERVICE_VERSION]: `${json['version']}`,
};
} catch {
return {};
Expand Down
6 changes: 3 additions & 3 deletions test/detectors/dockerdetector.test.mts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai';
import { type TestDouble, func, replaceEsm, when } from 'testdouble';
import type { ResourceDetectionConfig } from '@opentelemetry/resources';
import { SEMRESATTRS_CONTAINER_ID } from '@opentelemetry/semantic-conventions';
import { ATTR_CONTAINER_ID } from '@opentelemetry/semantic-conventions/incubating';
import type { DockerDetector } from '../../lib/detectors/dockerdetector.mjs';
import { runDetector } from './helpers.mjs';

Expand Down Expand Up @@ -57,7 +57,7 @@ describe('DockerDetector', function () {
return expect(runDetector(dockerDetector, config))
.to.eventually.be.an('object')
.and.have.deep.property('attributes', {
[SEMRESATTRS_CONTAINER_ID]: expectedID,
[ATTR_CONTAINER_ID]: expectedID,
});
});

Expand All @@ -73,7 +73,7 @@ describe('DockerDetector', function () {
return expect(runDetector(dockerDetector, config))
.to.eventually.be.an('object')
.and.have.deep.property('attributes', {
[SEMRESATTRS_CONTAINER_ID]: expectedID,
[ATTR_CONTAINER_ID]: expectedID,
});
});
});
32 changes: 16 additions & 16 deletions test/detectors/k8sdetector.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { expect } from 'chai';
import { type TestDouble, func, matchers, replaceEsm, when } from 'testdouble';
import type { ResourceDetectionConfig } from '@opentelemetry/resources';
import {
SEMRESATTRS_CONTAINER_ID,
SEMRESATTRS_HOST_ID,
SEMRESATTRS_HOST_NAME,
SEMRESATTRS_K8S_DEPLOYMENT_NAME,
SEMRESATTRS_K8S_NAMESPACE_NAME,
SEMRESATTRS_K8S_POD_NAME,
} from '@opentelemetry/semantic-conventions';
ATTR_CONTAINER_ID,
ATTR_HOST_ID,
ATTR_HOST_NAME,
ATTR_K8S_DEPLOYMENT_NAME,
ATTR_K8S_NAMESPACE_NAME,
ATTR_K8S_POD_NAME,
} from '@opentelemetry/semantic-conventions/incubating';
import type { K8sDetector } from '../../lib/detectors/k8sdetector.mjs';
import { runDetector } from './helpers.mjs';

Expand Down Expand Up @@ -83,12 +83,12 @@ describe('K8sDetector', function () {
return expect(runDetector(k8sDetector, config))
.to.eventually.be.an('object')
.and.have.deep.property('attributes', {
[SEMRESATTRS_HOST_NAME]: expectedHostname,
[SEMRESATTRS_HOST_ID]: expectedUID,
[SEMRESATTRS_K8S_POD_NAME]: expectedPod,
[SEMRESATTRS_K8S_DEPLOYMENT_NAME]: expectedDeployment,
[SEMRESATTRS_K8S_NAMESPACE_NAME]: expectedNS,
[SEMRESATTRS_CONTAINER_ID]: expectedCID,
[ATTR_HOST_NAME]: expectedHostname,
[ATTR_HOST_ID]: expectedUID,
[ATTR_K8S_POD_NAME]: expectedPod,
[ATTR_K8S_DEPLOYMENT_NAME]: expectedDeployment,
[ATTR_K8S_NAMESPACE_NAME]: expectedNS,
[ATTR_CONTAINER_ID]: expectedCID,
});
});

Expand All @@ -106,9 +106,9 @@ describe('K8sDetector', function () {
return expect(runDetector(k8sDetector, config))
.to.eventually.be.an('object')
.and.have.deep.property('attributes', {
[SEMRESATTRS_HOST_NAME]: expectedHostname,
[SEMRESATTRS_K8S_POD_NAME]: expectedPod,
[SEMRESATTRS_K8S_DEPLOYMENT_NAME]: expectedDeployment,
[ATTR_HOST_NAME]: expectedHostname,
[ATTR_K8S_POD_NAME]: expectedPod,
[ATTR_K8S_DEPLOYMENT_NAME]: expectedDeployment,
});
});
});
22 changes: 11 additions & 11 deletions test/detectors/osdetector.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { expect } from 'chai';
import { type TestDouble, func, replaceEsm, when } from 'testdouble';
import type { ResourceDetectionConfig } from '@opentelemetry/resources';
import {
HOSTARCHVALUES_ARM32,
OSTYPEVALUES_LINUX,
SEMRESATTRS_HOST_ARCH,
SEMRESATTRS_HOST_NAME,
SEMRESATTRS_OS_TYPE,
} from '@opentelemetry/semantic-conventions';
ATTR_HOST_ARCH,
ATTR_HOST_NAME,
ATTR_OS_TYPE,
HOST_ARCH_VALUE_ARM32,
OS_TYPE_VALUE_LINUX,
} from '@opentelemetry/semantic-conventions/incubating';
import type { OSDetector } from '../../lib/detectors/osdetector.mjs';

describe('OSDetector', function () {
Expand Down Expand Up @@ -51,7 +51,7 @@ describe('OSDetector', function () {
.to.be.an('object')
.and.have.property('attributes')
.that.is.an('object')
.and.has.keys([SEMRESATTRS_HOST_NAME, SEMRESATTRS_HOST_ARCH, SEMRESATTRS_OS_TYPE]);
.and.has.keys([ATTR_HOST_NAME, ATTR_HOST_ARCH, ATTR_OS_TYPE]);
});

it('should prefer lookup table values for architecure', function () {
Expand All @@ -62,7 +62,7 @@ describe('OSDetector', function () {
.to.be.an('object')
.and.have.property('attributes')
.that.is.an('object')
.and.has.property(SEMRESATTRS_HOST_ARCH, HOSTARCHVALUES_ARM32);
.and.has.property(ATTR_HOST_ARCH, HOST_ARCH_VALUE_ARM32);
});

it('should fall back to the original value for unknown architecure', function () {
Expand All @@ -74,7 +74,7 @@ describe('OSDetector', function () {
.to.be.an('object')
.and.have.property('attributes')
.that.is.an('object')
.and.has.property(SEMRESATTRS_HOST_ARCH, expected);
.and.has.property(ATTR_HOST_ARCH, expected);
});

it('should prefer lookup table values for OS type', function () {
Expand All @@ -85,7 +85,7 @@ describe('OSDetector', function () {
.to.be.an('object')
.and.have.property('attributes')
.that.is.an('object')
.and.has.property(SEMRESATTRS_OS_TYPE, OSTYPEVALUES_LINUX);
.and.has.property(ATTR_OS_TYPE, OS_TYPE_VALUE_LINUX);
});

it('should fall back to the original value for unknown OS type', function () {
Expand All @@ -96,6 +96,6 @@ describe('OSDetector', function () {
.to.be.an('object')
.and.have.property('attributes')
.that.is.an('object')
.and.has.property(SEMRESATTRS_OS_TYPE, 'MYSUPEROS');
.and.has.property(ATTR_OS_TYPE, 'MYSUPEROS');
});
});
6 changes: 3 additions & 3 deletions test/detectors/packagejsondetector.test.mts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai';
import { type TestDouble, func, matchers, replaceEsm, when } from 'testdouble';
import type { ResourceDetectionConfig } from '@opentelemetry/resources';
import { SEMRESATTRS_SERVICE_NAME, SEMRESATTRS_SERVICE_VERSION } from '@opentelemetry/semantic-conventions';
import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION } from '@opentelemetry/semantic-conventions';
import type { PackageJsonDetector } from '../../lib/detectors/packagejsondetector.mjs';
import { runDetector } from './helpers.mjs';

Expand Down Expand Up @@ -45,8 +45,8 @@ describe('PackageJsonDetector', function () {
return expect(runDetector(packageJsonDetector, config))
.to.eventually.be.an('object')
.and.have.deep.property('attributes', {
[SEMRESATTRS_SERVICE_NAME]: obj.name,
[SEMRESATTRS_SERVICE_VERSION]: obj.version,
[ATTR_SERVICE_NAME]: obj.name,
[ATTR_SERVICE_VERSION]: obj.version,
});
});
});

0 comments on commit 7ac2b14

Please sign in to comment.