diff --git a/backwards-compatability/node10/tsconfig.json b/backwards-compatability/node10/tsconfig.json index b5317ec3ef..557ca62042 100644 --- a/backwards-compatability/node10/tsconfig.json +++ b/backwards-compatability/node10/tsconfig.json @@ -8,9 +8,6 @@ "index.ts" ], "references": [ - { - "path": "../../packages/opentelemetry-sdk-node" - }, { "path": "../../packages/opentelemetry-sdk-trace-base" } diff --git a/backwards-compatability/node12/tsconfig.json b/backwards-compatability/node12/tsconfig.json index b5317ec3ef..557ca62042 100644 --- a/backwards-compatability/node12/tsconfig.json +++ b/backwards-compatability/node12/tsconfig.json @@ -8,9 +8,6 @@ "index.ts" ], "references": [ - { - "path": "../../packages/opentelemetry-sdk-node" - }, { "path": "../../packages/opentelemetry-sdk-trace-base" } diff --git a/backwards-compatability/node8/tsconfig.json b/backwards-compatability/node8/tsconfig.json index b5317ec3ef..557ca62042 100644 --- a/backwards-compatability/node8/tsconfig.json +++ b/backwards-compatability/node8/tsconfig.json @@ -8,9 +8,6 @@ "index.ts" ], "references": [ - { - "path": "../../packages/opentelemetry-sdk-node" - }, { "path": "../../packages/opentelemetry-sdk-trace-base" } diff --git a/packages/opentelemetry-sdk-node/.eslintignore b/experimental/packages/opentelemetry-sdk-node/.eslintignore similarity index 100% rename from packages/opentelemetry-sdk-node/.eslintignore rename to experimental/packages/opentelemetry-sdk-node/.eslintignore diff --git a/packages/opentelemetry-sdk-node/.eslintrc.js b/experimental/packages/opentelemetry-sdk-node/.eslintrc.js similarity index 65% rename from packages/opentelemetry-sdk-node/.eslintrc.js rename to experimental/packages/opentelemetry-sdk-node/.eslintrc.js index f726f3becb..f756f4488b 100644 --- a/packages/opentelemetry-sdk-node/.eslintrc.js +++ b/experimental/packages/opentelemetry-sdk-node/.eslintrc.js @@ -3,5 +3,5 @@ module.exports = { "mocha": true, "node": true }, - ...require('../../eslint.config.js') + ...require('../../../eslint.config.js') } diff --git a/packages/opentelemetry-sdk-node/LICENSE b/experimental/packages/opentelemetry-sdk-node/LICENSE similarity index 100% rename from packages/opentelemetry-sdk-node/LICENSE rename to experimental/packages/opentelemetry-sdk-node/LICENSE diff --git a/packages/opentelemetry-sdk-node/README.md b/experimental/packages/opentelemetry-sdk-node/README.md similarity index 100% rename from packages/opentelemetry-sdk-node/README.md rename to experimental/packages/opentelemetry-sdk-node/README.md diff --git a/packages/opentelemetry-sdk-node/package.json b/experimental/packages/opentelemetry-sdk-node/package.json similarity index 97% rename from packages/opentelemetry-sdk-node/package.json rename to experimental/packages/opentelemetry-sdk-node/package.json index 6aff110494..c4a18e84ac 100644 --- a/packages/opentelemetry-sdk-node/package.json +++ b/experimental/packages/opentelemetry-sdk-node/package.json @@ -12,7 +12,7 @@ "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", "lint": "eslint . --ext .ts", "lint:fix": "eslint . --ext .ts --fix", - "version": "node ../../scripts/version-update.js", + "version": "node ../../../scripts/version-update.js", "watch": "tsc --build --watch", "precompile": "lerna run version --scope $(npm pkg get name) --include-filtered-dependencies", "prewatch": "npm run precompile" diff --git a/packages/opentelemetry-sdk-node/src/index.ts b/experimental/packages/opentelemetry-sdk-node/src/index.ts similarity index 100% rename from packages/opentelemetry-sdk-node/src/index.ts rename to experimental/packages/opentelemetry-sdk-node/src/index.ts diff --git a/packages/opentelemetry-sdk-node/src/sdk.ts b/experimental/packages/opentelemetry-sdk-node/src/sdk.ts similarity index 100% rename from packages/opentelemetry-sdk-node/src/sdk.ts rename to experimental/packages/opentelemetry-sdk-node/src/sdk.ts diff --git a/packages/opentelemetry-sdk-node/src/types.ts b/experimental/packages/opentelemetry-sdk-node/src/types.ts similarity index 100% rename from packages/opentelemetry-sdk-node/src/types.ts rename to experimental/packages/opentelemetry-sdk-node/src/types.ts diff --git a/packages/opentelemetry-sdk-node/test/sdk.test.ts b/experimental/packages/opentelemetry-sdk-node/test/sdk.test.ts similarity index 99% rename from packages/opentelemetry-sdk-node/test/sdk.test.ts rename to experimental/packages/opentelemetry-sdk-node/test/sdk.test.ts index 6584f5f870..5b593cba4c 100644 --- a/packages/opentelemetry-sdk-node/test/sdk.test.ts +++ b/experimental/packages/opentelemetry-sdk-node/test/sdk.test.ts @@ -37,7 +37,7 @@ import { assertCloudResource, assertHostResource, assertServiceResource, -} from '@opentelemetry/resources/build/test/util/resource-assertions'; +} from './util/resource-assertions'; import { ConsoleSpanExporter, SimpleSpanProcessor, diff --git a/experimental/packages/opentelemetry-sdk-node/test/util/resource-assertions.ts b/experimental/packages/opentelemetry-sdk-node/test/util/resource-assertions.ts new file mode 100644 index 0000000000..206c9bcf86 --- /dev/null +++ b/experimental/packages/opentelemetry-sdk-node/test/util/resource-assertions.ts @@ -0,0 +1,328 @@ +/* + * 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 { SDK_INFO } from '@opentelemetry/core'; +import * as assert from 'assert'; +import { Resource } from '@opentelemetry/resources'; +import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'; + +/** + * Test utility method to validate a cloud resource + * + * @param resource the Resource to validate + * @param validations validations for the resource attributes + */ +export const assertCloudResource = ( + resource: Resource, + validations: { + provider?: string; + accountId?: string; + region?: string; + zone?: string; + } +) => { + assertHasOneLabel('CLOUD', resource); + if (validations.provider) + assert.strictEqual( + resource.attributes[SemanticResourceAttributes.CLOUD_PROVIDER], + validations.provider + ); + if (validations.accountId) + assert.strictEqual( + resource.attributes[SemanticResourceAttributes.CLOUD_ACCOUNT_ID], + validations.accountId + ); + if (validations.region) + assert.strictEqual( + resource.attributes[SemanticResourceAttributes.CLOUD_REGION], + validations.region + ); + if (validations.zone) + assert.strictEqual( + resource.attributes[SemanticResourceAttributes.CLOUD_AVAILABILITY_ZONE], + validations.zone + ); +}; + +/** + * Test utility method to validate a container resource + * + * @param resource the Resource to validate + * @param validations validations for the resource attributes + */ +export const assertContainerResource = ( + resource: Resource, + validations: { + name?: string; + id?: string; + imageName?: string; + imageTag?: string; + } +) => { + assertHasOneLabel('CONTAINER', resource); + if (validations.name) + assert.strictEqual( + resource.attributes[SemanticResourceAttributes.CONTAINER_NAME], + validations.name + ); + if (validations.id) + assert.strictEqual( + resource.attributes[SemanticResourceAttributes.CONTAINER_ID], + validations.id + ); + if (validations.imageName) + assert.strictEqual( + resource.attributes[SemanticResourceAttributes.CONTAINER_IMAGE_NAME], + validations.imageName + ); + if (validations.imageTag) + assert.strictEqual( + resource.attributes[SemanticResourceAttributes.CONTAINER_IMAGE_TAG], + validations.imageTag + ); +}; + +/** + * Test utility method to validate a host resource + * + * @param resource the Resource to validate + * @param validations validations for the resource attributes + */ +export const assertHostResource = ( + resource: Resource, + validations: { + hostName?: string; + id?: string; + name?: string; + hostType?: string; + imageName?: string; + imageId?: string; + imageVersion?: string; + } +) => { + assertHasOneLabel('HOST', resource); + if (validations.id) + assert.strictEqual( + resource.attributes[SemanticResourceAttributes.HOST_ID], + validations.id + ); + if (validations.name) + assert.strictEqual( + resource.attributes[SemanticResourceAttributes.HOST_NAME], + validations.name + ); + if (validations.hostType) + assert.strictEqual( + resource.attributes[SemanticResourceAttributes.HOST_TYPE], + validations.hostType + ); + if (validations.imageName) + assert.strictEqual( + resource.attributes[SemanticResourceAttributes.HOST_IMAGE_NAME], + validations.imageName + ); + if (validations.imageId) + assert.strictEqual( + resource.attributes[SemanticResourceAttributes.HOST_IMAGE_ID], + validations.imageId + ); + if (validations.imageVersion) + assert.strictEqual( + resource.attributes[SemanticResourceAttributes.HOST_IMAGE_VERSION], + validations.imageVersion + ); +}; + +/** + * Test utility method to validate a K8s resource + * + * @param resource the Resource to validate + * @param validations validations for the resource attributes + */ +export const assertK8sResource = ( + resource: Resource, + validations: { + clusterName?: string; + namespaceName?: string; + podName?: string; + deploymentName?: string; + } +) => { + assertHasOneLabel('K8S', resource); + if (validations.clusterName) + assert.strictEqual( + resource.attributes[SemanticResourceAttributes.K8S_CLUSTER_NAME], + validations.clusterName + ); + if (validations.namespaceName) + assert.strictEqual( + resource.attributes[SemanticResourceAttributes.K8S_NAMESPACE_NAME], + validations.namespaceName + ); + if (validations.podName) + assert.strictEqual( + resource.attributes[SemanticResourceAttributes.K8S_POD_NAME], + validations.podName + ); + if (validations.deploymentName) + assert.strictEqual( + resource.attributes[SemanticResourceAttributes.K8S_DEPLOYMENT_NAME], + validations.deploymentName + ); +}; + +/** + * Test utility method to validate a telemetry sdk resource + * + * @param resource the Resource to validate + * @param validations validations for the resource attributes + */ +export const assertTelemetrySDKResource = ( + resource: Resource, + validations: { + name?: string; + language?: string; + version?: string; + } +) => { + const defaults = { + name: SDK_INFO.NAME, + language: SDK_INFO.LANGUAGE, + version: SDK_INFO.VERSION, + }; + validations = { ...defaults, ...validations }; + + if (validations.name) + assert.strictEqual( + resource.attributes[SemanticResourceAttributes.TELEMETRY_SDK_NAME], + validations.name + ); + if (validations.language) + assert.strictEqual( + resource.attributes[SemanticResourceAttributes.TELEMETRY_SDK_LANGUAGE], + validations.language + ); + if (validations.version) + assert.strictEqual( + resource.attributes[SemanticResourceAttributes.TELEMETRY_SDK_VERSION], + validations.version + ); +}; + +/** + * Test utility method to validate a service resource + * + * @param resource the Resource to validate + * @param validations validations for the resource attributes + */ +export const assertServiceResource = ( + resource: Resource, + validations: { + name: string; + instanceId: string; + namespace?: string; + version?: string; + } +) => { + assert.strictEqual( + resource.attributes[SemanticResourceAttributes.SERVICE_NAME], + validations.name + ); + assert.strictEqual( + resource.attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID], + validations.instanceId + ); + if (validations.namespace) + assert.strictEqual( + resource.attributes[SemanticResourceAttributes.SERVICE_NAMESPACE], + validations.namespace + ); + if (validations.version) + assert.strictEqual( + resource.attributes[SemanticResourceAttributes.SERVICE_VERSION], + validations.version + ); +}; + +/** + * Test utility method to validate a process resources + * + * @param resource the Resource to validate + * @param validations validations for the resource attributes + */ +export const assertProcessResource = ( + resource: Resource, + validations: { + pid?: number; + name?: string; + command?: string; + commandLine?: string; + } +) => { + assert.strictEqual( + resource.attributes[SemanticResourceAttributes.PROCESS_PID], + validations.pid + ); + if (validations.name) { + assert.strictEqual( + resource.attributes[SemanticResourceAttributes.PROCESS_EXECUTABLE_NAME], + validations.name + ); + } + if (validations.command) { + assert.strictEqual( + resource.attributes[SemanticResourceAttributes.PROCESS_COMMAND], + validations.command + ); + } + if (validations.commandLine) { + assert.strictEqual( + resource.attributes[SemanticResourceAttributes.PROCESS_COMMAND_LINE], + validations.commandLine + ); + } +}; + +/** + * Test utility method to validate an empty resource + * + * @param resource the Resource to validate + */ +export const assertEmptyResource = (resource: Resource) => { + assert.strictEqual(Object.keys(resource.attributes).length, 0); +}; + +const assertHasOneLabel = (prefix: string, resource: Resource): void => { + const hasOne = Object.entries(SemanticResourceAttributes).find(([key, value]) => { + return ( + key.startsWith(prefix) && + Object.prototype.hasOwnProperty.call(resource.attributes, value) + ); + }); + + assert.ok( + hasOne, + 'Resource must have one of the following attributes: ' + + Object.entries(SemanticResourceAttributes) + .reduce((result, [key, value]) => { + if (key.startsWith(prefix)) { + result.push(value); + } + return result; + }) + .join(', ') + ); +}; diff --git a/experimental/packages/opentelemetry-sdk-node/tsconfig.json b/experimental/packages/opentelemetry-sdk-node/tsconfig.json new file mode 100644 index 0000000000..36c71e90d8 --- /dev/null +++ b/experimental/packages/opentelemetry-sdk-node/tsconfig.json @@ -0,0 +1,22 @@ +{ + "extends": "../../../tsconfig.base.json", + "compilerOptions": { + "rootDir": ".", + "outDir": "build" + }, + "include": [ + "src/**/*.ts", + "test/**/*.ts" + ], + "references": [ + { + "path": "../opentelemetry-api-metrics" + }, + { + "path": "../opentelemetry-instrumentation" + }, + { + "path": "../opentelemetry-sdk-metrics-base" + } + ] +} diff --git a/experimental/tsconfig.esm.json b/experimental/tsconfig.esm.json index f8c358faae..cd3052ad27 100644 --- a/experimental/tsconfig.esm.json +++ b/experimental/tsconfig.esm.json @@ -22,6 +22,9 @@ }, { "path": "packages/opentelemetry-sdk-metrics-base/tsconfig.esm.json" + }, + { + "path": "packages/opentelemetry-sdk-node" } ] } diff --git a/experimental/tsconfig.json b/experimental/tsconfig.json index f92274f504..a4220672a8 100644 --- a/experimental/tsconfig.json +++ b/experimental/tsconfig.json @@ -22,6 +22,9 @@ }, { "path": "packages/opentelemetry-sdk-metrics-base" + }, + { + "path": "packages/opentelemetry-sdk-node" } ] } diff --git a/packages/opentelemetry-sdk-node/tsconfig.json b/packages/opentelemetry-sdk-node/tsconfig.json deleted file mode 100644 index 3c83ad6dc0..0000000000 --- a/packages/opentelemetry-sdk-node/tsconfig.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "compilerOptions": { - "rootDir": ".", - "outDir": "build" - }, - "include": [ - "src/**/*.ts", - "test/**/*.ts" - ], - "references": [ - { - "path": "../opentelemetry-context-async-hooks" - }, - { - "path": "../opentelemetry-core" - }, - { - "path": "../opentelemetry-resources" - }, - { - "path": "../opentelemetry-sdk-trace-base" - }, - { - "path": "../opentelemetry-sdk-trace-node" - } - ] -} diff --git a/tsconfig.esm.json b/tsconfig.esm.json index fe08269051..fbac179b7c 100644 --- a/tsconfig.esm.json +++ b/tsconfig.esm.json @@ -50,9 +50,6 @@ { "path": "packages/opentelemetry-resources/tsconfig.esm.json" }, - { - "path": "packages/opentelemetry-sdk-node" - }, { "path": "packages/opentelemetry-sdk-trace-base/tsconfig.esm.json" }, diff --git a/tsconfig.json b/tsconfig.json index a1a6d880b5..0c64abed8c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -89,9 +89,6 @@ { "path": "packages/opentelemetry-resources" }, - { - "path": "packages/opentelemetry-sdk-node" - }, { "path": "packages/opentelemetry-sdk-trace-base" },