-
Notifications
You must be signed in to change notification settings - Fork 804
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use resource detector for service instance id
use a resource detector for service instance id
- Loading branch information
Showing
9 changed files
with
92 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
packages/opentelemetry-resources/src/platform/node/ServiceInstanceIDDetector.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { Detector } from '../../types'; | ||
import { ResourceDetectionConfig } from '../../config'; | ||
import { IResource } from '../../IResource'; | ||
import { serviceInstanceIDDetectorSync } from '../browser/ServiceInstanceIDDetectorSync'; | ||
|
||
/** | ||
* ServiceInstanceIDDetector detects the resources related to the service instance ID. | ||
*/ | ||
class ServiceInstanceIDDetector implements Detector { | ||
detect(_config?: ResourceDetectionConfig): Promise<IResource> { | ||
return Promise.resolve(serviceInstanceIDDetectorSync.detect()); | ||
} | ||
} | ||
|
||
export const serviceInstanceIDDetector = new ServiceInstanceIDDetector(); |
37 changes: 37 additions & 0 deletions
37
packages/opentelemetry-resources/src/platform/node/ServiceInstanceIDDetectorSync.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { SEMRESATTRS_SERVICE_INSTANCE_ID } from '@opentelemetry/semantic-conventions'; | ||
import { Resource } from '../../Resource'; | ||
import { DetectorSync, ResourceAttributes } from '../../types'; | ||
import { ResourceDetectionConfig } from '../../config'; | ||
import { randomUUID } from 'crypto'; | ||
|
||
/** | ||
* ServiceInstanceIDDetectorSync detects the resources related to the service instance ID. | ||
*/ | ||
class ServiceInstanceIDDetectorSync implements DetectorSync { | ||
detect(_config?: ResourceDetectionConfig): Resource { | ||
const attributes: ResourceAttributes = { | ||
[SEMRESATTRS_SERVICE_INSTANCE_ID]: randomUUID(), | ||
}; | ||
|
||
return new Resource(attributes); | ||
} | ||
} | ||
|
||
export const serviceInstanceIDDetectorSync = | ||
new ServiceInstanceIDDetectorSync(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters