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

opentelemetry-instrumentation-elasticsearch

Package Overview
Dependencies
Maintainers
2
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

opentelemetry-instrumentation-elasticsearch - npm Package Compare versions

Comparing version 0.0.0-2023-10-17--13-06 to 0.0.0-2024-05-16--12-47

5

dist/src/elasticsearch.d.ts

@@ -1,5 +0,4 @@

import type elasticsearch from '@elastic/elasticsearch';
import { ElasticsearchInstrumentationConfig } from './types';
import { InstrumentationBase, InstrumentationModuleDefinition } from '@opentelemetry/instrumentation';
export declare class ElasticsearchInstrumentation extends InstrumentationBase<typeof elasticsearch> {
export declare class ElasticsearchInstrumentation extends InstrumentationBase {
static readonly component = "@elastic/elasticsearch";

@@ -11,3 +10,3 @@ protected _config: ElasticsearchInstrumentationConfig;

setConfig(config?: ElasticsearchInstrumentationConfig): void;
protected init(): InstrumentationModuleDefinition<typeof elasticsearch>;
protected init(): InstrumentationModuleDefinition;
private patchObject;

@@ -14,0 +13,0 @@ protected patch(operationClassName: string, moduleExports: any, moduleVersion: string): any;

20

dist/src/elasticsearch.js

@@ -73,10 +73,10 @@ "use strict";

}
const [params, options, originalCallback] = utils_1.normalizeArguments(args[0], args[1], args[2]);
const [params, options, originalCallback] = (0, utils_1.normalizeArguments)(args[0], args[1], args[2]);
const operation = `${apiClassName}.${functionName}`;
const span = utils_1.startSpan({
const span = (0, utils_1.startSpan)({
tracer: self.tracer,
attributes: {
[semantic_conventions_1.SemanticAttributes.DB_OPERATION]: operation,
[enums_1.AttributeNames.ELASTICSEARCH_INDICES]: utils_1.getIndexName(params),
[semantic_conventions_1.SemanticAttributes.DB_STATEMENT]: (self._config.dbStatementSerializer || utils_1.defaultDbStatementSerializer)(operation, params, options),
[semantic_conventions_1.SEMATTRS_DB_OPERATION]: operation,
[enums_1.AttributeNames.ELASTICSEARCH_INDICES]: (0, utils_1.getIndexName)(params),
[semantic_conventions_1.SEMATTRS_DB_STATEMENT]: (self._config.dbStatementSerializer || utils_1.defaultDbStatementSerializer)(operation, params, options),
},

@@ -88,6 +88,6 @@ });

if (err) {
utils_1.onError(span, err);
(0, utils_1.onError)(span, err);
}
else {
utils_1.onResponse(span, result, self._config.responseHook);
(0, utils_1.onResponse)(span, result, self._config.responseHook);
}

@@ -101,6 +101,6 @@ return originalCallback.call(this, err, result);

promise.then((result) => {
utils_1.onResponse(span, result, self._config.responseHook);
(0, utils_1.onResponse)(span, result, self._config.responseHook);
return result;
}, (err) => {
utils_1.onError(span, err);
(0, utils_1.onError)(span, err);
return err;

@@ -115,3 +115,3 @@ });

if ((_a = this._config) === null || _a === void 0 ? void 0 : _a.suppressInternalInstrumentation) {
return api_1.context.with(core_1.suppressTracing(api_1.context.active()), originalFunction);
return api_1.context.with((0, core_1.suppressTracing)(api_1.context.active()), originalFunction);
}

@@ -118,0 +118,0 @@ else {

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

AttributeNames["ELASTICSEARCH_INDICES"] = "elasticsearch.request.indices";
})(AttributeNames = exports.AttributeNames || (exports.AttributeNames = {}));
})(AttributeNames || (exports.AttributeNames = AttributeNames = {}));
//# sourceMappingURL=enums.js.map
"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]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

