Skip to content

Commit

Permalink
remove OTEL_NODE_EXPERIMENTAL_DEFAULT_SERVICE_INSTANCE_ID
Browse files Browse the repository at this point in the history
Signed-off-by: maryliag <[email protected]>
  • Loading branch information
maryliag committed Apr 15, 2024
1 parent 223bb95 commit 109f488
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 70 deletions.
5 changes: 1 addition & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/
* feat(sdk-trace-base): log resource attributes in ConsoleSpanExporter [#4605](https://github.com/open-telemetry/opentelemetry-js/pull/4605) @pichlermarc
* feat(resources): new experimental detector ServiceInstanceIdDetectorSync that sets the value for `service.instance.id` as random UUID.
* feat(resources): add usage for the detector ServiceInstanceIDDetector.
* The resource detector can be added to default resource detector list by
* setting the environment variable `OTEL_NODE_EXPERIMENTAL_DEFAULT_SERVICE_INSTANCE_ID` as `true`
* adding the value `serviceinstance` to the list of resource detectors on the environment variable `OTEL_NODE_RESOURCE_DETECTORS`, e.g `OTEL_NODE_RESOURCE_DETECTORS=env,host,os,serviceinstance`
* The resource detector can be added to default resource detector list by adding the value `serviceinstance` to the list of resource detectors on the environment variable `OTEL_NODE_RESOURCE_DETECTORS`, e.g `OTEL_NODE_RESOURCE_DETECTORS=env,host,os,serviceinstance`
* The value can be overwritten by
* merging a resource containing the `service.instance.id` attribute
* setting `service.instance.id` via the `OTEL_RESOURCE_ATTRIBUTES` environment variable when using `envDetector`
* using another resource detector which writes `service.instance.id`

### :bug: (Bug Fix)
Expand Down
4 changes: 0 additions & 4 deletions experimental/packages/opentelemetry-sdk-node/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import {
processDetector,
Resource,
ResourceDetectionConfig,
serviceInstanceIDDetector,
} from '@opentelemetry/resources';
import { LogRecordProcessor, LoggerProvider } from '@opentelemetry/sdk-logs';
import { MeterProvider, MetricReader, View } from '@opentelemetry/sdk-metrics';
Expand Down Expand Up @@ -130,9 +129,6 @@ export class NodeSDK {
defaultDetectors = getResourceDetectorsFromEnv();
} else {
defaultDetectors = [envDetector, processDetector, hostDetector];
if (env.OTEL_NODE_EXPERIMENTAL_DEFAULT_SERVICE_INSTANCE_ID) {
defaultDetectors.push(serviceInstanceIDDetector);
}
}

this._resourceDetectors =
Expand Down
12 changes: 4 additions & 8 deletions experimental/packages/opentelemetry-sdk-node/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ import {
InstrumentationOption,
} from '@opentelemetry/instrumentation';
import {
Detector,
DetectorSync,
envDetectorSync,
hostDetectorSync,
osDetectorSync,
processDetectorSync,
serviceInstanceIDDetectorSync,
serviceInstanceIDDetector,
} from '@opentelemetry/resources';

// TODO: This part of a workaround to fix https://github.com/open-telemetry/opentelemetry-js/issues/3609
Expand Down Expand Up @@ -58,15 +57,12 @@ const RESOURCE_DETECTOR_OS = 'os';
const RESOURCE_DETECTOR_PROCESS = 'process';
const RESOURCE_DETECTOR_SERVICE_INSTANCE_ID = 'serviceinstance';

export function getResourceDetectorsFromEnv(): Array<Detector | DetectorSync> {
const resourceDetectors = new Map<
string,
Detector | DetectorSync | Detector[]
>([
export function getResourceDetectorsFromEnv(): Array<DetectorSync> {
const resourceDetectors = new Map<string, DetectorSync>([
[RESOURCE_DETECTOR_ENVIRONMENT, envDetectorSync],
[RESOURCE_DETECTOR_HOST, hostDetectorSync],
[RESOURCE_DETECTOR_OS, osDetectorSync],
[RESOURCE_DETECTOR_SERVICE_INSTANCE_ID, serviceInstanceIDDetectorSync],
[RESOURCE_DETECTOR_SERVICE_INSTANCE_ID, serviceInstanceIDDetector],
[RESOURCE_DETECTOR_PROCESS, processDetectorSync],
]);

Expand Down
49 changes: 0 additions & 49 deletions experimental/packages/opentelemetry-sdk-node/test/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -728,55 +728,6 @@ describe('Node SDK', () => {
await resource.waitForAsyncAttributes?.();

assertServiceInstanceIDIsUUID(resource);
delete process.env.OTEL_NODE_EXPERIMENTAL_DEFAULT_SERVICE_INSTANCE_ID;
await sdk.shutdown();
});

it('should configure service instance id with random UUID with OTEL_NODE_EXPERIMENTAL_DEFAULT_SERVICE_INSTANCE_ID env var', async () => {
process.env.OTEL_NODE_EXPERIMENTAL_DEFAULT_SERVICE_INSTANCE_ID = 'true';
const sdk = new NodeSDK();

sdk.start();
const resource = sdk['_resource'];
await resource.waitForAsyncAttributes?.();

assertServiceInstanceIDIsUUID(resource);
delete process.env.OTEL_NODE_EXPERIMENTAL_DEFAULT_SERVICE_INSTANCE_ID;
await sdk.shutdown();
});

it('should configure service instance id via OTEL_RESOURCE_ATTRIBUTES env var even with OTEL_NODE_EXPERIMENTAL_DEFAULT_SERVICE_INSTANCE_ID env var', async () => {
process.env.OTEL_RESOURCE_ATTRIBUTES =
'service.instance.id=627cc493,service.name=my-service';
process.env.OTEL_NODE_EXPERIMENTAL_DEFAULT_SERVICE_INSTANCE_ID = 'true';
const sdk = new NodeSDK();

sdk.start();
const resource = sdk['_resource'];
await resource.waitForAsyncAttributes?.();

assertServiceResource(resource, {
name: 'my-service',
instanceId: '627cc493',
});
delete process.env.OTEL_RESOURCE_ATTRIBUTES;
delete process.env.OTEL_NODE_EXPERIMENTAL_DEFAULT_SERVICE_INSTANCE_ID;
sdk.shutdown();
});

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 () => {
process.env.OTEL_RESOURCE_ATTRIBUTES = 'service.name=my-service';
process.env.OTEL_NODE_EXPERIMENTAL_DEFAULT_SERVICE_INSTANCE_ID = 'false';
const sdk = new NodeSDK();

sdk.start();
const resource = sdk['_resource'];
await resource.waitForAsyncAttributes?.();

assertServiceResource(resource, {
name: 'my-service',
});
delete process.env.OTEL_RESOURCE_ATTRIBUTES;
await sdk.shutdown();
});
});
Expand Down
6 changes: 1 addition & 5 deletions packages/opentelemetry-core/src/utils/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ const DEFAULT_LIST_SEPARATOR = ',';
* Environment interface to define all names
*/

const ENVIRONMENT_BOOLEAN_KEYS = [
'OTEL_SDK_DISABLED',
'OTEL_NODE_EXPERIMENTAL_DEFAULT_SERVICE_INSTANCE_ID',
] as const;
const ENVIRONMENT_BOOLEAN_KEYS = ['OTEL_SDK_DISABLED'] as const;

type ENVIRONMENT_BOOLEANS = {
[K in (typeof ENVIRONMENT_BOOLEAN_KEYS)[number]]?: boolean;
Expand Down Expand Up @@ -241,7 +238,6 @@ export const DEFAULT_ENVIRONMENT: Required<ENVIRONMENT> = {
OTEL_EXPORTER_OTLP_METRICS_PROTOCOL: 'http/protobuf',
OTEL_EXPORTER_OTLP_LOGS_PROTOCOL: 'http/protobuf',
OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE: 'cumulative',
OTEL_NODE_EXPERIMENTAL_DEFAULT_SERVICE_INSTANCE_ID: false,
};

/**
Expand Down

0 comments on commit 109f488

Please sign in to comment.