Skip to content

Commit fb1acac

Browse files
authored
Merge branch 'main' into remove-xray-propagator
2 parents 628d0c1 + 9f5a867 commit fb1acac

File tree

23 files changed

+250
-214
lines changed

23 files changed

+250
-214
lines changed

package-lock.json

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/node/instrumentation-mongoose/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,23 @@ The instrumentation's config `responseHook` functions signature changed, so the
5252

5353
The `moduleVersionAttributeName` config option is removed. To add the mongoose package version to spans, use the `moduleVersion` attribute in hook info for `responseHook` function.
5454

55+
## Semantic Conventions
56+
57+
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)
58+
59+
Attributes collected:
60+
61+
| Attribute | Short Description |
62+
| ----------------------- | --------------------------------------------------------------------------- |
63+
| `db.mongodb.collection` | The collection being accessed within the database stated in `db.name`. |
64+
| `db.name` | This attribute is used to report the name of the database being accessed. |
65+
| `db.operation` | The name of the operation being executed, or the SQL keyword. |
66+
| `db.statement` | The database statement being executed. |
67+
| `db.system` | An identifier for the database management system (DBMS) product being used. |
68+
| `db.user` | Username for accessing the database. |
69+
| `net.peer.name` | Remote hostname or similar. |
70+
| `net.peer.port` | Remote port number. |
71+
5572
## Useful links
5673

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

plugins/node/instrumentation-mongoose/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"dependencies": {
6363
"@opentelemetry/core": "^1.8.0",
6464
"@opentelemetry/instrumentation": "^0.50.0",
65-
"@opentelemetry/semantic-conventions": "^1.0.0"
65+
"@opentelemetry/semantic-conventions": "^1.22.0"
6666
},
6767
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-mongoose#readme"
6868
}

plugins/node/instrumentation-mongoose/src/mongoose.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import {
17-
context,
18-
Span,
19-
trace,
20-
SpanAttributes,
21-
SpanKind,
22-
} from '@opentelemetry/api';
16+
import { context, Span, trace, Attributes, SpanKind } from '@opentelemetry/api';
2317
import { suppressTracing } from '@opentelemetry/core';
2418
import type * as mongoose from 'mongoose';
2519
import { MongooseInstrumentationConfig, SerializerPayload } from './types';
@@ -34,7 +28,11 @@ import {
3428
InstrumentationNodeModuleDefinition,
3529
} from '@opentelemetry/instrumentation';
3630
import { VERSION } from './version';
37-
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
31+
import {
32+
SEMATTRS_DB_OPERATION,
33+
SEMATTRS_DB_STATEMENT,
34+
SEMATTRS_DB_SYSTEM,
35+
} from '@opentelemetry/semantic-conventions';
3836

