Skip to content

Commit e28bda6

Browse files
committed
fix test and add readme
1 parent 616cca6 commit e28bda6

File tree

2 files changed

+49
-7
lines changed

2 files changed

+49
-7
lines changed

plugins/node/opentelemetry-instrumentation-pg/README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,48 @@ PostgreSQL instrumentation has few options available to choose from. You can set
5151
| `requireParentSpan` | `boolean` | If true, requires a parent span to create new spans (default false) |
5252
| `addSqlCommenterCommentToQueries` | `boolean` | If true, adds [sqlcommenter](https://github.com/open-telemetry/opentelemetry-sqlcommenter) specification compliant comment to queries with tracing context (default false). _NOTE: A comment will not be added to queries that already contain `--` or `/* ... */` in them, even if these are not actually part of comments_ |
5353

54+
## Semantic Conventions
55+
56+
Prior to version `0.55.0`, this instrumentation created spans and metrics targeting an experimental semantic convention Version 1.27.0.
57+
58+
Database semantic conventions (semconv) were stabilized in v1.34.0, and a [migration process](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/non-normative/db-migration.md) was defined.
59+
`opentelemetry-instrumentation-pg` versions 0.55.0 and later include support for migrating to stable Database semantic conventions, as described below.
60+
The intent is to provide an approximate 6 month time window for users of this instrumentation to migrate to the new Database semconv, after which a new minor version will use the *new* semconv by default and drop support for the old semconv.
61+
62+
To select which semconv version(s) is emitted from this instrumentation, use the `OTEL_SEMCONV_STABILITY_OPT_IN` environment variable.
63+
64+
- `database`: emit the new (stable) v1.34.0+ semantics
65+
- `database/dup`: emit **both** the old v1.27.0 and the new (stable) v1.34.0+ semantics
66+
- By default, if `OTEL_SEMCONV_STABILITY_OPT_IN` includes neither of the above tokens, the old v1.27.0 semconv is used.
67+
68+
### Attributes collected
69+
70+
| v1.27.0 semconv | v1.34.0 semconv | Short Description |
71+
| ----------------------- | ----------------------------------------------- | ------------------------------------------------------------------------------------------ |
72+
| `db.connection_string` | Removed | String used to connect to the database |
73+
| `db.user` | Removed | User used to connect to the database |
74+
| `db.name` | Removed, integrated into the new `db.namespace` | The name of the database. |
75+
| (not included) | `db.namespace` | The name of the database, fully qualified within the server address and port. |
76+
| `db.statement` | `db.query.text` | The database query being executed. |
77+
| `db.system` | `db.system.name` | The database management system (DBMS) product as identified by the client instrumentation. |
78+
| `net.peer.port` | `network.peer.port` | Peer port number of the network connection. |
79+
| `net.peer.name` | `network.peer.address` | Peer address of the database node where the operation was performed. |
80+
81+
Metrics Exported:
82+
83+
- [`db.client.operation.duration`](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/database/database-metrics.md#metric-dbclientoperationduration)
84+
85+
### Upgrading Semantic Conventions
86+
87+
When upgrading to the new semantic conventions, it is recommended to do so in the following order:
88+
89+
1. Upgrade `@opentelemetry/opentelemetry-instrumentation-pg` to the latest version
90+
2. Set `OTEL_SEMCONV_STABILITY_OPT_IN=database/dup` to emit both old and new semantic conventions
91+
3. Modify alerts, dashboards, metrics, and other processes to expect the new semantic conventions
92+
4. Set `OTEL_SEMCONV_STABILITY_OPT_IN=database` to emit only the new semantic conventions
93+
94+
This will cause both the old and new semantic conventions to be emitted during the transition period.
95+
5496
## Useful links
5597

5698
- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>

plugins/node/opentelemetry-instrumentation-pg/src/semconv.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,43 +109,43 @@ export const ATTR_DB_SYSTEM = 'db.system';
109109
* An identifier for the database management system (DBMS) product being used. See below for a list of well-known identifiers.
110110
*
111111
*/
112-
export const DB_SYSTEM_VALUE_POSTGRESQL = "postgresql";
112+
export const DB_SYSTEM_VALUE_POSTGRESQL = 'postgresql';
113113

114114
/**
115115
* If no [tech-specific attribute](#call-level-attributes-for-specific-technologies) is defined, this attribute is used to report the name of the database being accessed. For commands that switch the database, this should be set to the target database (even if the command fails).
116116
*
117117
* Note: In some SQL databases, the database name to be used is called &#34;schema name&#34;.
118118
*
119119
*/
120-
export const ATTR_DB_NAME = "db.name";
120+
export const ATTR_DB_NAME = 'db.name';
121121

122122
/**
123123
* The connection string used to connect to the database. It is recommended to remove embedded credentials.
124124
*
125125
*/
126-
export const ATTR_DB_CONNECTION_STRING = "db.connection_string";
126+
export const ATTR_DB_CONNECTION_STRING = 'db.connection_string';
127127

128128
/**
129129
* Username for accessing the database.
130130
*
131131
*/
132-
export const ATTR_DB_USER = "db.user";
132+
export const ATTR_DB_USER = 'db.user';
133133

134134
/**
135135
* Remote port number.
136136
*
137137
*/
138-
export const ATTR_NET_PEER_PORT = "net.peer.port";
138+
export const ATTR_NET_PEER_PORT = 'net.peer.port';
139139
/**
140140
* Remote hostname or similar.
141141
*
142142
*/
143-
export const ATTR_NET_PEER_NAME = "net.peer.name";
143+
export const ATTR_NET_PEER_NAME = 'net.peer.name';
144144

145145
/**
146146
* The database statement being executed.
147147
*
148148
* Note: The value may be sanitized to exclude sensitive information.
149149
*
150150
*/
151-
export const ATTR_DB_STATEMENT = "db.statement";
151+
export const ATTR_DB_STATEMENT = 'db.statement';

0 commit comments

Comments
 (0)