Skip to content

Commit 078777b

Browse files
authored
Merge branch 'main' into gcp-resource-detector-unit-test
2 parents 0017b71 + 19a2ad5 commit 078777b

File tree

15 files changed

+107
-52
lines changed

15 files changed

+107
-52
lines changed

detectors/node/opentelemetry-resource-detector-instana/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ sdk.start()
3838

3939
## Available detectors
4040

41-
This package uses `@opentelemetry/semantic-conventions` version `1.22+`, which implements Semantic Convention [Version 1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md)
41+
This package implements Semantic Convention v1.33.1.
4242

4343
### Instana Agent Detector
4444

detectors/node/opentelemetry-resource-detector-instana/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@
5353
},
5454
"dependencies": {
5555
"@opentelemetry/core": "^2.0.0",
56-
"@opentelemetry/resources": "^2.0.0",
57-
"@opentelemetry/semantic-conventions": "^1.27.0"
56+
"@opentelemetry/resources": "^2.0.0"
5857
},
5958
"peerDependencies": {
6059
"@opentelemetry/api": "^1.3.0"

detectors/node/opentelemetry-resource-detector-instana/src/detectors/InstanaAgentDetector.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ import {
2121
DetectedResource,
2222
DetectedResourceAttributes,
2323
} from '@opentelemetry/resources';
24-
import {
25-
SEMRESATTRS_PROCESS_PID,
26-
SEMRESATTRS_SERVICE_INSTANCE_ID,
27-
} from '@opentelemetry/semantic-conventions';
24+
import { ATTR_PROCESS_PID, ATTR_SERVICE_INSTANCE_ID } from '../semconv';
2825
import * as http from 'http';
2926

3027
class InstanaAgentDetector implements ResourceDetector {
@@ -36,10 +33,7 @@ class InstanaAgentDetector implements ResourceDetector {
3633
this._gatherData()
3734
);
3835

39-
const attrNames = [
40-
SEMRESATTRS_PROCESS_PID,
41-
SEMRESATTRS_SERVICE_INSTANCE_ID,
42-
];
36+
const attrNames = [ATTR_PROCESS_PID, ATTR_SERVICE_INSTANCE_ID];
4337

4438
const attributes = {} as DetectedResourceAttributes;
4539
attrNames.forEach(name => {
@@ -61,8 +55,8 @@ class InstanaAgentDetector implements ResourceDetector {
6155
const data = await this._retryHandler(host, port, 0);
6256

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

plugins/node/opentelemetry-instrumentation-connect/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ See [examples/connect](https://github.com/open-telemetry/opentelemetry-js-contri
5555

5656
## Semantic Conventions
5757

58-
This package uses `@opentelemetry/semantic-conventions` version `1.22+`, which implements Semantic Convention [Version 1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md)
58+
This package implements Semantic Convention v1.33.1.
5959

6060
Attributes collected:
6161

plugins/node/opentelemetry-instrumentation-connect/src/instrumentation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
InstrumentationNodeModuleDefinition,
3333
isWrapped,
3434
} from '@opentelemetry/instrumentation';
35-
import { SEMATTRS_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';
35+
import { ATTR_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';
3636
import {
3737
replaceCurrentStackRoute,
3838
addNewStackLayer,
@@ -101,7 +101,7 @@ export class ConnectInstrumentation extends InstrumentationBase {
101101
const spanName = `${connectTypeName} - ${connectName}`;
102102
const options: SpanOptions = {
103103
attributes: {
104-
[SEMATTRS_HTTP_ROUTE]: routeName.length > 0 ? routeName : '/',
104+
[ATTR_HTTP_ROUTE]: routeName.length > 0 ? routeName : '/',
105105
[AttributeNames.CONNECT_TYPE]: connectType,
106106
[AttributeNames.CONNECT_NAME]: connectName,
107107
},

plugins/node/opentelemetry-instrumentation-connect/test/instrumentation.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import * as assert from 'assert';
1717

1818
import { context, trace } from '@opentelemetry/api';
1919
import { RPCType, setRPCMetadata, RPCMetadata } from '@opentelemetry/core';
20-
import { SEMATTRS_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';
20+
import { ATTR_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';
2121
import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks';
2222
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
2323
import {
@@ -145,7 +145,7 @@ describe('connect', () => {
145145
assert.deepStrictEqual(span.attributes, {
146146
'connect.type': 'middleware',
147147
'connect.name': ANONYMOUS_NAME,
148-
[SEMATTRS_HTTP_ROUTE]: '/',
148+
[ATTR_HTTP_ROUTE]: '/',
149149
});
150150
assert.strictEqual(span.name, 'middleware - anonymous');
151151
});
@@ -164,7 +164,7 @@ describe('connect', () => {
164164
assert.deepStrictEqual(span.attributes, {
165165
'connect.type': 'middleware',
166166
'connect.name': 'middleware1',
167-
[SEMATTRS_HTTP_ROUTE]: '/',
167+
[ATTR_HTTP_ROUTE]: '/',
168168
});
169169
assert.strictEqual(span.name, 'middleware - middleware1');
170170
});
@@ -182,7 +182,7 @@ describe('connect', () => {
182182
assert.deepStrictEqual(span.attributes, {
183183
'connect.type': 'request_handler',
184184
'connect.name': '/foo',
185-
[SEMATTRS_HTTP_ROUTE]: '/foo',
185+
[ATTR_HTTP_ROUTE]: '/foo',
186186
});
187187
assert.strictEqual(span.name, 'request handler - /foo');
188188
});

plugins/node/opentelemetry-instrumentation-express/src/instrumentation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import {
4141
isWrapped,
4242
safeExecuteInTheMiddle,
4343
} from '@opentelemetry/instrumentation';
44-
import { SEMATTRS_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';
44+
import { ATTR_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';
4545
import {
4646
ExpressLayer,
4747
ExpressRouter,
@@ -195,7 +195,7 @@ export class ExpressInstrumentation extends InstrumentationBase<ExpressInstrumen
195195
.replace(/\/{2,}/g, '/');
196196

197197
const attributes: Attributes = {
198-
[SEMATTRS_HTTP_ROUTE]: route.length > 0 ? route : '/',
198+
[ATTR_HTTP_ROUTE]: route.length > 0 ? route : '/',
199199
};
200200
const metadata = getLayerMetadata(route, layer, layerPath);
201201
const type = metadata.attributes[

plugins/node/opentelemetry-instrumentation-express/test/custom-config.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
InMemorySpanExporter,
2222
SimpleSpanProcessor,
2323
} from '@opentelemetry/sdk-trace-base';
24-
import { SEMATTRS_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';
24+
import { ATTR_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';
2525
import * as assert from 'assert';
2626
import { RPCMetadata, RPCType, setRPCMetadata } from '@opentelemetry/core';
2727
import { ExpressLayerType } from '../src/enums/ExpressLayerType';
@@ -145,7 +145,7 @@ describe('ExpressInstrumentation', () => {
145145
.find(span => span.name.includes('request handler'));
146146
assert.notStrictEqual(requestHandlerSpan, undefined);
147147
assert.strictEqual(
148-
requestHandlerSpan?.attributes[SEMATTRS_HTTP_ROUTE],
148+
requestHandlerSpan?.attributes[ATTR_HTTP_ROUTE],
149149
'/mw'
150150
);
151151

@@ -196,7 +196,7 @@ describe('ExpressInstrumentation', () => {
196196
.find(span => span.name.includes('request handler'));
197197
assert.notStrictEqual(requestHandlerSpan, undefined);
198198
assert.strictEqual(
199-
requestHandlerSpan?.attributes[SEMATTRS_HTTP_ROUTE],
199+
requestHandlerSpan?.attributes[ATTR_HTTP_ROUTE],
200200
'/'
201201
);
202202

plugins/node/opentelemetry-instrumentation-express/test/express.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import * as semver from 'semver';
2626
import { AttributeNames } from '../src/enums/AttributeNames';
2727
import { ExpressInstrumentation } from '../src';
2828
import { createServer, httpRequest, serverWithMiddleware } from './utils';
29-
import { SEMATTRS_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';
29+
import { ATTR_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';
3030
import * as testUtils from '@opentelemetry/contrib-test-utils';
3131

3232
const instrumentation = new ExpressInstrumentation();
@@ -119,7 +119,7 @@ describe('ExpressInstrumentation', () => {
119119
.find(span => span.name.includes('request handler'));
120120
assert.notStrictEqual(requestHandlerSpan, undefined);
121121
assert.strictEqual(
122-
requestHandlerSpan?.attributes[SEMATTRS_HTTP_ROUTE],
122+
requestHandlerSpan?.attributes[ATTR_HTTP_ROUTE],
123123
'/toto/:id'
124124
);
125125
assert.strictEqual(
@@ -486,7 +486,7 @@ describe('ExpressInstrumentation', () => {
486486
.getFinishedSpans()
487487
.find(span => span.name.includes('request handler'));
488488
assert.strictEqual(
489-
requestHandlerSpan?.attributes[SEMATTRS_HTTP_ROUTE],
489+
requestHandlerSpan?.attributes[ATTR_HTTP_ROUTE],
490490
'/double-slashes/:id'
491491
);
492492
assert.strictEqual(rpcMetadata?.route, '/double-slashes/:id');

0 commit comments

Comments
 (0)