From 47cb52c28d6517c07713f950d4be5744aa92c546 Mon Sep 17 00:00:00 2001 From: maryliag Date: Fri, 10 May 2024 15:56:48 -0400 Subject: [PATCH 1/2] chore(instrumentation-memcached): use exported strings for attributes Update to use strings exported for Resource Attributes Signed-off-by: maryliag --- package-lock.json | 9 ++++----- .../package.json | 2 +- .../src/instrumentation.ts | 12 +++++++----- .../src/utils.ts | 11 +++++++---- .../test/index.test.ts | 15 +++++++++------ 5 files changed, 28 insertions(+), 21 deletions(-) diff --git a/package-lock.json b/package-lock.json index a948005334..66a3f6149e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -37276,11 +37276,10 @@ "version": "0.1.0", "license": "Apache-2.0", "dependencies": { - "@opentelemetry/api": "^1.0.0", "@opentelemetry/sdk-trace-base": "^1.0.0" }, "devDependencies": { - "@opentelemetry/api": "^1.3.0", + "@opentelemetry/api": "^1.0.0", "@types/mocha": "8.2.3", "@types/node": "18.6.5", "expect": "29.2.0", @@ -38653,7 +38652,7 @@ "license": "Apache-2.0", "dependencies": { "@opentelemetry/instrumentation": "^0.51.0", - "@opentelemetry/semantic-conventions": "^1.0.0", + "@opentelemetry/semantic-conventions": "^1.23.0", "@types/memcached": "^2.2.6" }, "devDependencies": { @@ -46856,7 +46855,7 @@ "@opentelemetry/baggage-span-processor": { "version": "file:packages/baggage-span-processor", "requires": { - "@opentelemetry/api": "^1.3.0", + "@opentelemetry/api": "^1.0.0", "@opentelemetry/sdk-trace-base": "^1.0.0", "@types/mocha": "8.2.3", "@types/node": "18.6.5", @@ -47721,7 +47720,7 @@ "@opentelemetry/instrumentation": "^0.51.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.23.0", "@types/memcached": "^2.2.6", "@types/mocha": "7.0.2", "@types/node": "18.6.5", diff --git a/plugins/node/opentelemetry-instrumentation-memcached/package.json b/plugins/node/opentelemetry-instrumentation-memcached/package.json index d34a39820c..bf47bf5d4a 100644 --- a/plugins/node/opentelemetry-instrumentation-memcached/package.json +++ b/plugins/node/opentelemetry-instrumentation-memcached/package.json @@ -61,7 +61,7 @@ }, "dependencies": { "@opentelemetry/instrumentation": "^0.51.0", - "@opentelemetry/semantic-conventions": "^1.0.0", + "@opentelemetry/semantic-conventions": "^1.23.0", "@types/memcached": "^2.2.6" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-memcached#readme" diff --git a/plugins/node/opentelemetry-instrumentation-memcached/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-memcached/src/instrumentation.ts index fba48b5434..b72ab76896 100644 --- a/plugins/node/opentelemetry-instrumentation-memcached/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-memcached/src/instrumentation.ts @@ -22,8 +22,10 @@ import { } from '@opentelemetry/instrumentation'; import type * as Memcached from 'memcached'; import { - DbSystemValues, - SemanticAttributes, + DBSYSTEMVALUES_MEMCACHED, + SEMATTRS_DB_OPERATION, + SEMATTRS_DB_STATEMENT, + SEMATTRS_DB_SYSTEM, } from '@opentelemetry/semantic-conventions'; import * as utils from './utils'; import { InstrumentationConfig } from './types'; @@ -32,7 +34,7 @@ import { VERSION } from './version'; export class Instrumentation extends InstrumentationBase { static readonly COMPONENT = 'memcached'; static readonly COMMON_ATTRIBUTES = { - [SemanticAttributes.DB_SYSTEM]: DbSystemValues.MEMCACHED, + [SEMATTRS_DB_SYSTEM]: DBSYSTEMVALUES_MEMCACHED, }; static readonly DEFAULT_CONFIG: InstrumentationConfig = { enhancedDatabaseReporting: false, @@ -135,8 +137,8 @@ export class Instrumentation extends InstrumentationBase { span.setAttributes({ 'db.memcached.key': query.key, 'db.memcached.lifetime': query.lifetime, - [SemanticAttributes.DB_OPERATION]: query.type, - [SemanticAttributes.DB_STATEMENT]: ( + [SEMATTRS_DB_OPERATION]: query.type, + [SEMATTRS_DB_STATEMENT]: ( instrumentation._config as InstrumentationConfig ).enhancedDatabaseReporting ? query.command diff --git a/plugins/node/opentelemetry-instrumentation-memcached/src/utils.ts b/plugins/node/opentelemetry-instrumentation-memcached/src/utils.ts index 4cebd4112e..f8f517071d 100644 --- a/plugins/node/opentelemetry-instrumentation-memcached/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-memcached/src/utils.ts @@ -15,7 +15,10 @@ */ import type * as Memcached from 'memcached'; -import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; +import { + SEMATTRS_NET_PEER_NAME, + SEMATTRS_NET_PEER_PORT, +} from '@opentelemetry/semantic-conventions'; export const getPeerAttributes = ( client: any /* Memcached, but the type definitions are lacking */, @@ -49,12 +52,12 @@ export const getPeerAttributes = ( const portNumber = parseInt(port, 10); if (!isNaN(portNumber)) { return { - [SemanticAttributes.NET_PEER_NAME]: host, - [SemanticAttributes.NET_PEER_PORT]: portNumber, + [SEMATTRS_NET_PEER_NAME]: host, + [SEMATTRS_NET_PEER_PORT]: portNumber, }; } return { - [SemanticAttributes.NET_PEER_NAME]: host, + [SEMATTRS_NET_PEER_NAME]: host, }; } } diff --git a/plugins/node/opentelemetry-instrumentation-memcached/test/index.test.ts b/plugins/node/opentelemetry-instrumentation-memcached/test/index.test.ts index 87b96b537e..4e32af5fa6 100644 --- a/plugins/node/opentelemetry-instrumentation-memcached/test/index.test.ts +++ b/plugins/node/opentelemetry-instrumentation-memcached/test/index.test.ts @@ -32,8 +32,11 @@ import type * as Memcached from 'memcached'; import * as assert from 'assert'; import Instrumentation from '../src'; import { - DbSystemValues, - SemanticAttributes, + DBSYSTEMVALUES_MEMCACHED, + SEMATTRS_DB_SYSTEM, + SEMATTRS_EXCEPTION_MESSAGE, + SEMATTRS_NET_PEER_NAME, + SEMATTRS_NET_PEER_PORT, } from '@opentelemetry/semantic-conventions'; import * as util from 'util'; @@ -48,9 +51,9 @@ const CONFIG = { }; const DEFAULT_ATTRIBUTES: Attributes = { - [SemanticAttributes.DB_SYSTEM]: DbSystemValues.MEMCACHED, - [SemanticAttributes.NET_PEER_NAME]: CONFIG.host, - [SemanticAttributes.NET_PEER_PORT]: CONFIG.port, + [SEMATTRS_DB_SYSTEM]: DBSYSTEMVALUES_MEMCACHED, + [SEMATTRS_NET_PEER_NAME]: CONFIG.host, + [SEMATTRS_NET_PEER_PORT]: CONFIG.port, }; interface ExtendedMemcached extends Memcached { @@ -178,7 +181,7 @@ describe('memcached@2.x', () => { assertMatch( instrumentationSpans?.[0]?.events[0]?.attributes?.[ - SemanticAttributes.EXCEPTION_MESSAGE + SEMATTRS_EXCEPTION_MESSAGE ] as 'string', /not stored/ ); From e1c7a09a6aeb476cfec152bbff37f5c61c25516f Mon Sep 17 00:00:00 2001 From: maryliag Date: Sat, 11 May 2024 19:51:29 -0400 Subject: [PATCH 2/2] update readme --- .../README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/plugins/node/opentelemetry-instrumentation-memcached/README.md b/plugins/node/opentelemetry-instrumentation-memcached/README.md index 6913253d98..24e6477889 100644 --- a/plugins/node/opentelemetry-instrumentation-memcached/README.md +++ b/plugins/node/opentelemetry-instrumentation-memcached/README.md @@ -48,6 +48,20 @@ registerInstrumentations({ | ------- | ---- | ------- | ----------- | | `enhancedDatabaseReporting` | `boolean` | `false` | Include full command statement in the span - **leaks potentially sensitive information to your spans**. Defaults to `false`. | +## 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.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. | +| `net.peer.name` | Remote hostname or similar. | +| `net.peer.port` | Remote port number. | + ## Useful links - For more information on OpenTelemetry, visit: