From acdc802c38da6b2d610ea6abc4aa51e8feec2a82 Mon Sep 17 00:00:00 2001 From: mottibec Date: Thu, 16 May 2024 15:43:14 +0300 Subject: [PATCH] upgrade otel versions (#272) * try to upgrade otel versions * run prettier * fix all ts errors * prettier * fix build and test * update aspecto-opentelemetry-instrumentation-mocha * update node version * update ts and skipLibCheck * update ts-node * fix tests * change neo4j docker version --------- Co-authored-by: Motti Bechhofer --- .github/workflows/daily-test.yml | 4 +- .github/workflows/test.yml | 8 +- .../resource-detector-deployment/package.json | 16 +-- .../node/resource-detector-git/package.json | 16 +-- .../resource-detector-service/package.json | 16 +-- .../resource-detector-sync-api/package.json | 10 +- lerna.json | 3 +- package.json | 8 +- .../package.json | 20 ++-- .../src/elasticsearch.ts | 20 ++-- .../src/utils.ts | 15 ++- .../test/utils.spec.ts | 15 ++- packages/instrumentation-express/package.json | 22 ++-- .../instrumentation-express/src/express.ts | 12 +- .../src/utils/attributes.ts | 28 +++-- .../src/utils/layer-path.ts | 4 +- .../test/opentelemetry-express.spec.ts | 43 ++++--- .../instrumentation-express/test/utils.ts | 6 +- packages/instrumentation-kafkajs/package.json | 20 ++-- .../instrumentation-kafkajs/src/kafkajs.ts | 31 +++-- .../test/kafkajs.spec.ts | 35 +++--- packages/instrumentation-neo4j/package.json | 20 ++-- packages/instrumentation-neo4j/src/neo4j.ts | 25 +++-- packages/instrumentation-neo4j/src/utils.ts | 19 +++- packages/instrumentation-neo4j/test/assert.ts | 21 ++-- .../instrumentation-neo4j/test/neo4j.spec.ts | 38 +++---- .../instrumentation-node-cache/package.json | 24 ++-- .../src/node-cache.ts | 23 ++-- .../test/node-cache.spec.ts | 71 ++++++------ .../instrumentation-sequelize/package.json | 22 ++-- .../src/sequelize.ts | 42 ++++--- .../test/sequelize.spec.ts | 106 ++++++++++-------- packages/instrumentation-typeorm/package.json | 22 ++-- .../instrumentation-typeorm/src/typeorm.ts | 74 ++++++------ .../src/utils/get-func-param-names.ts | 6 +- .../test/Connection.spec.ts | 16 ++- .../test/EntityManager.spec.ts | 65 ++++++----- .../test/QueryBuilder.spec.ts | 25 +++-- .../test/Repository.spec.ts | 4 +- .../test/config.spec.ts | 46 +++++--- packages/propagation-utils/package.json | 6 +- packages/span-transformations/package.json | 8 +- propagators/propagator-selective/package.json | 10 +- .../src/SelectivePropagator.ts | 5 +- tsconfig.base.json | 3 +- 45 files changed, 592 insertions(+), 461 deletions(-) diff --git a/.github/workflows/daily-test.yml b/.github/workflows/daily-test.yml index ef68e6ce..d75ee6dc 100644 --- a/.github/workflows/daily-test.yml +++ b/.github/workflows/daily-test.yml @@ -24,12 +24,12 @@ jobs: - 27017:27017 neo4j: - image: neo4j:4.2.3 + image: neo4j:4.4.34 ports: - 7474:7474 - 11011:7687 env: - NEO4J_AUTH: neo4j/test + NEO4J_AUTH: neo4j/your_password steps: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e828c309..867fafbe 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,12 +23,12 @@ jobs: - 27017:27017 neo4j: - image: neo4j:4.2.3 + image: neo4j:4.4.34 ports: - 7474:7474 - 11011:7687 env: - NEO4J_AUTH: neo4j/test + NEO4J_AUTH: neo4j/your_password steps: @@ -39,10 +39,10 @@ jobs: - name: Fetch all history for all tags and branches run: git fetch - - name: Use Node.js 14 + - name: Use Node.js 18 uses: actions/setup-node@v1 with: - node-version: 14 + node-version: 18 - name: Install Dependencies run: yarn install diff --git a/detectors/node/resource-detector-deployment/package.json b/detectors/node/resource-detector-deployment/package.json index a042bf01..c0eb2ebc 100644 --- a/detectors/node/resource-detector-deployment/package.json +++ b/detectors/node/resource-detector-deployment/package.json @@ -33,21 +33,21 @@ "url": "https://github.com/aspecto-io/opentelemetry-ext-js/issues" }, "peerDependencies": { - "@opentelemetry/api": "^1.6.0" + "@opentelemetry/api": "^1.8.0" }, "dependencies": { - "@opentelemetry/resources": "~1.17.1", - "@opentelemetry/semantic-conventions": "^1.17.1", + "@opentelemetry/resources": "~1.24.1", + "@opentelemetry/semantic-conventions": "^1.24.1", "opentelemetry-resource-detector-sync-api": "^0.29.0" }, "devDependencies": { - "@opentelemetry/api": "^1.6.0", + "@opentelemetry/api": "^1.8.0", "@types/mocha": "^8.2.2", "expect": "^26.6.2", "mocha": "^8.4.0", - "opentelemetry-instrumentation-mocha": "0.0.7-alpha.1", - "ts-node": "^9.1.1", - "typescript": "4.3.4" + "aspecto-opentelemetry-instrumentation-mocha": "0.0.9-alpha.0", + "ts-node": "^10.9.2", + "typescript": "5.4.5" }, "mocha": { "extension": [ @@ -56,7 +56,7 @@ "spec": "test/**/*.spec.ts", "require": [ "ts-node/register", - "opentelemetry-instrumentation-mocha" + "aspecto-opentelemetry-instrumentation-mocha" ] } } diff --git a/detectors/node/resource-detector-git/package.json b/detectors/node/resource-detector-git/package.json index af304641..def814e7 100644 --- a/detectors/node/resource-detector-git/package.json +++ b/detectors/node/resource-detector-git/package.json @@ -34,24 +34,24 @@ "url": "https://github.com/aspecto-io/opentelemetry-ext-js/issues" }, "peerDependencies": { - "@opentelemetry/api": "^1.6.0" + "@opentelemetry/api": "^1.8.0" }, "dependencies": { - "@opentelemetry/resources": "~1.17.1", - "@opentelemetry/semantic-conventions": "^1.17.1", + "@opentelemetry/resources": "~1.24.1", + "@opentelemetry/semantic-conventions": "^1.24.1", "opentelemetry-resource-detector-sync-api": "^0.29.0", "uuid": "^8.3.2" }, "devDependencies": { - "@opentelemetry/api": "^1.6.0", + "@opentelemetry/api": "^1.8.0", "@types/mocha": "^8.2.2", "@types/node": "^14.0.0", "expect": "^26.6.2", "mocha": "^8.4.0", - "opentelemetry-instrumentation-mocha": "0.0.7-alpha.1", + "aspecto-opentelemetry-instrumentation-mocha": "0.0.9-alpha.0", "sinon": "^11.1.1", - "ts-node": "^9.1.1", - "typescript": "4.3.4" + "ts-node": "^10.9.2", + "typescript": "5.4.5" }, "mocha": { "extension": [ @@ -60,7 +60,7 @@ "spec": "test/**/*.spec.ts", "require": [ "ts-node/register", - "opentelemetry-instrumentation-mocha" + "aspecto-opentelemetry-instrumentation-mocha" ] } } diff --git a/detectors/node/resource-detector-service/package.json b/detectors/node/resource-detector-service/package.json index f7760300..9f2c7bec 100644 --- a/detectors/node/resource-detector-service/package.json +++ b/detectors/node/resource-detector-service/package.json @@ -33,22 +33,22 @@ "url": "https://github.com/aspecto-io/opentelemetry-ext-js/issues" }, "peerDependencies": { - "@opentelemetry/api": "^1.6.0" + "@opentelemetry/api": "^1.8.0" }, "dependencies": { - "@opentelemetry/resources": "~1.17.1", - "@opentelemetry/semantic-conventions": "^1.17.1", + "@opentelemetry/resources": "~1.24.1", + "@opentelemetry/semantic-conventions": "^1.24.1", "opentelemetry-resource-detector-sync-api": "^0.29.0", "uuid": "^8.3.2" }, "devDependencies": { - "@opentelemetry/api": "^1.6.0", + "@opentelemetry/api": "^1.8.0", "@types/mocha": "^8.2.2", "expect": "^26.6.2", "mocha": "^8.4.0", - "opentelemetry-instrumentation-mocha": "0.0.7-alpha.1", - "ts-node": "^9.1.1", - "typescript": "4.3.4" + "aspecto-opentelemetry-instrumentation-mocha": "0.0.9-alpha.0", + "ts-node": "^10.9.2", + "typescript": "5.4.5" }, "mocha": { "extension": [ @@ -57,7 +57,7 @@ "spec": "test/**/*.spec.ts", "require": [ "ts-node/register", - "opentelemetry-instrumentation-mocha" + "aspecto-opentelemetry-instrumentation-mocha" ] } } diff --git a/detectors/resource-detector-sync-api/package.json b/detectors/resource-detector-sync-api/package.json index 1a8570d8..1362e08e 100644 --- a/detectors/resource-detector-sync-api/package.json +++ b/detectors/resource-detector-sync-api/package.json @@ -30,14 +30,14 @@ "url": "https://github.com/aspecto-io/opentelemetry-ext-js/issues" }, "peerDependencies": { - "@opentelemetry/api": "^1.6.0" + "@opentelemetry/api": "^1.8.0" }, "dependencies": { - "@opentelemetry/resources": "~1.17.1" + "@opentelemetry/resources": "~1.24.1" }, "devDependencies": { - "@opentelemetry/api": "^1.6.0", - "ts-node": "^9.1.1", - "typescript": "4.3.4" + "@opentelemetry/api": "^1.8.0", + "ts-node": "^10.9.2", + "typescript": "5.4.5" } } diff --git a/lerna.json b/lerna.json index a1a773c7..f2121b28 100644 --- a/lerna.json +++ b/lerna.json @@ -1,6 +1,5 @@ { "packages": ["packages/*", "detectors/*", "detectors/node/*", "propagators/*", "examples/*"], "version": "independent", - "npmClient": "yarn", - "useWorkspaces": true + "npmClient": "yarn" } diff --git a/package.json b/package.json index c7150f94..82eb60a1 100644 --- a/package.json +++ b/package.json @@ -8,17 +8,17 @@ "test:ci:all": "lerna run test:ci --parallel", "build": "lerna run build", "build:ci": "lerna run build", - "postinstall": "lerna bootstrap", "prettier": "prettier --config .prettierrc.yml --write --ignore-unknown \"**/*\"", - "prettier:check": "npx prettier@2.3.2 --config .prettierrc.yml --check --ignore-unknown \"**/*\"", + "prettier:check": "npx prettier@3.2.5 --config .prettierrc.yml --check --ignore-unknown \"**/*\"", "version:update": "lerna run version:update", "version": "git add packages/**/version.ts", "publish:ci": "lerna publish --yes --allow-branch master --create-release github --conventionalCommits", "publish:ci:prerelease": "lerna publish --yes --no-git-tag-version --no-push --no-changelog --dist-tag alpha" }, "devDependencies": { - "lerna": "^3.22.1", - "prettier": "2.3.2" + "@types/node": "^20.12.12", + "lerna": "^8.1.3", + "prettier": "3.2.5" }, "workspaces": [ "packages/*", diff --git a/packages/instrumentation-elasticsearch/package.json b/packages/instrumentation-elasticsearch/package.json index 6c2686ac..c351f4ec 100644 --- a/packages/instrumentation-elasticsearch/package.json +++ b/packages/instrumentation-elasticsearch/package.json @@ -42,28 +42,28 @@ "url": "https://github.com/aspecto-io/opentelemetry-ext-js/issues" }, "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", "chai": "^4.3.0", "expect": "^26.6.2", "mocha": "^8.4.0", "nock": "^13.0.9", - "opentelemetry-instrumentation-mocha": "0.0.7-alpha.1", + "aspecto-opentelemetry-instrumentation-mocha": "0.0.9-alpha.0", "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" }, "mocha": { "extension": [ @@ -72,7 +72,7 @@ "spec": "test/**/*.spec.ts", "require": [ "ts-node/register", - "opentelemetry-instrumentation-mocha" + "aspecto-opentelemetry-instrumentation-mocha" ] } } diff --git a/packages/instrumentation-elasticsearch/src/elasticsearch.ts b/packages/instrumentation-elasticsearch/src/elasticsearch.ts index 54a8eb8d..04af95b1 100644 --- a/packages/instrumentation-elasticsearch/src/elasticsearch.ts +++ b/packages/instrumentation-elasticsearch/src/elasticsearch.ts @@ -10,7 +10,7 @@ import { } from '@opentelemetry/instrumentation'; import { VERSION } from './version'; import { AttributeNames } from './enums'; -import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; +import { SEMATTRS_DB_OPERATION, SEMATTRS_DB_STATEMENT, SemanticAttributes } from '@opentelemetry/semantic-conventions'; import { startSpan, onError, @@ -21,7 +21,7 @@ import { } from './utils'; import { ELASTICSEARCH_API_FILES } from './helpers'; -export class ElasticsearchInstrumentation extends InstrumentationBase { +export class ElasticsearchInstrumentation extends InstrumentationBase { static readonly component = '@elastic/elasticsearch'; protected override _config: ElasticsearchInstrumentationConfig; @@ -36,10 +36,10 @@ export class ElasticsearchInstrumentation extends InstrumentationBase { + protected init(): InstrumentationModuleDefinition { const apiModuleFiles = ELASTICSEARCH_API_FILES.map( ({ path, operationClassName }) => - new InstrumentationNodeModuleFile( + new InstrumentationNodeModuleFile( `@elastic/elasticsearch/api/${path}`, ['>=5 <8'], this.patch.bind(this, operationClassName), @@ -47,7 +47,7 @@ export class ElasticsearchInstrumentation extends InstrumentationBase( + const module = new InstrumentationNodeModuleDefinition( ElasticsearchInstrumentation.component, ['*'], undefined, @@ -120,11 +120,13 @@ export class ElasticsearchInstrumentation extends InstrumentationBase { const spanMock = { @@ -92,15 +97,15 @@ describe('elasticsearch utils', () => { const attributes = Utils.getNetAttributes(url); it('should get hostname from url', () => { - expect(attributes[SemanticAttributes.NET_PEER_NAME]).to.equal('localhost'); + expect(attributes[SEMATTRS_NET_PEER_NAME]).to.equal('localhost'); }); it('should get hostname from url', () => { - expect(attributes[SemanticAttributes.NET_PEER_PORT]).to.equal('9200'); + expect(attributes[SEMATTRS_NET_PEER_PORT]).to.equal('9200'); }); it('should set net.transport', () => { - expect(attributes[SemanticAttributes.NET_TRANSPORT]).to.equal('IP.TCP'); + expect(attributes[SEMATTRS_NET_TRANSPORT]).to.equal('IP.TCP'); }); }); @@ -190,7 +195,7 @@ describe('elasticsearch utils', () => { expect(operation).to.equal('elasticsearch.request'); expect(options.kind).to.equal(SpanKind.CLIENT); - expect(options.attributes[SemanticAttributes.DB_SYSTEM]).to.equal('elasticsearch'); + expect(options.attributes[SEMATTRS_DB_SYSTEM]).to.equal('elasticsearch'); expect(options.attributes.testAttribute).to.equal('testValue'); }); }); diff --git a/packages/instrumentation-express/package.json b/packages/instrumentation-express/package.json index ca28cb22..2c905cd4 100644 --- a/packages/instrumentation-express/package.json +++ b/packages/instrumentation-express/package.json @@ -32,20 +32,20 @@ "access": "public" }, "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", "parseurl": "~1.3.3", "path-to-regexp": "0.1.7" }, "devDependencies": { - "@opentelemetry/api": "^1.6.0", - "@opentelemetry/contrib-test-utils": "^0.34.2", + "@opentelemetry/api": "^1.8.0", + "@opentelemetry/contrib-test-utils": "^0.39.0", "@opentelemetry/instrumentation-http": "^0.44.0", - "@opentelemetry/sdk-trace-base": "^1.17.1", + "@opentelemetry/sdk-trace-base": "^1.24.1", "@types/express": "4.17.8", "@types/mocha": "^8.2.2", "axios": "0.21.1", @@ -53,10 +53,10 @@ "expect": "^26.6.2", "express": "4.17.1", "mocha": "^8.4.0", - "opentelemetry-instrumentation-mocha": "0.0.7-alpha.1", + "aspecto-opentelemetry-instrumentation-mocha": "0.0.9-alpha.0", "test-all-versions": "^5.0.1", - "ts-node": "^9.1.1", - "typescript": "4.3.4" + "ts-node": "^10.9.2", + "typescript": "5.4.5" }, "mocha": { "extension": [ @@ -65,7 +65,7 @@ "spec": "test/**/*.spec.ts", "require": [ "ts-node/register", - "opentelemetry-instrumentation-mocha" + "aspecto-opentelemetry-instrumentation-mocha" ] } } diff --git a/packages/instrumentation-express/src/express.ts b/packages/instrumentation-express/src/express.ts index 5b153ec5..431421e6 100644 --- a/packages/instrumentation-express/src/express.ts +++ b/packages/instrumentation-express/src/express.ts @@ -31,11 +31,11 @@ import { } from './utils/attributes'; import { consumeLayerPathAndUpdateState, createInitialRouteState } from './utils/route-context'; import { getLayerPathFromFirstArg } from './utils/layer-path'; -import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; +import { SEMATTRS_HTTP_ROUTE, SemanticAttributes } from '@opentelemetry/semantic-conventions'; const originalLayerStore = Symbol('otel.express-plugins.orig-layer-export'); -export class ExpressInstrumentation extends InstrumentationBase { +export class ExpressInstrumentation extends InstrumentationBase { static readonly supportedVersions = ['^4.9.0']; protected override _config: ExpressInstrumentationConfig; @@ -47,15 +47,15 @@ export class ExpressInstrumentation extends InstrumentationBase this._config = Object.assign({}, config); } - protected init(): InstrumentationModuleDefinition { - const layerModule = new InstrumentationNodeModuleFile( + protected init(): InstrumentationModuleDefinition { + const layerModule = new InstrumentationNodeModuleFile( 'express/lib/router/layer.js', ExpressInstrumentation.supportedVersions, this._patchExpressLayer.bind(this), this._unpatchExpressLayer.bind(this) ); - const module = new InstrumentationNodeModuleDefinition( + const module = new InstrumentationNodeModuleDefinition( 'express', ExpressInstrumentation.supportedVersions, this.patch.bind(this), @@ -226,7 +226,7 @@ export class ExpressInstrumentation extends InstrumentationBase res.end = function () { const routeState = plugin.getCurrentRouteState(req); const routeAttributes = getRouteAttributes(routeState); - const route = routeAttributes[SemanticAttributes.HTTP_ROUTE] as string; + const route = routeAttributes[SEMATTRS_HTTP_ROUTE] as string; if (route) { const rpcMetadata = getRPCMetadata(context.active()); if (rpcMetadata) { diff --git a/packages/instrumentation-express/src/utils/attributes.ts b/packages/instrumentation-express/src/utils/attributes.ts index ebd9b575..c8deaf87 100644 --- a/packages/instrumentation-express/src/utils/attributes.ts +++ b/packages/instrumentation-express/src/utils/attributes.ts @@ -1,5 +1,15 @@ import { SpanAttributes, SpanStatus, SpanStatusCode } from '@opentelemetry/api'; -import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; +import { + SEMATTRS_HTTP_FLAVOR, + SEMATTRS_HTTP_HOST, + SEMATTRS_HTTP_METHOD, + SEMATTRS_HTTP_ROUTE, + SEMATTRS_HTTP_SCHEME, + SEMATTRS_HTTP_STATUS_CODE, + SEMATTRS_HTTP_TARGET, + SEMATTRS_NET_PEER_IP, + SemanticAttributes, +} from '@opentelemetry/semantic-conventions'; import { ExpressConsumedRouteState, ExpressInstrumentationAttributes } from '../types'; import type express from 'express'; @@ -8,7 +18,7 @@ export const getRouteAttributes = (routeState: ExpressConsumedRouteState): SpanA const resolvedRoute = getResolvedRoute(routeState); if (resolvedRoute != null) { - attributes[SemanticAttributes.HTTP_ROUTE] = resolvedRoute; + attributes[SEMATTRS_HTTP_ROUTE] = resolvedRoute; } const fullRoute = getFullRoute(routeState); @@ -55,7 +65,7 @@ export const getResolvedRoute = (expressRoutContext: ExpressConsumedRouteState): export const getHttpSpanAttributeFromRes = (res: express.Response): SpanAttributes => { return { - [SemanticAttributes.HTTP_STATUS_CODE]: res.statusCode, + [SEMATTRS_HTTP_STATUS_CODE]: res.statusCode, }; }; @@ -83,12 +93,12 @@ export const createHostAttribute = (req: express.Request): string => { export const getHttpSpanAttributesFromReq = (req: express.Request): SpanAttributes => { return { - [SemanticAttributes.HTTP_METHOD]: req.method.toUpperCase(), - [SemanticAttributes.HTTP_TARGET]: req.originalUrl, - [SemanticAttributes.HTTP_FLAVOR]: req.httpVersion, - [SemanticAttributes.HTTP_HOST]: createHostAttribute(req), - [SemanticAttributes.HTTP_SCHEME]: req.protocol, - [SemanticAttributes.NET_PEER_IP]: req.ip, + [SEMATTRS_HTTP_METHOD]: req.method.toUpperCase(), + [SEMATTRS_HTTP_TARGET]: req.originalUrl, + [SEMATTRS_HTTP_FLAVOR]: req.httpVersion, + [SEMATTRS_HTTP_HOST]: createHostAttribute(req), + [SEMATTRS_HTTP_SCHEME]: req.protocol, + [SEMATTRS_NET_PEER_IP]: req.ip, }; }; diff --git a/packages/instrumentation-express/src/utils/layer-path.ts b/packages/instrumentation-express/src/utils/layer-path.ts index d93c3811..da2f1b27 100644 --- a/packages/instrumentation-express/src/utils/layer-path.ts +++ b/packages/instrumentation-express/src/utils/layer-path.ts @@ -37,8 +37,8 @@ const getLayerPathAlternativeFromFirstArg = ( typeof alternativePath === 'string' ? pathStringToDisplayValue(alternativePath, options) : alternativePath instanceof RegExp - ? alternativePath.toString() - : undefined, + ? alternativePath.toString() + : undefined, regexp: pathRegexp(alternativePath, [], options), })); } diff --git a/packages/instrumentation-express/test/opentelemetry-express.spec.ts b/packages/instrumentation-express/test/opentelemetry-express.spec.ts index d219ffd0..2721625f 100644 --- a/packages/instrumentation-express/test/opentelemetry-express.spec.ts +++ b/packages/instrumentation-express/test/opentelemetry-express.spec.ts @@ -4,7 +4,16 @@ import { SpanKind, trace } from '@opentelemetry/api'; import { ExpressInstrumentation } from '../src'; import { AddressInfo } from 'net'; import { ReadableSpan } from '@opentelemetry/sdk-trace-base'; -import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; +import { + SEMATTRS_HTTP_FLAVOR, + SEMATTRS_HTTP_HOST, + SEMATTRS_HTTP_METHOD, + SEMATTRS_HTTP_ROUTE, + SEMATTRS_HTTP_SCHEME, + SEMATTRS_HTTP_STATUS_CODE, + SEMATTRS_HTTP_TARGET, + SEMATTRS_NET_PEER_IP, +} from '@opentelemetry/semantic-conventions'; import { HttpInstrumentation } from '@opentelemetry/instrumentation-http'; import { getTestSpans, registerInstrumentationTesting } from '@opentelemetry/contrib-test-utils'; import * as bodyParser from 'body-parser'; @@ -74,19 +83,19 @@ describe('opentelemetry-express', () => { expect(span.name).toBe('POST /toto/:id'); // HTTP Attributes - expect(span.attributes[SemanticAttributes.HTTP_METHOD]).toBeUndefined(); - expect(span.attributes[SemanticAttributes.HTTP_TARGET]).toBeUndefined(); - expect(span.attributes[SemanticAttributes.HTTP_SCHEME]).toBeUndefined(); - expect(span.attributes[SemanticAttributes.HTTP_STATUS_CODE]).toBeUndefined(); - expect(span.attributes[SemanticAttributes.HTTP_HOST]).toBeUndefined(); - expect(span.attributes[SemanticAttributes.HTTP_FLAVOR]).toBeUndefined(); - expect(span.attributes[SemanticAttributes.NET_PEER_IP]).toBeUndefined(); + expect(span.attributes[SEMATTRS_HTTP_METHOD]).toBeUndefined(); + expect(span.attributes[SEMATTRS_HTTP_TARGET]).toBeUndefined(); + expect(span.attributes[SEMATTRS_HTTP_SCHEME]).toBeUndefined(); + expect(span.attributes[SEMATTRS_HTTP_STATUS_CODE]).toBeUndefined(); + expect(span.attributes[SEMATTRS_HTTP_HOST]).toBeUndefined(); + expect(span.attributes[SEMATTRS_HTTP_FLAVOR]).toBeUndefined(); + expect(span.attributes[SEMATTRS_NET_PEER_IP]).toBeUndefined(); // http span route const [incomingHttpSpan] = getTestSpans().filter( (s) => s.kind === SpanKind.SERVER && s.instrumentationLibrary.name.includes('http') ); - expect(incomingHttpSpan.attributes[SemanticAttributes.HTTP_ROUTE]).toMatch('/toto/:id'); + expect(incomingHttpSpan.attributes[SEMATTRS_HTTP_ROUTE]).toMatch('/toto/:id'); done(); } catch (error) { done(error); @@ -131,15 +140,13 @@ describe('opentelemetry-express', () => { const span: ReadableSpan = expressSpans[0]; // HTTP Attributes - expect(span.attributes[SemanticAttributes.HTTP_METHOD]).toBe('POST'); - expect(span.attributes[SemanticAttributes.HTTP_TARGET]).toBe( - '/toto/tata?req-query-param-key=req-query-param-val' - ); - expect(span.attributes[SemanticAttributes.HTTP_SCHEME]).toBe('http'); - expect(span.attributes[SemanticAttributes.HTTP_STATUS_CODE]).toBe(200); - expect(span.attributes[SemanticAttributes.HTTP_HOST]).toBe(`localhost:${port}`); - expect(span.attributes[SemanticAttributes.HTTP_FLAVOR]).toBe('1.1'); - expect(span.attributes[SemanticAttributes.NET_PEER_IP]).toBe('::ffff:127.0.0.1'); + expect(span.attributes[SEMATTRS_HTTP_METHOD]).toBe('POST'); + expect(span.attributes[SEMATTRS_HTTP_TARGET]).toBe('/toto/tata?req-query-param-key=req-query-param-val'); + expect(span.attributes[SEMATTRS_HTTP_SCHEME]).toBe('http'); + expect(span.attributes[SEMATTRS_HTTP_STATUS_CODE]).toBe(200); + expect(span.attributes[SEMATTRS_HTTP_HOST]).toBe(`localhost:${port}`); + expect(span.attributes[SEMATTRS_HTTP_FLAVOR]).toBe('1.1'); + expect(span.attributes[SEMATTRS_NET_PEER_IP]).toBe('::ffff:127.0.0.1'); server.close(); done(); diff --git a/packages/instrumentation-express/test/utils.ts b/packages/instrumentation-express/test/utils.ts index 7e6e27e8..4ebddfc8 100644 --- a/packages/instrumentation-express/test/utils.ts +++ b/packages/instrumentation-express/test/utils.ts @@ -1,4 +1,4 @@ -import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; +import { SEMATTRS_HTTP_ROUTE, SemanticAttributes } from '@opentelemetry/semantic-conventions'; import type { ReadableSpan } from '@opentelemetry/sdk-trace-base'; import expect from 'expect'; import { ExpressInstrumentationAttributes } from '../src/types'; @@ -17,7 +17,7 @@ export const expectRouteAttributes = ( options?: expectRouteAttributesAdvancedOptions ) => { const { expectedParams, configuredRoute } = options ?? {}; - expect(span.attributes[SemanticAttributes.HTTP_ROUTE]).toEqual(expectedRoute); + expect(span.attributes[SEMATTRS_HTTP_ROUTE]).toEqual(expectedRoute); expect(span.attributes[ExpressInstrumentationAttributes.EXPRESS_ROUTE_FULL]).toEqual(expectedFullRoute); const actualParams = JSON.parse(span.attributes[ExpressInstrumentationAttributes.EXPRESS_ROUTE_PARAMS] as string); expect(actualParams).toStrictEqual(expectedParams ?? {}); @@ -29,7 +29,7 @@ export const expectRouteAttributes = ( }; export const expectRouteFromFinalHandler = (span: ReadableSpan, fullRoute: string) => { - expect(span.attributes[SemanticAttributes.HTTP_ROUTE]).toEqual(''); + expect(span.attributes[SEMATTRS_HTTP_ROUTE]).toEqual(''); // we need to patch final handler to extract the full url expect(span.attributes[ExpressInstrumentationAttributes.EXPRESS_ROUTE_FULL]).toEqual(fullRoute); expect(span.attributes[ExpressInstrumentationAttributes.EXPRESS_UNHANDLED]).toEqual(true); diff --git a/packages/instrumentation-kafkajs/package.json b/packages/instrumentation-kafkajs/package.json index bae6b983..0f3c8a5a 100644 --- a/packages/instrumentation-kafkajs/package.json +++ b/packages/instrumentation-kafkajs/package.json @@ -35,23 +35,23 @@ "url": "https://github.com/aspecto-io/opentelemetry-ext-js/issues" }, "peerDependencies": { - "@opentelemetry/api": "^1.6.0" + "@opentelemetry/api": "^1.8.0" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.44.0", - "@opentelemetry/semantic-conventions": "^1.17.1" + "@opentelemetry/instrumentation": "^0.51.1", + "@opentelemetry/semantic-conventions": "^1.24.1" }, "devDependencies": { - "@opentelemetry/api": "^1.3.0", - "@opentelemetry/contrib-test-utils": "^0.34.2", - "@opentelemetry/sdk-trace-base": "^1.17.1", + "@opentelemetry/api": "^1.8.0", + "@opentelemetry/contrib-test-utils": "^0.39.0", + "@opentelemetry/sdk-trace-base": "^1.24.1", "@types/mocha": "^8.2.2", "expect": "^26.6.2", "kafkajs": "^1.16.0", "mocha": "^8.4.0", - "opentelemetry-instrumentation-mocha": "0.0.7-alpha.1", - "ts-node": "^9.1.1", - "typescript": "4.3.4" + "aspecto-opentelemetry-instrumentation-mocha": "0.0.9-alpha.0", + "ts-node": "^10.9.2", + "typescript": "5.4.5" }, "mocha": { "extension": [ @@ -60,7 +60,7 @@ "spec": "test/**/*.spec.ts", "require": [ "ts-node/register", - "opentelemetry-instrumentation-mocha" + "aspecto-opentelemetry-instrumentation-mocha" ] } } diff --git a/packages/instrumentation-kafkajs/src/kafkajs.ts b/packages/instrumentation-kafkajs/src/kafkajs.ts index 6c7bb711..fa3b7873 100644 --- a/packages/instrumentation-kafkajs/src/kafkajs.ts +++ b/packages/instrumentation-kafkajs/src/kafkajs.ts @@ -14,6 +14,10 @@ import { SemanticAttributes, MessagingOperationValues, MessagingDestinationKindValues, + SEMATTRS_MESSAGING_SYSTEM, + SEMATTRS_MESSAGING_DESTINATION_KIND, + SEMATTRS_MESSAGING_DESTINATION, + SEMATTRS_MESSAGING_OPERATION, } from '@opentelemetry/semantic-conventions'; import * as kafkaJs from 'kafkajs'; import { @@ -39,7 +43,7 @@ import { isWrapped, } from '@opentelemetry/instrumentation'; -export class KafkaJsInstrumentation extends InstrumentationBase { +export class KafkaJsInstrumentation extends InstrumentationBase { static readonly component = 'kafkajs'; protected override _config!: KafkaJsInstrumentationConfig; private moduleVersion: string; @@ -52,10 +56,13 @@ export class KafkaJsInstrumentation extends InstrumentationBase this._config = Object.assign({}, config); } - protected init(): InstrumentationModuleDefinition { - const module: InstrumentationModuleDefinition = new InstrumentationNodeModuleDefinition< - typeof kafkaJs - >(KafkaJsInstrumentation.component, ['*'], this.patch.bind(this), this.unpatch.bind(this)); + protected init(): InstrumentationModuleDefinition { + const module: InstrumentationModuleDefinition = new InstrumentationNodeModuleDefinition( + KafkaJsInstrumentation.component, + ['*'], + this.patch.bind(this), + this.unpatch.bind(this) + ); module.includePrerelease = true; return module; } @@ -247,10 +254,10 @@ export class KafkaJsInstrumentation extends InstrumentationBase { kind: SpanKind.CONSUMER, attributes: { - [SemanticAttributes.MESSAGING_SYSTEM]: 'kafka', - [SemanticAttributes.MESSAGING_DESTINATION]: topic, - [SemanticAttributes.MESSAGING_DESTINATION_KIND]: MessagingDestinationKindValues.TOPIC, - [SemanticAttributes.MESSAGING_OPERATION]: operation, + [SEMATTRS_MESSAGING_SYSTEM]: 'kafka', + [SEMATTRS_MESSAGING_DESTINATION]: topic, + [SEMATTRS_MESSAGING_DESTINATION_KIND]: MessagingDestinationKindValues.TOPIC, + [SEMATTRS_MESSAGING_OPERATION]: operation, }, links: link ? [link] : [], }, @@ -278,9 +285,9 @@ export class KafkaJsInstrumentation extends InstrumentationBase const span = this.tracer.startSpan(topic, { kind: SpanKind.PRODUCER, attributes: { - [SemanticAttributes.MESSAGING_SYSTEM]: 'kafka', - [SemanticAttributes.MESSAGING_DESTINATION]: topic, - [SemanticAttributes.MESSAGING_DESTINATION_KIND]: MessagingDestinationKindValues.TOPIC, + [SEMATTRS_MESSAGING_SYSTEM]: 'kafka', + [SEMATTRS_MESSAGING_DESTINATION]: topic, + [SEMATTRS_MESSAGING_DESTINATION_KIND]: MessagingDestinationKindValues.TOPIC, }, }); diff --git a/packages/instrumentation-kafkajs/test/kafkajs.spec.ts b/packages/instrumentation-kafkajs/test/kafkajs.spec.ts index c9e954dd..365a5dc8 100644 --- a/packages/instrumentation-kafkajs/test/kafkajs.spec.ts +++ b/packages/instrumentation-kafkajs/test/kafkajs.spec.ts @@ -3,7 +3,14 @@ import expect from 'expect'; import { KafkaJsInstrumentation, KafkaJsInstrumentationConfig } from '../src'; import { ReadableSpan } from '@opentelemetry/sdk-trace-base'; import { propagation, context, SpanKind, SpanStatusCode, Span } from '@opentelemetry/api'; -import { MessagingDestinationKindValues, SemanticAttributes } from '@opentelemetry/semantic-conventions'; +import { + MessagingDestinationKindValues, + SEMATTRS_MESSAGING_DESTINATION, + SEMATTRS_MESSAGING_DESTINATION_KIND, + SEMATTRS_MESSAGING_OPERATION, + SEMATTRS_MESSAGING_SYSTEM, + SemanticAttributes, +} from '@opentelemetry/semantic-conventions'; import { getTestSpans, registerInstrumentationTesting } from '@opentelemetry/contrib-test-utils'; const instrumentation = registerInstrumentationTesting(new KafkaJsInstrumentation()); @@ -119,11 +126,11 @@ describe('instrumentation-kafkajs', () => { expect(span.kind).toStrictEqual(SpanKind.PRODUCER); expect(span.name).toStrictEqual('topic-name-1'); expect(span.status.code).toStrictEqual(SpanStatusCode.UNSET); - expect(span.attributes[SemanticAttributes.MESSAGING_SYSTEM]).toStrictEqual('kafka'); - expect(span.attributes[SemanticAttributes.MESSAGING_DESTINATION_KIND]).toStrictEqual( + expect(span.attributes[SEMATTRS_MESSAGING_SYSTEM]).toStrictEqual('kafka'); + expect(span.attributes[SEMATTRS_MESSAGING_DESTINATION_KIND]).toStrictEqual( MessagingDestinationKindValues.TOPIC ); - expect(span.attributes[SemanticAttributes.MESSAGING_DESTINATION]).toStrictEqual('topic-name-1'); + expect(span.attributes[SEMATTRS_MESSAGING_DESTINATION]).toStrictEqual('topic-name-1'); expect(messagesSent.length).toBe(1); expectKafkaHeadersToMatchSpanContext(messagesSent[0], span as ReadableSpan); @@ -426,12 +433,12 @@ describe('instrumentation-kafkajs', () => { expect(span.parentSpanId).toBeUndefined(); expect(span.kind).toStrictEqual(SpanKind.CONSUMER); expect(span.status.code).toStrictEqual(SpanStatusCode.UNSET); - expect(span.attributes[SemanticAttributes.MESSAGING_SYSTEM]).toStrictEqual('kafka'); - expect(span.attributes[SemanticAttributes.MESSAGING_DESTINATION_KIND]).toStrictEqual( + expect(span.attributes[SEMATTRS_MESSAGING_SYSTEM]).toStrictEqual('kafka'); + expect(span.attributes[SEMATTRS_MESSAGING_DESTINATION_KIND]).toStrictEqual( MessagingDestinationKindValues.TOPIC ); - expect(span.attributes[SemanticAttributes.MESSAGING_DESTINATION]).toStrictEqual('topic-name-1'); - expect(span.attributes[SemanticAttributes.MESSAGING_OPERATION]).toStrictEqual('process'); + expect(span.attributes[SEMATTRS_MESSAGING_DESTINATION]).toStrictEqual('topic-name-1'); + expect(span.attributes[SEMATTRS_MESSAGING_OPERATION]).toStrictEqual('process'); }); it('consumer eachMessage with non promise return value', async () => { @@ -611,23 +618,23 @@ describe('instrumentation-kafkajs', () => { spans.forEach((span) => { expect(span.name).toStrictEqual('topic-name-1'); expect(span.status.code).toStrictEqual(SpanStatusCode.UNSET); - expect(span.attributes[SemanticAttributes.MESSAGING_SYSTEM]).toStrictEqual('kafka'); - expect(span.attributes[SemanticAttributes.MESSAGING_DESTINATION_KIND]).toStrictEqual( + expect(span.attributes[SEMATTRS_MESSAGING_SYSTEM]).toStrictEqual('kafka'); + expect(span.attributes[SEMATTRS_MESSAGING_DESTINATION_KIND]).toStrictEqual( MessagingDestinationKindValues.TOPIC ); - expect(span.attributes[SemanticAttributes.MESSAGING_DESTINATION]).toStrictEqual('topic-name-1'); + expect(span.attributes[SEMATTRS_MESSAGING_DESTINATION]).toStrictEqual('topic-name-1'); }); const [recvSpan, msg1Span, msg2Span] = spans; expect(recvSpan.parentSpanId).toBeUndefined(); - expect(recvSpan.attributes[SemanticAttributes.MESSAGING_OPERATION]).toStrictEqual('receive'); + expect(recvSpan.attributes[SEMATTRS_MESSAGING_OPERATION]).toStrictEqual('receive'); expect(msg1Span.parentSpanId).toStrictEqual(recvSpan.spanContext().spanId); - expect(msg1Span.attributes[SemanticAttributes.MESSAGING_OPERATION]).toStrictEqual('process'); + expect(msg1Span.attributes[SEMATTRS_MESSAGING_OPERATION]).toStrictEqual('process'); expect(msg2Span.parentSpanId).toStrictEqual(recvSpan.spanContext().spanId); - expect(msg2Span.attributes[SemanticAttributes.MESSAGING_OPERATION]).toStrictEqual('process'); + expect(msg2Span.attributes[SEMATTRS_MESSAGING_OPERATION]).toStrictEqual('process'); }); it('consumer eachBatch with non promise return value', async () => { diff --git a/packages/instrumentation-neo4j/package.json b/packages/instrumentation-neo4j/package.json index a7f19ebb..8b85fac9 100644 --- a/packages/instrumentation-neo4j/package.json +++ b/packages/instrumentation-neo4j/package.json @@ -41,24 +41,24 @@ "url": "https://github.com/aspecto-io/opentelemetry-ext-js/issues" }, "peerDependencies": { - "@opentelemetry/api": "^1.6.0" + "@opentelemetry/api": "^1.8.0" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.44.0", - "@opentelemetry/semantic-conventions": "^1.17.1" + "@opentelemetry/instrumentation": "^0.51.1", + "@opentelemetry/semantic-conventions": "^1.24.1" }, "devDependencies": { - "@opentelemetry/api": "^1.6.0", - "@opentelemetry/contrib-test-utils": "^0.34.2", - "@opentelemetry/sdk-trace-base": "^1.17.1", + "@opentelemetry/api": "^1.8.0", + "@opentelemetry/contrib-test-utils": "^0.39.0", + "@opentelemetry/sdk-trace-base": "^1.24.1", "@types/mocha": "^8.2.2", "expect": "^26.6.2", "mocha": "^8.4.0", "neo4j-driver": "^4.2.2", - "opentelemetry-instrumentation-mocha": "0.0.7-alpha.1", + "aspecto-opentelemetry-instrumentation-mocha": "0.0.9-alpha.0", "test-all-versions": "^5.0.1", - "ts-node": "^9.1.1", - "typescript": "4.3.4" + "ts-node": "^10.9.2", + "typescript": "5.4.5" }, "mocha": { "extension": [ @@ -67,7 +67,7 @@ "spec": "test/**/*.spec.ts", "require": [ "ts-node/register", - "opentelemetry-instrumentation-mocha" + "aspecto-opentelemetry-instrumentation-mocha" ] } } diff --git a/packages/instrumentation-neo4j/src/neo4j.ts b/packages/instrumentation-neo4j/src/neo4j.ts index e3823400..e035c1f1 100644 --- a/packages/instrumentation-neo4j/src/neo4j.ts +++ b/packages/instrumentation-neo4j/src/neo4j.ts @@ -1,5 +1,10 @@ import { SpanStatusCode, diag, trace, context, SpanKind } from '@opentelemetry/api'; -import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; +import { + SEMATTRS_DB_NAME, + SEMATTRS_DB_OPERATION, + SEMATTRS_DB_STATEMENT, + SEMATTRS_DB_SYSTEM, +} from '@opentelemetry/semantic-conventions'; import { VERSION } from './version'; import type * as neo4j from 'neo4j-driver'; import { @@ -14,7 +19,7 @@ import { getAttributesFromNeo4jSession } from './utils'; type Neo4J = typeof neo4j; -export class Neo4jInstrumentation extends InstrumentationBase { +export class Neo4jInstrumentation extends InstrumentationBase { protected override _config!: Neo4jInstrumentationConfig; constructor(config: Neo4jInstrumentationConfig = {}) { @@ -25,17 +30,17 @@ export class Neo4jInstrumentation extends InstrumentationBase { this._config = config; } - protected init(): InstrumentationModuleDefinition[] { + protected init(): InstrumentationModuleDefinition[] { return [ this.getModuleDefinition('neo4j-driver-core', ['>=4.3.0 <5']), this.getModuleDefinition('neo4j-driver', ['>=4.0.0 <4.3.0']), ]; } - private getModuleDefinition(name: string, supportedVersions: string[]): InstrumentationNodeModuleDefinition { + private getModuleDefinition(name: string, supportedVersions: string[]): InstrumentationNodeModuleDefinition { const apiModuleFiles = ['session', 'transaction'].map( (file) => - new InstrumentationNodeModuleFile( + new InstrumentationNodeModuleFile( `${name}/lib/${file}.js`, supportedVersions, this.patchSessionOrTransaction.bind(this), @@ -43,7 +48,7 @@ export class Neo4jInstrumentation extends InstrumentationBase { ) ); - const module = new InstrumentationNodeModuleDefinition( + const module = new InstrumentationNodeModuleDefinition( name, supportedVersions, undefined, @@ -67,12 +72,12 @@ export class Neo4jInstrumentation extends InstrumentationBase { const connectionAttributes = getAttributesFromNeo4jSession(this); const operation = query.trim().split(/\s+/)[0]; - const span = self.tracer.startSpan(`${operation} ${connectionAttributes[SemanticAttributes.DB_NAME]}`, { + const span = self.tracer.startSpan(`${operation} ${connectionAttributes[SEMATTRS_DB_NAME]}`, { attributes: { ...connectionAttributes, - [SemanticAttributes.DB_SYSTEM]: 'neo4j', - [SemanticAttributes.DB_OPERATION]: operation, - [SemanticAttributes.DB_STATEMENT]: query, + [SEMATTRS_DB_SYSTEM]: 'neo4j', + [SEMATTRS_DB_OPERATION]: operation, + [SEMATTRS_DB_STATEMENT]: query, }, kind: SpanKind.CLIENT, }); diff --git a/packages/instrumentation-neo4j/src/utils.ts b/packages/instrumentation-neo4j/src/utils.ts index ed5fbd0b..f5424f4b 100644 --- a/packages/instrumentation-neo4j/src/utils.ts +++ b/packages/instrumentation-neo4j/src/utils.ts @@ -1,4 +1,11 @@ -import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; +import { + SEMATTRS_DB_NAME, + SEMATTRS_DB_USER, + SEMATTRS_NET_PEER_NAME, + SEMATTRS_NET_PEER_PORT, + SEMATTRS_NET_TRANSPORT, + SemanticAttributes, +} from '@opentelemetry/semantic-conventions'; export function getAttributesFromNeo4jSession(session: any) { const connectionHolder = @@ -12,16 +19,16 @@ export function getAttributesFromNeo4jSession(session: any) { const auth = connectionProvider._authToken; const attributes = { - [SemanticAttributes.NET_TRANSPORT]: 'IP.TCP', + [SEMATTRS_NET_TRANSPORT]: 'IP.TCP', // "neo4j" is the default database name. When used, "session._database" is an empty string - [SemanticAttributes.DB_NAME]: session._database ? session._database : 'neo4j', + [SEMATTRS_DB_NAME]: session._database ? session._database : 'neo4j', }; if (address) { - attributes[SemanticAttributes.NET_PEER_NAME] = address._host; - attributes[SemanticAttributes.NET_PEER_PORT] = address._port; + attributes[SEMATTRS_NET_PEER_NAME] = address._host; + attributes[SEMATTRS_NET_PEER_PORT] = address._port; } if (auth?.principal) { - attributes[SemanticAttributes.DB_USER] = auth.principal; + attributes[SEMATTRS_DB_USER] = auth.principal; } return attributes; } diff --git a/packages/instrumentation-neo4j/test/assert.ts b/packages/instrumentation-neo4j/test/assert.ts index b6af02db..ab55dbc3 100644 --- a/packages/instrumentation-neo4j/test/assert.ts +++ b/packages/instrumentation-neo4j/test/assert.ts @@ -1,15 +1,22 @@ import expect from 'expect'; import { ReadableSpan } from '@opentelemetry/sdk-trace-base'; -import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; +import { + SEMATTRS_DB_NAME, + SEMATTRS_DB_SYSTEM, + SEMATTRS_DB_USER, + SEMATTRS_NET_PEER_NAME, + SEMATTRS_NET_PEER_PORT, + SEMATTRS_NET_TRANSPORT, +} from '@opentelemetry/semantic-conventions'; import { SpanKind, SpanStatusCode } from '@opentelemetry/api'; export const assertSpan = (span: ReadableSpan) => { expect(span.kind).toBe(SpanKind.CLIENT); expect(span.status.code).toBe(SpanStatusCode.UNSET); - expect(span.attributes[SemanticAttributes.DB_SYSTEM]).toEqual('neo4j'); - expect(span.attributes[SemanticAttributes.DB_NAME]).toEqual('neo4j'); - expect(span.attributes[SemanticAttributes.DB_USER]).toEqual('neo4j'); - expect(span.attributes[SemanticAttributes.NET_PEER_NAME]).toEqual('localhost'); - expect(span.attributes[SemanticAttributes.NET_PEER_PORT]).toEqual(11011); - expect(span.attributes[SemanticAttributes.NET_TRANSPORT]).toEqual('IP.TCP'); + expect(span.attributes[SEMATTRS_DB_SYSTEM]).toEqual('neo4j'); + expect(span.attributes[SEMATTRS_DB_NAME]).toEqual('neo4j'); + expect(span.attributes[SEMATTRS_DB_USER]).toEqual('neo4j'); + expect(span.attributes[SEMATTRS_NET_PEER_NAME]).toEqual('localhost'); + expect(span.attributes[SEMATTRS_NET_PEER_PORT]).toEqual(11011); + expect(span.attributes[SEMATTRS_NET_TRANSPORT]).toEqual('IP.TCP'); }; diff --git a/packages/instrumentation-neo4j/test/neo4j.spec.ts b/packages/instrumentation-neo4j/test/neo4j.spec.ts index 01189d7e..a548d70e 100644 --- a/packages/instrumentation-neo4j/test/neo4j.spec.ts +++ b/packages/instrumentation-neo4j/test/neo4j.spec.ts @@ -3,7 +3,7 @@ import expect from 'expect'; import { context, ROOT_CONTEXT, SpanStatusCode, trace } from '@opentelemetry/api'; import { Neo4jInstrumentation } from '../src'; import { assertSpan } from './assert'; -import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; +import { SEMATTRS_DB_OPERATION, SEMATTRS_DB_STATEMENT } from '@opentelemetry/semantic-conventions'; import { normalizeResponse } from './test-utils'; import { map, mergeMap } from 'rxjs/operators'; import { concat } from 'rxjs'; @@ -20,7 +20,7 @@ import { ReadableSpan } from '@opentelemetry/sdk-trace-base'; * Tests require neo4j to run, and expose bolt port of 11011 * * Use this command to run the required neo4j using docker: - * docker run --name testneo4j -p7474:7474 -p11011:7687 -d --env NEO4J_AUTH=neo4j/test neo4j:4.2.3 + * docker run --name testneo4j -p7474:7474 -p11011:7687 -d --env NEO4J_AUTH=neo4j/test neo4j:4.4.34 * */ describe('neo4j instrumentation', function () { @@ -34,7 +34,7 @@ describe('neo4j instrumentation', function () { }; before(async () => { - driver = neo4j.driver('bolt://localhost:11011', neo4j.auth.basic('neo4j', 'test'), { + driver = neo4j.driver('bolt://localhost:11011', neo4j.auth.basic('neo4j', 'your_password'), { disableLosslessIntegers: true, }); @@ -78,8 +78,8 @@ describe('neo4j instrumentation', function () { const span = getSingleSpan(); assertSpan(span as ReadableSpan); expect(span.name).toBe('CREATE neo4j'); - expect(span.attributes[SemanticAttributes.DB_OPERATION]).toBe('CREATE'); - expect(span.attributes[SemanticAttributes.DB_STATEMENT]).toBe('CREATE (n:MyLabel) RETURN n'); + expect(span.attributes[SEMATTRS_DB_OPERATION]).toBe('CREATE'); + expect(span.attributes[SEMATTRS_DB_STATEMENT]).toBe('CREATE (n:MyLabel) RETURN n'); }); it('instruments "run" with subscribe', (done) => { @@ -90,8 +90,8 @@ describe('neo4j instrumentation', function () { onCompleted: () => { const span = getSingleSpan(); assertSpan(span as ReadableSpan); - expect(span.attributes[SemanticAttributes.DB_OPERATION]).toBe('CREATE'); - expect(span.attributes[SemanticAttributes.DB_STATEMENT]).toBe('CREATE (n:MyLabel) RETURN n'); + expect(span.attributes[SEMATTRS_DB_OPERATION]).toBe('CREATE'); + expect(span.attributes[SEMATTRS_DB_STATEMENT]).toBe('CREATE (n:MyLabel) RETURN n'); done(); }, }); @@ -169,14 +169,14 @@ describe('neo4j instrumentation', function () { expect(spans.length).toBe(3); for (let span of spans) { assertSpan(span as ReadableSpan); - expect(span.attributes[SemanticAttributes.DB_OPERATION]).toBe('MATCH'); + expect(span.attributes[SEMATTRS_DB_OPERATION]).toBe('MATCH'); } }); it('captures operation with trailing white spaces', async () => { await driver.session().run(' MATCH (k) RETURN k '); const span = getSingleSpan(); - expect(span.attributes[SemanticAttributes.DB_OPERATION]).toBe('MATCH'); + expect(span.attributes[SEMATTRS_DB_OPERATION]).toBe('MATCH'); }); it('set module versions when config is set', async () => { @@ -288,10 +288,8 @@ describe('neo4j instrumentation', function () { }); const span = getSingleSpan(); assertSpan(span as ReadableSpan); - expect(span.attributes[SemanticAttributes.DB_OPERATION]).toBe('MATCH'); - expect(span.attributes[SemanticAttributes.DB_STATEMENT]).toBe( - 'MATCH (person:Person) RETURN person.name AS name' - ); + expect(span.attributes[SEMATTRS_DB_OPERATION]).toBe('MATCH'); + expect(span.attributes[SEMATTRS_DB_STATEMENT]).toBe('MATCH (person:Person) RETURN person.name AS name'); }); it('instruments session writeTransaction', async () => { @@ -300,10 +298,8 @@ describe('neo4j instrumentation', function () { }); const span = getSingleSpan(); assertSpan(span as ReadableSpan); - expect(span.attributes[SemanticAttributes.DB_OPERATION]).toBe('MATCH'); - expect(span.attributes[SemanticAttributes.DB_STATEMENT]).toBe( - 'MATCH (person:Person) RETURN person.name AS name' - ); + expect(span.attributes[SEMATTRS_DB_OPERATION]).toBe('MATCH'); + expect(span.attributes[SEMATTRS_DB_STATEMENT]).toBe('MATCH (person:Person) RETURN person.name AS name'); }); it('instruments explicit transactions', async () => { @@ -345,7 +341,7 @@ describe('neo4j instrumentation', function () { complete: () => { const span = getSingleSpan(); assertSpan(span as ReadableSpan); - expect(span.attributes[SemanticAttributes.DB_STATEMENT]).toBe( + expect(span.attributes[SEMATTRS_DB_STATEMENT]).toBe( 'MERGE (james:Person {name: $nameParam}) RETURN james.name AS name' ); done(); @@ -393,7 +389,7 @@ describe('neo4j instrumentation', function () { complete: () => { const span = getSingleSpan(); assertSpan(span as ReadableSpan); - expect(span.attributes[SemanticAttributes.DB_STATEMENT]).toBe( + expect(span.attributes[SEMATTRS_DB_STATEMENT]).toBe( 'MATCH (person:Person) RETURN person.name AS name' ); done(); @@ -416,7 +412,7 @@ describe('neo4j instrumentation', function () { complete: () => { const span = getSingleSpan(); assertSpan(span as ReadableSpan); - expect(span.attributes[SemanticAttributes.DB_STATEMENT]).toBe( + expect(span.attributes[SEMATTRS_DB_STATEMENT]).toBe( 'MATCH (person:Person) RETURN person.name AS name' ); done(); @@ -468,7 +464,7 @@ describe('neo4j instrumentation', function () { before(() => { if (shouldCheck) { - routingDriver = neo4j.driver('neo4j://localhost:11011', neo4j.auth.basic('neo4j', 'test')); + routingDriver = neo4j.driver('neo4j://localhost:11011', neo4j.auth.basic('neo4j', 'your_password')); } }); diff --git a/packages/instrumentation-node-cache/package.json b/packages/instrumentation-node-cache/package.json index cd1ed0d9..c07be6d2 100644 --- a/packages/instrumentation-node-cache/package.json +++ b/packages/instrumentation-node-cache/package.json @@ -39,26 +39,26 @@ "url": "https://github.com/aspecto-io/opentelemetry-ext-js/issues" }, "peerDependencies": { - "@opentelemetry/api": "^1.6.0" + "@opentelemetry/api": "^1.8.0" }, "dependencies": { - "@opentelemetry/contrib-test-utils": "^0.34.2", - "@opentelemetry/core": "^1.17.1", - "@opentelemetry/instrumentation": "^0.44.0", - "@opentelemetry/semantic-conventions": "^1.17.1" + "@opentelemetry/contrib-test-utils": "^0.39.0", + "@opentelemetry/core": "^1.24.1", + "@opentelemetry/instrumentation": "^0.51.1", + "@opentelemetry/semantic-conventions": "^1.24.1" }, "devDependencies": { - "@opentelemetry/api": "^1.6.0", - "@opentelemetry/contrib-test-utils": "^0.34.2", - "@opentelemetry/sdk-trace-base": "^1.17.1", + "@opentelemetry/api": "^1.8.0", + "@opentelemetry/contrib-test-utils": "^0.39.0", + "@opentelemetry/sdk-trace-base": "^1.24.1", "@types/mocha": "^8.2.2", "expect": "^26.6.2", "mocha": "^8.4.0", "node-cache": "^5.1.2", - "opentelemetry-instrumentation-mocha": "0.0.7-alpha.1", + "aspecto-opentelemetry-instrumentation-mocha": "0.0.9-alpha.0", "test-all-versions": "^5.0.1", - "ts-node": "^9.1.1", - "typescript": "4.3.4" + "ts-node": "^10.9.2", + "typescript": "5.4.5" }, "mocha": { "extension": [ @@ -67,7 +67,7 @@ "spec": "test/**/*.spec.ts", "require": [ "ts-node/register", - "opentelemetry-instrumentation-mocha" + "aspecto-opentelemetry-instrumentation-mocha" ] } } diff --git a/packages/instrumentation-node-cache/src/node-cache.ts b/packages/instrumentation-node-cache/src/node-cache.ts index 9da73c0b..7a0bbedc 100644 --- a/packages/instrumentation-node-cache/src/node-cache.ts +++ b/packages/instrumentation-node-cache/src/node-cache.ts @@ -8,11 +8,16 @@ import { NodeCacheInstrumentationConfig } from './types'; import { VERSION } from './version'; import { diag, SpanKind, SpanStatusCode, context, trace } from '@opentelemetry/api'; import { suppressTracing } from '@opentelemetry/core'; -import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; +import { + SEMATTRS_DB_OPERATION, + SEMATTRS_DB_STATEMENT, + SEMATTRS_DB_SYSTEM, + SemanticAttributes, +} from '@opentelemetry/semantic-conventions'; type NodeCacheType = typeof NodeCache; -export class NodeCacheInstrumentation extends InstrumentationBase { +export class NodeCacheInstrumentation extends InstrumentationBase { constructor(protected override _config: NodeCacheInstrumentationConfig = {}) { super('opentelemetry-instrumentation-node-cache', VERSION, _config); } @@ -21,12 +26,8 @@ export class NodeCacheInstrumentation extends InstrumentationBase this._config = config; } - protected init(): InstrumentationModuleDefinition { - const module = new InstrumentationNodeModuleDefinition( - 'node-cache', - ['>=5.0.0'], - this.patch.bind(this) - ); + protected init(): InstrumentationModuleDefinition { + const module = new InstrumentationNodeModuleDefinition('node-cache', ['>=5.0.0'], this.patch.bind(this)); return module; } @@ -84,9 +85,9 @@ export class NodeCacheInstrumentation extends InstrumentationBase const span = self.tracer.startSpan(`node-cache ${opName}`, { kind: SpanKind.INTERNAL, attributes: { - [SemanticAttributes.DB_SYSTEM]: 'node-cache', - [SemanticAttributes.DB_OPERATION]: opName, - [SemanticAttributes.DB_STATEMENT]: toStatement(arguments), + [SEMATTRS_DB_SYSTEM]: 'node-cache', + [SEMATTRS_DB_OPERATION]: opName, + [SEMATTRS_DB_STATEMENT]: toStatement(arguments), }, }); diff --git a/packages/instrumentation-node-cache/test/node-cache.spec.ts b/packages/instrumentation-node-cache/test/node-cache.spec.ts index 96d838d0..ae2e88a8 100644 --- a/packages/instrumentation-node-cache/test/node-cache.spec.ts +++ b/packages/instrumentation-node-cache/test/node-cache.spec.ts @@ -9,7 +9,12 @@ const instrumentation = registerInstrumentationTesting(new NodeCacheInstrumentat instrumentation.enable(); import NodeCache from 'node-cache'; -import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; +import { + SEMATTRS_DB_OPERATION, + SEMATTRS_DB_STATEMENT, + SEMATTRS_DB_SYSTEM, + SemanticAttributes, +} from '@opentelemetry/semantic-conventions'; describe('node-cache instrumentation', () => { let cache = new NodeCache(); @@ -40,8 +45,8 @@ describe('node-cache instrumentation', () => { const span = getSingleSpan(); expect(span.name).toBe('node-cache set'); - expect(span.attributes[SemanticAttributes.DB_SYSTEM]).toBe('node-cache'); - expect(span.attributes[SemanticAttributes.DB_OPERATION]).toBe('set'); + expect(span.attributes[SEMATTRS_DB_SYSTEM]).toBe('node-cache'); + expect(span.attributes[SEMATTRS_DB_OPERATION]).toBe('set'); expect(span.attributes[DB_RESPONSE]).toBe(true); }); @@ -52,9 +57,9 @@ describe('node-cache instrumentation', () => { const span = getSingleSpan(); expect(span.name).toBe('node-cache get'); - expect(span.attributes[SemanticAttributes.DB_SYSTEM]).toBe('node-cache'); - expect(span.attributes[SemanticAttributes.DB_OPERATION]).toBe('get'); - expect(span.attributes[SemanticAttributes.DB_STATEMENT]).toBe('get some-key'); + expect(span.attributes[SEMATTRS_DB_SYSTEM]).toBe('node-cache'); + expect(span.attributes[SEMATTRS_DB_OPERATION]).toBe('get'); + expect(span.attributes[SEMATTRS_DB_STATEMENT]).toBe('get some-key'); expect(span.attributes[DB_RESPONSE]).toBe('some-value'); }); @@ -63,9 +68,9 @@ describe('node-cache instrumentation', () => { const span = getSingleSpan(); expect(span.name).toBe('node-cache has'); - expect(span.attributes[SemanticAttributes.DB_SYSTEM]).toBe('node-cache'); - expect(span.attributes[SemanticAttributes.DB_OPERATION]).toBe('has'); - expect(span.attributes[SemanticAttributes.DB_STATEMENT]).toBe('has some-key'); + expect(span.attributes[SEMATTRS_DB_SYSTEM]).toBe('node-cache'); + expect(span.attributes[SEMATTRS_DB_OPERATION]).toBe('has'); + expect(span.attributes[SEMATTRS_DB_STATEMENT]).toBe('has some-key'); expect(span.attributes[DB_RESPONSE]).toBe(false); }); @@ -78,9 +83,9 @@ describe('node-cache instrumentation', () => { const span = getSingleSpan(); expect(span.name).toBe('node-cache take'); - expect(span.attributes[SemanticAttributes.DB_SYSTEM]).toBe('node-cache'); - expect(span.attributes[SemanticAttributes.DB_OPERATION]).toBe('take'); - expect(span.attributes[SemanticAttributes.DB_STATEMENT]).toBe('take some-key'); + expect(span.attributes[SEMATTRS_DB_SYSTEM]).toBe('node-cache'); + expect(span.attributes[SEMATTRS_DB_OPERATION]).toBe('take'); + expect(span.attributes[SEMATTRS_DB_STATEMENT]).toBe('take some-key'); expect(span.attributes[DB_RESPONSE]).toBe('some-value'); }); @@ -91,9 +96,9 @@ describe('node-cache instrumentation', () => { const span = getSingleSpan(); expect(span.name).toBe('node-cache del'); - expect(span.attributes[SemanticAttributes.DB_SYSTEM]).toBe('node-cache'); - expect(span.attributes[SemanticAttributes.DB_OPERATION]).toBe('del'); - expect(span.attributes[SemanticAttributes.DB_STATEMENT]).toBe('del some-key'); + expect(span.attributes[SEMATTRS_DB_SYSTEM]).toBe('node-cache'); + expect(span.attributes[SEMATTRS_DB_OPERATION]).toBe('del'); + expect(span.attributes[SEMATTRS_DB_STATEMENT]).toBe('del some-key'); expect(span.attributes[DB_RESPONSE]).toBe(1); }); @@ -105,9 +110,9 @@ describe('node-cache instrumentation', () => { const span = getSingleSpan(); expect(span.name).toBe('node-cache del'); - expect(span.attributes[SemanticAttributes.DB_SYSTEM]).toBe('node-cache'); - expect(span.attributes[SemanticAttributes.DB_OPERATION]).toBe('del'); - expect(span.attributes[SemanticAttributes.DB_STATEMENT]).toBe('del some-key,some-other-key'); + expect(span.attributes[SEMATTRS_DB_SYSTEM]).toBe('node-cache'); + expect(span.attributes[SEMATTRS_DB_OPERATION]).toBe('del'); + expect(span.attributes[SEMATTRS_DB_STATEMENT]).toBe('del some-key,some-other-key'); expect(span.attributes[DB_RESPONSE]).toBe(2); }); @@ -120,9 +125,9 @@ describe('node-cache instrumentation', () => { const span = getSingleSpan(); expect(span.name).toBe('node-cache mget'); - expect(span.attributes[SemanticAttributes.DB_SYSTEM]).toBe('node-cache'); - expect(span.attributes[SemanticAttributes.DB_OPERATION]).toBe('mget'); - expect(span.attributes[SemanticAttributes.DB_STATEMENT]).toBe('mget a,b,c'); + expect(span.attributes[SEMATTRS_DB_SYSTEM]).toBe('node-cache'); + expect(span.attributes[SEMATTRS_DB_OPERATION]).toBe('mget'); + expect(span.attributes[SEMATTRS_DB_STATEMENT]).toBe('mget a,b,c'); expect(JSON.parse(span.attributes[DB_RESPONSE] as string)).toEqual({ a: 'x', b: 'y' }); }); @@ -134,9 +139,9 @@ describe('node-cache instrumentation', () => { const span = getSingleSpan(); expect(span.name).toBe('node-cache mset'); - expect(span.attributes[SemanticAttributes.DB_SYSTEM]).toBe('node-cache'); - expect(span.attributes[SemanticAttributes.DB_OPERATION]).toBe('mset'); - expect(span.attributes[SemanticAttributes.DB_STATEMENT]).toBe('mset a,b'); + expect(span.attributes[SEMATTRS_DB_SYSTEM]).toBe('node-cache'); + expect(span.attributes[SEMATTRS_DB_OPERATION]).toBe('mset'); + expect(span.attributes[SEMATTRS_DB_STATEMENT]).toBe('mset a,b'); expect(span.attributes[DB_RESPONSE]).toEqual(true); }); @@ -145,9 +150,9 @@ describe('node-cache instrumentation', () => { const span = getSingleSpan(); expect(span.name).toBe('node-cache getTtl'); - expect(span.attributes[SemanticAttributes.DB_SYSTEM]).toBe('node-cache'); - expect(span.attributes[SemanticAttributes.DB_OPERATION]).toBe('getTtl'); - expect(span.attributes[SemanticAttributes.DB_STATEMENT]).toBe('getTtl some-key'); + expect(span.attributes[SEMATTRS_DB_SYSTEM]).toBe('node-cache'); + expect(span.attributes[SEMATTRS_DB_OPERATION]).toBe('getTtl'); + expect(span.attributes[SEMATTRS_DB_STATEMENT]).toBe('getTtl some-key'); }); it('ttl', () => { @@ -155,9 +160,9 @@ describe('node-cache instrumentation', () => { const span = getSingleSpan(); expect(span.name).toBe('node-cache ttl'); - expect(span.attributes[SemanticAttributes.DB_SYSTEM]).toBe('node-cache'); - expect(span.attributes[SemanticAttributes.DB_OPERATION]).toBe('ttl'); - expect(span.attributes[SemanticAttributes.DB_STATEMENT]).toBe('ttl some-key 12345'); + expect(span.attributes[SEMATTRS_DB_SYSTEM]).toBe('node-cache'); + expect(span.attributes[SEMATTRS_DB_OPERATION]).toBe('ttl'); + expect(span.attributes[SEMATTRS_DB_STATEMENT]).toBe('ttl some-key 12345'); }); it('flushAll', () => { @@ -165,9 +170,9 @@ describe('node-cache instrumentation', () => { const span = getSingleSpan(); expect(span.name).toBe('node-cache flushAll'); - expect(span.attributes[SemanticAttributes.DB_SYSTEM]).toBe('node-cache'); - expect(span.attributes[SemanticAttributes.DB_OPERATION]).toBe('flushAll'); - expect(span.attributes[SemanticAttributes.DB_STATEMENT]).toBe('flushAll'); + expect(span.attributes[SEMATTRS_DB_SYSTEM]).toBe('node-cache'); + expect(span.attributes[SEMATTRS_DB_OPERATION]).toBe('flushAll'); + expect(span.attributes[SEMATTRS_DB_STATEMENT]).toBe('flushAll'); }); }); diff --git a/packages/instrumentation-sequelize/package.json b/packages/instrumentation-sequelize/package.json index f1bd6a5f..0aeeaec5 100644 --- a/packages/instrumentation-sequelize/package.json +++ b/packages/instrumentation-sequelize/package.json @@ -39,27 +39,27 @@ "url": "https://github.com/aspecto-io/opentelemetry-ext-js/issues" }, "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": { - "@opentelemetry/api": "^1.6.0", - "@opentelemetry/contrib-test-utils": "^0.34.2", - "@opentelemetry/sdk-trace-base": "^1.17.1", + "@opentelemetry/api": "^1.8.0", + "@opentelemetry/contrib-test-utils": "^0.39.0", + "@opentelemetry/sdk-trace-base": "^1.24.1", "@types/mocha": "^8.2.2", "expect": "^26.6.2", "mocha": "^8.4.0", "mysql2": "^2.2.5", - "opentelemetry-instrumentation-mocha": "0.0.7-alpha.1", + "aspecto-opentelemetry-instrumentation-mocha": "0.0.9-alpha.0", "pg": "^8.4.2", "sequelize": "^5.22.0", "sqlite3": "^5.0.2", - "ts-node": "^9.1.1", - "typescript": "4.3.4" + "ts-node": "^10.9.2", + "typescript": "5.4.5" }, "mocha": { "extension": [ @@ -68,7 +68,7 @@ "spec": "test/**/*.spec.ts", "require": [ "ts-node/register", - "opentelemetry-instrumentation-mocha" + "aspecto-opentelemetry-instrumentation-mocha" ] } } diff --git a/packages/instrumentation-sequelize/src/sequelize.ts b/packages/instrumentation-sequelize/src/sequelize.ts index 2804eddf..3b4f7ee9 100644 --- a/packages/instrumentation-sequelize/src/sequelize.ts +++ b/packages/instrumentation-sequelize/src/sequelize.ts @@ -1,6 +1,18 @@ import { context, Span, SpanKind, SpanStatusCode, trace, diag } from '@opentelemetry/api'; import { suppressTracing } from '@opentelemetry/core'; -import { NetTransportValues, SemanticAttributes } from '@opentelemetry/semantic-conventions'; +import { + NetTransportValues, + SEMATTRS_NET_TRANSPORT, + SEMATTRS_DB_NAME, + SEMATTRS_DB_OPERATION, + SEMATTRS_DB_SQL_TABLE, + SEMATTRS_DB_STATEMENT, + SEMATTRS_DB_SYSTEM, + SEMATTRS_DB_USER, + SEMATTRS_NET_PEER_NAME, + SEMATTRS_NET_PEER_PORT, + SemanticAttributes, +} from '@opentelemetry/semantic-conventions'; import * as sequelize from 'sequelize'; import { SequelizeInstrumentationConfig } from './types'; import { VERSION } from './version'; @@ -14,7 +26,7 @@ import { safeExecuteInTheMiddle, } from '@opentelemetry/instrumentation'; -export class SequelizeInstrumentation extends InstrumentationBase { +export class SequelizeInstrumentation extends InstrumentationBase { static readonly component = 'sequelize'; protected override _config!: SequelizeInstrumentationConfig; private moduleVersion: string; @@ -27,15 +39,15 @@ export class SequelizeInstrumentation extends InstrumentationBase { - const connectionManagerInstrumentation = new InstrumentationNodeModuleFile( + protected init(): InstrumentationModuleDefinition { + const connectionManagerInstrumentation = new InstrumentationNodeModuleFile( 'sequelize/lib/dialects/abstract/connection-manager.js', ['*'], this.patchConnectionManager.bind(this), this.unpatchConnectionManager.bind(this) ); - const module = new InstrumentationNodeModuleDefinition( + const module = new InstrumentationNodeModuleDefinition( SequelizeInstrumentation.component, ['*'], this.patch.bind(this), @@ -115,16 +127,16 @@ export class SequelizeInstrumentation extends InstrumentationBase { expect(spans[0].status.code).toBe(SpanStatusCode.ERROR); const attributes = spans[0].attributes; - expect(attributes[SemanticAttributes.DB_SYSTEM]).toBe(DB_SYSTEM); - expect(attributes[SemanticAttributes.DB_USER]).toBe(DB_USER); - expect(attributes[SemanticAttributes.NET_PEER_NAME]).toBe(NET_PEER_NAME); - expect(attributes[SemanticAttributes.NET_PEER_PORT]).toBe(NET_PEER_PORT); - expect(attributes[SemanticAttributes.DB_NAME]).toBe(DB_NAME); - expect(attributes[SemanticAttributes.DB_OPERATION]).toBe('INSERT'); - expect(attributes[SemanticAttributes.DB_SQL_TABLE]).toBe('Users'); - expect(attributes[SemanticAttributes.DB_STATEMENT]).toBe( + expect(attributes[SEMATTRS_DB_SYSTEM]).toBe(DB_SYSTEM); + expect(attributes[SEMATTRS_DB_USER]).toBe(DB_USER); + expect(attributes[SEMATTRS_NET_PEER_NAME]).toBe(NET_PEER_NAME); + expect(attributes[SEMATTRS_NET_PEER_PORT]).toBe(NET_PEER_PORT); + expect(attributes[SEMATTRS_DB_NAME]).toBe(DB_NAME); + expect(attributes[SEMATTRS_DB_OPERATION]).toBe('INSERT'); + expect(attributes[SEMATTRS_DB_SQL_TABLE]).toBe('Users'); + expect(attributes[SEMATTRS_DB_STATEMENT]).toBe( 'INSERT INTO "Users" ("id","firstName","createdAt","updatedAt") VALUES (DEFAULT,$1,$2,$3) RETURNING *;' ); }); @@ -72,9 +82,9 @@ describe('instrumentation-sequelize', () => { expect(spans.length).toBe(1); const attributes = spans[0].attributes; - expect(attributes[SemanticAttributes.DB_OPERATION]).toBe('SELECT'); - expect(attributes[SemanticAttributes.DB_SQL_TABLE]).toBe('Users'); - expect(attributes[SemanticAttributes.DB_STATEMENT]).toBe( + expect(attributes[SEMATTRS_DB_OPERATION]).toBe('SELECT'); + expect(attributes[SEMATTRS_DB_SQL_TABLE]).toBe('Users'); + expect(attributes[SEMATTRS_DB_STATEMENT]).toBe( 'SELECT "id", "firstName", "createdAt", "updatedAt" FROM "Users" AS "User";' ); }); @@ -85,9 +95,9 @@ describe('instrumentation-sequelize', () => { expect(spans.length).toBe(1); const attributes = spans[0].attributes; - expect(attributes[SemanticAttributes.DB_OPERATION]).toBe('BULKDELETE'); - expect(attributes[SemanticAttributes.DB_SQL_TABLE]).toBe('Users'); - expect(attributes[SemanticAttributes.DB_STATEMENT]).toBe('TRUNCATE "Users"'); + expect(attributes[SEMATTRS_DB_OPERATION]).toBe('BULKDELETE'); + expect(attributes[SEMATTRS_DB_SQL_TABLE]).toBe('Users'); + expect(attributes[SEMATTRS_DB_STATEMENT]).toBe('TRUNCATE "Users"'); }); it('count is instrumented', async () => { @@ -96,11 +106,9 @@ describe('instrumentation-sequelize', () => { expect(spans.length).toBe(1); const attributes = spans[0].attributes; - expect(attributes[SemanticAttributes.DB_OPERATION]).toBe('SELECT'); - expect(attributes[SemanticAttributes.DB_SQL_TABLE]).toBe('Users'); - expect(attributes[SemanticAttributes.DB_STATEMENT]).toBe( - 'SELECT count(*) AS "count" FROM "Users" AS "User";' - ); + expect(attributes[SEMATTRS_DB_OPERATION]).toBe('SELECT'); + expect(attributes[SEMATTRS_DB_SQL_TABLE]).toBe('Users'); + expect(attributes[SEMATTRS_DB_STATEMENT]).toBe('SELECT count(*) AS "count" FROM "Users" AS "User";'); }); it('handled complex query', async () => { @@ -125,9 +133,9 @@ describe('instrumentation-sequelize', () => { expect(spans.length).toBe(1); const attributes = spans[0].attributes; - expect(attributes[SemanticAttributes.DB_OPERATION]).toBe('SELECT'); - expect(attributes[SemanticAttributes.DB_SQL_TABLE]).toBe('Users'); - expect(attributes[SemanticAttributes.DB_STATEMENT]).toBe( + expect(attributes[SEMATTRS_DB_OPERATION]).toBe('SELECT'); + expect(attributes[SEMATTRS_DB_SQL_TABLE]).toBe('Users'); + expect(attributes[SEMATTRS_DB_STATEMENT]).toBe( `SELECT "id", "username" FROM "Users" AS "User" WHERE "User"."username" = 'Shlomi' AND ("User"."rank" < 1000 OR "User"."rank" IS NULL) ORDER BY "User"."username" DESC LIMIT 10 OFFSET 5;` ); }); @@ -141,7 +149,7 @@ describe('instrumentation-sequelize', () => { const spans = getSequelizeSpans(); expect(spans.length).toBe(1); const attributes = spans[0].attributes; - expect(attributes[SemanticAttributes.DB_SQL_TABLE]).toBe(expectedTableName); + expect(attributes[SEMATTRS_DB_SQL_TABLE]).toBe(expectedTableName); }); it('handles JOIN queries', async () => { @@ -171,9 +179,9 @@ describe('instrumentation-sequelize', () => { expect(spans.length).toBe(1); const attributes = spans[0].attributes; - expect(attributes[SemanticAttributes.DB_OPERATION]).toBe('SELECT'); - expect(attributes[SemanticAttributes.DB_SQL_TABLE]).toBe('Dogs,Users'); - expect(attributes[SemanticAttributes.DB_STATEMENT]).toBe( + expect(attributes[SEMATTRS_DB_OPERATION]).toBe('SELECT'); + expect(attributes[SEMATTRS_DB_SQL_TABLE]).toBe('Dogs,Users'); + expect(attributes[SEMATTRS_DB_STATEMENT]).toBe( `SELECT "Dog"."id", "Dog"."firstName", "Dog"."owner", "User"."id" AS "User.id", "User"."firstName" AS "User.firstName" FROM "Dogs" AS "Dog" INNER JOIN "Users" AS "User" ON "Dog"."firstName" = "User"."id" LIMIT 1;` ); }); @@ -201,14 +209,14 @@ describe('instrumentation-sequelize', () => { expect(spans[0].status.code).toBe(SpanStatusCode.ERROR); const attributes = spans[0].attributes; - expect(attributes[SemanticAttributes.DB_SYSTEM]).toBe(DB_SYSTEM); - expect(attributes[SemanticAttributes.DB_USER]).toBe(DB_USER); - expect(attributes[SemanticAttributes.NET_PEER_NAME]).toBe(NET_PEER_NAME); - expect(attributes[SemanticAttributes.NET_PEER_PORT]).toBe(NET_PEER_PORT); - expect(attributes[SemanticAttributes.DB_NAME]).toBe(DB_NAME); - expect(attributes[SemanticAttributes.DB_OPERATION]).toBe('INSERT'); - expect(attributes[SemanticAttributes.DB_SQL_TABLE]).toBe('Users'); - expect(attributes[SemanticAttributes.DB_STATEMENT]).toBe( + expect(attributes[SEMATTRS_DB_SYSTEM]).toBe(DB_SYSTEM); + expect(attributes[SEMATTRS_DB_USER]).toBe(DB_USER); + expect(attributes[SEMATTRS_NET_PEER_NAME]).toBe(NET_PEER_NAME); + expect(attributes[SEMATTRS_NET_PEER_PORT]).toBe(NET_PEER_PORT); + expect(attributes[SEMATTRS_DB_NAME]).toBe(DB_NAME); + expect(attributes[SEMATTRS_DB_OPERATION]).toBe('INSERT'); + expect(attributes[SEMATTRS_DB_SQL_TABLE]).toBe('Users'); + expect(attributes[SEMATTRS_DB_STATEMENT]).toBe( 'INSERT INTO `Users` (`id`,`firstName`,`createdAt`,`updatedAt`) VALUES (DEFAULT,$1,$2,$3);' ); }); @@ -219,9 +227,9 @@ describe('instrumentation-sequelize', () => { expect(spans.length).toBe(1); const attributes = spans[0].attributes; - expect(attributes[SemanticAttributes.DB_OPERATION]).toBe('SELECT'); - expect(attributes[SemanticAttributes.DB_SQL_TABLE]).toBe('Users'); - expect(attributes[SemanticAttributes.DB_STATEMENT]).toBe( + expect(attributes[SEMATTRS_DB_OPERATION]).toBe('SELECT'); + expect(attributes[SEMATTRS_DB_SQL_TABLE]).toBe('Users'); + expect(attributes[SEMATTRS_DB_STATEMENT]).toBe( 'SELECT `id`, `firstName`, `createdAt`, `updatedAt` FROM `Users` AS `User`;' ); }); @@ -237,8 +245,8 @@ describe('instrumentation-sequelize', () => { expect(spans.length).toBe(1); const attributes = spans[0].attributes; - expect(attributes[SemanticAttributes.DB_OPERATION]).toBe('SELECT'); - expect(attributes[SemanticAttributes.DB_STATEMENT]).toBe('SELECT 1 + 1'); + expect(attributes[SEMATTRS_DB_OPERATION]).toBe('SELECT'); + expect(attributes[SEMATTRS_DB_STATEMENT]).toBe('SELECT 1 + 1'); }); it('with type not specified in options', async () => { try { @@ -250,8 +258,8 @@ describe('instrumentation-sequelize', () => { expect(spans.length).toBe(1); const attributes = spans[0].attributes; - expect(attributes[SemanticAttributes.DB_OPERATION]).toBe('SELECT'); - expect(attributes[SemanticAttributes.DB_STATEMENT]).toBe('SELECT 1 + 1'); + expect(attributes[SEMATTRS_DB_OPERATION]).toBe('SELECT'); + expect(attributes[SEMATTRS_DB_STATEMENT]).toBe('SELECT 1 + 1'); }); it('with type specified in options', async () => { @@ -264,8 +272,8 @@ describe('instrumentation-sequelize', () => { expect(spans.length).toBe(1); const attributes = spans[0].attributes; - expect(attributes[SemanticAttributes.DB_OPERATION]).toBe('RAW'); - expect(attributes[SemanticAttributes.DB_STATEMENT]).toBe('SELECT 1 + 1'); + expect(attributes[SEMATTRS_DB_OPERATION]).toBe('RAW'); + expect(attributes[SEMATTRS_DB_STATEMENT]).toBe('SELECT 1 + 1'); }); }); }); @@ -281,11 +289,11 @@ describe('instrumentation-sequelize', () => { const spans = getSequelizeSpans(); expect(spans.length).toBe(1); const attributes = spans[0].attributes; - expect(attributes[SemanticAttributes.DB_SYSTEM]).toBe('sqlite'); - expect(attributes[SemanticAttributes.NET_PEER_NAME]).toBe('memory'); - expect(attributes[SemanticAttributes.DB_OPERATION]).toBe('INSERT'); - expect(attributes[SemanticAttributes.DB_SQL_TABLE]).toBe('Users'); - expect(attributes[SemanticAttributes.DB_STATEMENT]).toBe( + expect(attributes[SEMATTRS_DB_SYSTEM]).toBe('sqlite'); + expect(attributes[SEMATTRS_NET_PEER_NAME]).toBe('memory'); + expect(attributes[SEMATTRS_DB_OPERATION]).toBe('INSERT'); + expect(attributes[SEMATTRS_DB_SQL_TABLE]).toBe('Users'); + expect(attributes[SEMATTRS_DB_STATEMENT]).toBe( 'INSERT INTO `Users` (`id`,`firstName`,`createdAt`,`updatedAt`) VALUES (NULL,$1,$2,$3);' ); }); diff --git a/packages/instrumentation-typeorm/package.json b/packages/instrumentation-typeorm/package.json index c403df3a..cb4d1943 100644 --- a/packages/instrumentation-typeorm/package.json +++ b/packages/instrumentation-typeorm/package.json @@ -35,28 +35,28 @@ "url": "https://github.com/aspecto-io/opentelemetry-ext-js/issues" }, "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", "is-promise": "^4.0.0" }, "devDependencies": { - "@opentelemetry/api": "^1.6.0", - "@opentelemetry/contrib-test-utils": "^0.34.2", - "@opentelemetry/sdk-trace-base": "^1.17.1", + "@opentelemetry/api": "^1.8.0", + "@opentelemetry/contrib-test-utils": "^0.39.0", + "@opentelemetry/sdk-trace-base": "^1.24.1", "@types/mocha": "^8.2.2", "expect": "^26.6.2", "mocha": "^8.4.0", - "opentelemetry-instrumentation-mocha": "0.0.7-alpha.1", + "aspecto-opentelemetry-instrumentation-mocha": "0.0.9-alpha.0", "reflect-metadata": "^0.1.13", "sqlite3": "^5.0.2", "test-all-versions": "^5.0.1", - "ts-node": "^9.1.1", + "ts-node": "^10.9.2", "typeorm": "^0.2.26", - "typescript": "4.3.4" + "typescript": "5.4.5" }, "mocha": { "extension": [ @@ -65,7 +65,7 @@ "spec": "test/**/*.spec.ts", "require": [ "ts-node/register", - "opentelemetry-instrumentation-mocha" + "aspecto-opentelemetry-instrumentation-mocha" ] } } diff --git a/packages/instrumentation-typeorm/src/typeorm.ts b/packages/instrumentation-typeorm/src/typeorm.ts index 5f93296e..25ee6b11 100644 --- a/packages/instrumentation-typeorm/src/typeorm.ts +++ b/packages/instrumentation-typeorm/src/typeorm.ts @@ -1,6 +1,16 @@ import { Span, SpanKind, SpanStatusCode, trace, context, diag } from '@opentelemetry/api'; import { suppressTracing } from '@opentelemetry/core'; -import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; +import { + SEMATTRS_DB_NAME, + SEMATTRS_DB_OPERATION, + SEMATTRS_DB_SQL_TABLE, + SEMATTRS_DB_STATEMENT, + SEMATTRS_DB_SYSTEM, + SEMATTRS_DB_USER, + SEMATTRS_NET_PEER_NAME, + SEMATTRS_NET_PEER_PORT, + SemanticAttributes, +} from '@opentelemetry/semantic-conventions'; import { ExtendedDatabaseAttribute, TypeormInstrumentationConfig } from './types'; import { getParamNames, isTypeormInternalTracingSuppressed, suppressTypeormInternalTracing } from './utils'; import { VERSION } from './version'; @@ -49,14 +59,14 @@ const entityManagerMethods: EntityManagerMethods[] = [ ...functionsUsingQueryBuilder, ]; -export class TypeormInstrumentation extends InstrumentationBase { +export class TypeormInstrumentation extends InstrumentationBase { protected override _config!: TypeormInstrumentationConfig; constructor(config: TypeormInstrumentationConfig = {}) { super('opentelemetry-instrumentation-typeorm', VERSION, Object.assign({}, config)); } - protected init(): InstrumentationModuleDefinition { - const selectQueryBuilder = new InstrumentationNodeModuleFile( + protected init(): InstrumentationModuleDefinition { + const selectQueryBuilder = new InstrumentationNodeModuleFile( 'typeorm/query-builder/SelectQueryBuilder.js', ['>0.2.28'], (moduleExports, moduleVersion) => { @@ -83,7 +93,7 @@ export class TypeormInstrumentation extends InstrumentationBase { } ); - const connection = new InstrumentationNodeModuleFile( + const connection = new InstrumentationNodeModuleFile( 'typeorm/connection/Connection.js', ['>0.2.28 <0.3.0'], (moduleExports, moduleVersion) => { @@ -102,7 +112,7 @@ export class TypeormInstrumentation extends InstrumentationBase { } ); - const dataSource = new InstrumentationNodeModuleFile( + const dataSource = new InstrumentationNodeModuleFile( 'typeorm/data-source/DataSource.js', ['>=0.3.0'], (moduleExports, moduleVersion) => { @@ -121,7 +131,7 @@ export class TypeormInstrumentation extends InstrumentationBase { } ); - const entityManager = new InstrumentationNodeModuleFile( + const entityManager = new InstrumentationNodeModuleFile( 'typeorm/entity-manager/EntityManager.js', ['>0.2.28'], (moduleExports, moduleVersion) => { @@ -148,7 +158,7 @@ export class TypeormInstrumentation extends InstrumentationBase { } ); - const module = new InstrumentationNodeModuleDefinition('typeorm', ['>0.2.28'], null, null, [ + const module = new InstrumentationNodeModuleDefinition('typeorm', ['>0.2.28'], null, null, [ selectQueryBuilder, entityManager, connection, @@ -167,13 +177,13 @@ export class TypeormInstrumentation extends InstrumentationBase { } const connectionOptions = this?.connection?.options ?? {}; const attributes = { - [SemanticAttributes.DB_SYSTEM]: connectionOptions.type, - [SemanticAttributes.DB_USER]: connectionOptions.username, - [SemanticAttributes.NET_PEER_NAME]: connectionOptions.host, - [SemanticAttributes.NET_PEER_PORT]: connectionOptions.port, - [SemanticAttributes.DB_NAME]: connectionOptions.database, - [SemanticAttributes.DB_OPERATION]: opName, - [SemanticAttributes.DB_STATEMENT]: JSON.stringify(buildStatement(original, args)), + [SEMATTRS_DB_SYSTEM]: connectionOptions.type, + [SEMATTRS_DB_USER]: connectionOptions.username, + [SEMATTRS_NET_PEER_NAME]: connectionOptions.host, + [SEMATTRS_NET_PEER_PORT]: connectionOptions.port, + [SEMATTRS_DB_NAME]: connectionOptions.database, + [SEMATTRS_DB_OPERATION]: opName, + [SEMATTRS_DB_STATEMENT]: JSON.stringify(buildStatement(original, args)), }; if (self._config.moduleVersionAttributeName && moduleVersion) { @@ -183,13 +193,13 @@ export class TypeormInstrumentation extends InstrumentationBase { //ignore EntityMetadataNotFoundError try { if (this.metadata) { - attributes[SemanticAttributes.DB_SQL_TABLE] = this.metadata.tableName; + attributes[SEMATTRS_DB_SQL_TABLE] = this.metadata.tableName; } else { const entity = args[0]; const name = typeof entity === 'object' ? entity?.constructor?.name : entity; const metadata = this.connection.getMetadata(name); if (metadata?.tableName) { - attributes[SemanticAttributes.DB_SQL_TABLE] = metadata.tableName; + attributes[SEMATTRS_DB_SQL_TABLE] = metadata.tableName; } } } catch {} @@ -234,14 +244,14 @@ export class TypeormInstrumentation extends InstrumentationBase { const operation = queryBuilder.expressionMap.queryType; const connectionOptions: any = queryBuilder?.connection?.options; const attributes = { - [SemanticAttributes.DB_SYSTEM]: connectionOptions.type, - [SemanticAttributes.DB_USER]: connectionOptions.username, - [SemanticAttributes.NET_PEER_NAME]: connectionOptions.host, - [SemanticAttributes.NET_PEER_PORT]: connectionOptions.port, - [SemanticAttributes.DB_NAME]: connectionOptions.database, - [SemanticAttributes.DB_OPERATION]: operation, - [SemanticAttributes.DB_STATEMENT]: sql, - [SemanticAttributes.DB_SQL_TABLE]: mainTableName, + [SEMATTRS_DB_SYSTEM]: connectionOptions.type, + [SEMATTRS_DB_USER]: connectionOptions.username, + [SEMATTRS_NET_PEER_NAME]: connectionOptions.host, + [SEMATTRS_NET_PEER_PORT]: connectionOptions.port, + [SEMATTRS_DB_NAME]: connectionOptions.database, + [SEMATTRS_DB_OPERATION]: operation, + [SEMATTRS_DB_STATEMENT]: sql, + [SEMATTRS_DB_SQL_TABLE]: mainTableName, }; if (self._config.collectParameters) { try { @@ -294,13 +304,13 @@ export class TypeormInstrumentation extends InstrumentationBase { const operation = self.getOperationName(sql); const connectionOptions: any = conn.options; const attributes = { - [SemanticAttributes.DB_SYSTEM]: connectionOptions.type, - [SemanticAttributes.DB_USER]: connectionOptions.username, - [SemanticAttributes.NET_PEER_NAME]: connectionOptions.host, - [SemanticAttributes.NET_PEER_PORT]: connectionOptions.port, - [SemanticAttributes.DB_NAME]: connectionOptions.database, - [SemanticAttributes.DB_OPERATION]: operation, - [SemanticAttributes.DB_STATEMENT]: sql, + [SEMATTRS_DB_SYSTEM]: connectionOptions.type, + [SEMATTRS_DB_USER]: connectionOptions.username, + [SEMATTRS_NET_PEER_NAME]: connectionOptions.host, + [SEMATTRS_NET_PEER_PORT]: connectionOptions.port, + [SEMATTRS_DB_NAME]: connectionOptions.database, + [SEMATTRS_DB_OPERATION]: operation, + [SEMATTRS_DB_STATEMENT]: sql, }; const span: Span = self.tracer.startSpan(`TypeORM ${operation}`, { diff --git a/packages/instrumentation-typeorm/src/utils/get-func-param-names.ts b/packages/instrumentation-typeorm/src/utils/get-func-param-names.ts index c409f441..e4b72347 100644 --- a/packages/instrumentation-typeorm/src/utils/get-func-param-names.ts +++ b/packages/instrumentation-typeorm/src/utils/get-func-param-names.ts @@ -3,7 +3,9 @@ const ARGUMENT_NAMES = /([^\s,]+)/g; export function getParamNames(func: Function) { const fnStr = func.toString().replace(STRIP_COMMENTS, ''); - let result = fnStr.slice(fnStr.indexOf('(') + 1, fnStr.indexOf(')')).match(ARGUMENT_NAMES); - if (result === null) result = []; + let result = fnStr.slice(fnStr.indexOf('(') + 1, fnStr.indexOf(')')).match(ARGUMENT_NAMES) as any; + if (result === null) { + result = []; + } return result; } diff --git a/packages/instrumentation-typeorm/test/Connection.spec.ts b/packages/instrumentation-typeorm/test/Connection.spec.ts index 0aeedcd7..f8387d50 100644 --- a/packages/instrumentation-typeorm/test/Connection.spec.ts +++ b/packages/instrumentation-typeorm/test/Connection.spec.ts @@ -1,7 +1,13 @@ import 'mocha'; import expect from 'expect'; import { SpanStatusCode } from '@opentelemetry/api'; -import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; +import { + SEMATTRS_DB_NAME, + SEMATTRS_DB_OPERATION, + SEMATTRS_DB_STATEMENT, + SEMATTRS_DB_SYSTEM, + SemanticAttributes, +} from '@opentelemetry/semantic-conventions'; import { TypeormInstrumentation } from '../src'; import { getTestSpans, registerInstrumentationTesting } from '@opentelemetry/contrib-test-utils'; @@ -31,10 +37,10 @@ describe('Connection', () => { expect(typeOrmSpans.length).toBe(1); expect(typeOrmSpans[0].status.code).toBe(SpanStatusCode.UNSET); const attributes = typeOrmSpans[0].attributes; - expect(attributes[SemanticAttributes.DB_SYSTEM]).toBe(options.type); - expect(attributes[SemanticAttributes.DB_NAME]).toBe(options.database); - expect(attributes[SemanticAttributes.DB_OPERATION]).toBe('SELECT'); - expect(attributes[SemanticAttributes.DB_STATEMENT]).toBe(query); + expect(attributes[SEMATTRS_DB_SYSTEM]).toBe(options.type); + expect(attributes[SEMATTRS_DB_NAME]).toBe(options.database); + expect(attributes[SEMATTRS_DB_OPERATION]).toBe('SELECT'); + expect(attributes[SEMATTRS_DB_STATEMENT]).toBe(query); await connection.close(); }); }); diff --git a/packages/instrumentation-typeorm/test/EntityManager.spec.ts b/packages/instrumentation-typeorm/test/EntityManager.spec.ts index 1c29663a..578648ca 100644 --- a/packages/instrumentation-typeorm/test/EntityManager.spec.ts +++ b/packages/instrumentation-typeorm/test/EntityManager.spec.ts @@ -1,7 +1,14 @@ import 'mocha'; import expect from 'expect'; import { SpanStatusCode } from '@opentelemetry/api'; -import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; +import { + SemanticAttributes, + SEMATTRS_DB_NAME, + SEMATTRS_DB_OPERATION, + SEMATTRS_DB_SQL_TABLE, + SEMATTRS_DB_STATEMENT, + SEMATTRS_DB_SYSTEM, +} from '@opentelemetry/semantic-conventions'; import { TypeormInstrumentation } from '../src'; import { getTestSpans } from '@opentelemetry/contrib-test-utils'; @@ -31,11 +38,11 @@ describe('EntityManager', () => { expect(typeOrmSpans.length).toBe(1); expect(typeOrmSpans[0].status.code).toBe(SpanStatusCode.UNSET); const attributes = typeOrmSpans[0].attributes; - expect(attributes[SemanticAttributes.DB_SQL_TABLE]).toBe('user'); - expect(attributes[SemanticAttributes.DB_SYSTEM]).toBe(options.type); - expect(attributes[SemanticAttributes.DB_NAME]).toBe(options.database); - expect(attributes[SemanticAttributes.DB_OPERATION]).toBe('save'); - expect(attributes[SemanticAttributes.DB_STATEMENT]).toBe(JSON.stringify({ targetOrEntity: user })); + expect(attributes[SEMATTRS_DB_SQL_TABLE]).toBe('user'); + expect(attributes[SEMATTRS_DB_SYSTEM]).toBe(options.type); + expect(attributes[SEMATTRS_DB_NAME]).toBe(options.database); + expect(attributes[SEMATTRS_DB_OPERATION]).toBe('save'); + expect(attributes[SEMATTRS_DB_STATEMENT]).toBe(JSON.stringify({ targetOrEntity: user })); await connection.close(); }); @@ -50,11 +57,11 @@ describe('EntityManager', () => { expect(typeOrmSpans.length).toBe(1); expect(typeOrmSpans[0].status.code).toBe(SpanStatusCode.UNSET); const attributes = typeOrmSpans[0].attributes; - expect(attributes[SemanticAttributes.DB_SQL_TABLE]).toBe('user'); - expect(attributes[SemanticAttributes.DB_SYSTEM]).toBe(options.type); - expect(attributes[SemanticAttributes.DB_NAME]).toBe(options.database); - expect(attributes[SemanticAttributes.DB_OPERATION]).toBe('save'); - expect(attributes[SemanticAttributes.DB_STATEMENT]).toBe(JSON.stringify({ targetOrEntity: user })); + expect(attributes[SEMATTRS_DB_SQL_TABLE]).toBe('user'); + expect(attributes[SEMATTRS_DB_SYSTEM]).toBe(options.type); + expect(attributes[SEMATTRS_DB_NAME]).toBe(options.database); + expect(attributes[SEMATTRS_DB_OPERATION]).toBe('save'); + expect(attributes[SEMATTRS_DB_STATEMENT]).toBe(JSON.stringify({ targetOrEntity: user })); await connection.close(); }); @@ -71,11 +78,11 @@ describe('EntityManager', () => { expect(typeOrmSpans.length).toBe(2); expect(typeOrmSpans[1].status.code).toBe(SpanStatusCode.UNSET); const attributes = typeOrmSpans[1].attributes; - expect(attributes[SemanticAttributes.DB_SQL_TABLE]).toBe('user'); - expect(attributes[SemanticAttributes.DB_SYSTEM]).toBe(options.type); - expect(attributes[SemanticAttributes.DB_NAME]).toBe(options.database); - expect(attributes[SemanticAttributes.DB_OPERATION]).toBe('remove'); - expect(attributes[SemanticAttributes.DB_STATEMENT]).toBe( + expect(attributes[SEMATTRS_DB_SQL_TABLE]).toBe('user'); + expect(attributes[SEMATTRS_DB_SYSTEM]).toBe(options.type); + expect(attributes[SEMATTRS_DB_NAME]).toBe(options.database); + expect(attributes[SEMATTRS_DB_OPERATION]).toBe('remove'); + expect(attributes[SEMATTRS_DB_STATEMENT]).toBe( JSON.stringify({ targetOrEntity: { id: 56, firstName: 'aspecto', lastName: 'io' } }) ); await connection.close(); @@ -94,11 +101,11 @@ describe('EntityManager', () => { expect(typeOrmSpans.length).toBe(2); expect(typeOrmSpans[1].status.code).toBe(SpanStatusCode.UNSET); const attributes = typeOrmSpans[1].attributes; - expect(attributes[SemanticAttributes.DB_SQL_TABLE]).toBe('user'); - expect(attributes[SemanticAttributes.DB_SYSTEM]).toBe(options.type); - expect(attributes[SemanticAttributes.DB_NAME]).toBe(options.database); - expect(attributes[SemanticAttributes.DB_OPERATION]).toBe('update'); - expect(attributes[SemanticAttributes.DB_STATEMENT]).toBe( + expect(attributes[SEMATTRS_DB_SQL_TABLE]).toBe('user'); + expect(attributes[SEMATTRS_DB_SYSTEM]).toBe(options.type); + expect(attributes[SEMATTRS_DB_NAME]).toBe(options.database); + expect(attributes[SEMATTRS_DB_OPERATION]).toBe('update'); + expect(attributes[SEMATTRS_DB_STATEMENT]).toBe( JSON.stringify({ target: 'User', criteria: 56, partialEntity }) ); await connection.close(); @@ -142,15 +149,15 @@ describe('EntityManager', () => { const sqlite1Span = spans[0]; const sqlite2Span = spans[1]; - expect(sqlite1Span.attributes[SemanticAttributes.DB_SYSTEM]).toBe(defaultOptions.type); - expect(sqlite1Span.attributes[SemanticAttributes.DB_NAME]).toBe(defaultOptions.database); - expect(sqlite1Span.attributes[SemanticAttributes.DB_OPERATION]).toBe('save'); - expect(sqlite1Span.attributes[SemanticAttributes.DB_SQL_TABLE]).toBe('user'); + expect(sqlite1Span.attributes[SEMATTRS_DB_SYSTEM]).toBe(defaultOptions.type); + expect(sqlite1Span.attributes[SEMATTRS_DB_NAME]).toBe(defaultOptions.database); + expect(sqlite1Span.attributes[SEMATTRS_DB_OPERATION]).toBe('save'); + expect(sqlite1Span.attributes[SEMATTRS_DB_SQL_TABLE]).toBe('user'); - expect(sqlite2Span.attributes[SemanticAttributes.DB_SYSTEM]).toBe(options2.type); - expect(sqlite2Span.attributes[SemanticAttributes.DB_NAME]).toBe(options2.database); - expect(sqlite2Span.attributes[SemanticAttributes.DB_OPERATION]).toBe('remove'); - expect(sqlite2Span.attributes[SemanticAttributes.DB_SQL_TABLE]).toBe('user'); + expect(sqlite2Span.attributes[SEMATTRS_DB_SYSTEM]).toBe(options2.type); + expect(sqlite2Span.attributes[SEMATTRS_DB_NAME]).toBe(options2.database); + expect(sqlite2Span.attributes[SEMATTRS_DB_OPERATION]).toBe('remove'); + expect(sqlite2Span.attributes[SEMATTRS_DB_SQL_TABLE]).toBe('user'); await sqlite1.close(); await sqlite2.close(); }); diff --git a/packages/instrumentation-typeorm/test/QueryBuilder.spec.ts b/packages/instrumentation-typeorm/test/QueryBuilder.spec.ts index 20de7949..6db08e9e 100644 --- a/packages/instrumentation-typeorm/test/QueryBuilder.spec.ts +++ b/packages/instrumentation-typeorm/test/QueryBuilder.spec.ts @@ -1,7 +1,16 @@ import 'mocha'; import expect from 'expect'; import { SpanStatusCode } from '@opentelemetry/api'; -import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; +import { + SEMATTRS_DB_NAME, + SEMATTRS_DB_SQL_TABLE, + SEMATTRS_DB_STATEMENT, + SEMATTRS_DB_SYSTEM, + SEMATTRS_DB_USER, + SEMATTRS_NET_PEER_NAME, + SEMATTRS_NET_PEER_PORT, + SemanticAttributes, +} from '@opentelemetry/semantic-conventions'; import { TypeormInstrumentation } from '../src'; import { getTestSpans, registerInstrumentationTesting } from '@opentelemetry/contrib-test-utils'; const instrumentation = registerInstrumentationTesting(new TypeormInstrumentation()); @@ -27,13 +36,13 @@ describe('QueryBuilder', () => { expect(typeOrmSpans.length).toBe(1); expect(typeOrmSpans[0].status.code).toBe(SpanStatusCode.UNSET); const attributes = typeOrmSpans[0].attributes; - expect(attributes[SemanticAttributes.DB_SYSTEM]).toBe(connectionOptions.type); - expect(attributes[SemanticAttributes.DB_USER]).toBe(connectionOptions.username); - expect(attributes[SemanticAttributes.NET_PEER_NAME]).toBe(connectionOptions.host); - expect(attributes[SemanticAttributes.NET_PEER_PORT]).toBe(connectionOptions.port); - expect(attributes[SemanticAttributes.DB_NAME]).toBe(connectionOptions.database); - expect(attributes[SemanticAttributes.DB_SQL_TABLE]).toBe('user'); - expect(attributes[SemanticAttributes.DB_STATEMENT]).toBe( + expect(attributes[SEMATTRS_DB_SYSTEM]).toBe(connectionOptions.type); + expect(attributes[SEMATTRS_DB_USER]).toBe(connectionOptions.username); + expect(attributes[SEMATTRS_NET_PEER_NAME]).toBe(connectionOptions.host); + expect(attributes[SEMATTRS_NET_PEER_PORT]).toBe(connectionOptions.port); + expect(attributes[SEMATTRS_DB_NAME]).toBe(connectionOptions.database); + expect(attributes[SEMATTRS_DB_SQL_TABLE]).toBe('user'); + expect(attributes[SEMATTRS_DB_STATEMENT]).toBe( 'SELECT "user"."id" AS "user_id", "user"."firstName" AS "user_firstName", "user"."lastName" AS "user_lastName" FROM "user" "user" WHERE "user"."id" = :userId' ); await connection.close(); diff --git a/packages/instrumentation-typeorm/test/Repository.spec.ts b/packages/instrumentation-typeorm/test/Repository.spec.ts index b9f16fbb..92fd94d0 100644 --- a/packages/instrumentation-typeorm/test/Repository.spec.ts +++ b/packages/instrumentation-typeorm/test/Repository.spec.ts @@ -6,7 +6,7 @@ import { getTestSpans, registerInstrumentationTesting } from '@opentelemetry/con const instrumentation = registerInstrumentationTesting(new TypeormInstrumentation()); import { defaultOptions, User } from './utils'; import * as typeorm from 'typeorm'; -import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; +import { SEMATTRS_DB_SQL_TABLE } from '@opentelemetry/semantic-conventions'; describe('Repository', () => { beforeEach(() => { @@ -28,7 +28,7 @@ describe('Repository', () => { expect(spans.length).toEqual(2); const span = spans[0]; const attributes = span.attributes; - expect(attributes[SemanticAttributes.DB_SQL_TABLE]).toBe('user'); + expect(attributes[SEMATTRS_DB_SQL_TABLE]).toBe('user'); await connection.close(); }); }); diff --git a/packages/instrumentation-typeorm/test/config.spec.ts b/packages/instrumentation-typeorm/test/config.spec.ts index f7c22579..25c8fd3c 100644 --- a/packages/instrumentation-typeorm/test/config.spec.ts +++ b/packages/instrumentation-typeorm/test/config.spec.ts @@ -1,7 +1,17 @@ import 'mocha'; import expect from 'expect'; import { Span } from '@opentelemetry/sdk-trace-base'; -import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; +import { + SEMATTRS_DB_NAME, + SEMATTRS_DB_OPERATION, + SEMATTRS_DB_SQL_TABLE, + SEMATTRS_DB_STATEMENT, + SEMATTRS_DB_SYSTEM, + SEMATTRS_DB_USER, + SEMATTRS_NET_PEER_NAME, + SEMATTRS_NET_PEER_PORT, + SemanticAttributes, +} from '@opentelemetry/semantic-conventions'; import { ExtendedDatabaseAttribute, TypeormInstrumentation, TypeormInstrumentationConfig } from '../src'; import { getTestSpans, registerInstrumentationTesting } from '@opentelemetry/contrib-test-utils'; @@ -30,8 +40,8 @@ describe('TypeormInstrumentationConfig', () => { const attributes = typeOrmSpans[0].attributes; expect(attributes['test']).toBe(JSON.stringify(user)); - expect(attributes[SemanticAttributes.DB_OPERATION]).toBe('save'); - expect(attributes[SemanticAttributes.DB_SYSTEM]).toBe(defaultOptions.type); + expect(attributes[SEMATTRS_DB_OPERATION]).toBe('save'); + expect(attributes[SEMATTRS_DB_SYSTEM]).toBe(defaultOptions.type); await connection.close(); }); @@ -50,7 +60,7 @@ describe('TypeormInstrumentationConfig', () => { expect(typeOrmSpans.length).toBe(1); const attributes = typeOrmSpans[0].attributes; - expect(attributes[SemanticAttributes.DB_SQL_TABLE]).toBe('user'); + expect(attributes[SEMATTRS_DB_SQL_TABLE]).toBe('user'); expect(attributes['module.version']).toMatch(/\d{1,4}\.\d{1,4}\.\d{1,5}.*/); await connection.close(); }); @@ -65,13 +75,13 @@ describe('TypeormInstrumentationConfig', () => { const findAndCountSpan = spans.find((s) => s.name.indexOf('findAndCount') !== -1); expect(findAndCountSpan).not.toBeUndefined(); - expect(findAndCountSpan.attributes[SemanticAttributes.DB_OPERATION]).toBe('findAndCount'); - expect(findAndCountSpan.attributes[SemanticAttributes.DB_SQL_TABLE]).toBe('user'); + expect(findAndCountSpan.attributes[SEMATTRS_DB_OPERATION]).toBe('findAndCount'); + expect(findAndCountSpan.attributes[SEMATTRS_DB_SQL_TABLE]).toBe('user'); const selectSpan = spans.find((s) => s.name.indexOf('select') !== -1); expect(selectSpan).not.toBeUndefined(); - expect(selectSpan.attributes[SemanticAttributes.DB_OPERATION]).toBe('select'); - expect(selectSpan.attributes[SemanticAttributes.DB_SQL_TABLE]).toBe('user'); + expect(selectSpan.attributes[SEMATTRS_DB_OPERATION]).toBe('select'); + expect(selectSpan.attributes[SEMATTRS_DB_SQL_TABLE]).toBe('user'); await connection.close(); }); @@ -83,9 +93,9 @@ describe('TypeormInstrumentationConfig', () => { const spans = getTestSpans(); expect(spans.length).toEqual(1); const attributes = spans[0].attributes; - expect(attributes[SemanticAttributes.DB_OPERATION]).toBe('findAndCount'); - expect(attributes[SemanticAttributes.DB_SYSTEM]).toBe(defaultOptions.type); - expect(attributes[SemanticAttributes.DB_SQL_TABLE]).toBe('user'); + expect(attributes[SEMATTRS_DB_OPERATION]).toBe('findAndCount'); + expect(attributes[SEMATTRS_DB_SYSTEM]).toBe(defaultOptions.type); + expect(attributes[SEMATTRS_DB_SQL_TABLE]).toBe('user'); await connection.close(); }); @@ -107,13 +117,13 @@ describe('TypeormInstrumentationConfig', () => { expect(typeOrmSpans.length).toBe(1); expect(typeOrmSpans[0].status.code).toBe(SpanStatusCode.UNSET); const attributes = typeOrmSpans[0].attributes; - expect(attributes[SemanticAttributes.DB_SYSTEM]).toBe(connectionOptions.type); - expect(attributes[SemanticAttributes.DB_USER]).toBe(connectionOptions.username); - expect(attributes[SemanticAttributes.NET_PEER_NAME]).toBe(connectionOptions.host); - expect(attributes[SemanticAttributes.NET_PEER_PORT]).toBe(connectionOptions.port); - expect(attributes[SemanticAttributes.DB_NAME]).toBe(connectionOptions.database); - expect(attributes[SemanticAttributes.DB_SQL_TABLE]).toBe('user'); - expect(attributes[SemanticAttributes.DB_STATEMENT]).toBe( + expect(attributes[SEMATTRS_DB_SYSTEM]).toBe(connectionOptions.type); + expect(attributes[SEMATTRS_DB_USER]).toBe(connectionOptions.username); + expect(attributes[SEMATTRS_NET_PEER_NAME]).toBe(connectionOptions.host); + expect(attributes[SEMATTRS_NET_PEER_PORT]).toBe(connectionOptions.port); + expect(attributes[SEMATTRS_DB_NAME]).toBe(connectionOptions.database); + expect(attributes[SEMATTRS_DB_SQL_TABLE]).toBe('user'); + expect(attributes[SEMATTRS_DB_STATEMENT]).toBe( 'SELECT "user"."id" AS "user_id", "user"."firstName" AS "user_firstName", "user"."lastName" AS "user_lastName" FROM "user" "user" WHERE "user"."id" = :userId AND "user"."firstName" = :firstName AND "user"."lastName" = :lastName' ); expect(attributes[ExtendedDatabaseAttribute.DB_STATEMENT_PARAMETERS]).toBe( diff --git a/packages/propagation-utils/package.json b/packages/propagation-utils/package.json index c9bf3685..b124eba9 100644 --- a/packages/propagation-utils/package.json +++ b/packages/propagation-utils/package.json @@ -34,11 +34,11 @@ "url": "https://github.com/aspecto-io/opentelemetry-ext-js/issues" }, "devDependencies": { - "@opentelemetry/api": "^1.6.0", + "@opentelemetry/api": "^1.8.0", "@types/node": "^14.14.8", - "typescript": "4.3.4" + "typescript": "5.4.5" }, "peerDependencies": { - "@opentelemetry/api": "^1.6.0" + "@opentelemetry/api": "^1.8.0" } } diff --git a/packages/span-transformations/package.json b/packages/span-transformations/package.json index 440ab7dc..2534d12f 100644 --- a/packages/span-transformations/package.json +++ b/packages/span-transformations/package.json @@ -24,16 +24,16 @@ "test": "mocha" }, "dependencies": { - "@opentelemetry/api": "^1.6.0", - "@opentelemetry/core": "^1.17.1", + "@opentelemetry/api": "^1.8.0", + "@opentelemetry/core": "^1.24.1", "@opentelemetry/sdk-trace-base": "^1.17.1" }, "devDependencies": { "@types/mocha": "^8.2.2", "expect": "^26.6.2", "mocha": "^8.4.0", - "ts-node": "^9.1.1", - "typescript": "4.3.4" + "ts-node": "^10.9.2", + "typescript": "5.4.5" }, "mocha": { "extension": [ diff --git a/propagators/propagator-selective/package.json b/propagators/propagator-selective/package.json index d844d33b..6d0ab0fb 100644 --- a/propagators/propagator-selective/package.json +++ b/propagators/propagator-selective/package.json @@ -28,16 +28,16 @@ "url": "https://github.com/aspecto-io/opentelemetry-ext-js/issues" }, "peerDependencies": { - "@opentelemetry/api": "^1.6.0" + "@opentelemetry/api": "^1.8.0" }, "devDependencies": { - "@opentelemetry/api": "^1.6.0", + "@opentelemetry/api": "^1.8.0", "@types/mocha": "^8.2.2", "expect": "^26.6.2", "mocha": "^8.4.0", "sinon": "^12.0.1", - "ts-node": "^9.1.1", - "typescript": "4.3.4" + "ts-node": "^10.9.2", + "typescript": "5.4.5" }, "mocha": { "extension": [ @@ -46,7 +46,7 @@ "spec": "test/**/*.spec.ts", "require": [ "ts-node/register", - "opentelemetry-instrumentation-mocha" + "aspecto-opentelemetry-instrumentation-mocha" ] } } diff --git a/propagators/propagator-selective/src/SelectivePropagator.ts b/propagators/propagator-selective/src/SelectivePropagator.ts index 12b7aa23..8ff6a864 100644 --- a/propagators/propagator-selective/src/SelectivePropagator.ts +++ b/propagators/propagator-selective/src/SelectivePropagator.ts @@ -2,7 +2,10 @@ import { Context, TextMapGetter, TextMapPropagator, TextMapSetter } from '@opent import { SelectivePropagatorConfig } from './types'; export class SelectivePropagator implements TextMapPropagator { - constructor(private propagator: TextMapPropagator, private config: SelectivePropagatorConfig = {}) {} + constructor( + private propagator: TextMapPropagator, + private config: SelectivePropagatorConfig = {} + ) {} inject(context: Context, carrier: any, setter: TextMapSetter): void { if (!this.config.injectEnabled) return; diff --git a/tsconfig.base.json b/tsconfig.base.json index 39ef2cff..374e2ed0 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -13,6 +13,7 @@ "types": ["node"], "allowSyntheticDefaultImports": true, "esModuleInterop": true, - "noImplicitOverride": true + "noImplicitOverride": true, + "skipLibCheck": true } }