Skip to content

Commit

Permalink
Merge branch 'main' into fix-graphql-operation-name
Browse files Browse the repository at this point in the history
  • Loading branch information
dyladan committed Feb 24, 2022
2 parents 670bc30 + bf39b90 commit aea5851
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"compile": "npm run version:update && tsc -p .",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"precompile": "tsc --version && lerna run version --scope $(npm pkg get name) --include-dependencies",
"precompile": "tsc --version && lerna run version --scope @opentelemetry/instrumentation-aws-sdk --include-dependencies",
"prewatch": "npm run precompile",
"prepare": "npm run compile",
"tdd": "npm run test -- --watch-extensions ts --watch",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
} from '../types';
import {
MessagingDestinationKindValues,
MessagingOperationValues,
SemanticAttributes,
} from '@opentelemetry/semantic-conventions';
import {
Expand Down Expand Up @@ -63,7 +64,8 @@ export class SqsServiceExtension implements ServiceExtension {
isIncoming = true;
spanKind = SpanKind.CONSUMER;
spanName = `${queueName} receive`;
spanAttributes[SemanticAttributes.MESSAGING_OPERATION] = 'receive';
spanAttributes[SemanticAttributes.MESSAGING_OPERATION] =
MessagingOperationValues.RECEIVE;

request.commandInput.MessageAttributeNames = (
request.commandInput.MessageAttributeNames ?? []
Expand Down Expand Up @@ -145,7 +147,8 @@ export class SqsServiceExtension implements ServiceExtension {
MessagingDestinationKindValues.QUEUE,
[SemanticAttributes.MESSAGING_MESSAGE_ID]: message.MessageId,
[SemanticAttributes.MESSAGING_URL]: queueUrl,
[SemanticAttributes.MESSAGING_OPERATION]: 'process',
[SemanticAttributes.MESSAGING_OPERATION]:
MessagingOperationValues.PROCESS,
},
}),
processHook: (span: Span, message: SQS.Message) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ const instrumentation = registerInstrumentationTesting(
import * as AWS from 'aws-sdk';
import { AWSError } from 'aws-sdk';

import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
import {
MessagingOperationValues,
SemanticAttributes,
} from '@opentelemetry/semantic-conventions';
import {
context,
SpanKind,
Expand Down Expand Up @@ -171,12 +174,16 @@ describe('SQS', () => {
numChildPerProcessSpan: number
) => {
const awsReceiveSpan = spans.filter(
s => s.attributes[SemanticAttributes.MESSAGING_OPERATION] === 'receive'
s =>
s.attributes[SemanticAttributes.MESSAGING_OPERATION] ===
MessagingOperationValues.RECEIVE
);
expect(awsReceiveSpan.length).toBe(1);

const processSpans = spans.filter(
s => s.attributes[SemanticAttributes.MESSAGING_OPERATION] === 'process'
s =>
s.attributes[SemanticAttributes.MESSAGING_OPERATION] ===
MessagingOperationValues.PROCESS
);
expect(processSpans.length).toBe(2);
expect(processSpans[0].parentSpanId).toStrictEqual(
Expand Down Expand Up @@ -380,7 +387,9 @@ describe('SQS', () => {
);

const processSpans = getTestSpans().filter(
s => s.attributes[SemanticAttributes.MESSAGING_OPERATION] === 'process'
s =>
s.attributes[SemanticAttributes.MESSAGING_OPERATION] ===
MessagingOperationValues.PROCESS
);
expect(processSpans.length).toBe(2);
expect(
Expand All @@ -402,7 +411,9 @@ describe('SQS', () => {
message => 'some mapping to create child process spans'
);
const processSpans = getTestSpans().filter(
s => s.attributes[SemanticAttributes.MESSAGING_OPERATION] === 'process'
s =>
s.attributes[SemanticAttributes.MESSAGING_OPERATION] ===
MessagingOperationValues.PROCESS
);
expect(processSpans.length).toBe(2);
});
Expand All @@ -429,7 +440,9 @@ describe('SQS', () => {
);

const processSpans = getTestSpans().filter(
s => s.attributes[SemanticAttributes.MESSAGING_OPERATION] === 'process'
s =>
s.attributes[SemanticAttributes.MESSAGING_OPERATION] ===
MessagingOperationValues.PROCESS
);
expect(processSpans.length).toBe(2);
expect(processSpans[0].status.code).toStrictEqual(SpanStatusCode.UNSET);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ export function getConnectionAttributes(
return {
[SemanticAttributes.NET_PEER_NAME]: host,
[SemanticAttributes.NET_PEER_PORT]: port,
[SemanticAttributes.NET_PEER_IP]: getJDBCString(host, port, database),
[SemanticAttributes.DB_CONNECTION_STRING]: getJDBCString(
host,
port,
database
),
[SemanticAttributes.DB_NAME]: database,
[SemanticAttributes.DB_USER]: user,
};
Expand Down
14 changes: 10 additions & 4 deletions plugins/node/opentelemetry-instrumentation-mysql2/.tav.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
mysql2:
versions: 2.*
commands: npm run test
- versions: 2.*
commands: npm run test

# Fix missing `test-utils` package
pretest: npm run --prefix ../../../ lerna:link
# Fix missing `test-utils` package
pretest: npm run --prefix ../../../ lerna:link
- versions: 1.4.2 || 1.5.0 || 1.5.1 || 1.5.2 || 1.5.3 || 1.6.0 || 1.6.3 || 1.6.4 || 1.6.5 || 1.7.0
# Skip v1.6.2, which is broken
commands: npm run test

# Fix missing `test-utils` package
pretest: npm run --prefix ../../../ lerna:link
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ npm install --save @opentelemetry/instrumentation-mysql2

## Supported Versions

- `2.x`
- `>= 1.4.2, < 3.0`

## Usage

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,15 @@
"@opentelemetry/contrib-test-utils": "^0.29.0",
"@opentelemetry/sdk-trace-base": "1.0.1",
"@types/mocha": "7.0.2",
"@types/mysql2": "github:types/mysql2",
"@types/node": "16.11.21",
"@types/semver": "7.3.8",
"gts": "3.1.0",
"mocha": "7.2.0",
"mysql2": "2.3.0",
"nyc": "15.1.0",
"rimraf": "3.0.2",
"semver": "7.3.5",
"test-all-versions": "5.0.1",
"ts-mocha": "8.0.0",
"typescript": "4.3.5"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class MySQL2Instrumentation extends InstrumentationBase<
return [
new InstrumentationNodeModuleDefinition<typeof mysqlTypes>(
'mysql2',
['2.*'],
['>= 1.4.2 < 3.0'],
(moduleExports: any, moduleVersion) => {
api.diag.debug(`Patching mysql@${moduleVersion}`);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ export function getConnectionAttributes(config: Config): SpanAttributes {
return {
[SemanticAttributes.NET_PEER_NAME]: host,
[SemanticAttributes.NET_PEER_PORT]: port,
[SemanticAttributes.NET_PEER_IP]: getJDBCString(host, port, database),
[SemanticAttributes.DB_CONNECTION_STRING]: getJDBCString(
host,
port,
database
),
[SemanticAttributes.DB_NAME]: database,
[SemanticAttributes.DB_USER]: user,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import * as semver from 'semver';
import { context, trace, SpanStatusCode } from '@opentelemetry/api';
import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks';
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
Expand Down Expand Up @@ -669,5 +670,5 @@ function assertSpan(
function isPoolClusterEndIgnoreCallback() {
// Since v2.2.0 `end` function respect callback
// https://github.com/sidorares/node-mysql2/commit/1481015626e506754adc4308e5508356a3a03aa0
return ['2.0.0', '2.0.1', '2.0.2', '2.1.0'].includes(LIB_VERSION);
return semver.lt(LIB_VERSION, '2.2.0');
}
6 changes: 4 additions & 2 deletions plugins/node/opentelemetry-instrumentation-redis/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export const getTracedInternalSendCommand = (
}
if (this.address) {
span.setAttribute(
SemanticAttributes.NET_PEER_IP,
SemanticAttributes.DB_CONNECTION_STRING,
`redis://${this.address}`
);
}
Expand All @@ -140,7 +140,9 @@ export const getTracedInternalSendCommand = (
responseHook(span, cmd.command, cmd.args, reply);
},
err => {
diag.error('Error executing responseHook', err);
if (err) {
diag.error('Error executing responseHook', err);
}
},
true
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const DEFAULT_ATTRIBUTES = {
[SemanticAttributes.DB_SYSTEM]: RedisInstrumentation.COMPONENT,
[SemanticAttributes.NET_PEER_NAME]: CONFIG.host,
[SemanticAttributes.NET_PEER_PORT]: CONFIG.port,
[SemanticAttributes.NET_PEER_IP]: URL,
[SemanticAttributes.DB_CONNECTION_STRING]: URL,
};

const unsetStatus: SpanStatus = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ registerInstrumentations({
new WinstonInstrumentation({
// Optional hook to insert additional context to log metadata.
// Called after trace context is injected to metadata.
logHook: (record, span) => {
logHook: (span, record) => {
record['resource.service.name'] = provider.resource.attributes['service.name'];
},
}),
Expand Down

0 comments on commit aea5851

Please sign in to comment.