Skip to content

Commit

Permalink
chore(deps): upgrade opentelemetry libs (#554)
Browse files Browse the repository at this point in the history
  • Loading branch information
aikoven authored Mar 11, 2024
1 parent 2300629 commit 1515913
Show file tree
Hide file tree
Showing 6 changed files with 207 additions and 196 deletions.
6 changes: 3 additions & 3 deletions packages/nice-grpc-opentelemetry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"author": "Daniel Lytkin <aikoven@deeplay.io>",
"license": "MIT",
"devDependencies": {
"@opentelemetry/sdk-node": "^0.45.1",
"@opentelemetry/sdk-node": "^0.49.1",
"@tsconfig/recommended": "^1.0.1",
"@types/defer-promise": "^1.0.0",
"defer-promise": "^2.0.1",
Expand All @@ -39,8 +39,8 @@
"ts-proto": "^1.112.0"
},
"dependencies": {
"@opentelemetry/api": "^1.3.0",
"@opentelemetry/semantic-conventions": "^1.5.0",
"@opentelemetry/api": "^1.8.0",
"@opentelemetry/semantic-conventions": "^1.22.0",
"abort-controller-x": "^0.4.0",
"ipaddr.js": "^2.0.1",
"nice-grpc-common": "^2.0.2"
Expand Down
30 changes: 19 additions & 11 deletions packages/nice-grpc-opentelemetry/src/attributes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import {Attributes} from '@opentelemetry/api';
import {SemanticAttributes} from '@opentelemetry/semantic-conventions';
import {
SEMATTRS_RPC_SYSTEM,
SEMATTRS_RPC_SERVICE,
SEMATTRS_RPC_METHOD,
SEMATTRS_RPC_GRPC_STATUS_CODE,
SEMATTRS_NET_PEER_NAME,
SEMATTRS_NET_PEER_IP,
SEMATTRS_NET_PEER_PORT,
} from '@opentelemetry/semantic-conventions';
import * as ipaddr from 'ipaddr.js';
import {Status} from 'nice-grpc-common';

Expand All @@ -12,9 +20,9 @@ export function getMethodAttributes(methodPath: string): Attributes {
const [, service, method] = methodPath.split('/');

return {
[SemanticAttributes.RPC_SYSTEM]: 'grpc',
[SemanticAttributes.RPC_SERVICE]: service,
[SemanticAttributes.RPC_METHOD]: method,
[SEMATTRS_RPC_SYSTEM]: 'grpc',
[SEMATTRS_RPC_SERVICE]: service,
[SEMATTRS_RPC_METHOD]: method,
};
}

Expand All @@ -23,7 +31,7 @@ export function getMethodAttributes(methodPath: string): Attributes {
*/
export function getStatusAttributes(status: Status): Attributes {
return {
[SemanticAttributes.RPC_GRPC_STATUS_CODE]: status,
[SEMATTRS_RPC_GRPC_STATUS_CODE]: status,
'rpc.grpc.status_text': Status[status],
};
}
Expand All @@ -38,7 +46,7 @@ export function getPeerAttributes(peer: string): Attributes {

if (lastColonIndex === -1) {
return {
[SemanticAttributes.NET_PEER_NAME]: peer,
[SEMATTRS_NET_PEER_NAME]: peer,
};
}

Expand All @@ -47,19 +55,19 @@ export function getPeerAttributes(peer: string): Attributes {

if (Number.isNaN(port)) {
return {
[SemanticAttributes.NET_PEER_NAME]: peer,
[SEMATTRS_NET_PEER_NAME]: peer,
};
}

if (ipaddr.isValid(host)) {
return {
[SemanticAttributes.NET_PEER_IP]: host,
[SemanticAttributes.NET_PEER_PORT]: port,
[SEMATTRS_NET_PEER_IP]: host,
[SEMATTRS_NET_PEER_PORT]: port,
};
}

return {
[SemanticAttributes.NET_PEER_NAME]: host,
[SemanticAttributes.NET_PEER_PORT]: port,
[SEMATTRS_NET_PEER_NAME]: host,
[SEMATTRS_NET_PEER_PORT]: port,
};
}
9 changes: 6 additions & 3 deletions packages/nice-grpc-opentelemetry/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import {
SpanKind,
SpanStatusCode,
} from '@opentelemetry/api';
import {MessageTypeValues} from '@opentelemetry/semantic-conventions';
import {
MESSAGETYPEVALUES_RECEIVED,
MESSAGETYPEVALUES_SENT,
} from '@opentelemetry/semantic-conventions';
import {isAbortError} from 'abort-controller-x';
import {
CallOptions,
Expand Down Expand Up @@ -62,7 +65,7 @@ async function* openTelemetryClientMiddlewareGenerator<Request, Response>(
if (!call.requestStream) {
request = call.request;
} else {
request = emitSpanEvents(call.request, span, MessageTypeValues.SENT);
request = emitSpanEvents(call.request, span, MESSAGETYPEVALUES_SENT);
}

if (!call.responseStream) {
Expand All @@ -75,7 +78,7 @@ async function* openTelemetryClientMiddlewareGenerator<Request, Response>(
yield* emitSpanEvents(
call.next(request, options),
span,
MessageTypeValues.RECEIVED,
MESSAGETYPEVALUES_RECEIVED,
);

settled = true;
Expand Down
12 changes: 7 additions & 5 deletions packages/nice-grpc-opentelemetry/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import {
SpanKind,
SpanStatusCode,
} from '@opentelemetry/api';
import {MessageTypeValues} from '@opentelemetry/semantic-conventions';
import {
MESSAGETYPEVALUES_RECEIVED,
MESSAGETYPEVALUES_SENT,
} from '@opentelemetry/semantic-conventions';
import {isAbortError} from 'abort-controller-x';
import {
CallContext,
Expand All @@ -21,9 +24,8 @@ import {
getStatusAttributes,
} from './attributes';
import {metadataGetter} from './propagation';
import {emitSpanEvents, getSpanName, tracer} from './traces';
import {bindAsyncGenerator} from './utils/bindAsyncGenerator';
import {tracer} from './traces';
import {emitSpanEvents, getSpanName} from './traces';

export function openTelemetryServerMiddleware(): ServerMiddleware {
return (call, context) =>
Expand Down Expand Up @@ -62,7 +64,7 @@ async function* openTelemetryServerMiddlewareGenerator<Request, Response>(
if (!call.requestStream) {
request = call.request;
} else {
request = emitSpanEvents(call.request, span, MessageTypeValues.RECEIVED);
request = emitSpanEvents(call.request, span, MESSAGETYPEVALUES_RECEIVED);
}

if (!call.responseStream) {
Expand All @@ -71,7 +73,7 @@ async function* openTelemetryServerMiddlewareGenerator<Request, Response>(
yield* emitSpanEvents(
call.next(request, context),
span,
MessageTypeValues.SENT,
MESSAGETYPEVALUES_SENT,
);

return;
Expand Down
12 changes: 7 additions & 5 deletions packages/nice-grpc-opentelemetry/src/traces.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import {Span, trace} from '@opentelemetry/api';
import {
MessageTypeValues,
SemanticAttributes,
MESSAGETYPEVALUES_RECEIVED,
MESSAGETYPEVALUES_SENT,
SEMATTRS_MESSAGE_ID,
SEMATTRS_MESSAGE_TYPE,
} from '@opentelemetry/semantic-conventions';
import {VERSION} from './version';

Expand Down Expand Up @@ -29,14 +31,14 @@ export function getSpanName(methodPath: string): string {
export async function* emitSpanEvents<T>(
iterable: AsyncIterable<T>,
span: Span,
type: MessageTypeValues,
type: typeof MESSAGETYPEVALUES_SENT | typeof MESSAGETYPEVALUES_RECEIVED,
): AsyncIterable<T> {
let nextId = 1;

for await (const item of iterable) {
span.addEvent('message', {
[SemanticAttributes.MESSAGE_TYPE]: type,
[SemanticAttributes.MESSAGE_ID]: nextId++,
[SEMATTRS_MESSAGE_TYPE]: type,
[SEMATTRS_MESSAGE_ID]: nextId++,
});

yield item;
Expand Down
Loading

0 comments on commit 1515913

Please sign in to comment.