Skip to content

Commit

Permalink
feat(auto-instrumentation-node): add options for serviceinstance
Browse files Browse the repository at this point in the history
Signed-off-by: maryliag <[email protected]>
  • Loading branch information
maryliag committed Apr 26, 2024
1 parent 7822461 commit 97a16cd
Show file tree
Hide file tree
Showing 5 changed files with 574 additions and 6 deletions.
3 changes: 2 additions & 1 deletion metapackages/auto-instrumentations-node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT="https://your-endpoint"
export OTEL_EXPORTER_OTLP_HEADERS="x-api-key=your-api-key"
export OTEL_EXPORTER_OTLP_TRACES_HEADERS="x-api-key=your-api-key"
export OTEL_RESOURCE_ATTRIBUTES="service.namespace=my-namespace"
export OTEL_NODE_RESOURCE_DETECTORS="env,host,os"
export OTEL_NODE_RESOURCE_DETECTORS="env,host,os,serviceinstace"
export OTEL_SERVICE_NAME="client"
export NODE_OPTIONS="--require @opentelemetry/auto-instrumentations-node/register"
node app.js
Expand All @@ -62,6 +62,7 @@ By default, all SDK resource detectors are used, but you can use the environment
- `host`
- `os`
- `process`
- `serviceinstance`
- `container`
- `alibaba`
- `aws`
Expand Down
2 changes: 1 addition & 1 deletion metapackages/auto-instrumentations-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"@opentelemetry/resource-detector-aws": "^1.4.2",
"@opentelemetry/resource-detector-container": "^0.3.9",
"@opentelemetry/resource-detector-gcp": "^0.29.9",
"@opentelemetry/resources": "^1.12.0",
"@opentelemetry/resources": "^1.24.0",
"@opentelemetry/sdk-node": "^0.51.0"
},
"files": [
Expand Down
3 changes: 3 additions & 0 deletions metapackages/auto-instrumentations-node/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@ import {
hostDetectorSync,
osDetectorSync,
processDetectorSync,
serviceInstanceIdDetectorSync,
} from '@opentelemetry/resources';

const RESOURCE_DETECTOR_CONTAINER = 'container';
const RESOURCE_DETECTOR_ENVIRONMENT = 'env';
const RESOURCE_DETECTOR_HOST = 'host';
const RESOURCE_DETECTOR_OS = 'os';
const RESOURCE_DETECTOR_SERVICE_INSTANCE_ID = 'serviceinstance';
const RESOURCE_DETECTOR_PROCESS = 'process';
const RESOURCE_DETECTOR_ALIBABA = 'alibaba';
const RESOURCE_DETECTOR_AWS = 'aws';
Expand Down Expand Up @@ -202,6 +204,7 @@ export function getResourceDetectorsFromEnv(): Array<Detector | DetectorSync> {
[RESOURCE_DETECTOR_ENVIRONMENT, envDetectorSync],
[RESOURCE_DETECTOR_HOST, hostDetectorSync],
[RESOURCE_DETECTOR_OS, osDetectorSync],
[RESOURCE_DETECTOR_SERVICE_INSTANCE_ID, serviceInstanceIdDetectorSync],
[RESOURCE_DETECTOR_PROCESS, processDetectorSync],
[RESOURCE_DETECTOR_ALIBABA, alibabaCloudEcsDetector],
[RESOURCE_DETECTOR_GCP, gcpDetector],
Expand Down
8 changes: 6 additions & 2 deletions metapackages/auto-instrumentations-node/test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,17 @@ describe('utils', () => {
});

it('should return specific resource detectors depending on OTEL_NODE_RESOURCE_DETECTORS', () => {
process.env.OTEL_NODE_RESOURCE_DETECTORS = 'env,host';
process.env.OTEL_NODE_RESOURCE_DETECTORS = 'env,host,serviceinstance';

const resourceDetectors = getResourceDetectorsFromEnv();

assert.equal(resourceDetectors.length, 2);
assert.equal(resourceDetectors.length, 3);
assert.equal(resourceDetectors[0].constructor.name, 'EnvDetectorSync');
assert.equal(resourceDetectors[1].constructor.name, 'HostDetectorSync');
assert.equal(
resourceDetectors[2].constructor.name,
'ServiceInstanceIDDetectorSync'
);

delete process.env.OTEL_NODE_RESOURCE_DETECTORS;
});
Expand Down
Loading

0 comments on commit 97a16cd

Please sign in to comment.