Skip to content

Commit

Permalink
Merge branch 'main' into te
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarchaud authored May 8, 2021
2 parents 7e273e8 + 1386d75 commit e4665e5
Show file tree
Hide file tree
Showing 20 changed files with 97 additions and 105 deletions.
4 changes: 2 additions & 2 deletions examples/postgres/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
"@opentelemetry/exporter-zipkin": "^0.19.0",
"@opentelemetry/instrumentation": "^0.19.0",
"@opentelemetry/instrumentation-http": "^0.19.0",
"@opentelemetry/instrumentation-pg": "^0.15.0",
"@opentelemetry/instrumentation-pg": "^0.16.0",
"@opentelemetry/node": "^0.19.0",
"@opentelemetry/tracing": "^0.19.0",
"express": "^4.17.1",
"pg": "^7.12.1"
"pg": "^8.6.0"
},
"homepage": "https://github.com/open-telemetry/opentelemetry-js#readme",
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
},
"devDependencies": {
"@opentelemetry/node": "0.19.0",
"@types/aws-lambda": "8.10.76",
"@types/mocha": "7.0.2",
"@types/node": "14.14.43",
"codecov": "3.8.1",
Expand All @@ -58,6 +57,7 @@
"@opentelemetry/instrumentation": "^0.19.0",
"@opentelemetry/resources": "^0.19.0",
"@opentelemetry/semantic-conventions": "^0.19.0",
"@opentelemetry/tracing": "^0.19.0"
"@opentelemetry/tracing": "^0.19.0",
"@types/aws-lambda": "8.10.76"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"@opentelemetry/context-async-hooks": "0.19.0",
"@opentelemetry/node": "0.19.0",
"@opentelemetry/tracing": "0.19.0",
"@types/bunyan": "1.8.6",
"@types/mocha": "7.0.2",
"@types/node": "14.14.43",
"@types/sinon": "9.0.11",
Expand All @@ -61,6 +60,7 @@
},
"dependencies": {
"@opentelemetry/api": "^1.0.0-rc.0",
"@opentelemetry/instrumentation": "^0.19.0"
"@opentelemetry/instrumentation": "^0.19.0",
"@types/bunyan": "1.8.6"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"@opentelemetry/context-async-hooks": "0.19.0",
"@opentelemetry/node": "0.19.0",
"@opentelemetry/tracing": "0.19.0",
"@types/express": "4.17.11",
"@types/mocha": "7.0.2",
"@types/node": "14.14.43",
"codecov": "3.8.1",
Expand All @@ -61,6 +60,7 @@
"@opentelemetry/api": "^1.0.0-rc.0",
"@opentelemetry/core": "^0.19.0",
"@opentelemetry/instrumentation": "^0.19.0",
"@opentelemetry/semantic-conventions": "^0.19.0"
"@opentelemetry/semantic-conventions": "^0.19.0",
"@types/express": "4.17.11"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
},
"devDependencies": {
"@opentelemetry/tracing": "0.19.0",
"@types/graphql": "14.5.0",
"@types/mocha": "8.2.2",
"@types/node": "14.14.43",
"codecov": "3.8.1",
Expand All @@ -58,6 +57,7 @@
},
"dependencies": {
"@opentelemetry/api": "^1.0.0-rc.0",
"@opentelemetry/instrumentation": "^0.19.0"
"@opentelemetry/instrumentation": "^0.19.0",
"@types/graphql": "14.5.0"
}
}
4 changes: 2 additions & 2 deletions plugins/node/opentelemetry-instrumentation-hapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"@opentelemetry/context-async-hooks": "0.19.0",
"@opentelemetry/node": "0.19.0",
"@opentelemetry/tracing": "0.19.0",
"@types/hapi__hapi": "20.0.8",
"@types/mocha": "7.0.2",
"@types/node": "12.20.11",
"codecov": "3.8.1",
Expand All @@ -60,6 +59,7 @@
"dependencies": {
"@opentelemetry/api": "^1.0.0-rc.0",
"@opentelemetry/instrumentation": "^0.19.0",
"@opentelemetry/semantic-conventions": "^0.19.0"
"@opentelemetry/semantic-conventions": "^0.19.0",
"@types/hapi__hapi": "20.0.8"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@
"@opentelemetry/node": "0.19.0",
"@opentelemetry/test-utils": "^0.16.0",
"@opentelemetry/tracing": "0.19.0",
"@types/ioredis": "4.26.1",
"@types/mocha": "7.0.2",
"@types/node": "14.14.43",
"@types/shimmer": "1.0.1",
"codecov": "3.8.1",
"cross-env": "7.0.3",
"gts": "3.1.0",
Expand All @@ -65,6 +63,7 @@
"dependencies": {
"@opentelemetry/api": "^1.0.0-rc.0",
"@opentelemetry/instrumentation": "^0.19.0",
"@opentelemetry/semantic-conventions": "^0.19.0"
"@opentelemetry/semantic-conventions": "^0.19.0",
"@types/ioredis": "4.26.0"
}
}
6 changes: 3 additions & 3 deletions plugins/node/opentelemetry-instrumentation-koa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@
"@opentelemetry/context-async-hooks": "0.19.0",
"@opentelemetry/node": "0.19.0",
"@opentelemetry/tracing": "0.19.0",
"@types/koa": "2.13.1",
"@types/koa__router": "8.0.4",
"@types/mocha": "7.0.2",
"@types/node": "12.20.11",
"codecov": "3.8.1",
Expand All @@ -63,6 +61,8 @@
"dependencies": {
"@opentelemetry/api": "^1.0.0-rc.0",
"@opentelemetry/instrumentation": "^0.19.0",
"@opentelemetry/semantic-conventions": "^0.19.0"
"@opentelemetry/semantic-conventions": "^0.19.0",
"@types/koa": "2.13.1",
"@types/koa__router": "8.0.4"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"@opentelemetry/node": "0.19.0",
"@opentelemetry/tracing": "0.19.0",
"@types/mocha": "7.0.2",
"@types/mongodb": "3.6.12",
"@types/node": "14.14.43",
"codecov": "3.8.1",
"gts": "3.1.0",
Expand All @@ -61,6 +60,7 @@
"dependencies": {
"@opentelemetry/api": "^1.0.0-rc.0",
"@opentelemetry/instrumentation": "^0.19.0",
"@opentelemetry/semantic-conventions": "^0.19.0"
"@opentelemetry/semantic-conventions": "^0.19.0",
"@types/mongodb": "3.6.12"
}
}
4 changes: 2 additions & 2 deletions plugins/node/opentelemetry-instrumentation-mysql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"@opentelemetry/test-utils": "^0.16.0",
"@opentelemetry/tracing": "0.19.0",
"@types/mocha": "7.0.2",
"@types/mysql": "2.15.18",
"@types/node": "14.14.43",
"codecov": "3.8.1",
"gts": "3.1.0",
Expand All @@ -59,6 +58,7 @@
"dependencies": {
"@opentelemetry/api": "^1.0.0-rc.0",
"@opentelemetry/instrumentation": "^0.19.0",
"@opentelemetry/semantic-conventions": "^0.19.0"
"@opentelemetry/semantic-conventions": "^0.19.0",
"@types/mysql": "2.15.18"
}
}
7 changes: 4 additions & 3 deletions plugins/node/opentelemetry-instrumentation-pg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@
"@opentelemetry/tracing": "0.19.0",
"@types/mocha": "7.0.2",
"@types/node": "14.14.43",
"@types/pg": "7.14.11",
"@types/pg-pool": "2.0.2",
"codecov": "3.8.1",
"cross-env": "7.0.3",
"gts": "3.1.0",
Expand All @@ -68,6 +66,9 @@
},
"dependencies": {
"@opentelemetry/api": "^1.0.0-rc.0",
"@opentelemetry/instrumentation": "^0.19.0"
"@opentelemetry/instrumentation": "^0.19.0",
"@opentelemetry/semantic-conventions": "^0.19.0",
"@types/pg": "7.14.11",
"@types/pg-pool": "2.0.2"
}
}
27 changes: 5 additions & 22 deletions plugins/node/opentelemetry-instrumentation-pg/src/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,10 @@
* limitations under the License.
*/

