refactor(resources): update semconv usage to ATTR_ exports (#5666)
This commit is contained in:
parent
6033e66530
commit
b76281a32c
|
@ -28,6 +28,7 @@ For notes on migrating to 2.x / 0.200.x see [the upgrade guide](doc/upgrade-to-2
|
|||
|
||||
### :house: Internal
|
||||
|
||||
* refactor(resources): update semconv usage to ATTR_ exports [#5666](https://github.com/open-telemetry/opentelemetry-js/pull/5666) @trentm
|
||||
* test(sdk-metrics): fix multiple problematic assertRejects() calls [#5611](https://github.com/open-telemetry/opentelemetry-js/pull/5611) @cjihrig
|
||||
* refactor: replace assertRejects() with assert.rejects() [#5614](https://github.com/open-telemetry/opentelemetry-js/pull/5614) @cjihrig
|
||||
* refactor(core): migrate from deprecated semconv constants [#5575](https://github.com/open-telemetry/opentelemetry-js/pull/5575) @alumni55748
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
*/
|
||||
|
||||
import { Attributes, diag } from '@opentelemetry/api';
|
||||
import { SEMRESATTRS_SERVICE_NAME } from '@opentelemetry/semantic-conventions';
|
||||
import { ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions';
|
||||
import { ResourceDetectionConfig } from '../config';
|
||||
import { DetectedResource, ResourceDetector } from '../types';
|
||||
import { getStringFromEnv } from '@opentelemetry/core';
|
||||
|
@ -67,7 +67,7 @@ class EnvDetector implements ResourceDetector {
|
|||
}
|
||||
|
||||
if (serviceName) {
|
||||
attributes[SEMRESATTRS_SERVICE_NAME] = serviceName;
|
||||
attributes[ATTR_SERVICE_NAME] = serviceName;
|
||||
}
|
||||
|
||||
return { attributes };
|
||||
|
|
|
@ -14,12 +14,95 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file contains a copy of unstable semantic convention definitions
|
||||
* used by this package.
|
||||
* @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv
|
||||
*/
|
||||
|
||||
/**
|
||||
* The cloud account ID the resource is assigned to.
|
||||
*
|
||||
* @example 111111111111
|
||||
* @example opentelemetry
|
||||
*
|
||||
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
||||
*/
|
||||
export const ATTR_CLOUD_ACCOUNT_ID = 'cloud.account.id' as const;
|
||||
|
||||
/**
|
||||
* Cloud regions often have multiple, isolated locations known as zones to increase availability. Availability zone represents the zone where the resource is running.
|
||||
*
|
||||
* @example us-east-1c
|
||||
*
|
||||
* @note Availability zones are called "zones" on Alibaba Cloud and Google Cloud.
|
||||
*
|
||||
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
||||
*/
|
||||
export const ATTR_CLOUD_AVAILABILITY_ZONE = 'cloud.availability_zone' as const;
|
||||
|
||||
/**
|
||||
* Name of the cloud provider.
|
||||
*
|
||||
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
||||
*/
|
||||
export const ATTR_CLOUD_PROVIDER = 'cloud.provider' as const;
|
||||
|
||||
/**
|
||||
* The geographical region the resource is running.
|
||||
*
|
||||
* @example us-central1
|
||||
* @example us-east-1
|
||||
*
|
||||
* @note Refer to your provider's docs to see the available regions, for example [Alibaba Cloud regions](https://www.alibabacloud.com/help/doc-detail/40654.htm), [AWS regions](https://aws.amazon.com/about-aws/global-infrastructure/regions_az/), [Azure regions](https://azure.microsoft.com/global-infrastructure/geographies/), [Google Cloud regions](https://cloud.google.com/about/locations), or [Tencent Cloud regions](https://www.tencentcloud.com/document/product/213/6091).
|
||||
*
|
||||
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
||||
*/
|
||||
export const ATTR_CLOUD_REGION = 'cloud.region' as const;
|
||||
|
||||
/**
|
||||
* Container ID. Usually a UUID, as for example used to [identify Docker containers](https://docs.docker.com/engine/containers/run/#container-identification). The UUID might be abbreviated.
|
||||
*
|
||||
* @example a3bf90e006b2
|
||||
*
|
||||
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
||||
*/
|
||||
export const ATTR_CONTAINER_ID = 'container.id' as const;
|
||||
|
||||
/**
|
||||
* Name of the image the container was built on.
|
||||
*
|
||||
* @example gcr.io/opentelemetry/operator
|
||||
*
|
||||
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
||||
*/
|
||||
export const ATTR_CONTAINER_IMAGE_NAME = 'container.image.name' as const;
|
||||
|
||||
/**
|
||||
* Container image tags. An example can be found in [Docker Image Inspect](https://docs.docker.com/engine/api/v1.43/#tag/Image/operation/ImageInspect). Should be only the `<tag>` section of the full name for example from `registry.example.com/my-org/my-image:<tag>`.
|
||||
*
|
||||
* @example ["v1.27.1", "3.5.7-0"]
|
||||
*
|
||||
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
||||
*/
|
||||
export const ATTR_CONTAINER_IMAGE_TAGS = 'container.image.tags' as const;
|
||||
|
||||
/**
|
||||
* Container name used by container runtime.
|
||||
*
|
||||
* @example opentelemetry-autoconf
|
||||
*
|
||||
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
||||
*/
|
||||
export const ATTR_CONTAINER_NAME = 'container.name' as const;
|
||||
|
||||
/**
|
||||
* The CPU architecture the host system is running on.
|
||||
*
|
||||
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
||||
*/
|
||||
export const ATTR_HOST_ARCH = 'host.arch' as const;
|
||||
|
||||
/**
|
||||
* Unique host ID. For Cloud, this must be the instance_id assigned by the cloud provider. For non-containerized systems, this should be the `machine-id`. See the table below for the sources to use to determine the `machine-id` based on operating system.
|
||||
*
|
||||
|
@ -28,6 +111,35 @@ export const ATTR_HOST_ARCH = 'host.arch' as const;
|
|||
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
||||
*/
|
||||
export const ATTR_HOST_ID = 'host.id' as const;
|
||||
|
||||
/**
|
||||
* VM image ID or host OS image ID. For Cloud, this value is from the provider.
|
||||
*
|
||||
* @example ami-07b06b442921831e5
|
||||
*
|
||||
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
||||
*/
|
||||
export const ATTR_HOST_IMAGE_ID = 'host.image.id' as const;
|
||||
|
||||
/**
|
||||
* Name of the VM image or OS install the host was instantiated from.
|
||||
*
|
||||
* @example infra-ami-eks-worker-node-7d4ec78312
|
||||
* @example CentOS-8-x86_64-1905
|
||||
*
|
||||
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
||||
*/
|
||||
export const ATTR_HOST_IMAGE_NAME = 'host.image.name' as const;
|
||||
|
||||
/**
|
||||
* The version string of the VM image or host OS as defined in [Version Attributes](/docs/resource/README.md#version-attributes).
|
||||
*
|
||||
* @example 0.1
|
||||
*
|
||||
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
||||
*/
|
||||
export const ATTR_HOST_IMAGE_VERSION = 'host.image.version' as const;
|
||||
|
||||
/**
|
||||
* Name of the host. On Unix systems, it may contain what the hostname command returns, or the fully qualified hostname, or another name specified by the user.
|
||||
*
|
||||
|
@ -36,12 +148,59 @@ export const ATTR_HOST_ID = 'host.id' as const;
|
|||
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
||||
*/
|
||||
export const ATTR_HOST_NAME = 'host.name' as const;
|
||||
|
||||
/**
|
||||
* Type of host. For Cloud, this must be the machine type.
|
||||
*
|
||||
* @example n1-standard-1
|
||||
*
|
||||
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
||||
*/
|
||||
export const ATTR_HOST_TYPE = 'host.type' as const;
|
||||
|
||||
/**
|
||||
* The name of the cluster.
|
||||
*
|
||||
* @example opentelemetry-cluster
|
||||
*
|
||||
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
||||
*/
|
||||
export const ATTR_K8S_CLUSTER_NAME = 'k8s.cluster.name' as const;
|
||||
|
||||
/**
|
||||
* The name of the Deployment.
|
||||
*
|
||||
* @example opentelemetry
|
||||
*
|
||||
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
||||
*/
|
||||
export const ATTR_K8S_DEPLOYMENT_NAME = 'k8s.deployment.name' as const;
|
||||
|
||||
/**
|
||||
* The name of the namespace that the pod is running in.
|
||||
*
|
||||
* @example default
|
||||
*
|
||||
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
||||
*/
|
||||
export const ATTR_K8S_NAMESPACE_NAME = 'k8s.namespace.name' as const;
|
||||
|
||||
/**
|
||||
* The name of the Pod.
|
||||
*
|
||||
* @example opentelemetry-pod-autoconf
|
||||
*
|
||||
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
||||
*/
|
||||
export const ATTR_K8S_POD_NAME = 'k8s.pod.name' as const;
|
||||
|
||||
/**
|
||||
* The operating system type.
|
||||
*
|
||||
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
||||
*/
|
||||
export const ATTR_OS_TYPE = 'os.type' as const;
|
||||
|
||||
/**
|
||||
* The version string of the operating system as defined in [Version Attributes](/docs/resource/README.md#version-attributes).
|
||||
*
|
||||
|
@ -51,6 +210,7 @@ export const ATTR_OS_TYPE = 'os.type' as const;
|
|||
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
||||
*/
|
||||
export const ATTR_OS_VERSION = 'os.version' as const;
|
||||
|
||||
/**
|
||||
* The command used to launch the process (i.e. the command name). On Linux based systems, can be set to the zeroth string in `proc/[pid]/cmdline`. On Windows, can be set to the first parameter extracted from `GetCommandLineW`.
|
||||
*
|
||||
|
@ -59,6 +219,7 @@ export const ATTR_OS_VERSION = 'os.version' as const;
|
|||
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
||||
*/
|
||||
export const ATTR_PROCESS_COMMAND = 'process.command' as const;
|
||||
|
||||
/**
|
||||
* All the command arguments (including the command/executable itself) as received by the process. On Linux-based systems (and some other Unixoid systems supporting procfs), can be set according to the list of null-delimited strings extracted from `proc/[pid]/cmdline`. For libc-based executables, this would be the full argv vector passed to `main`.
|
||||
*
|
||||
|
@ -67,14 +228,16 @@ export const ATTR_PROCESS_COMMAND = 'process.command' as const;
|
|||
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
||||
*/
|
||||
export const ATTR_PROCESS_COMMAND_ARGS = 'process.command_args' as const;
|
||||
|
||||
/**
|
||||
* The name of the process executable. On Linux based systems, can be set to the `Name` in `proc/[pid]/status`. On Windows, can be set to the base name of `GetProcessImageFileNameW`.
|
||||
* The name of the process executable. On Linux based systems, this **SHOULD** be set to the base name of the target of `/proc/[pid]/exe`. On Windows, this **SHOULD** be set to the base name of `GetProcessImageFileNameW`.
|
||||
*
|
||||
* @example otelcol
|
||||
*
|
||||
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
||||
*/
|
||||
export const ATTR_PROCESS_EXECUTABLE_NAME = 'process.executable.name' as const;
|
||||
|
||||
/**
|
||||
* The full path to the process executable. On Linux based systems, can be set to the target of `proc/[pid]/exe`. On Windows, can be set to the result of `GetProcessImageFileNameW`.
|
||||
*
|
||||
|
@ -83,6 +246,7 @@ export const ATTR_PROCESS_EXECUTABLE_NAME = 'process.executable.name' as const;
|
|||
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
||||
*/
|
||||
export const ATTR_PROCESS_EXECUTABLE_PATH = 'process.executable.path' as const;
|
||||
|
||||
/**
|
||||
* The username of the user that owns the process.
|
||||
*
|
||||
|
@ -91,6 +255,7 @@ export const ATTR_PROCESS_EXECUTABLE_PATH = 'process.executable.path' as const;
|
|||
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
||||
*/
|
||||
export const ATTR_PROCESS_OWNER = 'process.owner' as const;
|
||||
|
||||
/**
|
||||
* Process identifier (PID).
|
||||
*
|
||||
|
@ -99,6 +264,7 @@ export const ATTR_PROCESS_OWNER = 'process.owner' as const;
|
|||
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
||||
*/
|
||||
export const ATTR_PROCESS_PID = 'process.pid' as const;
|
||||
|
||||
/**
|
||||
* An additional description about the runtime of the process, for example a specific vendor customization of the runtime environment.
|
||||
*
|
||||
|
@ -108,6 +274,7 @@ export const ATTR_PROCESS_PID = 'process.pid' as const;
|
|||
*/
|
||||
export const ATTR_PROCESS_RUNTIME_DESCRIPTION =
|
||||
'process.runtime.description' as const;
|
||||
|
||||
/**
|
||||
* The name of the runtime of this process.
|
||||
*
|
||||
|
@ -116,6 +283,7 @@ export const ATTR_PROCESS_RUNTIME_DESCRIPTION =
|
|||
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
||||
*/
|
||||
export const ATTR_PROCESS_RUNTIME_NAME = 'process.runtime.name' as const;
|
||||
|
||||
/**
|
||||
* The version of the runtime of this process, as returned by the runtime without modification.
|
||||
*
|
||||
|
@ -124,6 +292,7 @@ export const ATTR_PROCESS_RUNTIME_NAME = 'process.runtime.name' as const;
|
|||
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
||||
*/
|
||||
export const ATTR_PROCESS_RUNTIME_VERSION = 'process.runtime.version' as const;
|
||||
|
||||
/**
|
||||
* The string ID of the service instance.
|
||||
*
|
||||
|
@ -159,3 +328,41 @@ export const ATTR_PROCESS_RUNTIME_VERSION = 'process.runtime.version' as const;
|
|||
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
||||
*/
|
||||
export const ATTR_SERVICE_INSTANCE_ID = 'service.instance.id' as const;
|
||||
|
||||
/**
|
||||
* A namespace for `service.name`.
|
||||
*
|
||||
* @example Shop
|
||||
*
|
||||
* @note A string value having a meaning that helps to distinguish a group of services, for example the team name that owns a group of services. `service.name` is expected to be unique within the same namespace. If `service.namespace` is not specified in the Resource then `service.name` is expected to be unique for all services that have no explicit namespace defined (so the empty/unspecified namespace is simply one more valid namespace). Zero-length namespace string is assumed equal to unspecified namespace.
|
||||
*
|
||||
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
||||
*/
|
||||
export const ATTR_SERVICE_NAMESPACE = 'service.namespace' as const;
|
||||
|
||||
/**
|
||||
* Additional description of the web engine (e.g. detailed version and edition information).
|
||||
*
|
||||
* @example WildFly Full 21.0.0.Final (WildFly Core 13.0.1.Final) - 2.2.2.Final
|
||||
*
|
||||
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
||||
*/
|
||||
export const ATTR_WEBENGINE_DESCRIPTION = 'webengine.description' as const;
|
||||
|
||||
/**
|
||||
* The name of the web engine.
|
||||
*
|
||||
* @example WildFly
|
||||
*
|
||||
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
||||
*/
|
||||
export const ATTR_WEBENGINE_NAME = 'webengine.name' as const;
|
||||
|
||||
/**
|
||||
* The version of the web engine.
|
||||
*
|
||||
* @example 21.0.0
|
||||
*
|
||||
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
||||
*/
|
||||
export const ATTR_WEBENGINE_VERSION = 'webengine.version' as const;
|
||||
|
|
|
@ -17,10 +17,10 @@
|
|||
import { diag } from '@opentelemetry/api';
|
||||
import { SDK_INFO } from '@opentelemetry/core';
|
||||
import {
|
||||
SEMRESATTRS_SERVICE_NAME,
|
||||
SEMRESATTRS_TELEMETRY_SDK_LANGUAGE,
|
||||
SEMRESATTRS_TELEMETRY_SDK_NAME,
|
||||
SEMRESATTRS_TELEMETRY_SDK_VERSION,
|
||||
ATTR_SERVICE_NAME,
|
||||
ATTR_TELEMETRY_SDK_LANGUAGE,
|
||||
ATTR_TELEMETRY_SDK_NAME,
|
||||
ATTR_TELEMETRY_SDK_VERSION,
|
||||
} from '@opentelemetry/semantic-conventions';
|
||||
import * as assert from 'assert';
|
||||
import * as sinon from 'sinon';
|
||||
|
@ -291,19 +291,19 @@ describe('Resource', () => {
|
|||
it('should return a default resource', () => {
|
||||
const resource = defaultResource();
|
||||
assert.strictEqual(
|
||||
resource.attributes[SEMRESATTRS_TELEMETRY_SDK_NAME],
|
||||
SDK_INFO[SEMRESATTRS_TELEMETRY_SDK_NAME]
|
||||
resource.attributes[ATTR_TELEMETRY_SDK_NAME],
|
||||
SDK_INFO[ATTR_TELEMETRY_SDK_NAME]
|
||||
);
|
||||
assert.strictEqual(
|
||||
resource.attributes[SEMRESATTRS_TELEMETRY_SDK_LANGUAGE],
|
||||
SDK_INFO[SEMRESATTRS_TELEMETRY_SDK_LANGUAGE]
|
||||
resource.attributes[ATTR_TELEMETRY_SDK_LANGUAGE],
|
||||
SDK_INFO[ATTR_TELEMETRY_SDK_LANGUAGE]
|
||||
);
|
||||
assert.strictEqual(
|
||||
resource.attributes[SEMRESATTRS_TELEMETRY_SDK_VERSION],
|
||||
SDK_INFO[SEMRESATTRS_TELEMETRY_SDK_VERSION]
|
||||
resource.attributes[ATTR_TELEMETRY_SDK_VERSION],
|
||||
SDK_INFO[ATTR_TELEMETRY_SDK_VERSION]
|
||||
);
|
||||
assert.strictEqual(
|
||||
resource.attributes[SEMRESATTRS_SERVICE_NAME],
|
||||
resource.attributes[ATTR_SERVICE_NAME],
|
||||
`unknown_service:${process.argv0}`
|
||||
);
|
||||
});
|
||||
|
@ -313,19 +313,19 @@ describe('Resource', () => {
|
|||
it('should return a default resource', () => {
|
||||
const resource = defaultResource();
|
||||
assert.strictEqual(
|
||||
resource.attributes[SEMRESATTRS_TELEMETRY_SDK_NAME],
|
||||
SDK_INFO[SEMRESATTRS_TELEMETRY_SDK_NAME]
|
||||
resource.attributes[ATTR_TELEMETRY_SDK_NAME],
|
||||
SDK_INFO[ATTR_TELEMETRY_SDK_NAME]
|
||||
);
|
||||
assert.strictEqual(
|
||||
resource.attributes[SEMRESATTRS_TELEMETRY_SDK_LANGUAGE],
|
||||
SDK_INFO[SEMRESATTRS_TELEMETRY_SDK_LANGUAGE]
|
||||
resource.attributes[ATTR_TELEMETRY_SDK_LANGUAGE],
|
||||
SDK_INFO[ATTR_TELEMETRY_SDK_LANGUAGE]
|
||||
);
|
||||
assert.strictEqual(
|
||||
resource.attributes[SEMRESATTRS_TELEMETRY_SDK_VERSION],
|
||||
SDK_INFO[SEMRESATTRS_TELEMETRY_SDK_VERSION]
|
||||
resource.attributes[ATTR_TELEMETRY_SDK_VERSION],
|
||||
SDK_INFO[ATTR_TELEMETRY_SDK_VERSION]
|
||||
);
|
||||
assert.strictEqual(
|
||||
resource.attributes[SEMRESATTRS_SERVICE_NAME],
|
||||
resource.attributes[ATTR_SERVICE_NAME],
|
||||
'unknown_service'
|
||||
);
|
||||
});
|
||||
|
|
|
@ -14,16 +14,16 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {
|
||||
SEMRESATTRS_HOST_ARCH,
|
||||
SEMRESATTRS_HOST_ID,
|
||||
SEMRESATTRS_HOST_NAME,
|
||||
} from '@opentelemetry/semantic-conventions';
|
||||
import * as assert from 'assert';
|
||||
import * as sinon from 'sinon';
|
||||
import { hostDetector } from '../../../src';
|
||||
import { resourceFromDetectedResource } from '../../../src/ResourceImpl';
|
||||
import { describeNode } from '../../util';
|
||||
import {
|
||||
ATTR_HOST_ARCH,
|
||||
ATTR_HOST_ID,
|
||||
ATTR_HOST_NAME,
|
||||
} from '../../../src/semconv';
|
||||
|
||||
describeNode('hostDetector() on Node.js', () => {
|
||||
afterEach(() => {
|
||||
|
@ -44,14 +44,11 @@ describeNode('hostDetector() on Node.js', () => {
|
|||
await resource.waitForAsyncAttributes?.();
|
||||
|
||||
assert.strictEqual(
|
||||
resource.attributes[SEMRESATTRS_HOST_NAME],
|
||||
resource.attributes[ATTR_HOST_NAME],
|
||||
'opentelemetry-test'
|
||||
);
|
||||
assert.strictEqual(resource.attributes[SEMRESATTRS_HOST_ARCH], 'amd64');
|
||||
assert.strictEqual(
|
||||
resource.attributes[SEMRESATTRS_HOST_ID],
|
||||
expectedHostId
|
||||
);
|
||||
assert.strictEqual(resource.attributes[ATTR_HOST_ARCH], 'amd64');
|
||||
assert.strictEqual(resource.attributes[ATTR_HOST_ID], expectedHostId);
|
||||
});
|
||||
|
||||
it('should pass through arch string if unknown', async () => {
|
||||
|
@ -62,7 +59,7 @@ describeNode('hostDetector() on Node.js', () => {
|
|||
const resource = resourceFromDetectedResource(hostDetector.detect());
|
||||
|
||||
assert.strictEqual(
|
||||
resource.attributes[SEMRESATTRS_HOST_ARCH],
|
||||
resource.attributes[ATTR_HOST_ARCH],
|
||||
'some-unknown-arch'
|
||||
);
|
||||
});
|
||||
|
@ -79,10 +76,10 @@ describeNode('hostDetector() on Node.js', () => {
|
|||
await resource.waitForAsyncAttributes?.();
|
||||
|
||||
assert.strictEqual(
|
||||
resource.attributes[SEMRESATTRS_HOST_NAME],
|
||||
resource.attributes[ATTR_HOST_NAME],
|
||||
'opentelemetry-test'
|
||||
);
|
||||
assert.strictEqual(resource.attributes[SEMRESATTRS_HOST_ARCH], 'amd64');
|
||||
assert.strictEqual(false, SEMRESATTRS_HOST_ID in resource.attributes);
|
||||
assert.strictEqual(resource.attributes[ATTR_HOST_ARCH], 'amd64');
|
||||
assert.strictEqual(false, ATTR_HOST_ID in resource.attributes);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -14,14 +14,11 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {
|
||||
SEMRESATTRS_OS_TYPE,
|
||||
SEMRESATTRS_OS_VERSION,
|
||||
} from '@opentelemetry/semantic-conventions';
|
||||
import * as assert from 'assert';
|
||||
import * as sinon from 'sinon';
|
||||
import { osDetector } from '../../../src';
|
||||
import { describeNode } from '../../util';
|
||||
import { ATTR_OS_TYPE, ATTR_OS_VERSION } from '../../../src/semconv';
|
||||
|
||||
describeNode('osDetector() on Node.js', () => {
|
||||
afterEach(() => {
|
||||
|
@ -37,9 +34,9 @@ describeNode('osDetector() on Node.js', () => {
|
|||
const resource = osDetector.detect();
|
||||
assert.ok(resource.attributes);
|
||||
|
||||
assert.strictEqual(resource.attributes[SEMRESATTRS_OS_TYPE], 'windows');
|
||||
assert.strictEqual(resource.attributes[ATTR_OS_TYPE], 'windows');
|
||||
assert.strictEqual(
|
||||
resource.attributes[SEMRESATTRS_OS_VERSION],
|
||||
resource.attributes[ATTR_OS_VERSION],
|
||||
'2.2.1(0.289/5/3)'
|
||||
);
|
||||
});
|
||||
|
@ -53,7 +50,7 @@ describeNode('osDetector() on Node.js', () => {
|
|||
assert.ok(resource.attributes);
|
||||
|
||||
assert.strictEqual(
|
||||
resource.attributes[SEMRESATTRS_OS_TYPE],
|
||||
resource.attributes[ATTR_OS_TYPE],
|
||||
'some-unknown-platform'
|
||||
);
|
||||
});
|
||||
|
|
|
@ -16,32 +16,34 @@
|
|||
|
||||
import { SDK_INFO } from '@opentelemetry/core';
|
||||
import {
|
||||
SEMRESATTRS_CLOUD_ACCOUNT_ID,
|
||||
SEMRESATTRS_CLOUD_AVAILABILITY_ZONE,
|
||||
SEMRESATTRS_CLOUD_PROVIDER,
|
||||
SEMRESATTRS_CLOUD_REGION,
|
||||
SEMRESATTRS_CONTAINER_ID,
|
||||
SEMRESATTRS_CONTAINER_IMAGE_NAME,
|
||||
SEMRESATTRS_CONTAINER_IMAGE_TAG,
|
||||
SEMRESATTRS_CONTAINER_NAME,
|
||||
SEMRESATTRS_HOST_ID,
|
||||
SEMRESATTRS_HOST_IMAGE_ID,
|
||||
SEMRESATTRS_HOST_IMAGE_NAME,
|
||||
SEMRESATTRS_HOST_IMAGE_VERSION,
|
||||
SEMRESATTRS_HOST_NAME,
|
||||
SEMRESATTRS_HOST_TYPE,
|
||||
SEMRESATTRS_K8S_CLUSTER_NAME,
|
||||
SEMRESATTRS_K8S_DEPLOYMENT_NAME,
|
||||
SEMRESATTRS_K8S_NAMESPACE_NAME,
|
||||
SEMRESATTRS_K8S_POD_NAME,
|
||||
SEMRESATTRS_SERVICE_INSTANCE_ID,
|
||||
SEMRESATTRS_SERVICE_NAME,
|
||||
SEMRESATTRS_SERVICE_NAMESPACE,
|
||||
SEMRESATTRS_SERVICE_VERSION,
|
||||
SEMRESATTRS_TELEMETRY_SDK_LANGUAGE,
|
||||
SEMRESATTRS_TELEMETRY_SDK_NAME,
|
||||
SEMRESATTRS_TELEMETRY_SDK_VERSION,
|
||||
ATTR_SERVICE_NAME,
|
||||
ATTR_SERVICE_VERSION,
|
||||
ATTR_TELEMETRY_SDK_LANGUAGE,
|
||||
ATTR_TELEMETRY_SDK_NAME,
|
||||
ATTR_TELEMETRY_SDK_VERSION,
|
||||
} from '@opentelemetry/semantic-conventions';
|
||||
import {
|
||||
ATTR_CLOUD_ACCOUNT_ID,
|
||||
ATTR_CLOUD_AVAILABILITY_ZONE,
|
||||
ATTR_CLOUD_PROVIDER,
|
||||
ATTR_CLOUD_REGION,
|
||||
ATTR_CONTAINER_ID,
|
||||
ATTR_CONTAINER_IMAGE_NAME,
|
||||
ATTR_CONTAINER_IMAGE_TAGS,
|
||||
ATTR_CONTAINER_NAME,
|
||||
ATTR_HOST_ID,
|
||||
ATTR_HOST_IMAGE_ID,
|
||||
ATTR_HOST_IMAGE_NAME,
|
||||
ATTR_HOST_IMAGE_VERSION,
|
||||
ATTR_HOST_NAME,
|
||||
ATTR_HOST_TYPE,
|
||||
ATTR_K8S_CLUSTER_NAME,
|
||||
ATTR_K8S_DEPLOYMENT_NAME,
|
||||
ATTR_K8S_NAMESPACE_NAME,
|
||||
ATTR_K8S_POD_NAME,
|
||||
ATTR_SERVICE_INSTANCE_ID,
|
||||
ATTR_SERVICE_NAMESPACE,
|
||||
} from '../src/semconv';
|
||||
import {
|
||||
assertCloudResource,
|
||||
assertContainerResource,
|
||||
|
@ -55,7 +57,7 @@ describe('assertCloudResource', () => {
|
|||
it('requires one cloud label', () => {
|
||||
const resource = {
|
||||
attributes: {
|
||||
[SEMRESATTRS_CLOUD_PROVIDER]: 'gcp',
|
||||
[ATTR_CLOUD_PROVIDER]: 'gcp',
|
||||
},
|
||||
};
|
||||
assertCloudResource(resource, {});
|
||||
|
@ -64,10 +66,10 @@ describe('assertCloudResource', () => {
|
|||
it('validates optional attributes', () => {
|
||||
const resource = {
|
||||
attributes: {
|
||||
[SEMRESATTRS_CLOUD_PROVIDER]: 'gcp',
|
||||
[SEMRESATTRS_CLOUD_ACCOUNT_ID]: 'opentelemetry',
|
||||
[SEMRESATTRS_CLOUD_REGION]: 'us-central1',
|
||||
[SEMRESATTRS_CLOUD_AVAILABILITY_ZONE]: 'us-central1-a',
|
||||
[ATTR_CLOUD_PROVIDER]: 'gcp',
|
||||
[ATTR_CLOUD_ACCOUNT_ID]: 'opentelemetry',
|
||||
[ATTR_CLOUD_REGION]: 'us-central1',
|
||||
[ATTR_CLOUD_AVAILABILITY_ZONE]: 'us-central1-a',
|
||||
},
|
||||
};
|
||||
assertCloudResource(resource, {
|
||||
|
@ -83,7 +85,7 @@ describe('assertContainerResource', () => {
|
|||
it('requires one container label', () => {
|
||||
const resource = {
|
||||
attributes: {
|
||||
[SEMRESATTRS_CONTAINER_NAME]: 'opentelemetry-autoconf',
|
||||
[ATTR_CONTAINER_NAME]: 'opentelemetry-autoconf',
|
||||
},
|
||||
};
|
||||
assertContainerResource(resource, {});
|
||||
|
@ -92,17 +94,17 @@ describe('assertContainerResource', () => {
|
|||
it('validates optional attributes', () => {
|
||||
const resource = {
|
||||
attributes: {
|
||||
[SEMRESATTRS_CONTAINER_NAME]: 'opentelemetry-autoconf',
|
||||
[SEMRESATTRS_CONTAINER_ID]: 'abc',
|
||||
[SEMRESATTRS_CONTAINER_IMAGE_NAME]: 'gcr.io/opentelemetry/operator',
|
||||
[SEMRESATTRS_CONTAINER_IMAGE_TAG]: '0.1',
|
||||
[ATTR_CONTAINER_NAME]: 'opentelemetry-autoconf',
|
||||
[ATTR_CONTAINER_ID]: 'abc',
|
||||
[ATTR_CONTAINER_IMAGE_NAME]: 'gcr.io/opentelemetry/operator',
|
||||
[ATTR_CONTAINER_IMAGE_TAGS]: ['0.1'],
|
||||
},
|
||||
};
|
||||
assertContainerResource(resource, {
|
||||
name: 'opentelemetry-autoconf',
|
||||
id: 'abc',
|
||||
imageName: 'gcr.io/opentelemetry/operator',
|
||||
imageTag: '0.1',
|
||||
imageTags: ['0.1'],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -111,7 +113,7 @@ describe('assertHostResource', () => {
|
|||
it('requires one host label', () => {
|
||||
const resource = {
|
||||
attributes: {
|
||||
[SEMRESATTRS_HOST_ID]: 'opentelemetry-test-id',
|
||||
[ATTR_HOST_ID]: 'opentelemetry-test-id',
|
||||
},
|
||||
};
|
||||
assertHostResource(resource, {});
|
||||
|
@ -120,13 +122,13 @@ describe('assertHostResource', () => {
|
|||
it('validates optional attributes', () => {
|
||||
const resource = {
|
||||
attributes: {
|
||||
[SEMRESATTRS_HOST_ID]: 'opentelemetry-test-id',
|
||||
[SEMRESATTRS_HOST_NAME]: 'opentelemetry-test-name',
|
||||
[SEMRESATTRS_HOST_TYPE]: 'n1-standard-1',
|
||||
[SEMRESATTRS_HOST_IMAGE_NAME]:
|
||||
[ATTR_HOST_ID]: 'opentelemetry-test-id',
|
||||
[ATTR_HOST_NAME]: 'opentelemetry-test-name',
|
||||
[ATTR_HOST_TYPE]: 'n1-standard-1',
|
||||
[ATTR_HOST_IMAGE_NAME]:
|
||||
'infra-ami-eks-worker-node-7d4ec78312, CentOS-8-x86_64-1905',
|
||||
[SEMRESATTRS_HOST_IMAGE_ID]: 'ami-07b06b442921831e5',
|
||||
[SEMRESATTRS_HOST_IMAGE_VERSION]: '0.1',
|
||||
[ATTR_HOST_IMAGE_ID]: 'ami-07b06b442921831e5',
|
||||
[ATTR_HOST_IMAGE_VERSION]: '0.1',
|
||||
},
|
||||
};
|
||||
assertHostResource(resource, {
|
||||
|
@ -145,7 +147,7 @@ describe('assertK8sResource', () => {
|
|||
it('requires one k8s label', () => {
|
||||
const resource = {
|
||||
attributes: {
|
||||
[SEMRESATTRS_K8S_CLUSTER_NAME]: 'opentelemetry-cluster',
|
||||
[ATTR_K8S_CLUSTER_NAME]: 'opentelemetry-cluster',
|
||||
},
|
||||
};
|
||||
assertK8sResource(resource, {});
|
||||
|
@ -154,10 +156,10 @@ describe('assertK8sResource', () => {
|
|||
it('validates optional attributes', () => {
|
||||
const resource = {
|
||||
attributes: {
|
||||
[SEMRESATTRS_K8S_CLUSTER_NAME]: 'opentelemetry-cluster',
|
||||
[SEMRESATTRS_K8S_NAMESPACE_NAME]: 'default',
|
||||
[SEMRESATTRS_K8S_POD_NAME]: 'opentelemetry-pod-autoconf',
|
||||
[SEMRESATTRS_K8S_DEPLOYMENT_NAME]: 'opentelemetry',
|
||||
[ATTR_K8S_CLUSTER_NAME]: 'opentelemetry-cluster',
|
||||
[ATTR_K8S_NAMESPACE_NAME]: 'default',
|
||||
[ATTR_K8S_POD_NAME]: 'opentelemetry-pod-autoconf',
|
||||
[ATTR_K8S_DEPLOYMENT_NAME]: 'opentelemetry',
|
||||
},
|
||||
};
|
||||
assertK8sResource(resource, {
|
||||
|
@ -173,12 +175,9 @@ describe('assertTelemetrySDKResource', () => {
|
|||
it('uses default validations', () => {
|
||||
const resource = {
|
||||
attributes: {
|
||||
[SEMRESATTRS_TELEMETRY_SDK_NAME]:
|
||||
SDK_INFO[SEMRESATTRS_TELEMETRY_SDK_NAME],
|
||||
[SEMRESATTRS_TELEMETRY_SDK_LANGUAGE]:
|
||||
SDK_INFO[SEMRESATTRS_TELEMETRY_SDK_LANGUAGE],
|
||||
[SEMRESATTRS_TELEMETRY_SDK_VERSION]:
|
||||
SDK_INFO[SEMRESATTRS_TELEMETRY_SDK_VERSION],
|
||||
[ATTR_TELEMETRY_SDK_NAME]: SDK_INFO[ATTR_TELEMETRY_SDK_NAME],
|
||||
[ATTR_TELEMETRY_SDK_LANGUAGE]: SDK_INFO[ATTR_TELEMETRY_SDK_LANGUAGE],
|
||||
[ATTR_TELEMETRY_SDK_VERSION]: SDK_INFO[ATTR_TELEMETRY_SDK_VERSION],
|
||||
},
|
||||
};
|
||||
assertTelemetrySDKResource(resource, {});
|
||||
|
@ -187,9 +186,9 @@ describe('assertTelemetrySDKResource', () => {
|
|||
it('validates optional attributes', () => {
|
||||
const resource = {
|
||||
attributes: {
|
||||
[SEMRESATTRS_TELEMETRY_SDK_NAME]: 'opentelemetry',
|
||||
[SEMRESATTRS_TELEMETRY_SDK_LANGUAGE]: 'nodejs',
|
||||
[SEMRESATTRS_TELEMETRY_SDK_VERSION]: '0.1.0',
|
||||
[ATTR_TELEMETRY_SDK_NAME]: 'opentelemetry',
|
||||
[ATTR_TELEMETRY_SDK_LANGUAGE]: 'nodejs',
|
||||
[ATTR_TELEMETRY_SDK_VERSION]: '0.1.0',
|
||||
},
|
||||
};
|
||||
assertTelemetrySDKResource(resource, {
|
||||
|
@ -204,9 +203,8 @@ describe('assertServiceResource', () => {
|
|||
it('validates required attributes', () => {
|
||||
const resource = {
|
||||
attributes: {
|
||||
[SEMRESATTRS_SERVICE_NAME]: 'shoppingcart',
|
||||
[SEMRESATTRS_SERVICE_INSTANCE_ID]:
|
||||
'627cc493-f310-47de-96bd-71410b7dec09',
|
||||
[ATTR_SERVICE_NAME]: 'shoppingcart',
|
||||
[ATTR_SERVICE_INSTANCE_ID]: '627cc493-f310-47de-96bd-71410b7dec09',
|
||||
},
|
||||
};
|
||||
assertServiceResource(resource, {
|
||||
|
@ -218,11 +216,10 @@ describe('assertServiceResource', () => {
|
|||
it('validates optional attributes', () => {
|
||||
const resource = {
|
||||
attributes: {
|
||||
[SEMRESATTRS_SERVICE_NAME]: 'shoppingcart',
|
||||
[SEMRESATTRS_SERVICE_INSTANCE_ID]:
|
||||
'627cc493-f310-47de-96bd-71410b7dec09',
|
||||
[SEMRESATTRS_SERVICE_NAMESPACE]: 'shop',
|
||||
[SEMRESATTRS_SERVICE_VERSION]: '0.1.0',
|
||||
[ATTR_SERVICE_NAME]: 'shoppingcart',
|
||||
[ATTR_SERVICE_INSTANCE_ID]: '627cc493-f310-47de-96bd-71410b7dec09',
|
||||
[ATTR_SERVICE_NAMESPACE]: 'shop',
|
||||
[ATTR_SERVICE_VERSION]: '0.1.0',
|
||||
},
|
||||
};
|
||||
assertServiceResource(resource, {
|
||||
|
|
|
@ -17,45 +17,48 @@
|
|||
import { SDK_INFO } from '@opentelemetry/core';
|
||||
import * as assert from 'assert';
|
||||
import {
|
||||
SEMRESATTRS_CLOUD_ACCOUNT_ID,
|
||||
SEMRESATTRS_CLOUD_AVAILABILITY_ZONE,
|
||||
SEMRESATTRS_CLOUD_PROVIDER,
|
||||
SEMRESATTRS_CLOUD_REGION,
|
||||
SEMRESATTRS_CONTAINER_ID,
|
||||
SEMRESATTRS_CONTAINER_IMAGE_NAME,
|
||||
SEMRESATTRS_CONTAINER_IMAGE_TAG,
|
||||
SEMRESATTRS_CONTAINER_NAME,
|
||||
SEMRESATTRS_HOST_ID,
|
||||
SEMRESATTRS_HOST_IMAGE_ID,
|
||||
SEMRESATTRS_HOST_IMAGE_NAME,
|
||||
SEMRESATTRS_HOST_IMAGE_VERSION,
|
||||
SEMRESATTRS_HOST_NAME,
|
||||
SEMRESATTRS_HOST_TYPE,
|
||||
SEMRESATTRS_K8S_CLUSTER_NAME,
|
||||
SEMRESATTRS_K8S_DEPLOYMENT_NAME,
|
||||
SEMRESATTRS_K8S_NAMESPACE_NAME,
|
||||
SEMRESATTRS_K8S_POD_NAME,
|
||||
SEMRESATTRS_PROCESS_COMMAND,
|
||||
SEMRESATTRS_PROCESS_COMMAND_ARGS,
|
||||
SEMRESATTRS_PROCESS_EXECUTABLE_NAME,
|
||||
SEMRESATTRS_PROCESS_EXECUTABLE_PATH,
|
||||
SEMRESATTRS_PROCESS_OWNER,
|
||||
SEMRESATTRS_PROCESS_PID,
|
||||
SEMRESATTRS_PROCESS_RUNTIME_DESCRIPTION,
|
||||
SEMRESATTRS_PROCESS_RUNTIME_NAME,
|
||||
SEMRESATTRS_PROCESS_RUNTIME_VERSION,
|
||||
SEMRESATTRS_SERVICE_INSTANCE_ID,
|
||||
SEMRESATTRS_SERVICE_NAME,
|
||||
SEMRESATTRS_SERVICE_NAMESPACE,
|
||||
SEMRESATTRS_SERVICE_VERSION,
|
||||
SEMRESATTRS_TELEMETRY_SDK_LANGUAGE,
|
||||
SEMRESATTRS_TELEMETRY_SDK_NAME,
|
||||
SEMRESATTRS_TELEMETRY_SDK_VERSION,
|
||||
SEMRESATTRS_WEBENGINE_DESCRIPTION,
|
||||
SEMRESATTRS_WEBENGINE_NAME,
|
||||
SEMRESATTRS_WEBENGINE_VERSION,
|
||||
ATTR_SERVICE_NAME,
|
||||
ATTR_SERVICE_VERSION,
|
||||
ATTR_TELEMETRY_SDK_LANGUAGE,
|
||||
ATTR_TELEMETRY_SDK_NAME,
|
||||
ATTR_TELEMETRY_SDK_VERSION,
|
||||
} from '@opentelemetry/semantic-conventions';
|
||||
import * as semconv from '@opentelemetry/semantic-conventions';
|
||||
import * as semconvIncubating from '@opentelemetry/semantic-conventions/incubating';
|
||||
|
||||
import {
|
||||
ATTR_CLOUD_ACCOUNT_ID,
|
||||
ATTR_CLOUD_AVAILABILITY_ZONE,
|
||||
ATTR_CLOUD_PROVIDER,
|
||||
ATTR_CLOUD_REGION,
|
||||
ATTR_CONTAINER_ID,
|
||||
ATTR_CONTAINER_IMAGE_NAME,
|
||||
ATTR_CONTAINER_IMAGE_TAGS,
|
||||
ATTR_CONTAINER_NAME,
|
||||
ATTR_HOST_ID,
|
||||
ATTR_HOST_IMAGE_ID,
|
||||
ATTR_HOST_IMAGE_NAME,
|
||||
ATTR_HOST_IMAGE_VERSION,
|
||||
ATTR_HOST_NAME,
|
||||
ATTR_HOST_TYPE,
|
||||
ATTR_K8S_CLUSTER_NAME,
|
||||
ATTR_K8S_DEPLOYMENT_NAME,
|
||||
ATTR_K8S_NAMESPACE_NAME,
|
||||
ATTR_K8S_POD_NAME,
|
||||
ATTR_PROCESS_COMMAND,
|
||||
ATTR_PROCESS_COMMAND_ARGS,
|
||||
ATTR_PROCESS_EXECUTABLE_NAME,
|
||||
ATTR_PROCESS_EXECUTABLE_PATH,
|
||||
ATTR_PROCESS_OWNER,
|
||||
ATTR_PROCESS_PID,
|
||||
ATTR_PROCESS_RUNTIME_DESCRIPTION,
|
||||
ATTR_PROCESS_RUNTIME_NAME,
|
||||
ATTR_PROCESS_RUNTIME_VERSION,
|
||||
ATTR_SERVICE_INSTANCE_ID,
|
||||
ATTR_SERVICE_NAMESPACE,
|
||||
ATTR_WEBENGINE_DESCRIPTION,
|
||||
ATTR_WEBENGINE_NAME,
|
||||
ATTR_WEBENGINE_VERSION,
|
||||
} from '../../src/semconv';
|
||||
import { DetectedResource } from '../../src/types';
|
||||
|
||||
/**
|
||||
|
@ -76,22 +79,22 @@ export const assertCloudResource = (
|
|||
assertHasOneLabel('CLOUD', resource);
|
||||
if (validations.provider)
|
||||
assert.strictEqual(
|
||||
resource.attributes?.[SEMRESATTRS_CLOUD_PROVIDER],
|
||||
resource.attributes?.[ATTR_CLOUD_PROVIDER],
|
||||
validations.provider
|
||||
);
|
||||
if (validations.accountId)
|
||||
assert.strictEqual(
|
||||
resource.attributes?.[SEMRESATTRS_CLOUD_ACCOUNT_ID],
|
||||
resource.attributes?.[ATTR_CLOUD_ACCOUNT_ID],
|
||||
validations.accountId
|
||||
);
|
||||
if (validations.region)
|
||||
assert.strictEqual(
|
||||
resource.attributes?.[SEMRESATTRS_CLOUD_REGION],
|
||||
resource.attributes?.[ATTR_CLOUD_REGION],
|
||||
validations.region
|
||||
);
|
||||
if (validations.zone)
|
||||
assert.strictEqual(
|
||||
resource.attributes?.[SEMRESATTRS_CLOUD_AVAILABILITY_ZONE],
|
||||
resource.attributes?.[ATTR_CLOUD_AVAILABILITY_ZONE],
|
||||
validations.zone
|
||||
);
|
||||
};
|
||||
|
@ -108,29 +111,29 @@ export const assertContainerResource = (
|
|||
name?: string;
|
||||
id?: string;
|
||||
imageName?: string;
|
||||
imageTag?: string;
|
||||
imageTags?: string[];
|
||||
}
|
||||
) => {
|
||||
assertHasOneLabel('CONTAINER', resource);
|
||||
if (validations.name)
|
||||
assert.strictEqual(
|
||||
resource.attributes?.[SEMRESATTRS_CONTAINER_NAME],
|
||||
resource.attributes?.[ATTR_CONTAINER_NAME],
|
||||
validations.name
|
||||
);
|
||||
if (validations.id)
|
||||
assert.strictEqual(
|
||||
resource.attributes?.[SEMRESATTRS_CONTAINER_ID],
|
||||
resource.attributes?.[ATTR_CONTAINER_ID],
|
||||
validations.id
|
||||
);
|
||||
if (validations.imageName)
|
||||
assert.strictEqual(
|
||||
resource.attributes?.[SEMRESATTRS_CONTAINER_IMAGE_NAME],
|
||||
resource.attributes?.[ATTR_CONTAINER_IMAGE_NAME],
|
||||
validations.imageName
|
||||
);
|
||||
if (validations.imageTag)
|
||||
assert.strictEqual(
|
||||
resource.attributes?.[SEMRESATTRS_CONTAINER_IMAGE_TAG],
|
||||
validations.imageTag
|
||||
if (validations.imageTags)
|
||||
assert.deepStrictEqual(
|
||||
resource.attributes?.[ATTR_CONTAINER_IMAGE_TAGS],
|
||||
validations.imageTags
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -154,33 +157,27 @@ export const assertHostResource = (
|
|||
) => {
|
||||
assertHasOneLabel('HOST', resource);
|
||||
if (validations.id)
|
||||
assert.strictEqual(
|
||||
resource.attributes?.[SEMRESATTRS_HOST_ID],
|
||||
validations.id
|
||||
);
|
||||
assert.strictEqual(resource.attributes?.[ATTR_HOST_ID], validations.id);
|
||||
if (validations.name)
|
||||
assert.strictEqual(
|
||||
resource.attributes?.[SEMRESATTRS_HOST_NAME],
|
||||
validations.name
|
||||
);
|
||||
assert.strictEqual(resource.attributes?.[ATTR_HOST_NAME], validations.name);
|
||||
if (validations.hostType)
|
||||
assert.strictEqual(
|
||||
resource.attributes?.[SEMRESATTRS_HOST_TYPE],
|
||||
resource.attributes?.[ATTR_HOST_TYPE],
|
||||
validations.hostType
|
||||
);
|
||||
if (validations.imageName)
|
||||
assert.strictEqual(
|
||||
resource.attributes?.[SEMRESATTRS_HOST_IMAGE_NAME],
|
||||
resource.attributes?.[ATTR_HOST_IMAGE_NAME],
|
||||
validations.imageName
|
||||
);
|
||||
if (validations.imageId)
|
||||
assert.strictEqual(
|
||||
resource.attributes?.[SEMRESATTRS_HOST_IMAGE_ID],
|
||||
resource.attributes?.[ATTR_HOST_IMAGE_ID],
|
||||
validations.imageId
|
||||
);
|
||||
if (validations.imageVersion)
|
||||
assert.strictEqual(
|
||||
resource.attributes?.[SEMRESATTRS_HOST_IMAGE_VERSION],
|
||||
resource.attributes?.[ATTR_HOST_IMAGE_VERSION],
|
||||
validations.imageVersion
|
||||
);
|
||||
};
|
||||
|
@ -203,22 +200,22 @@ export const assertK8sResource = (
|
|||
assertHasOneLabel('K8S', resource);
|
||||
if (validations.clusterName)
|
||||
assert.strictEqual(
|
||||
resource.attributes?.[SEMRESATTRS_K8S_CLUSTER_NAME],
|
||||
resource.attributes?.[ATTR_K8S_CLUSTER_NAME],
|
||||
validations.clusterName
|
||||
);
|
||||
if (validations.namespaceName)
|
||||
assert.strictEqual(
|
||||
resource.attributes?.[SEMRESATTRS_K8S_NAMESPACE_NAME],
|
||||
resource.attributes?.[ATTR_K8S_NAMESPACE_NAME],
|
||||
validations.namespaceName
|
||||
);
|
||||
if (validations.podName)
|
||||
assert.strictEqual(
|
||||
resource.attributes?.[SEMRESATTRS_K8S_POD_NAME],
|
||||
resource.attributes?.[ATTR_K8S_POD_NAME],
|
||||
validations.podName
|
||||
);
|
||||
if (validations.deploymentName)
|
||||
assert.strictEqual(
|
||||
resource.attributes?.[SEMRESATTRS_K8S_DEPLOYMENT_NAME],
|
||||
resource.attributes?.[ATTR_K8S_DEPLOYMENT_NAME],
|
||||
validations.deploymentName
|
||||
);
|
||||
};
|
||||
|
@ -238,25 +235,25 @@ export const assertTelemetrySDKResource = (
|
|||
}
|
||||
) => {
|
||||
const defaults = {
|
||||
name: SDK_INFO[SEMRESATTRS_TELEMETRY_SDK_NAME],
|
||||
language: SDK_INFO[SEMRESATTRS_TELEMETRY_SDK_LANGUAGE],
|
||||
version: SDK_INFO[SEMRESATTRS_TELEMETRY_SDK_VERSION],
|
||||
name: SDK_INFO[ATTR_TELEMETRY_SDK_NAME],
|
||||
language: SDK_INFO[ATTR_TELEMETRY_SDK_LANGUAGE],
|
||||
version: SDK_INFO[ATTR_TELEMETRY_SDK_VERSION],
|
||||
};
|
||||
validations = { ...defaults, ...validations };
|
||||
|
||||
if (validations.name)
|
||||
assert.strictEqual(
|
||||
resource.attributes?.[SEMRESATTRS_TELEMETRY_SDK_NAME],
|
||||
resource.attributes?.[ATTR_TELEMETRY_SDK_NAME],
|
||||
validations.name
|
||||
);
|
||||
if (validations.language)
|
||||
assert.strictEqual(
|
||||
resource.attributes?.[SEMRESATTRS_TELEMETRY_SDK_LANGUAGE],
|
||||
resource.attributes?.[ATTR_TELEMETRY_SDK_LANGUAGE],
|
||||
validations.language
|
||||
);
|
||||
if (validations.version)
|
||||
assert.strictEqual(
|
||||
resource.attributes?.[SEMRESATTRS_TELEMETRY_SDK_VERSION],
|
||||
resource.attributes?.[ATTR_TELEMETRY_SDK_VERSION],
|
||||
validations.version
|
||||
);
|
||||
};
|
||||
|
@ -277,21 +274,21 @@ export const assertServiceResource = (
|
|||
}
|
||||
) => {
|
||||
assert.strictEqual(
|
||||
resource.attributes?.[SEMRESATTRS_SERVICE_NAME],
|
||||
resource.attributes?.[ATTR_SERVICE_NAME],
|
||||
validations.name
|
||||
);
|
||||
assert.strictEqual(
|
||||
resource.attributes?.[SEMRESATTRS_SERVICE_INSTANCE_ID],
|
||||
resource.attributes?.[ATTR_SERVICE_INSTANCE_ID],
|
||||
validations.instanceId
|
||||
);
|
||||
if (validations.namespace)
|
||||
assert.strictEqual(
|
||||
resource.attributes?.[SEMRESATTRS_SERVICE_NAMESPACE],
|
||||
resource.attributes?.[ATTR_SERVICE_NAMESPACE],
|
||||
validations.namespace
|
||||
);
|
||||
if (validations.version)
|
||||
assert.strictEqual(
|
||||
resource.attributes?.[SEMRESATTRS_SERVICE_VERSION],
|
||||
resource.attributes?.[ATTR_SERVICE_VERSION],
|
||||
validations.version
|
||||
);
|
||||
};
|
||||
|
@ -316,55 +313,52 @@ export const assertResource = (
|
|||
runtimeDescription?: string;
|
||||
}
|
||||
) => {
|
||||
assert.strictEqual(
|
||||
resource.attributes?.[SEMRESATTRS_PROCESS_PID],
|
||||
validations.pid
|
||||
);
|
||||
assert.strictEqual(resource.attributes?.[ATTR_PROCESS_PID], validations.pid);
|
||||
if (validations.name) {
|
||||
assert.strictEqual(
|
||||
resource.attributes?.[SEMRESATTRS_PROCESS_EXECUTABLE_NAME],
|
||||
resource.attributes?.[ATTR_PROCESS_EXECUTABLE_NAME],
|
||||
validations.name
|
||||
);
|
||||
}
|
||||
if (validations.command) {
|
||||
assert.strictEqual(
|
||||
resource.attributes?.[SEMRESATTRS_PROCESS_COMMAND],
|
||||
resource.attributes?.[ATTR_PROCESS_COMMAND],
|
||||
validations.command
|
||||
);
|
||||
}
|
||||
if (validations.commandArgs) {
|
||||
assert.deepStrictEqual(
|
||||
resource.attributes?.[SEMRESATTRS_PROCESS_COMMAND_ARGS],
|
||||
resource.attributes?.[ATTR_PROCESS_COMMAND_ARGS],
|
||||
validations.commandArgs
|
||||
);
|
||||
}
|
||||
if (validations.executablePath) {
|
||||
assert.strictEqual(
|
||||
resource.attributes?.[SEMRESATTRS_PROCESS_EXECUTABLE_PATH],
|
||||
resource.attributes?.[ATTR_PROCESS_EXECUTABLE_PATH],
|
||||
validations.executablePath
|
||||
);
|
||||
}
|
||||
if (validations.owner) {
|
||||
assert.strictEqual(
|
||||
resource.attributes?.[SEMRESATTRS_PROCESS_OWNER],
|
||||
resource.attributes?.[ATTR_PROCESS_OWNER],
|
||||
validations.owner
|
||||
);
|
||||
}
|
||||
if (validations.version) {
|
||||
assert.strictEqual(
|
||||
resource.attributes?.[SEMRESATTRS_PROCESS_RUNTIME_VERSION],
|
||||
resource.attributes?.[ATTR_PROCESS_RUNTIME_VERSION],
|
||||
validations.version
|
||||
);
|
||||
}
|
||||
if (validations.runtimeName) {
|
||||
assert.strictEqual(
|
||||
resource.attributes?.[SEMRESATTRS_PROCESS_RUNTIME_NAME],
|
||||
resource.attributes?.[ATTR_PROCESS_RUNTIME_NAME],
|
||||
validations.runtimeName
|
||||
);
|
||||
}
|
||||
if (validations.runtimeDescription) {
|
||||
assert.strictEqual(
|
||||
resource.attributes?.[SEMRESATTRS_PROCESS_RUNTIME_DESCRIPTION],
|
||||
resource.attributes?.[ATTR_PROCESS_RUNTIME_DESCRIPTION],
|
||||
validations.runtimeDescription
|
||||
);
|
||||
}
|
||||
|
@ -380,19 +374,19 @@ export const assertWebEngineResource = (
|
|||
) => {
|
||||
if (validations.name) {
|
||||
assert.strictEqual(
|
||||
resource.attributes?.[SEMRESATTRS_WEBENGINE_NAME],
|
||||
resource.attributes?.[ATTR_WEBENGINE_NAME],
|
||||
validations.name
|
||||
);
|
||||
}
|
||||
if (validations.version) {
|
||||
assert.strictEqual(
|
||||
resource.attributes?.[SEMRESATTRS_WEBENGINE_VERSION],
|
||||
resource.attributes?.[ATTR_WEBENGINE_VERSION],
|
||||
validations.version
|
||||
);
|
||||
}
|
||||
if (validations.description) {
|
||||
assert.strictEqual(
|
||||
resource.attributes?.[SEMRESATTRS_WEBENGINE_DESCRIPTION],
|
||||
resource.attributes?.[ATTR_WEBENGINE_DESCRIPTION],
|
||||
validations.description
|
||||
);
|
||||
}
|
||||
|
@ -415,9 +409,11 @@ const assertHasOneLabel = (
|
|||
prefix: string,
|
||||
resource: DetectedResource
|
||||
): void => {
|
||||
const semconvModPrefix = `SEMRESATTRS_${prefix.toUpperCase()}_`;
|
||||
const semconvModPrefix = `ATTR_${prefix.toUpperCase()}_`;
|
||||
// Look at exports from the "incubating" entry-point because it includes both
|
||||
// stable and unstable semconv exports.
|
||||
const knownAttrs: Set<string> = new Set(
|
||||
Object.entries(semconv)
|
||||
Object.entries(semconvIncubating)
|
||||
.filter(
|
||||
([k, v]) => typeof v === 'string' && k.startsWith(semconvModPrefix)
|
||||
)
|
||||
|
@ -432,6 +428,6 @@ const assertHasOneLabel = (
|
|||
prefix +
|
||||
'] matching the following attributes: ' +
|
||||
Array.from(knownAttrs).join(', ') +
|
||||
JSON.stringify(Object.keys(semconv))
|
||||
JSON.stringify(Object.keys(semconvIncubating))
|
||||
);
|
||||
};
|
||||
|
|
|
@ -15,13 +15,13 @@
|
|||
*/
|
||||
|
||||
import {
|
||||
SEMRESATTRS_CLOUD_ACCOUNT_ID,
|
||||
SEMRESATTRS_CLOUD_AVAILABILITY_ZONE,
|
||||
SEMRESATTRS_CLOUD_PROVIDER,
|
||||
SEMRESATTRS_CLOUD_REGION,
|
||||
SEMRESATTRS_HOST_ID,
|
||||
SEMRESATTRS_HOST_TYPE,
|
||||
} from '@opentelemetry/semantic-conventions';
|
||||
ATTR_CLOUD_ACCOUNT_ID,
|
||||
ATTR_CLOUD_AVAILABILITY_ZONE,
|
||||
ATTR_CLOUD_PROVIDER,
|
||||
ATTR_CLOUD_REGION,
|
||||
ATTR_HOST_ID,
|
||||
ATTR_HOST_TYPE,
|
||||
} from '../../src/semconv';
|
||||
import { ResourceDetector } from '../../src';
|
||||
import { DetectedResource } from '../../src/types';
|
||||
|
||||
|
@ -29,12 +29,12 @@ class SampleDetector implements ResourceDetector {
|
|||
detect(): DetectedResource {
|
||||
return {
|
||||
attributes: {
|
||||
[SEMRESATTRS_CLOUD_PROVIDER]: 'provider',
|
||||
[SEMRESATTRS_CLOUD_ACCOUNT_ID]: 'accountId',
|
||||
[SEMRESATTRS_CLOUD_REGION]: 'region',
|
||||
[SEMRESATTRS_CLOUD_AVAILABILITY_ZONE]: 'zone',
|
||||
[SEMRESATTRS_HOST_ID]: 'instanceId',
|
||||
[SEMRESATTRS_HOST_TYPE]: 'instanceType',
|
||||
[ATTR_CLOUD_PROVIDER]: 'provider',
|
||||
[ATTR_CLOUD_ACCOUNT_ID]: 'accountId',
|
||||
[ATTR_CLOUD_REGION]: 'region',
|
||||
[ATTR_CLOUD_AVAILABILITY_ZONE]: 'zone',
|
||||
[ATTR_HOST_ID]: 'instanceId',
|
||||
[ATTR_HOST_TYPE]: 'instanceType',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue