Skip to content

Commit

Permalink
Merge branch 'main' into restify-request-hook
Browse files Browse the repository at this point in the history
  • Loading branch information
blumamir authored Dec 13, 2022
2 parents bbbe3f7 + 97305e1 commit b537dd1
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 41 deletions.
6 changes: 3 additions & 3 deletions plugins/node/opentelemetry-instrumentation-aws-sdk/.tav.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
"aws-sdk":
# there are so many version to test, it can take forever.
# we will just sample few of them
versions: ">=2.1230.0 || 2.1219.0 || 2.1152.0 || 2.1048.0 || 2.1012.0 || 2.647.0 || 2.308.0"
versions: ">=2.1266.0 || 2.1262.0 || 2.1219.0 || 2.1048.0 || 2.1012.0 || 2.647.0 || 2.308.0"
commands:
- npm run test
# Fix missing `contrib-test-utils` package
pretest: npm run --prefix ../../../ lerna:link

"@aws-sdk/client-s3":
versions: ">=3.188.0 || 3.154.0 || 3.107.0 || 3.54.0 || 3.6.1"
versions: ">=3.223.0 || 3.218.0 || 3.216.0 || 3.154.0 || 3.107.0 || 3.54.0 || 3.6.1"
commands:
- npm run test
# Fix missing `contrib-test-utils` package
pretest: npm run --prefix ../../../ lerna:link

"@aws-sdk/client-sqs":
versions: ">=3.188.0 || 3.171.0 || 3.107.0 || 3.58.0 || 3.54.0 || 3.43.0 || 3.24.0"
versions: ">=3.216.0 || 3.171.0 || 3.58.0 || 3.54.0 || 3.43.0 || 3.24.0"
commands:
- npm run test
# Fix missing `contrib-test-utils` package
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ Setup [Jaeger Tracing](https://www.jaegertracing.io/docs/latest/getting-started/
npm run zipkin:server
```

- Run the zipkin:client
- Run the client

```sh
# from this directory
npm run client
npm run zipkin:client
```

#### Zipkin UI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ export class MongoDBInstrumentation extends InstrumentationBase {
ns,
server,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
ops[0] as any
ops[0] as any,
operationName
);
const patchedCallback = instrumentation._patchEnd(span, resultHandler);
// handle when options is the callback to send the correct number of args
Expand Down Expand Up @@ -255,7 +256,9 @@ export class MongoDBInstrumentation extends InstrumentationBase {
const span = instrumentation.tracer.startSpan(`mongodb.${type}`, {
kind: SpanKind.CLIENT,
});
instrumentation._populateV3Attributes(span, ns, server, cmd);
const operation =
commandType === MongodbCommandType.UNKNOWN ? undefined : commandType;
instrumentation._populateV3Attributes(span, ns, server, cmd, operation);
const patchedCallback = instrumentation._patchEnd(span, resultHandler);
// handle when options is the callback to send the correct number of args
if (typeof options === 'function') {
Expand Down Expand Up @@ -296,7 +299,7 @@ export class MongoDBInstrumentation extends InstrumentationBase {
kind: SpanKind.CLIENT,
}
);
instrumentation._populateV4Attributes(span, this, ns, cmd);
instrumentation._populateV4Attributes(span, this, ns, cmd, commandType);
const patchedCallback = instrumentation._patchEnd(span, resultHandler);
return original.call(this, ns, cmd, options, patchedCallback);
};
Expand Down Expand Up @@ -341,7 +344,7 @@ export class MongoDBInstrumentation extends InstrumentationBase {
const span = instrumentation.tracer.startSpan('mongodb.find', {
kind: SpanKind.CLIENT,
});
instrumentation._populateV3Attributes(span, ns, server, cmd);
instrumentation._populateV3Attributes(span, ns, server, cmd, 'find');
const patchedCallback = instrumentation._patchEnd(span, resultHandler);
// handle when options is the callback to send the correct number of args
if (typeof options === 'function') {
Expand Down Expand Up @@ -413,7 +416,8 @@ export class MongoDBInstrumentation extends InstrumentationBase {
span,
ns,
server,
cursorState.cmd
cursorState.cmd,
'getMore'
);
const patchedCallback = instrumentation._patchEnd(span, resultHandler);
// handle when options is the callback to send the correct number of args
Expand Down Expand Up @@ -472,7 +476,8 @@ export class MongoDBInstrumentation extends InstrumentationBase {
span: Span,
connectionCtx: any,
ns: any,
command?: any
command?: any,
operation?: string
) {
let host, port: undefined | string;
if (connectionCtx) {
Expand Down Expand Up @@ -501,7 +506,8 @@ export class MongoDBInstrumentation extends InstrumentationBase {
ns.collection,
host,
port,
commandObj
commandObj,
operation
);
}

Expand All @@ -516,7 +522,8 @@ export class MongoDBInstrumentation extends InstrumentationBase {
span: Span,
ns: string,
topology: MongoInternalTopology,
command?: MongoInternalCommand
command?: MongoInternalCommand,
operation?: string | undefined
) {
// add network attributes to determine the remote server
let host: undefined | string;
Expand Down Expand Up @@ -548,7 +555,8 @@ export class MongoDBInstrumentation extends InstrumentationBase {
dbCollection,
host,
port,
commandObj
commandObj,
operation
);
}

Expand All @@ -558,13 +566,15 @@ export class MongoDBInstrumentation extends InstrumentationBase {
dbCollection?: string,
host?: undefined | string,
port?: undefined | string,
commandObj?: any
commandObj?: any,
operation?: string | undefined
) {
// add database related attributes
span.setAttributes({
[SemanticAttributes.DB_SYSTEM]: DbSystemValues.MONGODB,
[SemanticAttributes.DB_NAME]: dbName,
[SemanticAttributes.DB_MONGODB_COLLECTION]: dbCollection,
[SemanticAttributes.DB_OPERATION]: operation,
});

if (host && port) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,12 @@ describe('MongoDBInstrumentation', () => {
.insertMany(insertData)
.then(() => {
span.end();
assertSpans(getTestSpans(), 'mongodb.insert', SpanKind.CLIENT);
assertSpans(
getTestSpans(),
'mongodb.insert',
SpanKind.CLIENT,
'insert'
);
done();
})
.catch(err => {
Expand All @@ -128,7 +133,12 @@ describe('MongoDBInstrumentation', () => {
.updateOne({ a: 2 }, { $set: { b: 1 } })
.then(() => {
span.end();
assertSpans(getTestSpans(), 'mongodb.update', SpanKind.CLIENT);
assertSpans(
getTestSpans(),
'mongodb.update',
SpanKind.CLIENT,
'update'
);
done();
})
.catch(err => {
Expand All @@ -144,7 +154,12 @@ describe('MongoDBInstrumentation', () => {
.deleteOne({ a: 3 })
.then(() => {
span.end();
assertSpans(getTestSpans(), 'mongodb.remove', SpanKind.CLIENT);
assertSpans(
getTestSpans(),
'mongodb.remove',
SpanKind.CLIENT,
'remove'
);
done();
})
.catch(err => {
Expand All @@ -164,7 +179,12 @@ describe('MongoDBInstrumentation', () => {
.toArray()
.then(() => {
span.end();
assertSpans(getTestSpans(), 'mongodb.find', SpanKind.CLIENT);
assertSpans(
getTestSpans(),
'mongodb.find',
SpanKind.CLIENT,
'find'
);
done();
})
.catch(err => {
Expand All @@ -190,15 +210,17 @@ describe('MongoDBInstrumentation', () => {
span => !span.name.includes('mongodb.getMore')
),
'mongodb.find',
SpanKind.CLIENT
SpanKind.CLIENT,
'find'
);
// assert that we correctly got the first as a find
assertSpans(
getTestSpans().filter(
span => !span.name.includes('mongodb.find')
),
'mongodb.getMore',
SpanKind.CLIENT
SpanKind.CLIENT,
'getMore'
);
done();
})
Expand All @@ -222,7 +244,8 @@ describe('MongoDBInstrumentation', () => {
assertSpans(
getTestSpans(),
'mongodb.createIndexes',
SpanKind.CLIENT
SpanKind.CLIENT,
'createIndexes'
);
done();
})
Expand Down Expand Up @@ -253,7 +276,14 @@ describe('MongoDBInstrumentation', () => {
span.end();
const spans = getTestSpans();
const operationName = 'mongodb.insert';
assertSpans(spans, operationName, SpanKind.CLIENT, false, false);
assertSpans(
spans,
operationName,
SpanKind.CLIENT,
'insert',
false,
false
);
const mongoSpan = spans.find(s => s.name === operationName);
const dbStatement = JSON.parse(
mongoSpan!.attributes[SemanticAttributes.DB_STATEMENT] as string
Expand Down Expand Up @@ -291,7 +321,14 @@ describe('MongoDBInstrumentation', () => {
span.end();
const spans = getTestSpans();
const operationName = 'mongodb.insert';
assertSpans(spans, operationName, SpanKind.CLIENT, false, true);
assertSpans(
spans,
operationName,
SpanKind.CLIENT,
'insert',
false,
true
);
const mongoSpan = spans.find(s => s.name === operationName);
const dbStatement = JSON.parse(
mongoSpan!.attributes[SemanticAttributes.DB_STATEMENT] as string
Expand Down Expand Up @@ -324,7 +361,7 @@ describe('MongoDBInstrumentation', () => {
.then(() => {
span.end();
const spans = getTestSpans();
assertSpans(spans, 'mongodb.insert', SpanKind.CLIENT);
assertSpans(spans, 'mongodb.insert', SpanKind.CLIENT, 'insert');
done();
})
.catch(err => {
Expand Down Expand Up @@ -421,7 +458,7 @@ describe('MongoDBInstrumentation', () => {
.then(() => {
span.end();
const spans = getTestSpans();
assertSpans(spans, 'mongodb.find', SpanKind.CLIENT);
assertSpans(spans, 'mongodb.find', SpanKind.CLIENT, 'find');
done();
})
.catch(err => {
Expand All @@ -443,7 +480,7 @@ describe('MongoDBInstrumentation', () => {
span.end();
const spans = getTestSpans();
const mainSpan = spans[spans.length - 1];
assertSpans(spans, 'mongodb.insert', SpanKind.CLIENT);
assertSpans(spans, 'mongodb.insert', SpanKind.CLIENT, 'insert');
resetMemoryExporter();

collection
Expand All @@ -453,7 +490,7 @@ describe('MongoDBInstrumentation', () => {
const spans2 = getTestSpans();
spans2.push(mainSpan);

assertSpans(spans2, 'mongodb.find', SpanKind.CLIENT);
assertSpans(spans2, 'mongodb.find', SpanKind.CLIENT, 'find');
assert.strictEqual(
mainSpan.spanContext().spanId,
spans2[0].parentSpanId
Expand Down
Loading

0 comments on commit b537dd1

Please sign in to comment.