// Postgresql specific attributes not covered by semantic conventions
export enum AttributeNames {
// required by https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/data-database.md
COMPONENT = 'component',
DB_TYPE = 'db.type',
DB_INSTANCE = 'db.instance',
DB_STATEMENT = 'db.statement',
PEER_ADDRESS = 'peer.address',
PEER_HOSTNAME = 'peer.host',

// optional
DB_USER = 'db.user',
PEER_PORT = 'peer.port',
PEER_IPV4 = 'peer.ipv4',
PEER_IPV6 = 'peer.ipv6',
PEER_SERVICE = 'peer.service',

// PG specific -- not specified by spec
PG_VALUES = 'pg.values',
PG_PLAN = 'pg.plan',

// PG-POOL specific -- not specified by spec
IDLE_TIMEOUT_MILLIS = 'idle.timeout.millis',
MAX_CLIENT = 'max',
PG_VALUES = 'db.postgresql.values',
PG_PLAN = 'db.postgresql.plan',
IDLE_TIMEOUT_MILLIS = 'db.postgresql.idle.timeout.millis',
MAX_CLIENT = 'db.postgresql.max.client',
}
18 changes: 10 additions & 8 deletions plugins/node/opentelemetry-instrumentation-pg/src/pg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ import {
} from './types';
import * as utils from './utils';
import { AttributeNames } from './enums';
import {
SemanticAttributes,
DbSystemValues,
} from '@opentelemetry/semantic-conventions';
import { VERSION } from './version';

