Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(test-utils): update semantic resource attributes #2080

Merged
merged 4 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/opentelemetry-test-utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ it('some test', () => {

That's it - supper short and easy.

## Semantic Conventions

This package uses `@opentelemetry/semantic-conventions` version `1.22+`, which implements Semantic Convention [Version 1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md)

## Useful links

- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-test-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@
"@opentelemetry/sdk-node": "^0.50.0",
"@opentelemetry/sdk-trace-base": "^1.8.0",
"@opentelemetry/sdk-trace-node": "^1.8.0",
"@opentelemetry/semantic-conventions": "^1.0.0"
"@opentelemetry/semantic-conventions": "^1.22.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/
import { Resource } from '@opentelemetry/resources';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { SEMRESATTRS_SERVICE_NAME } from '@opentelemetry/semantic-conventions';
import { getInstrumentation } from './instrumentation-singleton';
import { registerInstrumentationTestingProvider } from './otel-default-provider';
import { resetMemoryExporter } from './otel-provider-api';
Expand All @@ -40,7 +40,7 @@ export const mochaHooks = {
}
const provider = registerInstrumentationTestingProvider({
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: serviceName,
[SEMRESATTRS_SERVICE_NAME]: serviceName,
}),
});
getInstrumentation()?.setTracerProvider(provider);
Expand Down
84 changes: 55 additions & 29 deletions packages/opentelemetry-test-utils/src/resource-assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,32 @@ import * as assert from 'assert';
import { Resource } from '@opentelemetry/resources';
import {
SemanticResourceAttributes,
SEMRESATTRS_CLOUD_ACCOUNT_ID,
SEMRESATTRS_CLOUD_AVAILABILITY_ZONE,
SEMRESATTRS_CLOUD_PROVIDER,
SEMRESATTRS_CLOUD_REGION,
SEMRESATTRS_CONTAINER_ID,
SEMRESATTRS_CONTAINER_IMAGE_NAME,
SEMRESATTRS_CONTAINER_IMAGE_TAG,
SEMRESATTRS_CONTAINER_NAME,
SEMRESATTRS_HOST_ID,
SEMRESATTRS_HOST_IMAGE_ID,
SEMRESATTRS_HOST_IMAGE_NAME,
SEMRESATTRS_HOST_IMAGE_VERSION,
SEMRESATTRS_HOST_NAME,
SEMRESATTRS_HOST_TYPE,
SEMRESATTRS_K8S_CLUSTER_NAME,
SEMRESATTRS_K8S_DEPLOYMENT_NAME,
SEMRESATTRS_K8S_NAMESPACE_NAME,
SEMRESATTRS_K8S_POD_NAME,
SEMRESATTRS_PROCESS_COMMAND,
SEMRESATTRS_PROCESS_COMMAND_LINE,
SEMRESATTRS_PROCESS_EXECUTABLE_NAME,
SEMRESATTRS_PROCESS_PID,
SEMRESATTRS_SERVICE_INSTANCE_ID,
SEMRESATTRS_SERVICE_NAME,
SEMRESATTRS_SERVICE_NAMESPACE,
SEMRESATTRS_SERVICE_VERSION,
SEMRESATTRS_TELEMETRY_SDK_LANGUAGE,
SEMRESATTRS_TELEMETRY_SDK_NAME,
SEMRESATTRS_TELEMETRY_SDK_VERSION,
Expand All @@ -42,22 +68,22 @@ export const assertCloudResource = (
assertHasOneLabel('CLOUD', resource);
if (validations.provider)
assert.strictEqual(
resource.attributes[SemanticResourceAttributes.CLOUD_PROVIDER],
resource.attributes[SEMRESATTRS_CLOUD_PROVIDER],
validations.provider
);
if (validations.accountId)
assert.strictEqual(
resource.attributes[SemanticResourceAttributes.CLOUD_ACCOUNT_ID],
resource.attributes[SEMRESATTRS_CLOUD_ACCOUNT_ID],
validations.accountId
);
if (validations.region)
assert.strictEqual(
resource.attributes[SemanticResourceAttributes.CLOUD_REGION],
resource.attributes[SEMRESATTRS_CLOUD_REGION],
validations.region
);
if (validations.zone)
assert.strictEqual(
resource.attributes[SemanticResourceAttributes.CLOUD_AVAILABILITY_ZONE],
resource.attributes[SEMRESATTRS_CLOUD_AVAILABILITY_ZONE],
validations.zone
);
};
Expand All @@ -80,22 +106,22 @@ export const assertContainerResource = (
assertHasOneLabel('CONTAINER', resource);
if (validations.name)
assert.strictEqual(
resource.attributes[SemanticResourceAttributes.CONTAINER_NAME],
resource.attributes[SEMRESATTRS_CONTAINER_NAME],
validations.name
);
if (validations.id)
assert.strictEqual(
resource.attributes[SemanticResourceAttributes.CONTAINER_ID],
resource.attributes[SEMRESATTRS_CONTAINER_ID],
validations.id
);
if (validations.imageName)
assert.strictEqual(
resource.attributes[SemanticResourceAttributes.CONTAINER_IMAGE_NAME],
resource.attributes[SEMRESATTRS_CONTAINER_IMAGE_NAME],
validations.imageName
);
if (validations.imageTag)
assert.strictEqual(
resource.attributes[SemanticResourceAttributes.CONTAINER_IMAGE_TAG],
resource.attributes[SEMRESATTRS_CONTAINER_IMAGE_TAG],
validations.imageTag
);
};
Expand All @@ -120,32 +146,32 @@ export const assertHostResource = (
assertHasOneLabel('HOST', resource);
if (validations.id)
assert.strictEqual(
resource.attributes[SemanticResourceAttributes.HOST_ID],
resource.attributes[SEMRESATTRS_HOST_ID],
validations.id
);
if (validations.name)
assert.strictEqual(
resource.attributes[SemanticResourceAttributes.HOST_NAME],
resource.attributes[SEMRESATTRS_HOST_NAME],
validations.name
);
if (validations.hostType)
assert.strictEqual(
resource.attributes[SemanticResourceAttributes.HOST_TYPE],
resource.attributes[SEMRESATTRS_HOST_TYPE],
validations.hostType
);
if (validations.imageName)
assert.strictEqual(
resource.attributes[SemanticResourceAttributes.HOST_IMAGE_NAME],
resource.attributes[SEMRESATTRS_HOST_IMAGE_NAME],
validations.imageName
);
if (validations.imageId)
assert.strictEqual(
resource.attributes[SemanticResourceAttributes.HOST_IMAGE_ID],
resource.attributes[SEMRESATTRS_HOST_IMAGE_ID],
validations.imageId
);
if (validations.imageVersion)
assert.strictEqual(
resource.attributes[SemanticResourceAttributes.HOST_IMAGE_VERSION],
resource.attributes[SEMRESATTRS_HOST_IMAGE_VERSION],
validations.imageVersion
);
};
Expand All @@ -168,22 +194,22 @@ export const assertK8sResource = (
assertHasOneLabel('K8S', resource);
if (validations.clusterName)
assert.strictEqual(
resource.attributes[SemanticResourceAttributes.K8S_CLUSTER_NAME],
resource.attributes[SEMRESATTRS_K8S_CLUSTER_NAME],
validations.clusterName
);
if (validations.namespaceName)
assert.strictEqual(
resource.attributes[SemanticResourceAttributes.K8S_NAMESPACE_NAME],
resource.attributes[SEMRESATTRS_K8S_NAMESPACE_NAME],
validations.namespaceName
);
if (validations.podName)
assert.strictEqual(
resource.attributes[SemanticResourceAttributes.K8S_POD_NAME],
resource.attributes[SEMRESATTRS_K8S_POD_NAME],
validations.podName
);
if (validations.deploymentName)
assert.strictEqual(
resource.attributes[SemanticResourceAttributes.K8S_DEPLOYMENT_NAME],
resource.attributes[SEMRESATTRS_K8S_DEPLOYMENT_NAME],
validations.deploymentName
);
};
Expand Down Expand Up @@ -211,17 +237,17 @@ export const assertTelemetrySDKResource = (

if (validations.name)
assert.strictEqual(
resource.attributes[SemanticResourceAttributes.TELEMETRY_SDK_NAME],
resource.attributes[SEMRESATTRS_TELEMETRY_SDK_NAME],
validations.name
);
if (validations.language)
assert.strictEqual(
resource.attributes[SemanticResourceAttributes.TELEMETRY_SDK_LANGUAGE],
resource.attributes[SEMRESATTRS_TELEMETRY_SDK_LANGUAGE],
validations.language
);
if (validations.version)
assert.strictEqual(
resource.attributes[SemanticResourceAttributes.TELEMETRY_SDK_VERSION],
resource.attributes[SEMRESATTRS_TELEMETRY_SDK_VERSION],
validations.version
);
};
Expand All @@ -242,21 +268,21 @@ export const assertServiceResource = (
}
) => {
assert.strictEqual(
resource.attributes[SemanticResourceAttributes.SERVICE_NAME],
resource.attributes[SEMRESATTRS_SERVICE_NAME],
validations.name
);
assert.strictEqual(
resource.attributes[SemanticResourceAttributes.SERVICE_INSTANCE_ID],
resource.attributes[SEMRESATTRS_SERVICE_INSTANCE_ID],
validations.instanceId
);
if (validations.namespace)
assert.strictEqual(
resource.attributes[SemanticResourceAttributes.SERVICE_NAMESPACE],
resource.attributes[SEMRESATTRS_SERVICE_NAMESPACE],
validations.namespace
);
if (validations.version)
assert.strictEqual(
resource.attributes[SemanticResourceAttributes.SERVICE_VERSION],
resource.attributes[SEMRESATTRS_SERVICE_VERSION],
validations.version
);
};
Expand All @@ -277,24 +303,24 @@ export const assertProcessResource = (
}
) => {
assert.strictEqual(
resource.attributes[SemanticResourceAttributes.PROCESS_PID],
resource.attributes[SEMRESATTRS_PROCESS_PID],
validations.pid
);
if (validations.name) {
assert.strictEqual(
resource.attributes[SemanticResourceAttributes.PROCESS_EXECUTABLE_NAME],
resource.attributes[SEMRESATTRS_PROCESS_EXECUTABLE_NAME],
validations.name
);
}
if (validations.command) {
assert.strictEqual(
resource.attributes[SemanticResourceAttributes.PROCESS_COMMAND],
resource.attributes[SEMRESATTRS_PROCESS_COMMAND],
validations.command
);
}
if (validations.commandLine) {
assert.strictEqual(
resource.attributes[SemanticResourceAttributes.PROCESS_COMMAND_LINE],
resource.attributes[SEMRESATTRS_PROCESS_COMMAND_LINE],
validations.commandLine
);
}
Expand Down
Loading