3937
const contextCaptureFunctions = [
4038
'remove',
@@ -155,9 +153,9 @@ export class MongooseInstrumentation extends InstrumentationBase<any> {
155153
}
156154

157155
const parentSpan = this[_STORED_PARENT_SPAN];
158-
const attributes: SpanAttributes = {};
156+
const attributes: Attributes = {};
159157
if (self._config.dbStatementSerializer) {
160-
attributes[SemanticAttributes.DB_STATEMENT] =
158+
attributes[SEMATTRS_DB_STATEMENT] =
161159
self._config.dbStatementSerializer('aggregate', {
162160
options: this.options,
163161
aggregatePipeline: this._pipeline,
@@ -197,9 +195,9 @@ export class MongooseInstrumentation extends InstrumentationBase<any> {
197195
}
198196

199197
const parentSpan = this[_STORED_PARENT_SPAN];
200-
const attributes: SpanAttributes = {};
198+
const attributes: Attributes = {};
201199
if (self._config.dbStatementSerializer) {
202-
attributes[SemanticAttributes.DB_STATEMENT] =
200+
attributes[SEMATTRS_DB_STATEMENT] =
203201
self._config.dbStatementSerializer(this.op, {
204202
condition: this._conditions,
205203
updates: this._update,
@@ -243,9 +241,9 @@ export class MongooseInstrumentation extends InstrumentationBase<any> {
243241
if (options && !(options instanceof Function)) {
244242
serializePayload.options = options;
245243
}
246-
const attributes: SpanAttributes = {};
244+
const attributes: Attributes = {};
247245
if (self._config.dbStatementSerializer) {
248-
attributes[SemanticAttributes.DB_STATEMENT] =
246+
attributes[SEMATTRS_DB_STATEMENT] =
249247
self._config.dbStatementSerializer(op, serializePayload);
250248
}
251249
const span = self._startSpan(
@@ -308,7 +306,7 @@ export class MongooseInstrumentation extends InstrumentationBase<any> {
308306
collection: mongoose.Collection,
309307
modelName: string,
310308
operation: string,
311-
attributes: SpanAttributes,
309+
attributes: Attributes,
312310
parentSpan?: Span
313311
): Span {
314312
return this.tracer.startSpan(
@@ -318,8 +316,8 @@ export class MongooseInstrumentation extends InstrumentationBase<any> {
318316
attributes: {
319317
...attributes,
320318
...getAttributesFromCollection(collection),
321-
[SemanticAttributes.DB_OPERATION]: operation,
322-
[SemanticAttributes.DB_SYSTEM]: 'mongoose',
319+
[SEMATTRS_DB_OPERATION]: operation,
320+
[SEMATTRS_DB_SYSTEM]: 'mongoose',
323321
},
324322
},
325323
parentSpan ? trace.setSpan(context.active(), parentSpan) : undefined

plugins/node/instrumentation-mongoose/src/utils.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,27 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import { SpanAttributes, SpanStatusCode, diag, Span } from '@opentelemetry/api';
16+
import { Attributes, SpanStatusCode, diag, Span } from '@opentelemetry/api';
1717
import type { Collection } from 'mongoose';
1818
import { MongooseResponseCustomAttributesFunction } from './types';
1919
import { safeExecuteInTheMiddle } from '@opentelemetry/instrumentation';
20-
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
20+
import {
21+
SEMATTRS_DB_MONGODB_COLLECTION,
22+
SEMATTRS_DB_NAME,
23+
SEMATTRS_DB_USER,
24+
SEMATTRS_NET_PEER_NAME,
25+
SEMATTRS_NET_PEER_PORT,
26+
} from '@opentelemetry/semantic-conventions';
2127

2228
export function getAttributesFromCollection(
2329
collection: Collection
24-
): SpanAttributes {
30+
): Attributes {
2531
return {
26-
[SemanticAttributes.DB_MONGODB_COLLECTION]: collection.name,
27-
[SemanticAttributes.DB_NAME]: collection.conn.name,
28-
[SemanticAttributes.DB_USER]: collection.conn.user,
29-
[SemanticAttributes.NET_PEER_NAME]: collection.conn.host,
30-
[SemanticAttributes.NET_PEER_PORT]: collection.conn.port,
32+
[SEMATTRS_DB_MONGODB_COLLECTION]: collection.name,
33+
[SEMATTRS_DB_NAME]: collection.conn.name,
34+
[SEMATTRS_DB_USER]: collection.conn.user,
35+
[SEMATTRS_NET_PEER_NAME]: collection.conn.host,
36+
[SEMATTRS_NET_PEER_PORT]: collection.conn.port,
3137
};
3238
}
3339

plugins/node/instrumentation-mongoose/test/asserts.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,26 @@
1515
*/
1616
import { expect } from 'expect';
1717
import { ReadableSpan } from '@opentelemetry/sdk-trace-base';
18-
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
18+
import {
19+
SEMATTRS_DB_MONGODB_COLLECTION,
20+
SEMATTRS_DB_NAME,
21+
SEMATTRS_DB_STATEMENT,
22+
SEMATTRS_DB_SYSTEM,
23+
SEMATTRS_NET_PEER_NAME,
24+
SEMATTRS_NET_PEER_PORT,
25+
} from '@opentelemetry/semantic-conventions';
1926
import { SpanStatusCode } from '@opentelemetry/api';
2027
import { SerializerPayload } from '../src';
2128
import { DB_NAME, MONGO_HOST, MONGO_PORT } from './config';
2229

2330
export const assertSpan = (span: ReadableSpan) => {
2431
expect(span.status.code).toBe(SpanStatusCode.UNSET);
25-
expect(span.attributes[SemanticAttributes.DB_SYSTEM]).toEqual('mongoose');
26-
expect(span.attributes[SemanticAttributes.DB_MONGODB_COLLECTION]).toEqual(
27-
'users'
28-
);
29-
expect(span.attributes[SemanticAttributes.DB_NAME]).toEqual(DB_NAME);
30-
expect(span.attributes[SemanticAttributes.NET_PEER_NAME]).toEqual(MONGO_HOST);
31-
expect(span.attributes[SemanticAttributes.NET_PEER_PORT]).toEqual(MONGO_PORT);
32+
expect(span.attributes[SEMATTRS_DB_SYSTEM]).toEqual('mongoose');
33+
expect(span.attributes[SEMATTRS_DB_MONGODB_COLLECTION]).toEqual('users');
34+
expect(span.attributes[SEMATTRS_DB_NAME]).toEqual(DB_NAME);
35+
expect(span.attributes[SEMATTRS_NET_PEER_NAME]).toEqual(MONGO_HOST);
36+
expect(span.attributes[SEMATTRS_NET_PEER_PORT]).toEqual(MONGO_PORT);
3237
};
3338

3439
export const getStatement = (span: ReadableSpan): SerializerPayload =>
35-
JSON.parse(span.attributes[SemanticAttributes.DB_STATEMENT] as string);
40+
JSON.parse(span.attributes[SEMATTRS_DB_STATEMENT] as string);

0 commit comments

Comments
 (0)