Skip to content

Commit 0665c85

Browse files
authored
refactor(sdk-node): update semconv usage to ATTR_ exports (#5668)
1 parent d07d630 commit 0665c85

File tree

4 files changed

+99
-324
lines changed

4 files changed

+99
-324
lines changed

experimental/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ For notes on migrating to 2.x / 0.200.x see [the upgrade guide](doc/upgrade-to-2
2929

3030
### :house: Internal
3131

32+
* refactor(sdk-node): update semconv usage to `ATTR_` exports [#5668](https://github.com/open-telemetry/opentelemetry-js/pull/5668) @trentm
3233
* chore(sdk-node): Refactored using `get*FromEnv` utility function instead of `process.env` for NodeSDK's resource detector setup. [#5582](https://github.com/open-telemetry/opentelemetry-js/pull/5582) @beeme1mr
3334
* chore(sdk-node): Refactored using `get*FromEnv` utility function instead of `process.env` for NodeSDK's logging setup. [#5563](https://github.com/open-telemetry/opentelemetry-js/issues/5563) @weyert
3435

experimental/packages/opentelemetry-sdk-node/test/sdk.test.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,10 @@ import { OTLPLogExporter as OTLPHttpLogExporter } from '@opentelemetry/exporter-
8282
import { OTLPLogExporter as OTLPGrpcLogExporter } from '@opentelemetry/exporter-logs-otlp-grpc';
8383
import { OTLPTraceExporter as OTLPProtoTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';
8484
import { OTLPTraceExporter as OTLPGrpcTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc';
85-
import {
86-
SEMRESATTRS_HOST_NAME,
87-
SEMRESATTRS_PROCESS_PID,
88-
} from '@opentelemetry/semantic-conventions';
8985
import { ZipkinExporter } from '@opentelemetry/exporter-zipkin';
9086

87+
import { ATTR_HOST_NAME, ATTR_PROCESS_PID } from './semconv';
88+
9189
describe('Node SDK', () => {
9290
let ctxManager: any;
9391
let propagator: any;
@@ -580,11 +578,8 @@ describe('Node SDK', () => {
580578
version: '0.0.1',
581579
});
582580

583-
assert.notEqual(
584-
resource.attributes[SEMRESATTRS_PROCESS_PID],
585-
undefined
586-
);
587-
assert.notEqual(resource.attributes[SEMRESATTRS_HOST_NAME], undefined);
581+
assert.notEqual(resource.attributes[ATTR_PROCESS_PID], undefined);
582+
assert.notEqual(resource.attributes[ATTR_HOST_NAME], undefined);
588583
});
589584
});
590585

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
* This file contains a copy of unstable semantic convention definitions
19+
* used by this package.
20+
* @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv
21+
*/
22+
23+
/**
24+
* 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.
25+
*
26+
* @example opentelemetry-test
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_NAME = 'host.name' as const;
31+
32+
/**
33+
* Process identifier (PID).
34+
*
35+
* @example 1234
36+
*
37+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
38+
*/
39+
export const ATTR_PROCESS_PID = 'process.pid' as const;
40+
41+
/**
42+
* The string ID of the service instance.
43+
*
44+
* @example 627cc493-f310-47de-96bd-71410b7dec09
45+
*
46+
* @note **MUST** be unique for each instance of the same `service.namespace,service.name` pair (in other words
47+
* `service.namespace,service.name,service.instance.id` triplet **MUST** be globally unique). The ID helps to
48+
* distinguish instances of the same service that exist at the same time (e.g. instances of a horizontally scaled
49+
* service).
50+
*
51+
* Implementations, such as SDKs, are recommended to generate a random Version 1 or Version 4 [RFC
52+
* 4122](https://www.ietf.org/rfc/rfc4122.txt) UUID, but are free to use an inherent unique ID as the source of
53+
* this value if stability is desirable. In that case, the ID **SHOULD** be used as source of a UUID Version 5 and
54+
* **SHOULD** use the following UUID as the namespace: `4d63009a-8d0f-11ee-aad7-4c796ed8e320`.
55+
*
56+
* UUIDs are typically recommended, as only an opaque value for the purposes of identifying a service instance is
57+
* needed. Similar to what can be seen in the man page for the
58+
* [`/etc/machine-id`](https://www.freedesktop.org/software/systemd/man/latest/machine-id.html) file, the underlying
59+
* data, such as pod name and namespace should be treated as confidential, being the user's choice to expose it
60+
* or not via another resource attribute.
61+
*
62+
* For applications running behind an application server (like unicorn), we do not recommend using one identifier
63+
* for all processes participating in the application. Instead, it's recommended each division (e.g. a worker
64+
* thread in unicorn) to have its own instance.id.
65+
*
66+
* It's not recommended for a Collector to set `service.instance.id` if it can't unambiguously determine the
67+
* service instance that is generating that telemetry. For instance, creating an UUID based on `pod.name` will
68+
* likely be wrong, as the Collector might not know from which container within that pod the telemetry originated.
69+
* However, Collectors can set the `service.instance.id` if they can unambiguously determine the service instance
70+
* for that telemetry. This is typically the case for scraping receivers, as they know the target address and
71+
* port.
72+
*
73+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
74+
*/
75+
export const ATTR_SERVICE_INSTANCE_ID = 'service.instance.id' as const;
76+
77+
/**
78+
* A namespace for `service.name`.
79+
*
80+
* @example Shop
81+
*
82+
* @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.
83+
*
84+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
85+
*/
86+
export const ATTR_SERVICE_NAMESPACE = 'service.namespace' as const;

0 commit comments

Comments
 (0)