export interface PgInstrumentationConfig extends InstrumentationConfig {
Expand All @@ -54,7 +58,6 @@ const PG_POOL_COMPONENT = 'pg-pool';

export class PgInstrumentation extends InstrumentationBase {
static readonly COMPONENT = 'pg';
static readonly DB_TYPE = 'sql';

static readonly BASE_SPAN_NAME = PgInstrumentation.COMPONENT + '.query';

Expand Down Expand Up @@ -227,13 +230,12 @@ export class PgInstrumentation extends InstrumentationBase {
const span = plugin.tracer.startSpan(`${PG_POOL_COMPONENT}.connect`, {
kind: SpanKind.CLIENT,
attributes: {
[AttributeNames.COMPONENT]: PgInstrumentation.COMPONENT, // required
[AttributeNames.DB_TYPE]: PgInstrumentation.DB_TYPE, // required
[AttributeNames.DB_INSTANCE]: this.options.database, // required
[AttributeNames.PEER_HOSTNAME]: this.options.host, // required
[AttributeNames.PEER_ADDRESS]: jdbcString, // required
[AttributeNames.PEER_PORT]: this.options.port,
[AttributeNames.DB_USER]: this.options.user,
[SemanticAttributes.DB_SYSTEM]: DbSystemValues.POSTGRESQL,
[SemanticAttributes.DB_NAME]: this.options.database, // required
[SemanticAttributes.NET_PEER_NAME]: this.options.host, // required
[SemanticAttributes.DB_CONNECTION_STRING]: jdbcString, // required
[SemanticAttributes.NET_PEER_PORT]: this.options.port,
[SemanticAttributes.DB_USER]: this.options.user,
[AttributeNames.IDLE_TIMEOUT_MILLIS]: this.options
.idleTimeoutMillis,
[AttributeNames.MAX_CLIENT]: this.options.maxClient,
Expand Down
23 changes: 13 additions & 10 deletions plugins/node/opentelemetry-instrumentation-pg/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
*/

import { Span, SpanStatusCode, Tracer, SpanKind } from '@opentelemetry/api';
import {
SemanticAttributes,
DbSystemValues,
} from '@opentelemetry/semantic-conventions';
import { AttributeNames } from './enums';
import {
PgClientExtended,
Expand Down Expand Up @@ -51,13 +55,12 @@ function pgStartSpan(tracer: Tracer, client: PgClientExtended, name: string) {
return tracer.startSpan(name, {
kind: SpanKind.CLIENT,
attributes: {
[AttributeNames.COMPONENT]: PgInstrumentation.COMPONENT, // required
[AttributeNames.DB_INSTANCE]: client.connectionParameters.database, // required
[AttributeNames.DB_TYPE]: PgInstrumentation.DB_TYPE, // required
[AttributeNames.PEER_ADDRESS]: jdbcString, // required
[AttributeNames.PEER_HOSTNAME]: client.connectionParameters.host, // required
[AttributeNames.PEER_PORT]: client.connectionParameters.port,
[AttributeNames.DB_USER]: client.connectionParameters.user,
[SemanticAttributes.DB_NAME]: client.connectionParameters.database, // required
[SemanticAttributes.DB_SYSTEM]: DbSystemValues.POSTGRESQL, // required
[SemanticAttributes.DB_CONNECTION_STRING]: jdbcString, // required
[SemanticAttributes.NET_PEER_NAME]: client.connectionParameters.host, // required
[SemanticAttributes.NET_PEER_PORT]: client.connectionParameters.port,
[SemanticAttributes.DB_USER]: client.connectionParameters.user,
},
});
}
Expand All @@ -76,7 +79,7 @@ export function handleConfigQuery(

// Set attributes
if (queryConfig.text) {
span.setAttribute(AttributeNames.DB_STATEMENT, queryConfig.text);
span.setAttribute(SemanticAttributes.DB_STATEMENT, queryConfig.text);
}
if (
instrumentationConfig.enhancedDatabaseReporting &&
Expand Down Expand Up @@ -109,7 +112,7 @@ export function handleParameterizedQuery(
const span = pgStartSpan(tracer, this, name);

// Set attributes
span.setAttribute(AttributeNames.DB_STATEMENT, query);
span.setAttribute(SemanticAttributes.DB_STATEMENT, query);
if (instrumentationConfig.enhancedDatabaseReporting) {
span.setAttribute(AttributeNames.PG_VALUES, arrayStringifyHelper(values));
}
Expand All @@ -129,7 +132,7 @@ export function handleTextQuery(
const span = pgStartSpan(tracer, this, name);

// Set attributes
span.setAttribute(AttributeNames.DB_STATEMENT, query);
span.setAttribute(SemanticAttributes.DB_STATEMENT, query);

return span;
}
Expand Down
Loading

0 comments on commit e4665e5

Please sign in to comment.