diff --git a/detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsBeanstalkDetectorSync.ts b/detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsBeanstalkDetectorSync.ts index 1716c97a49..0cce5a5c7a 100644 --- a/detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsBeanstalkDetectorSync.ts +++ b/detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsBeanstalkDetectorSync.ts @@ -33,7 +33,7 @@ import { ATTR_SERVICE_INSTANCE_ID, CLOUD_PROVIDER_VALUE_AWS, CLOUD_PLATFORM_VALUE_AWS_ELASTIC_BEANSTALK, -} from '@opentelemetry/semantic-conventions/incubating'; +} from '../lib/semconv'; import * as fs from 'fs'; import * as util from 'util'; diff --git a/detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsEc2DetectorSync.ts b/detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsEc2DetectorSync.ts index 471b2b9085..cba878e04c 100644 --- a/detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsEc2DetectorSync.ts +++ b/detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsEc2DetectorSync.ts @@ -34,7 +34,7 @@ import { ATTR_HOST_NAME, CLOUD_PROVIDER_VALUE_AWS, CLOUD_PLATFORM_VALUE_AWS_EC2, -} from '@opentelemetry/semantic-conventions/incubating'; +} from '../lib/semconv'; import * as http from 'http'; /** diff --git a/detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsEcsDetectorSync.ts b/detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsEcsDetectorSync.ts index 5b4f4ccd09..9dd1fa7c08 100644 --- a/detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsEcsDetectorSync.ts +++ b/detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsEcsDetectorSync.ts @@ -42,7 +42,7 @@ import { ATTR_AWS_LOG_STREAM_ARNS, CLOUD_PROVIDER_VALUE_AWS, CLOUD_PLATFORM_VALUE_AWS_ECS, -} from '@opentelemetry/semantic-conventions/incubating'; +} from '../lib/semconv'; // Patch until the OpenTelemetry SDK is updated to ship this attribute import { SemanticResourceAttributes as AdditionalSemanticResourceAttributes } from './SemanticResourceAttributes'; import * as http from 'http'; diff --git a/detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsEksDetectorSync.ts b/detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsEksDetectorSync.ts index 857fb2f217..57b4773c54 100644 --- a/detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsEksDetectorSync.ts +++ b/detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsEksDetectorSync.ts @@ -30,7 +30,7 @@ import { ATTR_CONTAINER_ID, CLOUD_PROVIDER_VALUE_AWS, CLOUD_PLATFORM_VALUE_AWS_EKS, -} from '@opentelemetry/semantic-conventions/incubating'; +} from '../lib/semconv'; import * as https from 'https'; import * as fs from 'fs'; import * as util from 'util'; diff --git a/detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsLambdaDetectorSync.ts b/detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsLambdaDetectorSync.ts index da7187e565..d715bf8fa7 100644 --- a/detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsLambdaDetectorSync.ts +++ b/detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsLambdaDetectorSync.ts @@ -29,7 +29,7 @@ import { ATTR_FAAS_NAME, CLOUD_PROVIDER_VALUE_AWS, CLOUD_PLATFORM_VALUE_AWS_LAMBDA, -} from '@opentelemetry/semantic-conventions/incubating'; +} from '../lib/semconv'; /** * The AwsLambdaDetector can be used to detect if a process is running in AWS Lambda diff --git a/detectors/node/opentelemetry-resource-detector-aws/src/lib/semconv.ts b/detectors/node/opentelemetry-resource-detector-aws/src/lib/semconv.ts new file mode 100644 index 0000000000..83ee3910d2 --- /dev/null +++ b/detectors/node/opentelemetry-resource-detector-aws/src/lib/semconv.ts @@ -0,0 +1,72 @@ +/* + * 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. + */ + +/** + * Following OpenTelemetry semantic conventions best practices, we copy the incubating + * semantic conventions into our codebase rather than importing them directly. + * This prevents breaking changes in minor versions and reduces disk usage from multiple versions. + * @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv + */ + +// AWS attributes +export const ATTR_AWS_ECS_CLUSTER_ARN = 'aws.ecs.cluster.arn'; +export const ATTR_AWS_ECS_CONTAINER_ARN = 'aws.ecs.container.arn'; +export const ATTR_AWS_ECS_LAUNCHTYPE = 'aws.ecs.launchtype'; +export const ATTR_AWS_ECS_TASK_ARN = 'aws.ecs.task.arn'; +export const ATTR_AWS_ECS_TASK_FAMILY = 'aws.ecs.task.family'; +export const ATTR_AWS_ECS_TASK_REVISION = 'aws.ecs.task.revision'; +export const ATTR_AWS_LOG_GROUP_ARNS = 'aws.log.group.arns'; +export const ATTR_AWS_LOG_GROUP_NAMES = 'aws.log.group.names'; +export const ATTR_AWS_LOG_STREAM_ARNS = 'aws.log.stream.arns'; +export const ATTR_AWS_LOG_STREAM_NAMES = 'aws.log.stream.names'; + +// Cloud attributes +export const ATTR_CLOUD_ACCOUNT_ID = 'cloud.account.id'; +export const ATTR_CLOUD_AVAILABILITY_ZONE = 'cloud.availability.zone'; +export const ATTR_CLOUD_PLATFORM = 'cloud.platform'; +export const ATTR_CLOUD_PROVIDER = 'cloud.provider'; +export const ATTR_CLOUD_REGION = 'cloud.region'; + +// Container attributes +export const ATTR_CONTAINER_ID = 'container.id'; +export const ATTR_CONTAINER_NAME = 'container.name'; + +// FaaS attributes +export const ATTR_FAAS_NAME = 'faas.name'; +export const ATTR_FAAS_VERSION = 'faas.version'; + +// Host attributes +export const ATTR_HOST_ID = 'host.id'; +export const ATTR_HOST_NAME = 'host.name'; +export const ATTR_HOST_TYPE = 'host.type'; + +// Kubernetes attributes +export const ATTR_K8S_CLUSTER_NAME = 'k8s.cluster.name'; + +// Service attributes +export const ATTR_SERVICE_INSTANCE_ID = 'service.instance.id'; +export const ATTR_SERVICE_NAME = 'service.name'; +export const ATTR_SERVICE_NAMESPACE = 'service.namespace'; +export const ATTR_SERVICE_VERSION = 'service.version'; + +// Cloud provider/platform values +export const CLOUD_PROVIDER_VALUE_AWS = 'aws'; +export const CLOUD_PLATFORM_VALUE_AWS_EC2 = 'aws_ec2'; +export const CLOUD_PLATFORM_VALUE_AWS_ECS = 'aws_ecs'; +export const CLOUD_PLATFORM_VALUE_AWS_EKS = 'aws_eks'; +export const CLOUD_PLATFORM_VALUE_AWS_ELASTIC_BEANSTALK = + 'aws_elastic_beanstalk'; +export const CLOUD_PLATFORM_VALUE_AWS_LAMBDA = 'aws_lambda'; diff --git a/package-lock.json b/package-lock.json index 616578c16c..4a32f6421a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -38732,7 +38732,7 @@ "dependencies": { "@opentelemetry/core": "^1.26.0", "@opentelemetry/instrumentation": "^0.57.0", - "@opentelemetry/semantic-conventions": "1.27.0", + "@opentelemetry/semantic-conventions": "^1.27.0", "@opentelemetry/sql-common": "^0.40.1", "@types/pg": "8.6.1", "@types/pg-pool": "2.0.6" @@ -38763,14 +38763,6 @@ "@opentelemetry/api": "^1.3.0" } }, - "plugins/node/opentelemetry-instrumentation-pg/node_modules/@opentelemetry/semantic-conventions": { - "version": "1.27.0", - "resolved": "https://registry.npmjs.org/@opentelemetry/semantic-conventions/-/semantic-conventions-1.27.0.tgz", - "integrity": "sha512-sAay1RrB+ONOem0OZanAR1ZI/k7yDpnOQSQmTMuGImUQb2y8EbSaCJ94FQluM74xoU03vlb2d2U90hZluL6nQg==", - "engines": { - "node": ">=14" - } - }, "plugins/node/opentelemetry-instrumentation-pg/node_modules/@types/mocha": { "version": "7.0.2", "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-7.0.2.tgz", @@ -48807,7 +48799,7 @@ "@opentelemetry/instrumentation": "^0.57.0", "@opentelemetry/sdk-trace-base": "^1.8.0", "@opentelemetry/sdk-trace-node": "^1.8.0", - "@opentelemetry/semantic-conventions": "1.27.0", + "@opentelemetry/semantic-conventions": "^1.27.0", "@opentelemetry/sql-common": "^0.40.1", "@types/mocha": "7.0.2", "@types/node": "18.18.14", @@ -48825,11 +48817,6 @@ "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/semantic-conventions": { - "version": "1.27.0", - "resolved": "https://registry.npmjs.org/@opentelemetry/semantic-conventions/-/semantic-conventions-1.27.0.tgz", - "integrity": "sha512-sAay1RrB+ONOem0OZanAR1ZI/k7yDpnOQSQmTMuGImUQb2y8EbSaCJ94FQluM74xoU03vlb2d2U90hZluL6nQg==" - }, "@types/mocha": { "version": "7.0.2", "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-7.0.2.tgz", diff --git a/plugins/node/opentelemetry-instrumentation-pg/package.json b/plugins/node/opentelemetry-instrumentation-pg/package.json index 4698da4a5c..bc2ec76777 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/package.json +++ b/plugins/node/opentelemetry-instrumentation-pg/package.json @@ -71,7 +71,7 @@ "dependencies": { "@opentelemetry/core": "^1.26.0", "@opentelemetry/instrumentation": "^0.57.0", - "@opentelemetry/semantic-conventions": "1.27.0", + "@opentelemetry/semantic-conventions": "^1.27.0", "@opentelemetry/sql-common": "^0.40.1", "@types/pg": "8.6.1", "@types/pg-pool": "2.0.6" diff --git a/plugins/node/opentelemetry-instrumentation-pg/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-pg/src/instrumentation.ts index 933796be7c..b7cd5d3406 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/src/instrumentation.ts @@ -65,7 +65,7 @@ import { METRIC_DB_CLIENT_OPERATION_DURATION, ATTR_DB_NAMESPACE, ATTR_DB_OPERATION_NAME, -} from '@opentelemetry/semantic-conventions/incubating'; +} from './semconv'; export class PgInstrumentation extends InstrumentationBase { private _operationDuration!: Histogram; diff --git a/plugins/node/opentelemetry-instrumentation-pg/src/semconv.ts b/plugins/node/opentelemetry-instrumentation-pg/src/semconv.ts new file mode 100644 index 0000000000..f7a2ba5624 --- /dev/null +++ b/plugins/node/opentelemetry-instrumentation-pg/src/semconv.ts @@ -0,0 +1,100 @@ +/* + * 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. + */ + +/** + * The name of the connection pool; unique within the instrumented application. In case the connection pool implementation doesn't provide a name, instrumentation **SHOULD** use a combination of parameters that would make the name unique, for example, combining attributes `server.address`, `server.port`, and `db.namespace`, formatted as `server.address:server.port/db.namespace`. Instrumentations that generate connection pool name following different patterns **SHOULD** document it. + * + * @example myDataSource + * + * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`. + */ +export const ATTR_DB_CLIENT_CONNECTION_POOL_NAME = + 'db.client.connection.pool.name'; + +/** + * The state of a connection in the pool + * + * @example idle + * + * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`. + */ +export const ATTR_DB_CLIENT_CONNECTION_STATE = 'db.client.connection.state'; + +/** + * The name of the database, fully qualified within the server address and port. + * + * @example customers + * @example test.users + * + * @note If a database system has multiple namespace components, they **SHOULD** be concatenated (potentially using database system specific conventions) from most general to most specific namespace component, and more specific namespaces **SHOULD NOT** be captured without the more general namespaces, to ensure that "startswith" queries for the more general namespaces will be valid. + * Semantic conventions for individual database systems **SHOULD** document what `db.namespace` means in the context of that system. + * It is **RECOMMENDED** to capture the value as provided by the application without attempting to do any case normalization. + * This attribute has stability level RELEASE CANDIDATE. + * + * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`. + */ +export const ATTR_DB_NAMESPACE = 'db.namespace'; + +/** + * The name of the operation or command being executed. + * + * @example findAndModify + * @example HMSET + * @example SELECT + * + * @note It is **RECOMMENDED** to capture the value as provided by the application without attempting to do any case normalization. + * If the operation name is parsed from the query text, it **SHOULD** be the first operation name found in the query. + * For batch operations, if the individual operations are known to have the same operation name then that operation name **SHOULD** be used prepended by `BATCH `, otherwise `db.operation.name` **SHOULD** be `BATCH` or some other database system specific term if more applicable. + * This attribute has stability level RELEASE CANDIDATE. + * + * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`. + */ +export const ATTR_DB_OPERATION_NAME = 'db.operation.name'; + +/** + * Enum value "used" for attribute {@link ATTR_DB_CLIENT_CONNECTION_STATE}. + */ +export const DB_CLIENT_CONNECTION_STATE_VALUE_USED = 'used'; + +/** + * Enum value "idle" for attribute {@link ATTR_DB_CLIENT_CONNECTION_STATE}. + */ +export const DB_CLIENT_CONNECTION_STATE_VALUE_IDLE = 'idle'; + +/** + * The number of connections that are currently in state described by the `state` attribute + * + * @experimental This metric is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`. + */ +export const METRIC_DB_CLIENT_CONNECTION_COUNT = 'db.client.connection.count'; + +/** + * The number of current pending requests for an open connection + * + * @experimental This metric is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`. + */ +export const METRIC_DB_CLIENT_CONNECTION_PENDING_REQUESTS = + 'db.client.connection.pending_requests'; + +/** + * Duration of database client operations. + * + * @note Batch operations **SHOULD** be recorded as a single operation. + * + * @experimental This metric is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`. + */ +export const METRIC_DB_CLIENT_OPERATION_DURATION = + 'db.client.operation.duration'; diff --git a/plugins/node/opentelemetry-instrumentation-pg/src/utils.ts b/plugins/node/opentelemetry-instrumentation-pg/src/utils.ts index de21084a95..c4ebd05640 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/src/utils.ts @@ -42,7 +42,7 @@ import { ATTR_DB_CLIENT_CONNECTION_STATE, DB_CLIENT_CONNECTION_STATE_VALUE_USED, DB_CLIENT_CONNECTION_STATE_VALUE_IDLE, -} from '@opentelemetry/semantic-conventions/incubating'; +} from './semconv'; import { PgClientExtended, PostgresCallback, diff --git a/plugins/node/opentelemetry-instrumentation-pg/test/pg-pool.test.ts b/plugins/node/opentelemetry-instrumentation-pg/test/pg-pool.test.ts index f0ac1508d9..98d9a1b7c8 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/test/pg-pool.test.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/test/pg-pool.test.ts @@ -55,7 +55,7 @@ import { METRIC_DB_CLIENT_CONNECTION_COUNT, METRIC_DB_CLIENT_CONNECTION_PENDING_REQUESTS, METRIC_DB_CLIENT_OPERATION_DURATION, -} from '@opentelemetry/semantic-conventions/incubating'; +} from '../src/semconv'; const memoryExporter = new InMemorySpanExporter(); diff --git a/plugins/node/opentelemetry-instrumentation-pg/test/pg.test.ts b/plugins/node/opentelemetry-instrumentation-pg/test/pg.test.ts index b7169ec785..8fda8a8fb8 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/test/pg.test.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/test/pg.test.ts @@ -56,7 +56,7 @@ import { import { METRIC_DB_CLIENT_OPERATION_DURATION, ATTR_DB_OPERATION_NAME, -} from '@opentelemetry/semantic-conventions/incubating'; +} from '../src/semconv'; import { addSqlCommenterComment } from '@opentelemetry/sql-common'; const memoryExporter = new InMemorySpanExporter();