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(instrumentation-memcached): use exported strings for attributes #2192

Merged
merged 3 commits into from
May 14, 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.
Jump to
Jump to file
Failed to load files.
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.

14 changes: 14 additions & 0 deletions plugins/node/opentelemetry-instrumentation-memcached/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: <https://opentelemetry.io/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */,
Expand Down Expand Up @@ -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,
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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 {
Expand Down Expand Up @@ -178,7 +181,7 @@ describe('memcached@2.x', () => {

assertMatch(
instrumentationSpans?.[0]?.events[0]?.attributes?.[
SemanticAttributes.EXCEPTION_MESSAGE
SEMATTRS_EXCEPTION_MESSAGE
] as 'string',
/not stored/
);
Expand Down