import { Span } from '@opentelemetry/api';
import { InstrumentationConfig } from '@opentelemetry/instrumentation';
export declare type DbStatementSerializer = (operation?: string, params?: object, options?: object) => string;
export declare type ResponseHook = (span: Span, response: any) => void;
export type DbStatementSerializer = (operation?: string, params?: object, options?: object) => string;
export type ResponseHook = (span: Span, response: any) => void;
export interface ElasticsearchInstrumentationConfig extends InstrumentationConfig {

@@ -6,0 +6,0 @@ /**

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

kind: api_1.SpanKind.CLIENT,
attributes: Object.assign({ [semantic_conventions_1.SemanticAttributes.DB_SYSTEM]: 'elasticsearch' }, attributes),
attributes: Object.assign({ [semantic_conventions_1.SEMATTRS_DB_SYSTEM]: 'elasticsearch' }, attributes),
});

@@ -54,5 +54,5 @@ }

return {
[semantic_conventions_1.SemanticAttributes.NET_TRANSPORT]: 'IP.TCP',
[semantic_conventions_1.SemanticAttributes.NET_PEER_NAME]: hostname,
[semantic_conventions_1.SemanticAttributes.NET_PEER_PORT]: getPort(port, protocol),
[semantic_conventions_1.SEMATTRS_NET_TRANSPORT]: 'IP.TCP',
[semantic_conventions_1.SEMATTRS_NET_PEER_NAME]: hostname,
[semantic_conventions_1.SEMATTRS_NET_PEER_PORT]: getPort(port, protocol),
};

@@ -67,3 +67,3 @@ }

if (responseHook) {
instrumentation_1.safeExecuteInTheMiddle(() => responseHook(span, result), (e) => {
(0, instrumentation_1.safeExecuteInTheMiddle)(() => responseHook(span, result), (e) => {
if (e) {

@@ -70,0 +70,0 @@ api_1.diag.error('elasticsearch instrumentation: responseHook error', e);

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

export declare const VERSION = "0.0.0-2023-10-17--13-06";
export declare const VERSION = "0.0.0-2024-05-16--12-47";
//# sourceMappingURL=version.d.ts.map

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

// this is autogenerated file, see scripts/version-update.js
exports.VERSION = '0.0.0-2023-10-17--13-06';
exports.VERSION = '0.0.0-2024-05-16--12-47';
//# sourceMappingURL=version.js.map

@@ -11,6 +11,6 @@ "use strict";

const elasticsearch_1 = require("../src/elasticsearch");
const instrumentation = contrib_test_utils_1.registerInstrumentationTesting(new elasticsearch_1.ElasticsearchInstrumentation());
const instrumentation = (0, contrib_test_utils_1.registerInstrumentationTesting)(new elasticsearch_1.ElasticsearchInstrumentation());
const elasticsearch_2 = require("@elastic/elasticsearch");
const esMockUrl = 'http://localhost:9200';
const esNock = nock_1.default(esMockUrl);
const esNock = (0, nock_1.default)(esMockUrl);
const client = new elasticsearch_2.Client({ node: esMockUrl });

@@ -40,5 +40,5 @@ describe('elasticsearch instrumentation', () => {

});
const spans = contrib_test_utils_1.getTestSpans();
chai_1.expect(spans === null || spans === void 0 ? void 0 : spans.length).to.equal(2);
chai_1.expect(spans[0].attributes).to.deep.equal({
const spans = (0, contrib_test_utils_1.getTestSpans)();
(0, chai_1.expect)(spans === null || spans === void 0 ? void 0 : spans.length).to.equal(2);
(0, chai_1.expect)(spans[0].attributes).to.deep.equal({
'db.system': 'elasticsearch',

@@ -52,3 +52,3 @@ 'elasticsearch.request.indices': 'the-simpsons',

});
chai_1.expect(spans[1].attributes).to.deep.equal({
(0, chai_1.expect)(spans[1].attributes).to.deep.equal({
'db.system': 'elasticsearch',

@@ -66,5 +66,5 @@ 'elasticsearch.request.indices': 'the-simpsons',

await client.cluster.getSettings();
const spans = contrib_test_utils_1.getTestSpans();
chai_1.expect(spans === null || spans === void 0 ? void 0 : spans.length).to.equal(1);
chai_1.expect(spans[0].attributes).to.deep.equal({
const spans = (0, contrib_test_utils_1.getTestSpans)();
(0, chai_1.expect)(spans === null || spans === void 0 ? void 0 : spans.length).to.equal(1);
(0, chai_1.expect)(spans[0].attributes).to.deep.equal({
'db.system': 'elasticsearch',

@@ -83,6 +83,6 @@ 'db.operation': 'cluster.getSettings',

instrumentation.enable();
const spans = contrib_test_utils_1.getTestSpans();
chai_1.expect(spans === null || spans === void 0 ? void 0 : spans.length).to.equal(0);
const spans = (0, contrib_test_utils_1.getTestSpans)();
(0, chai_1.expect)(spans === null || spans === void 0 ? void 0 : spans.length).to.equal(0);
});
});
//# sourceMappingURL=elastic.spec.js.map
"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]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -38,3 +42,3 @@ if (k2 === undefined) k2 = k;

const result = Utils.defaultDbStatementSerializer('operationName', { index: 'test' }, {});
chai_1.expect(result).to.equal('{"params":{"index":"test"},"options":{}}');
(0, chai_1.expect)(result).to.equal('{"params":{"index":"test"},"options":{}}');
});

@@ -44,5 +48,5 @@ });

it('should record error', () => {
const recordExceptionStub = sinon_1.stub(spanMock, 'recordException');
const setStatusStub = sinon_1.stub(spanMock, 'setStatus');
const endStub = sinon_1.stub(spanMock, 'end');
const recordExceptionStub = (0, sinon_1.stub)(spanMock, 'recordException');
const setStatusStub = (0, sinon_1.stub)(spanMock, 'setStatus');
const endStub = (0, sinon_1.stub)(spanMock, 'end');
const error = new Error('test error');

@@ -63,5 +67,5 @@ // @ts-ignore

it('should record response without responseHook', () => {
const setAttributesStub = sinon_1.stub(spanMock, 'setAttributes');
const setStatusStub = sinon_1.stub(spanMock, 'setStatus');
const endStub = sinon_1.stub(spanMock, 'end');
const setAttributesStub = (0, sinon_1.stub)(spanMock, 'setAttributes');
const setStatusStub = (0, sinon_1.stub)(spanMock, 'setStatus');
const endStub = (0, sinon_1.stub)(spanMock, 'end');
// @ts-ignore

@@ -78,6 +82,6 @@ Utils.onResponse(spanMock, { meta: { connection: { url: 'http://localhost' } } });

it('should record response with responseHook', () => {
const setAttributesStub = sinon_1.stub(spanMock, 'setAttributes');
const setStatusStub = sinon_1.stub(spanMock, 'setStatus');
const endStub = sinon_1.stub(spanMock, 'end');
const responseHook = sinon_1.spy();
const setAttributesStub = (0, sinon_1.stub)(spanMock, 'setAttributes');
const setStatusStub = (0, sinon_1.stub)(spanMock, 'setStatus');
const endStub = (0, sinon_1.stub)(spanMock, 'end');
const responseHook = (0, sinon_1.spy)();
// @ts-ignore

@@ -89,3 +93,3 @@ Utils.onResponse(spanMock, { meta: { connection: { url: 'http://localhost' } } }, responseHook);

sinon_1.assert.calledWith(setStatusStub, { code: api_1.SpanStatusCode.OK });
chai_1.expect(responseHook.called).to.be.true;
(0, chai_1.expect)(responseHook.called).to.be.true;
setAttributesStub.restore();

@@ -100,9 +104,9 @@ setStatusStub.restore();

it('should get hostname from url', () => {
chai_1.expect(attributes[semantic_conventions_1.SemanticAttributes.NET_PEER_NAME]).to.equal('localhost');
(0, chai_1.expect)(attributes[semantic_conventions_1.SEMATTRS_NET_PEER_NAME]).to.equal('localhost');
});
it('should get hostname from url', () => {
chai_1.expect(attributes[semantic_conventions_1.SemanticAttributes.NET_PEER_PORT]).to.equal('9200');
(0, chai_1.expect)(attributes[semantic_conventions_1.SEMATTRS_NET_PEER_PORT]).to.equal('9200');
});
it('should set net.transport', () => {
chai_1.expect(attributes[semantic_conventions_1.SemanticAttributes.NET_TRANSPORT]).to.equal('IP.TCP');
(0, chai_1.expect)(attributes[semantic_conventions_1.SEMATTRS_NET_TRANSPORT]).to.equal('IP.TCP');
});

@@ -113,11 +117,11 @@ });

const result = Utils.getPort('3030', 'http:');
chai_1.expect(result).to.equal('3030');
(0, chai_1.expect)(result).to.equal('3030');
});
it('should get port from http protocol', () => {
const result = Utils.getPort('', 'http:');
chai_1.expect(result).to.equal('80');
(0, chai_1.expect)(result).to.equal('80');
});
it('should get port from https protocol', () => {
const result = Utils.getPort('', 'https:');
chai_1.expect(result).to.equal('443');
(0, chai_1.expect)(result).to.equal('443');
});

@@ -130,5 +134,5 @@ });

const [params, options, callback] = Utils.normalizeArguments(callbackFunction);
chai_1.expect(params).to.be.empty;
chai_1.expect(options).to.be.empty;
chai_1.expect(callback).to.be.equal(callbackFunction);
(0, chai_1.expect)(params).to.be.empty;
(0, chai_1.expect)(options).to.be.empty;
(0, chai_1.expect)(callback).to.be.equal(callbackFunction);
});

@@ -138,5 +142,5 @@ it('should normalize with params only', () => {

const [params, options, callback] = Utils.normalizeArguments({ index: 'test' });
chai_1.expect(params).to.deep.equal({ index: 'test' });
chai_1.expect(options).to.be.undefined;
chai_1.expect(callback).to.be.undefined;
(0, chai_1.expect)(params).to.deep.equal({ index: 'test' });
(0, chai_1.expect)(options).to.be.undefined;
(0, chai_1.expect)(callback).to.be.undefined;
});

@@ -147,7 +151,7 @@ });

const index = Utils.getIndexName({ index: 'test' });
chai_1.expect(index).to.equal('test');
(0, chai_1.expect)(index).to.equal('test');
});
it('should accept index array', () => {
const indexes = Utils.getIndexName({ index: ['index1', 'index2'] });
chai_1.expect(indexes).to.equal('index1,index2');
(0, chai_1.expect)(indexes).to.equal('index1,index2');
});

@@ -157,4 +161,4 @@ it('should accept no index', () => {

const emptyObject = Utils.getIndexName({});
chai_1.expect(undefinedParams).to.be.undefined;
chai_1.expect(emptyObject).to.be.undefined;
(0, chai_1.expect)(undefinedParams).to.be.undefined;
(0, chai_1.expect)(emptyObject).to.be.undefined;
});

@@ -164,4 +168,4 @@ it('should ignore unexpected index', () => {

const objectIndex = Utils.getIndexName({ index: {} });
chai_1.expect(functionIndex).to.be.undefined;
chai_1.expect(objectIndex).to.be.undefined;
(0, chai_1.expect)(functionIndex).to.be.undefined;
(0, chai_1.expect)(objectIndex).to.be.undefined;
});

@@ -175,3 +179,3 @@ });

it('should start span with client kind', () => {
const startSpanStub = sinon_1.stub(tracerMock, 'startSpan');
const startSpanStub = (0, sinon_1.stub)(tracerMock, 'startSpan');
Utils.startSpan({

@@ -183,6 +187,6 @@ tracer: tracerMock,

const [operation, options] = startSpanStub.getCall(0).args;
chai_1.expect(operation).to.equal('elasticsearch.request');
chai_1.expect(options.kind).to.equal(api_1.SpanKind.CLIENT);
chai_1.expect(options.attributes[semantic_conventions_1.SemanticAttributes.DB_SYSTEM]).to.equal('elasticsearch');
chai_1.expect(options.attributes.testAttribute).to.equal('testValue');
(0, chai_1.expect)(operation).to.equal('elasticsearch.request');
(0, chai_1.expect)(options.kind).to.equal(api_1.SpanKind.CLIENT);
(0, chai_1.expect)(options.attributes[semantic_conventions_1.SEMATTRS_DB_SYSTEM]).to.equal('elasticsearch');
(0, chai_1.expect)(options.attributes.testAttribute).to.equal('testValue');
});

@@ -189,0 +193,0 @@ });

{
"name": "opentelemetry-instrumentation-elasticsearch",
"version": "0.0.0-2023-10-17--13-06",
"version": "0.0.0-2024-05-16--12-47",
"description": "open telemetry instrumentation for the `elasticsearch` module",

@@ -45,15 +45,16 @@ "keywords": [

"peerDependencies": {
"@opentelemetry/api": "^1.6.0"
"@opentelemetry/api": "^1.8.0"
},
"dependencies": {
"@opentelemetry/core": "^1.17.1",
"@opentelemetry/instrumentation": "^0.44.0",
"@opentelemetry/semantic-conventions": "^1.17.1"
"@opentelemetry/core": "^1.24.1",
"@opentelemetry/instrumentation": "^0.51.1",
"@opentelemetry/semantic-conventions": "^1.24.1"
},
"devDependencies": {
"@elastic/elasticsearch": "^7.8.0",
"@opentelemetry/api": "^1.6.0",
"@opentelemetry/contrib-test-utils": "^0.34.2",
"@opentelemetry/api": "^1.8.0",
"@opentelemetry/contrib-test-utils": "^0.39.0",
"@types/chai": "^4.2.15",
"@types/mocha": "^8.2.2",
"aspecto-opentelemetry-instrumentation-mocha": "0.0.9-alpha.0",
"chai": "^4.3.0",

@@ -63,7 +64,6 @@ "expect": "^26.6.2",

"nock": "^13.0.9",
"opentelemetry-instrumentation-mocha": "0.0.7-alpha.1",
"sinon": "^9.2.4",
"test-all-versions": "^5.0.1",
"ts-node": "^9.1.1",
"typescript": "4.3.4"
"ts-node": "^10.9.2",
"typescript": "5.4.5"
},

@@ -77,6 +77,6 @@ "mocha": {

"ts-node/register",
"opentelemetry-instrumentation-mocha"
"aspecto-opentelemetry-instrumentation-mocha"
]
},
"gitHead": "f8da552adae250e08f2062df741972440df3ac97"
"gitHead": "0f32591c71be0933eae844b744a70f9c9aedb84d"
}

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

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