diff --git a/package-lock.json b/package-lock.json index eaf2bb882c..1bfd2fcf51 100644 --- a/package-lock.json +++ b/package-lock.json @@ -38198,7 +38198,7 @@ "license": "Apache-2.0", "dependencies": { "@opentelemetry/instrumentation": "^0.50.0", - "@opentelemetry/semantic-conventions": "^1.0.0", + "@opentelemetry/semantic-conventions": "^1.22.0", "@types/mysql": "2.15.22" }, "devDependencies": { @@ -46599,7 +46599,7 @@ "@opentelemetry/instrumentation": "^0.50.0", "@opentelemetry/sdk-metrics": "^1.8.0", "@opentelemetry/sdk-trace-base": "^1.8.0", - "@opentelemetry/semantic-conventions": "^1.0.0", + "@opentelemetry/semantic-conventions": "^1.22.0", "@types/mocha": "7.0.2", "@types/mysql": "2.15.22", "@types/node": "18.6.5", diff --git a/plugins/node/opentelemetry-instrumentation-mysql/README.md b/plugins/node/opentelemetry-instrumentation-mysql/README.md index 6b86badf8e..e632521fb6 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql/README.md +++ b/plugins/node/opentelemetry-instrumentation-mysql/README.md @@ -49,6 +49,23 @@ See [examples/mysql](https://github.com/open-telemetry/opentelemetry-js-contrib/ | [`enhancedDatabaseReporting`](./src/types.ts#L24) | `boolean` | `false` | If true, an attribute containing the query's parameters will be attached the spans generated to represent the query | | +## 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) + +Attributes collected: + +| Attribute | Short Description | +| ----------------------- | ------------------------------------------------------------------------------ | +| `db.connection_string` | The connection string used to connect to the database. | +| `db.name` | This attribute is used to report the name of the database being accessed. | +| `db.operation` | The name of the operation being executed. | +| `db.statement` | The database statement being executed. | +| `db.system` | An identifier for the database management system (DBMS) product being used. | +| `db.user` | Username for accessing the database. | +| `net.peer.name` | Remote hostname or similar. | +| `net.peer.port` | Remote port number. | + ## Useful links - For more information on OpenTelemetry, visit: diff --git a/plugins/node/opentelemetry-instrumentation-mysql/package.json b/plugins/node/opentelemetry-instrumentation-mysql/package.json index fccb9fe6ae..13d2c6d3af 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql/package.json +++ b/plugins/node/opentelemetry-instrumentation-mysql/package.json @@ -60,7 +60,7 @@ }, "dependencies": { "@opentelemetry/instrumentation": "^0.50.0", - "@opentelemetry/semantic-conventions": "^1.0.0", + "@opentelemetry/semantic-conventions": "^1.22.0", "@types/mysql": "2.15.22" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-mysql#readme" diff --git a/plugins/node/opentelemetry-instrumentation-mysql/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-mysql/src/instrumentation.ts index 8ef20b9e2b..9ff48fd684 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-mysql/src/instrumentation.ts @@ -29,8 +29,9 @@ import { isWrapped, } from '@opentelemetry/instrumentation'; import { - DbSystemValues, - SemanticAttributes, + DBSYSTEMVALUES_MYSQL, + SEMATTRS_DB_STATEMENT, + SEMATTRS_DB_SYSTEM, } from '@opentelemetry/semantic-conventions'; import type * as mysqlTypes from 'mysql'; import { AttributeNames } from './AttributeNames'; @@ -54,7 +55,7 @@ export class MySQLInstrumentation extends InstrumentationBase< typeof mysqlTypes > { static readonly COMMON_ATTRIBUTES = { - [SemanticAttributes.DB_SYSTEM]: DbSystemValues.MYSQL, + [SEMATTRS_DB_SYSTEM]: DBSYSTEMVALUES_MYSQL, }; private _connectionsUsage!: UpDownCounter; @@ -331,10 +332,7 @@ export class MySQLInstrumentation extends InstrumentationBase< }, }); - span.setAttribute( - SemanticAttributes.DB_STATEMENT, - getDbStatement(query) - ); + span.setAttribute(SEMATTRS_DB_STATEMENT, getDbStatement(query)); const instrumentationConfig: MySQLInstrumentationConfig = thisPlugin.getConfig(); diff --git a/plugins/node/opentelemetry-instrumentation-mysql/src/utils.ts b/plugins/node/opentelemetry-instrumentation-mysql/src/utils.ts index 05eb1d809f..8230052d0e 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-mysql/src/utils.ts @@ -14,8 +14,14 @@ * limitations under the License. */ -import { SpanAttributes } from '@opentelemetry/api'; -import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; +import { Attributes } from '@opentelemetry/api'; +import { + SEMATTRS_DB_CONNECTION_STRING, + SEMATTRS_DB_NAME, + SEMATTRS_DB_USER, + SEMATTRS_NET_PEER_NAME, + SEMATTRS_NET_PEER_PORT, +} from '@opentelemetry/semantic-conventions'; import type { ConnectionConfig, PoolActualConfig, @@ -25,37 +31,29 @@ import type { import type * as mysqlTypes from 'mysql'; /** - * Get an SpanAttributes map from a mysql connection config object + * Get an Attributes map from a mysql connection config object * * @param config ConnectionConfig */ export function getConnectionAttributes( config: ConnectionConfig | PoolActualConfig -): SpanAttributes { +): Attributes { const { host, port, database, user } = getConfig(config); const portNumber = parseInt(port, 10); if (!isNaN(portNumber)) { return { - [SemanticAttributes.NET_PEER_NAME]: host, - [SemanticAttributes.NET_PEER_PORT]: portNumber, - [SemanticAttributes.DB_CONNECTION_STRING]: getJDBCString( - host, - port, - database - ), - [SemanticAttributes.DB_NAME]: database, - [SemanticAttributes.DB_USER]: user, + [SEMATTRS_NET_PEER_NAME]: host, + [SEMATTRS_NET_PEER_PORT]: portNumber, + [SEMATTRS_DB_CONNECTION_STRING]: getJDBCString(host, port, database), + [SEMATTRS_DB_NAME]: database, + [SEMATTRS_DB_USER]: user, }; } return { - [SemanticAttributes.NET_PEER_NAME]: host, - [SemanticAttributes.DB_CONNECTION_STRING]: getJDBCString( - host, - port, - database - ), - [SemanticAttributes.DB_NAME]: database, - [SemanticAttributes.DB_USER]: user, + [SEMATTRS_NET_PEER_NAME]: host, + [SEMATTRS_DB_CONNECTION_STRING]: getJDBCString(host, port, database), + [SEMATTRS_DB_NAME]: database, + [SEMATTRS_DB_USER]: user, }; } diff --git a/plugins/node/opentelemetry-instrumentation-mysql/test/index.test.ts b/plugins/node/opentelemetry-instrumentation-mysql/test/index.test.ts index eaef649b3c..676081d47e 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql/test/index.test.ts +++ b/plugins/node/opentelemetry-instrumentation-mysql/test/index.test.ts @@ -17,8 +17,13 @@ import { context, Context, trace, SpanStatusCode } from '@opentelemetry/api'; import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks'; import { - DbSystemValues, - SemanticAttributes, + DBSYSTEMVALUES_MYSQL, + SEMATTRS_DB_NAME, + SEMATTRS_DB_STATEMENT, + SEMATTRS_DB_SYSTEM, + SEMATTRS_DB_USER, + SEMATTRS_NET_PEER_NAME, + SEMATTRS_NET_PEER_PORT, } from '@opentelemetry/semantic-conventions'; import * as testUtils from '@opentelemetry/contrib-test-utils'; import { @@ -868,15 +873,12 @@ function assertSpan( values?: any, errorMessage?: string ) { - assert.strictEqual( - span.attributes[SemanticAttributes.DB_SYSTEM], - DbSystemValues.MYSQL - ); - assert.strictEqual(span.attributes[SemanticAttributes.DB_NAME], database); - assert.strictEqual(span.attributes[SemanticAttributes.NET_PEER_PORT], port); - assert.strictEqual(span.attributes[SemanticAttributes.NET_PEER_NAME], host); - assert.strictEqual(span.attributes[SemanticAttributes.DB_USER], user); - assert.strictEqual(span.attributes[SemanticAttributes.DB_STATEMENT], sql); + assert.strictEqual(span.attributes[SEMATTRS_DB_SYSTEM], DBSYSTEMVALUES_MYSQL); + assert.strictEqual(span.attributes[SEMATTRS_DB_NAME], database); + assert.strictEqual(span.attributes[SEMATTRS_NET_PEER_PORT], port); + assert.strictEqual(span.attributes[SEMATTRS_NET_PEER_NAME], host); + assert.strictEqual(span.attributes[SEMATTRS_DB_USER], user); + assert.strictEqual(span.attributes[SEMATTRS_DB_STATEMENT], sql); if (errorMessage) { assert.strictEqual(span.status.message, errorMessage); assert.strictEqual(span.status.code, SpanStatusCode.ERROR);