Skip to content

Commit 2c60ac0

Browse files
Roxxas96trentm
andauthored
refactor(resources): replace deprecated semconv consts (#5581)
Signed-off-by: Alexandre Gomez <[email protected]> Co-authored-by: Trent Mick <[email protected]>
1 parent dd4b39c commit 2c60ac0

File tree

5 files changed

+189
-35
lines changed

5 files changed

+189
-35
lines changed

packages/opentelemetry-resources/src/detectors/platform/node/HostDetector.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {
18-
SEMRESATTRS_HOST_ARCH,
19-
SEMRESATTRS_HOST_ID,
20-
SEMRESATTRS_HOST_NAME,
21-
} from '@opentelemetry/semantic-conventions';
17+
import { ATTR_HOST_ARCH, ATTR_HOST_ID, ATTR_HOST_NAME } from '../../../semconv';
2218
import { arch, hostname } from 'os';
2319
import { ResourceDetectionConfig } from '../../../config';
2420
import {
@@ -36,9 +32,9 @@ import { normalizeArch } from './utils';
3632
class HostDetector implements ResourceDetector {
3733
detect(_config?: ResourceDetectionConfig): DetectedResource {
3834
const attributes: DetectedResourceAttributes = {
39-
[SEMRESATTRS_HOST_NAME]: hostname(),
40-
[SEMRESATTRS_HOST_ARCH]: normalizeArch(arch()),
41-
[SEMRESATTRS_HOST_ID]: getMachineId(),
35+
[ATTR_HOST_NAME]: hostname(),
36+
[ATTR_HOST_ARCH]: normalizeArch(arch()),
37+
[ATTR_HOST_ID]: getMachineId(),
4238
};
4339

4440
return { attributes };

packages/opentelemetry-resources/src/detectors/platform/node/OSDetector.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515
*/
1616

1717
import { Attributes } from '@opentelemetry/api';
18-
import {
19-
SEMRESATTRS_OS_TYPE,
20-
SEMRESATTRS_OS_VERSION,
21-
} from '@opentelemetry/semantic-conventions';
18+
import { ATTR_OS_TYPE, ATTR_OS_VERSION } from '../../../semconv';
2219
import { platform, release } from 'os';
2320
import { ResourceDetectionConfig } from '../../../config';
2421
import { DetectedResource, ResourceDetector } from '../../../types';
@@ -31,8 +28,8 @@ import { normalizeType } from './utils';
3128
class OSDetector implements ResourceDetector {
3229
detect(_config?: ResourceDetectionConfig): DetectedResource {
3330
const attributes: Attributes = {
34-
[SEMRESATTRS_OS_TYPE]: normalizeType(platform()),
35-
[SEMRESATTRS_OS_VERSION]: release(),
31+
[ATTR_OS_TYPE]: normalizeType(platform()),
32+
[ATTR_OS_VERSION]: release(),
3633
};
3734
return { attributes };
3835
}

packages/opentelemetry-resources/src/detectors/platform/node/ProcessDetector.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@
1616

1717
import { Attributes, diag } from '@opentelemetry/api';
1818
import {
19-
SEMRESATTRS_PROCESS_COMMAND,
20-
SEMRESATTRS_PROCESS_COMMAND_ARGS,
21-
SEMRESATTRS_PROCESS_EXECUTABLE_NAME,
22-
SEMRESATTRS_PROCESS_EXECUTABLE_PATH,
23-
SEMRESATTRS_PROCESS_OWNER,
24-
SEMRESATTRS_PROCESS_PID,
25-
SEMRESATTRS_PROCESS_RUNTIME_DESCRIPTION,
26-
SEMRESATTRS_PROCESS_RUNTIME_NAME,
27-
SEMRESATTRS_PROCESS_RUNTIME_VERSION,
28-
} from '@opentelemetry/semantic-conventions';
19+
ATTR_PROCESS_COMMAND,
20+
ATTR_PROCESS_COMMAND_ARGS,
21+
ATTR_PROCESS_EXECUTABLE_NAME,
22+
ATTR_PROCESS_EXECUTABLE_PATH,
23+
ATTR_PROCESS_OWNER,
24+
ATTR_PROCESS_PID,
25+
ATTR_PROCESS_RUNTIME_DESCRIPTION,
26+
ATTR_PROCESS_RUNTIME_NAME,
27+
ATTR_PROCESS_RUNTIME_VERSION,
28+
} from '../../../semconv';
2929
import * as os from 'os';
3030
import { ResourceDetectionConfig } from '../../../config';
3131
import { DetectedResource, ResourceDetector } from '../../../types';
@@ -37,26 +37,26 @@ import { DetectedResource, ResourceDetector } from '../../../types';
3737
class ProcessDetector implements ResourceDetector {
3838
detect(_config?: ResourceDetectionConfig): DetectedResource {
3939
const attributes: Attributes = {
40-
[SEMRESATTRS_PROCESS_PID]: process.pid,
41-
[SEMRESATTRS_PROCESS_EXECUTABLE_NAME]: process.title,
42-
[SEMRESATTRS_PROCESS_EXECUTABLE_PATH]: process.execPath,
43-
[SEMRESATTRS_PROCESS_COMMAND_ARGS]: [
40+
[ATTR_PROCESS_PID]: process.pid,
41+
[ATTR_PROCESS_EXECUTABLE_NAME]: process.title,
42+
[ATTR_PROCESS_EXECUTABLE_PATH]: process.execPath,
43+
[ATTR_PROCESS_COMMAND_ARGS]: [
4444
process.argv[0],
4545
...process.execArgv,
4646
...process.argv.slice(1),
4747
],
48-
[SEMRESATTRS_PROCESS_RUNTIME_VERSION]: process.versions.node,
49-
[SEMRESATTRS_PROCESS_RUNTIME_NAME]: 'nodejs',
50-
[SEMRESATTRS_PROCESS_RUNTIME_DESCRIPTION]: 'Node.js',
48+
[ATTR_PROCESS_RUNTIME_VERSION]: process.versions.node,
49+
[ATTR_PROCESS_RUNTIME_NAME]: 'nodejs',
50+
[ATTR_PROCESS_RUNTIME_DESCRIPTION]: 'Node.js',
5151
};
5252

5353
if (process.argv.length > 1) {
54-
attributes[SEMRESATTRS_PROCESS_COMMAND] = process.argv[1];
54+
attributes[ATTR_PROCESS_COMMAND] = process.argv[1];
5555
}
5656

5757
try {
5858
const userInfo = os.userInfo();
59-
attributes[SEMRESATTRS_PROCESS_OWNER] = userInfo.username;
59+
attributes[ATTR_PROCESS_OWNER] = userInfo.username;
6060
} catch (e) {
6161
diag.debug(`error obtaining process owner: ${e}`);
6262
}

packages/opentelemetry-resources/src/detectors/platform/node/ServiceInstanceIdDetector.ts

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

17-
import { SEMRESATTRS_SERVICE_INSTANCE_ID } from '@opentelemetry/semantic-conventions';
17+
import { ATTR_SERVICE_INSTANCE_ID } from '../../../semconv';
1818
import { randomUUID } from 'crypto';
1919
import { ResourceDetectionConfig } from '../../../config';
2020
import { DetectedResource, ResourceDetector } from '../../../types';
@@ -26,7 +26,7 @@ class ServiceInstanceIdDetector implements ResourceDetector {
2626
detect(_config?: ResourceDetectionConfig): DetectedResource {
2727
return {
2828
attributes: {
29-
[SEMRESATTRS_SERVICE_INSTANCE_ID]: randomUUID(),
29+
[ATTR_SERVICE_INSTANCE_ID]: randomUUID(),
3030
},
3131
};
3232
}
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* The CPU architecture the host system is running on.
19+
*
20+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
21+
*/
22+
export const ATTR_HOST_ARCH = 'host.arch' as const;
23+
/**
24+
* 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.
25+
*
26+
* @example fdbf79e8af94cb7f9e8df36789187052
27+
*
28+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
29+
*/
30+
export const ATTR_HOST_ID = 'host.id' as const;
31+
/**
32+
* 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.
33+
*
34+
* @example opentelemetry-test
35+
*
36+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
37+
*/
38+
export const ATTR_HOST_NAME = 'host.name' as const;
39+
/**
40+
* The operating system type.
41+
*
42+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
43+
*/
44+
export const ATTR_OS_TYPE = 'os.type' as const;
45+
/**
46+
* The version string of the operating system as defined in [Version Attributes](/docs/resource/README.md#version-attributes).
47+
*
48+
* @example 14.2.1
49+
* @example 18.04.1
50+
*
51+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
52+
*/
53+
export const ATTR_OS_VERSION = 'os.version' as const;
54+
/**
55+
* 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`.
56+
*
57+
* @example cmd/otelcol
58+
*
59+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
60+
*/
61+
export const ATTR_PROCESS_COMMAND = 'process.command' as const;
62+
/**
63+
* 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`.
64+
*
65+
* @example ["cmd/otecol", "--config=config.yaml"]
66+
*
67+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
68+
*/
69+
export const ATTR_PROCESS_COMMAND_ARGS = 'process.command_args' as const;
70+
/**
71+
* 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`.
72+
*
73+
* @example otelcol
74+
*
75+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
76+
*/
77+
export const ATTR_PROCESS_EXECUTABLE_NAME = 'process.executable.name' as const;
78+
/**
79+
* 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`.
80+
*
81+
* @example /usr/bin/cmd/otelcol
82+
*
83+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
84+
*/
85+
export const ATTR_PROCESS_EXECUTABLE_PATH = 'process.executable.path' as const;
86+
/**
87+
* The username of the user that owns the process.
88+
*
89+
* @example root
90+
*
91+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
92+
*/
93+
export const ATTR_PROCESS_OWNER = 'process.owner' as const;
94+
/**
95+
* Process identifier (PID).
96+
*
97+
* @example 1234
98+
*
99+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
100+
*/
101+
export const ATTR_PROCESS_PID = 'process.pid' as const;
102+
/**
103+
* An additional description about the runtime of the process, for example a specific vendor customization of the runtime environment.
104+
*
105+
* @example "Eclipse OpenJ9 Eclipse OpenJ9 VM openj9-0.21.0"
106+
*
107+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
108+
*/
109+
export const ATTR_PROCESS_RUNTIME_DESCRIPTION =
110+
'process.runtime.description' as const;
111+
/**
112+
* The name of the runtime of this process.
113+
*
114+
* @example OpenJDK Runtime Environment
115+
*
116+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
117+
*/
118+
export const ATTR_PROCESS_RUNTIME_NAME = 'process.runtime.name' as const;
119+
/**
120+
* The version of the runtime of this process, as returned by the runtime without modification.
121+
*
122+
* @example "14.0.2"
123+
*
124+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
125+
*/
126+
export const ATTR_PROCESS_RUNTIME_VERSION = 'process.runtime.version' as const;
127+
/**
128+
* The string ID of the service instance.
129+
*
130+
* @example 627cc493-f310-47de-96bd-71410b7dec09
131+
*
132+
* @note **MUST** be unique for each instance of the same `service.namespace,service.name` pair (in other words
133+
* `service.namespace,service.name,service.instance.id` triplet **MUST** be globally unique). The ID helps to
134+
* distinguish instances of the same service that exist at the same time (e.g. instances of a horizontally scaled
135+
* service).
136+
*
137+
* Implementations, such as SDKs, are recommended to generate a random Version 1 or Version 4 [RFC
138+
* 4122](https://www.ietf.org/rfc/rfc4122.txt) UUID, but are free to use an inherent unique ID as the source of
139+
* this value if stability is desirable. In that case, the ID **SHOULD** be used as source of a UUID Version 5 and
140+
* **SHOULD** use the following UUID as the namespace: `4d63009a-8d0f-11ee-aad7-4c796ed8e320`.
141+
*
142+
* UUIDs are typically recommended, as only an opaque value for the purposes of identifying a service instance is
143+
* needed. Similar to what can be seen in the man page for the
144+
* [`/etc/machine-id`](https://www.freedesktop.org/software/systemd/man/latest/machine-id.html) file, the underlying
145+
* data, such as pod name and namespace should be treated as confidential, being the user's choice to expose it
146+
* or not via another resource attribute.
147+
*
148+
* For applications running behind an application server (like unicorn), we do not recommend using one identifier
149+
* for all processes participating in the application. Instead, it's recommended each division (e.g. a worker
150+
* thread in unicorn) to have its own instance.id.
151+
*
152+
* It's not recommended for a Collector to set `service.instance.id` if it can't unambiguously determine the
153+
* service instance that is generating that telemetry. For instance, creating an UUID based on `pod.name` will
154+
* likely be wrong, as the Collector might not know from which container within that pod the telemetry originated.
155+
* However, Collectors can set the `service.instance.id` if they can unambiguously determine the service instance
156+
* for that telemetry. This is typically the case for scraping receivers, as they know the target address and
157+
* port.
158+
*
159+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
160+
*/
161+
export const ATTR_SERVICE_INSTANCE_ID = 'service.instance.id' as const;

0 commit comments

Comments
 (0)