Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
fix all ts errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Motti Bechhofer committed May 15, 2024
1 parent 0135fbd commit 4cb976a
Show file tree
Hide file tree
Showing 32 changed files with 295 additions and 292 deletions.
3 changes: 1 addition & 2 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"packages": ["packages/*", "detectors/*", "detectors/node/*", "propagators/*", "examples/*"],
"version": "independent",
"npmClient": "yarn",
"useWorkspaces": true
"npmClient": "yarn"
}
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected].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/*",
Expand Down
2 changes: 1 addition & 1 deletion packages/instrumentation-elasticsearch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"devDependencies": {
"@elastic/elasticsearch": "^7.8.0",
"@opentelemetry/api": "^1.8.0",
"@opentelemetry/contrib-test-utils": "^0.34.2",
"@opentelemetry/contrib-test-utils": "^0.39.0",
"@types/chai": "^4.2.15",
"@types/mocha": "^8.2.2",
"chai": "^4.3.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/instrumentation-elasticsearch/src/elasticsearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -120,9 +120,9 @@ export class ElasticsearchInstrumentation extends InstrumentationBase {
const span = startSpan({
tracer: self.tracer,
attributes: {
[SemanticAttributes.DB_OPERATION]: operation,
[SEMATTRS_DB_OPERATION]: operation,
[AttributeNames.ELASTICSEARCH_INDICES]: getIndexName(params),
[SemanticAttributes.DB_STATEMENT]: (
[SEMATTRS_DB_STATEMENT]: (
self._config.dbStatementSerializer || defaultDbStatementSerializer
)(operation, params, options),
},
Expand Down
10 changes: 5 additions & 5 deletions packages/instrumentation-elasticsearch/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Tracer, SpanAttributes, SpanStatusCode, diag, Span, SpanKind } from '@opentelemetry/api';
import { DbStatementSerializer, ResponseHook } from './types';
import { safeExecuteInTheMiddle } from '@opentelemetry/instrumentation';
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
import { SEMATTRS_DB_SYSTEM, SEMATTRS_NET_PEER_NAME, SEMATTRS_NET_PEER_PORT, SEMATTRS_NET_TRANSPORT } from '@opentelemetry/semantic-conventions';
import { ApiResponse } from '@elastic/elasticsearch/lib/Transport';

interface StartSpanPayload {
Expand All @@ -27,7 +27,7 @@ export function startSpan({ tracer, attributes }: StartSpanPayload): Span {
return tracer.startSpan('elasticsearch.request', {
kind: SpanKind.CLIENT,
attributes: {
[SemanticAttributes.DB_SYSTEM]: 'elasticsearch',
[SEMATTRS_DB_SYSTEM]: 'elasticsearch',
...attributes,
},
});
Expand Down Expand Up @@ -60,9 +60,9 @@ export function getNetAttributes(url: string): SpanAttributes {
const { port, protocol, hostname } = new URL(url);

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

Expand Down
10 changes: 5 additions & 5 deletions packages/instrumentation-elasticsearch/test/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { stub, assert, spy } from 'sinon';
import { expect } from 'chai';
import * as Utils from '../src/utils';
import { SpanKind, SpanStatusCode } from '@opentelemetry/api';
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
import { SEMATTRS_DB_SYSTEM, SEMATTRS_NET_PEER_NAME, SEMATTRS_NET_PEER_PORT } from '@opentelemetry/semantic-conventions';

describe('elasticsearch utils', () => {
const spanMock = {
Expand Down Expand Up @@ -92,15 +92,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_PEER_PORT]).to.equal('IP.TCP');
});
});

Expand Down Expand Up @@ -190,7 +190,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');
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/instrumentation-express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
},
"devDependencies": {
"@opentelemetry/api": "^1.8.0",
"@opentelemetry/contrib-test-utils": "^0.34.2",
"@opentelemetry/contrib-test-utils": "^0.39.0",
"@opentelemetry/instrumentation-http": "^0.44.0",
"@opentelemetry/sdk-trace-base": "^1.24.1",
"@types/express": "4.17.8",
Expand Down
4 changes: 2 additions & 2 deletions packages/instrumentation-express/src/express.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ 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');

Expand Down Expand Up @@ -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) {
Expand Down
18 changes: 9 additions & 9 deletions packages/instrumentation-express/src/utils/attributes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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';

Expand All @@ -8,7 +8,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);
Expand Down Expand Up @@ -55,7 +55,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,
};
};

Expand Down Expand Up @@ -83,12 +83,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,
};
};

Expand Down
32 changes: 16 additions & 16 deletions packages/instrumentation-express/test/opentelemetry-express.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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';
Expand Down Expand Up @@ -74,19 +74,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);
Expand Down Expand Up @@ -131,15 +131,15 @@ 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(
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[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_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();
Expand Down
6 changes: 3 additions & 3 deletions packages/instrumentation-express/test/utils.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 ?? {});
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion packages/instrumentation-kafkajs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
},
"devDependencies": {
"@opentelemetry/api": "^1.8.0",
"@opentelemetry/contrib-test-utils": "^0.34.2",
"@opentelemetry/contrib-test-utils": "^0.39.0",
"@opentelemetry/sdk-trace-base": "^1.24.1",
"@types/mocha": "^8.2.2",
"expect": "^26.6.2",
Expand Down
18 changes: 11 additions & 7 deletions packages/instrumentation-kafkajs/src/kafkajs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -250,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] : [],
},
Expand Down Expand Up @@ -281,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,
},
});

Expand Down
Loading

0 comments on commit 4cb976a

Please sign in to comment.