Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@opentelemetry/instrumentation-pg

Package Overview
Dependencies
Maintainers
3
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opentelemetry/instrumentation-pg - npm Package Compare versions

Comparing version 0.35.3 to 0.36.0

17

build/src/index.js

@@ -17,16 +17,7 @@ "use strict";

*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./instrumentation"), exports);
__exportStar(require("./types"), exports);
__exportStar(require("./enums/AttributeNames"), exports);
const tslib_1 = require("tslib");
(0, tslib_1.__exportStar)(require("./instrumentation"), exports);
(0, tslib_1.__exportStar)(require("./types"), exports);
(0, tslib_1.__exportStar)(require("./enums/AttributeNames"), exports);
//# sourceMappingURL=index.js.map

@@ -24,2 +24,3 @@ "use strict";

const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
const sql_common_1 = require("@opentelemetry/sql-common");
const version_1 = require("./version");

@@ -124,11 +125,7 @@ const PG_POOL_COMPONENT = 'pg-pool';

// tracing, but only if args[0] has one of our expected shapes.
//
// TODO: remove the `as ...` casts below when the TS version is upgraded.
// Newer TS versions will use the result of firstArgIsQueryObjectWithText
// to properly narrow arg0, but TS 4.3.5 does not.
if (instrumentationConfig.addSqlCommenterCommentToQueries) {
args[0] = firstArgIsString
? utils.addSqlCommenterComment(span, arg0)
? (0, sql_common_1.addSqlCommenterComment)(span, arg0)
: firstArgIsQueryObjectWithText
? Object.assign(Object.assign({}, arg0), { text: utils.addSqlCommenterComment(span, arg0.text) }) : args[0];
? Object.assign(Object.assign({}, arg0), { text: (0, sql_common_1.addSqlCommenterComment)(span, arg0.text) }) : args[0];
}

@@ -135,0 +132,0 @@ // Bind callback (if any) to parent span (if any)

@@ -42,3 +42,2 @@ import { Span, Tracer } from '@opentelemetry/api';

export declare function patchClientConnectCallback(span: Span, cb: Function): Function;
export declare function addSqlCommenterComment(span: Span, query: string): string;
/**

@@ -45,0 +44,0 @@ * Attempt to get a message string from a thrown value, while being quite

@@ -18,5 +18,4 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.isObjectWithTextString = exports.getErrorMessage = exports.addSqlCommenterComment = 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.getSemanticAttributesFromConnection = exports.getConnectionString = exports.getQuerySpanName = void 0;
const api_1 = require("@opentelemetry/api");
const core_1 = require("@opentelemetry/core");
const AttributeNames_1 = require("./enums/AttributeNames");

@@ -195,51 +194,2 @@ const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");

exports.patchClientConnectCallback = patchClientConnectCallback;
// NOTE: This function currently is returning false-positives
// in cases where comment characters appear in string literals
// ("SELECT '-- not a comment';" would return true, although has no comment)
function hasValidSqlComment(query) {
const indexOpeningDashDashComment = query.indexOf('--');
if (indexOpeningDashDashComment >= 0) {
return true;
}
const indexOpeningSlashComment = query.indexOf('/*');
if (indexOpeningSlashComment < 0) {
return false;
}
const indexClosingSlashComment = query.indexOf('*/');
return indexOpeningDashDashComment < indexClosingSlashComment;
}
// sqlcommenter specification (https://google.github.io/sqlcommenter/spec/#value-serialization)
// expects us to URL encode based on the RFC 3986 spec (https://en.wikipedia.org/wiki/Percent-encoding),
// but encodeURIComponent does not handle some characters correctly (! ' ( ) *),
// which means we need special handling for this
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
function fixedEncodeURIComponent(str) {
return encodeURIComponent(str).replace(/[!'()*]/g, c => `%${c.charCodeAt(0).toString(16).toUpperCase()}`);
}
function addSqlCommenterComment(span, query) {
if (typeof query !== 'string' || query.length === 0) {
return query;
}
// As per sqlcommenter spec we shall not add a comment if there already is a comment
// in the query
if (hasValidSqlComment(query)) {
return query;
}
const propagator = new core_1.W3CTraceContextPropagator();
const headers = {};
propagator.inject(api_1.trace.setSpan(api_1.ROOT_CONTEXT, span), headers, api_1.defaultTextMapSetter);
// sqlcommenter spec requires keys in the comment to be sorted lexicographically
const sortedKeys = Object.keys(headers).sort();
if (sortedKeys.length === 0) {
return query;
}
const commentString = sortedKeys
.map(key => {
const encodedValue = fixedEncodeURIComponent(headers[key]);
return `${key}='${encodedValue}'`;
})
.join(',');
return `${query} /*${commentString}*/`;
}
exports.addSqlCommenterComment = addSqlCommenterComment;
/**

@@ -246,0 +196,0 @@ * Attempt to get a message string from a thrown value, while being quite

@@ -1,2 +0,2 @@

export declare const VERSION = "0.35.3";
export declare const VERSION = "0.36.0";
//# sourceMappingURL=version.d.ts.map

@@ -20,3 +20,3 @@ "use strict";

// this is autogenerated file, see scripts/version-update.js
exports.VERSION = '0.35.3';
exports.VERSION = '0.36.0';
//# sourceMappingURL=version.js.map
{
"name": "@opentelemetry/instrumentation-pg",
"version": "0.35.3",
"version": "0.36.0",
"description": "OpenTelemetry postgres automatic instrumentation package.",

@@ -58,3 +58,3 @@ "main": "build/src/index.js",

"@opentelemetry/context-async-hooks": "^1.8.0",
"@opentelemetry/contrib-test-utils": "^0.33.4",
"@opentelemetry/contrib-test-utils": "^0.34.0",
"@opentelemetry/sdk-trace-base": "^1.8.0",

@@ -79,9 +79,11 @@ "@opentelemetry/sdk-trace-node": "^1.8.0",

"@opentelemetry/core": "^1.8.0",
"@opentelemetry/instrumentation": "^0.40.0",
"@opentelemetry/instrumentation": "^0.41.0",
"@opentelemetry/semantic-conventions": "^1.0.0",
"@opentelemetry/sql-common": "^0.40.0",
"@types/pg": "8.6.1",
"@types/pg-pool": "2.0.3"
"@types/pg-pool": "2.0.3",
"tslib": "^2.3.1"
},
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-pg#readme",
"gitHead": "efdfc727a49090accee7fea8ff93011b6b84c1e4"
"gitHead": "f81f8a76a8f0af2101c62dbc73cde442f875d833"
}

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc