@opentelemetry/instrumentation-pg
Advanced tools
Comparing version 0.39.1 to 0.40.0
@@ -6,4 +6,2 @@ import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation'; | ||
export declare class PgInstrumentation extends InstrumentationBase { | ||
static readonly COMPONENT = "pg"; | ||
static readonly BASE_SPAN_NAME: string; | ||
constructor(config?: PgInstrumentationConfig); | ||
@@ -10,0 +8,0 @@ protected init(): (InstrumentationNodeModuleDefinition<typeof pgTypes> | InstrumentationNodeModuleDefinition<typeof pgPoolTypes>)[]; |
@@ -22,7 +22,5 @@ "use strict"; | ||
const utils = require("./utils"); | ||
const AttributeNames_1 = require("./enums/AttributeNames"); | ||
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions"); | ||
const sql_common_1 = require("@opentelemetry/sql-common"); | ||
const version_1 = require("./version"); | ||
const PG_POOL_COMPONENT = 'pg-pool'; | ||
const SpanNames_1 = require("./enums/SpanNames"); | ||
class PgInstrumentation extends instrumentation_1.InstrumentationBase { | ||
@@ -84,5 +82,5 @@ constructor(config = {}) { | ||
} | ||
const span = plugin.tracer.startSpan(`${PgInstrumentation.COMPONENT}.connect`, { | ||
const span = plugin.tracer.startSpan(SpanNames_1.SpanNames.CONNECT, { | ||
kind: api_1.SpanKind.CLIENT, | ||
attributes: Object.assign({ [semantic_conventions_1.SemanticAttributes.DB_SYSTEM]: semantic_conventions_1.DbSystemValues.POSTGRESQL }, utils.getSemanticAttributesFromConnection(this)), | ||
attributes: utils.getSemanticAttributesFromConnection(this), | ||
}); | ||
@@ -106,3 +104,3 @@ if (callback) { | ||
return (original) => { | ||
this._diag.debug(`Patching ${PgInstrumentation.COMPONENT}.Client.prototype.query`); | ||
this._diag.debug('Patching pg.Client.prototype.query'); | ||
return function query(...args) { | ||
@@ -250,5 +248,5 @@ if (utils.shouldSkipInstrumentation(plugin.getConfig())) { | ||
// setup span | ||
const span = plugin.tracer.startSpan(`${PG_POOL_COMPONENT}.connect`, { | ||
const span = plugin.tracer.startSpan(SpanNames_1.SpanNames.POOL_CONNECT, { | ||
kind: api_1.SpanKind.CLIENT, | ||
attributes: Object.assign(Object.assign({ [semantic_conventions_1.SemanticAttributes.DB_SYSTEM]: semantic_conventions_1.DbSystemValues.POSTGRESQL }, utils.getSemanticAttributesFromConnection(this.options)), { [AttributeNames_1.AttributeNames.IDLE_TIMEOUT_MILLIS]: this.options.idleTimeoutMillis, [AttributeNames_1.AttributeNames.MAX_CLIENT]: this.options.maxClient }), | ||
attributes: utils.getSemanticAttributesFromPool(this.options), | ||
}); | ||
@@ -272,4 +270,2 @@ if (callback) { | ||
exports.PgInstrumentation = PgInstrumentation; | ||
PgInstrumentation.COMPONENT = 'pg'; | ||
PgInstrumentation.BASE_SPAN_NAME = PgInstrumentation.COMPONENT + '.query'; | ||
function handleConnectResult(span, connectResult) { | ||
@@ -276,0 +272,0 @@ if (!(connectResult instanceof Promise)) { |
import { Span, Tracer } from '@opentelemetry/api'; | ||
import { PgClientExtended, PostgresCallback, PgPoolCallback, PgParsedConnectionParams } from './internal-types'; | ||
import { PgClientExtended, PostgresCallback, PgPoolCallback, PgParsedConnectionParams, PgPoolOptionsParams } from './internal-types'; | ||
import { PgInstrumentationConfig } from './types'; | ||
@@ -30,2 +30,3 @@ import type * as pgTypes from 'pg'; | ||
export declare function getSemanticAttributesFromConnection(params: PgParsedConnectionParams): { | ||
"db.system": string; | ||
"db.name": string | undefined; | ||
@@ -37,2 +38,12 @@ "db.connection_string": string; | ||
}; | ||
export declare function getSemanticAttributesFromPool(params: PgPoolOptionsParams): { | ||
"db.system": string; | ||
"db.name": string; | ||
"db.connection_string": string; | ||
"net.peer.name": string; | ||
"net.peer.port": number | undefined; | ||
"db.user": string; | ||
"db.postgresql.idle.timeout.millis": number; | ||
"db.postgresql.max.client": number; | ||
}; | ||
export declare function shouldSkipInstrumentation(instrumentationConfig: PgInstrumentationConfig): boolean; | ||
@@ -39,0 +50,0 @@ export declare function handleConfigQuery(this: PgClientExtended, tracer: Tracer, instrumentationConfig: PgInstrumentationConfig, queryConfig?: { |
@@ -18,8 +18,8 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isObjectWithTextString = exports.getErrorMessage = exports.patchClientConnectCallback = exports.patchCallbackPGPool = exports.patchCallback = exports.handleExecutionResult = exports.handleConfigQuery = exports.shouldSkipInstrumentation = exports.getSemanticAttributesFromConnection = exports.getConnectionString = exports.getQuerySpanName = void 0; | ||
exports.isObjectWithTextString = exports.getErrorMessage = exports.patchClientConnectCallback = exports.patchCallbackPGPool = exports.patchCallback = exports.handleExecutionResult = exports.handleConfigQuery = exports.shouldSkipInstrumentation = exports.getSemanticAttributesFromPool = exports.getSemanticAttributesFromConnection = exports.getConnectionString = exports.getQuerySpanName = void 0; | ||
const api_1 = require("@opentelemetry/api"); | ||
const AttributeNames_1 = require("./enums/AttributeNames"); | ||
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions"); | ||
const _1 = require("./"); | ||
const instrumentation_1 = require("@opentelemetry/instrumentation"); | ||
const SpanNames_1 = require("./enums/SpanNames"); | ||
/** | ||
@@ -49,3 +49,3 @@ * Helper function to get a low cardinality span name from whatever info we have | ||
if (!queryConfig) | ||
return _1.PgInstrumentation.BASE_SPAN_NAME; | ||
return SpanNames_1.SpanNames.QUERY_PREFIX; | ||
// Either the name of a prepared statement; or an attempted parse | ||
@@ -56,3 +56,3 @@ // of the SQL command, normalized to uppercase; or unknown. | ||
: parseNormalizedOperationName(queryConfig.text); | ||
return `${_1.PgInstrumentation.BASE_SPAN_NAME}:${command}${dbName ? ` ${dbName}` : ''}`; | ||
return `${SpanNames_1.SpanNames.QUERY_PREFIX}:${command}${dbName ? ` ${dbName}` : ''}`; | ||
} | ||
@@ -83,10 +83,24 @@ exports.getQuerySpanName = getQuerySpanName; | ||
return { | ||
[semantic_conventions_1.SemanticAttributes.DB_NAME]: params.database, | ||
[semantic_conventions_1.SemanticAttributes.DB_CONNECTION_STRING]: getConnectionString(params), | ||
[semantic_conventions_1.SemanticAttributes.NET_PEER_NAME]: params.host, | ||
[semantic_conventions_1.SemanticAttributes.NET_PEER_PORT]: getPort(params.port), | ||
[semantic_conventions_1.SemanticAttributes.DB_USER]: params.user, | ||
[semantic_conventions_1.SEMATTRS_DB_SYSTEM]: semantic_conventions_1.DBSYSTEMVALUES_POSTGRESQL, | ||
[semantic_conventions_1.SEMATTRS_DB_NAME]: params.database, | ||
[semantic_conventions_1.SEMATTRS_DB_CONNECTION_STRING]: getConnectionString(params), | ||
[semantic_conventions_1.SEMATTRS_NET_PEER_NAME]: params.host, | ||
[semantic_conventions_1.SEMATTRS_NET_PEER_PORT]: getPort(params.port), | ||
[semantic_conventions_1.SEMATTRS_DB_USER]: params.user, | ||
}; | ||
} | ||
exports.getSemanticAttributesFromConnection = getSemanticAttributesFromConnection; | ||
function getSemanticAttributesFromPool(params) { | ||
return { | ||
[semantic_conventions_1.SEMATTRS_DB_SYSTEM]: semantic_conventions_1.DBSYSTEMVALUES_POSTGRESQL, | ||
[semantic_conventions_1.SEMATTRS_DB_NAME]: params.database, | ||
[semantic_conventions_1.SEMATTRS_DB_CONNECTION_STRING]: getConnectionString(params), | ||
[semantic_conventions_1.SEMATTRS_NET_PEER_NAME]: params.host, | ||
[semantic_conventions_1.SEMATTRS_NET_PEER_PORT]: getPort(params.port), | ||
[semantic_conventions_1.SEMATTRS_DB_USER]: params.user, | ||
[AttributeNames_1.AttributeNames.IDLE_TIMEOUT_MILLIS]: params.idleTimeoutMillis, | ||
[AttributeNames_1.AttributeNames.MAX_CLIENT]: params.maxClient, | ||
}; | ||
} | ||
exports.getSemanticAttributesFromPool = getSemanticAttributesFromPool; | ||
function shouldSkipInstrumentation(instrumentationConfig) { | ||
@@ -106,3 +120,3 @@ return (instrumentationConfig.requireParentSpan === true && | ||
kind: api_1.SpanKind.CLIENT, | ||
attributes: Object.assign({ [semantic_conventions_1.SemanticAttributes.DB_SYSTEM]: semantic_conventions_1.DbSystemValues.POSTGRESQL }, getSemanticAttributesFromConnection(connectionParameters)), | ||
attributes: getSemanticAttributesFromConnection(connectionParameters), | ||
}); | ||
@@ -114,3 +128,3 @@ if (!queryConfig) { | ||
if (queryConfig.text) { | ||
span.setAttribute(semantic_conventions_1.SemanticAttributes.DB_STATEMENT, queryConfig.text); | ||
span.setAttribute(semantic_conventions_1.SEMATTRS_DB_STATEMENT, queryConfig.text); | ||
} | ||
@@ -117,0 +131,0 @@ if (instrumentationConfig.enhancedDatabaseReporting && |
@@ -1,2 +0,2 @@ | ||
export declare const VERSION = "0.39.1"; | ||
export declare const VERSION = "0.40.0"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -20,3 +20,3 @@ "use strict"; | ||
// this is autogenerated file, see scripts/version-update.js | ||
exports.VERSION = '0.39.1'; | ||
exports.VERSION = '0.40.0'; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "@opentelemetry/instrumentation-pg", | ||
"version": "0.39.1", | ||
"version": "0.40.0", | ||
"description": "OpenTelemetry postgres automatic instrumentation package.", | ||
@@ -55,3 +55,3 @@ "main": "build/src/index.js", | ||
"@opentelemetry/context-async-hooks": "^1.8.0", | ||
"@opentelemetry/contrib-test-utils": "^0.37.0", | ||
"@opentelemetry/contrib-test-utils": "^0.38.0", | ||
"@opentelemetry/sdk-trace-base": "^1.8.0", | ||
@@ -75,4 +75,4 @@ "@opentelemetry/sdk-trace-node": "^1.8.0", | ||
"dependencies": { | ||
"@opentelemetry/instrumentation": "^0.49.1", | ||
"@opentelemetry/semantic-conventions": "^1.0.0", | ||
"@opentelemetry/instrumentation": "^0.50.0", | ||
"@opentelemetry/semantic-conventions": "^1.22.0", | ||
"@opentelemetry/sql-common": "^0.40.0", | ||
@@ -83,3 +83,3 @@ "@types/pg": "8.6.1", | ||
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-pg#readme", | ||
"gitHead": "9d19ca4103bc72bd42e28979fee19bd08d85b721" | ||
"gitHead": "17a0bc1da3baa472ba9b867eee3c60730cc130fb" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
104889
27
829
+ Added@opentelemetry/api-logs@0.50.0(transitive)
+ Added@opentelemetry/instrumentation@0.50.0(transitive)
- Removed@opentelemetry/api-logs@0.49.1(transitive)
- Removed@opentelemetry/instrumentation@0.49.1(transitive)