Skip to content

Commit 670d528

Browse files
committed
remove references to env variables
1 parent 19c7189 commit 670d528

File tree

4 files changed

+18
-60
lines changed

4 files changed

+18
-60
lines changed

CHANGELOG.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/
1212
### :rocket: (Enhancement)
1313

1414
* feat(sdk-trace-base): log resource attributes in ConsoleSpanExporter [#4605](https://github.com/open-telemetry/opentelemetry-js/pull/4605) @pichlermarc
15-
* feat(resources): set value for `service.instance.id` as random UUID by default if environment variable `OTEL_NODE_EXPERIMENTAL_DEFAULT_SERVICE_INSTANCE_ID` is set to true.
16-
* The value can be overwritten by
17-
* merging a resource containing the `service.instance.id` attribute
18-
* setting `service.instance.id` via the `OTEL_RESOURCE_ATTRIBUTES` environment variable when using `envDetector`
19-
* using another resource detector which writes `service.instance.id`
15+
* feat(resources): new detector ServiceInstanceIDDetector that sets the value for `service.instance.id` as random UUID.
2016

2117
### :bug: (Bug Fix)
2218

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

+5-8
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import {
3636
processDetector,
3737
Resource,
3838
ResourceDetectionConfig,
39-
serviceInstanceIDDetector,
4039
} from '@opentelemetry/resources';
4140
import { LogRecordProcessor, LoggerProvider } from '@opentelemetry/sdk-logs';
4241
import { MeterProvider, MetricReader, View } from '@opentelemetry/sdk-metrics';
@@ -122,13 +121,11 @@ export class NodeSDK {
122121
this._configuration = configuration;
123122

124123
this._resource = configuration.resource ?? new Resource({});
125-
const defaultDetectors = [envDetector, processDetector, hostDetector];
126-
127-
if (env.OTEL_NODE_EXPERIMENTAL_DEFAULT_SERVICE_INSTANCE_ID) {
128-
defaultDetectors.push(serviceInstanceIDDetector);
129-
}
130-
this._resourceDetectors =
131-
configuration.resourceDetectors ?? defaultDetectors;
124+
this._resourceDetectors = configuration.resourceDetectors ?? [
125+
envDetector,
126+
processDetector,
127+
hostDetector,
128+
];
132129

133130
this._serviceName = configuration.serviceName;
134131

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

+11-42
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import {
5959
processDetector,
6060
hostDetector,
6161
Resource,
62+
serviceInstanceIDDetector,
6263
} from '@opentelemetry/resources';
6364
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
6465
import { logs } from '@opentelemetry/api-logs';
@@ -696,10 +697,16 @@ describe('Node SDK', () => {
696697
sdk.shutdown();
697698
});
698699

699-
it('should configure service instance id with random UUID with OTEL_NODE_EXPERIMENTAL_DEFAULT_SERVICE_INSTANCE_ID env var', async () => {
700-
process.env.OTEL_RESOURCE_ATTRIBUTES = 'service.name=my-service';
701-
process.env.OTEL_NODE_EXPERIMENTAL_DEFAULT_SERVICE_INSTANCE_ID = 'true';
702-
const sdk = new NodeSDK();
700+
it('should configure service instance id with random UUID', async () => {
701+
const sdk = new NodeSDK({
702+
autoDetectResources: true,
703+
resourceDetectors: [
704+
processDetector,
705+
envDetector,
706+
hostDetector,
707+
serviceInstanceIDDetector,
708+
],
709+
});
703710

704711
sdk.start();
705712
const resource = sdk['_resource'];
@@ -713,44 +720,6 @@ describe('Node SDK', () => {
713720
),
714721
true
715722
);
716-
717-
delete process.env.OTEL_RESOURCE_ATTRIBUTES;
718-
delete process.env.OTEL_NODE_EXPERIMENTAL_DEFAULT_SERVICE_INSTANCE_ID;
719-
await sdk.shutdown();
720-
});
721-
722-
it('should configure service instance id via OTEL_RESOURCE_ATTRIBUTES env var even with OTEL_NODE_EXPERIMENTAL_DEFAULT_SERVICE_INSTANCE_ID env var', async () => {
723-
process.env.OTEL_RESOURCE_ATTRIBUTES =
724-
'service.instance.id=627cc493,service.name=my-service';
725-
process.env.OTEL_NODE_EXPERIMENTAL_DEFAULT_SERVICE_INSTANCE_ID = 'true';
726-
const sdk = new NodeSDK();
727-
728-
sdk.start();
729-
const resource = sdk['_resource'];
730-
await resource.waitForAsyncAttributes?.();
731-
732-
assertServiceResource(resource, {
733-
name: 'my-service',
734-
instanceId: '627cc493',
735-
});
736-
delete process.env.OTEL_RESOURCE_ATTRIBUTES;
737-
delete process.env.OTEL_NODE_EXPERIMENTAL_DEFAULT_SERVICE_INSTANCE_ID;
738-
sdk.shutdown();
739-
});
740-
741-
it('should not configure service instance id with no value for it on OTEL_RESOURCE_ATTRIBUTES env var and OTEL_NODE_EXPERIMENTAL_DEFAULT_SERVICE_INSTANCE_ID env var as false', async () => {
742-
process.env.OTEL_RESOURCE_ATTRIBUTES = 'service.name=my-service';
743-
process.env.OTEL_NODE_EXPERIMENTAL_DEFAULT_SERVICE_INSTANCE_ID = 'false';
744-
const sdk = new NodeSDK();
745-
746-
sdk.start();
747-
const resource = sdk['_resource'];
748-
await resource.waitForAsyncAttributes?.();
749-
750-
assertServiceResource(resource, {
751-
name: 'my-service',
752-
});
753-
delete process.env.OTEL_RESOURCE_ATTRIBUTES;
754723
await sdk.shutdown();
755724
});
756725
});

packages/opentelemetry-core/src/utils/environment.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ const DEFAULT_LIST_SEPARATOR = ',';
2424
* Environment interface to define all names
2525
*/
2626

27-
const ENVIRONMENT_BOOLEAN_KEYS = [
28-
'OTEL_SDK_DISABLED',
29-
'OTEL_NODE_EXPERIMENTAL_DEFAULT_SERVICE_INSTANCE_ID',
30-
] as const;
27+
const ENVIRONMENT_BOOLEAN_KEYS = ['OTEL_SDK_DISABLED'] as const;
3128

3229
type ENVIRONMENT_BOOLEANS = {
3330
[K in (typeof ENVIRONMENT_BOOLEAN_KEYS)[number]]?: boolean;
@@ -239,7 +236,6 @@ export const DEFAULT_ENVIRONMENT: Required<ENVIRONMENT> = {
239236
OTEL_EXPORTER_OTLP_METRICS_PROTOCOL: 'http/protobuf',
240237
OTEL_EXPORTER_OTLP_LOGS_PROTOCOL: 'http/protobuf',
241238
OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE: 'cumulative',
242-
OTEL_NODE_EXPERIMENTAL_DEFAULT_SERVICE_INSTANCE_ID: false,
243239
};
244240

245241
/**

0 commit comments

Comments
 (0)