Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
update to use new ATTR
  • Loading branch information
JamieDanielson committed Sep 18, 2024
commit e7650585d75303eb318f3a2a9bbd7d41020f2328
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import type {
} from './internal-types';

import { propagation, context } from '@opentelemetry/api';
import { SEMATTRS_RPC_GRPC_STATUS_CODE } from '@opentelemetry/semantic-conventions';
import { ATTR_RPC_GRPC_STATUS_CODE } from '@opentelemetry/semantic-conventions/incubating';
import { AttributeNames } from './enums/AttributeNames';
import { GRPC_STATUS_CODE_OK } from './status-code';
import {
Expand Down Expand Up @@ -81,14 +81,14 @@ export function patchedCallback(
if (err) {
if (err.code) {
span.setStatus(_grpcStatusCodeToSpanStatus(err.code));
span.setAttribute(SEMATTRS_RPC_GRPC_STATUS_CODE, err.code);
span.setAttribute(ATTR_RPC_GRPC_STATUS_CODE, err.code);
}
span.setAttributes({
[AttributeNames.GRPC_ERROR_NAME]: err.name,
[AttributeNames.GRPC_ERROR_MESSAGE]: err.message,
});
} else {
span.setAttribute(SEMATTRS_RPC_GRPC_STATUS_CODE, GRPC_STATUS_CODE_OK);
span.setAttribute(ATTR_RPC_GRPC_STATUS_CODE, GRPC_STATUS_CODE_OK);
}

span.end();
Expand Down Expand Up @@ -130,7 +130,7 @@ export function patchResponseStreamEvents(span: Span, call: EventEmitter) {
span.setAttributes({
[AttributeNames.GRPC_ERROR_NAME]: err.name,
[AttributeNames.GRPC_ERROR_MESSAGE]: err.message,
[SEMATTRS_RPC_GRPC_STATUS_CODE]: err.code,
[ATTR_RPC_GRPC_STATUS_CODE]: err.code,
});

endSpan();
Expand All @@ -142,7 +142,7 @@ export function patchResponseStreamEvents(span: Span, call: EventEmitter) {
}

span.setStatus(_grpcStatusCodeToSpanStatus(status.code));
span.setAttribute(SEMATTRS_RPC_GRPC_STATUS_CODE, status.code);
span.setAttribute(ATTR_RPC_GRPC_STATUS_CODE, status.code);

endSpan();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ import {
InstrumentationBase,
} from '@opentelemetry/instrumentation';
import {
SEMATTRS_NET_PEER_NAME,
SEMATTRS_NET_PEER_PORT,
SEMATTRS_RPC_METHOD,
SEMATTRS_RPC_SERVICE,
SEMATTRS_RPC_SYSTEM,
} from '@opentelemetry/semantic-conventions';
ATTR_NET_PEER_NAME,
ATTR_NET_PEER_PORT,
ATTR_RPC_METHOD,
ATTR_RPC_SERVICE,
ATTR_RPC_SYSTEM,
} from '@opentelemetry/semantic-conventions/incubating';

import {
shouldNotTraceServerCall,
Expand Down Expand Up @@ -241,9 +241,9 @@ export class GrpcInstrumentation extends InstrumentationBase<GrpcInstrumentation
const span = instrumentation.tracer
.startSpan(spanName, spanOptions)
.setAttributes({
[SEMATTRS_RPC_SYSTEM]: AttributeValues.RPC_SYSTEM,
[SEMATTRS_RPC_METHOD]: method,
[SEMATTRS_RPC_SERVICE]: service,
[ATTR_RPC_SYSTEM]: AttributeValues.RPC_SYSTEM,
[ATTR_RPC_METHOD]: method,
[ATTR_RPC_SERVICE]: service,
});

instrumentation._metadataCapture.server.captureRequestMetadata(
Expand Down Expand Up @@ -435,9 +435,9 @@ export class GrpcInstrumentation extends InstrumentationBase<GrpcInstrumentation
const span = instrumentation.tracer
.startSpan(name, { kind: SpanKind.CLIENT })
.setAttributes({
[SEMATTRS_RPC_SYSTEM]: 'grpc',
[SEMATTRS_RPC_METHOD]: method,
[SEMATTRS_RPC_SERVICE]: service,
[ATTR_RPC_SYSTEM]: AttributeValues.RPC_SYSTEM,
[ATTR_RPC_METHOD]: method,
[ATTR_RPC_SERVICE]: service,
});
instrumentation.extractNetMetadata(this, span);

Expand Down Expand Up @@ -480,9 +480,9 @@ export class GrpcInstrumentation extends InstrumentationBase<GrpcInstrumentation
const span = this.tracer
.startSpan(name, { kind: SpanKind.CLIENT })
.setAttributes({
[SEMATTRS_RPC_SYSTEM]: 'grpc',
[SEMATTRS_RPC_METHOD]: methodAttributeValue,
[SEMATTRS_RPC_SERVICE]: service,
[ATTR_RPC_SYSTEM]: 'grpc',
[ATTR_RPC_METHOD]: methodAttributeValue,
[ATTR_RPC_SERVICE]: service,
});

if (metadata != null) {
Expand All @@ -495,11 +495,8 @@ export class GrpcInstrumentation extends InstrumentationBase<GrpcInstrumentation
// set net.peer.* from target (e.g., "dns:otel-productcatalogservice:8080") as a hint to APMs
const parsedUri = URI_REGEX.exec(client.getChannel().getTarget());
if (parsedUri != null && parsedUri.groups != null) {
span.setAttribute(SEMATTRS_NET_PEER_NAME, parsedUri.groups['name']);
span.setAttribute(
SEMATTRS_NET_PEER_PORT,
parseInt(parsedUri.groups['port'])
);
span.setAttribute(ATTR_NET_PEER_NAME, parsedUri.groups['name']);
span.setAttribute(ATTR_NET_PEER_PORT, parseInt(parsedUri.groups['port']));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import type {
import type { IgnoreMatcher } from './types';

import { context, SpanStatusCode } from '@opentelemetry/api';
import { SEMATTRS_RPC_GRPC_STATUS_CODE } from '@opentelemetry/semantic-conventions';
import { ATTR_RPC_GRPC_STATUS_CODE } from '@opentelemetry/semantic-conventions/incubating';

import {
_grpcStatusCodeToOpenTelemetryStatusCode,
Expand Down Expand Up @@ -81,7 +81,7 @@ function serverStreamAndBidiHandler<RequestType, ResponseType>(
span.setStatus({
code: SpanStatusCode.UNSET,
});
span.setAttribute(SEMATTRS_RPC_GRPC_STATUS_CODE, GRPC_STATUS_CODE_OK);
span.setAttribute(ATTR_RPC_GRPC_STATUS_CODE, GRPC_STATUS_CODE_OK);

endSpan();
});
Expand All @@ -101,7 +101,7 @@ function serverStreamAndBidiHandler<RequestType, ResponseType>(
span.setAttributes({
[AttributeNames.GRPC_ERROR_NAME]: err.name,
[AttributeNames.GRPC_ERROR_MESSAGE]: err.message,
[SEMATTRS_RPC_GRPC_STATUS_CODE]: err.code,
[ATTR_RPC_GRPC_STATUS_CODE]: err.code,
});
endSpan();
});
Expand Down Expand Up @@ -131,15 +131,15 @@ function clientStreamAndUnaryHandler<RequestType, ResponseType>(
code: _grpcStatusCodeToOpenTelemetryStatusCode(err.code),
message: err.message,
});
span.setAttribute(SEMATTRS_RPC_GRPC_STATUS_CODE, err.code);
span.setAttribute(ATTR_RPC_GRPC_STATUS_CODE, err.code);
}
span.setAttributes({
[AttributeNames.GRPC_ERROR_NAME]: err.name,
[AttributeNames.GRPC_ERROR_MESSAGE]: err.message,
});
} else {
span.setStatus({ code: SpanStatusCode.UNSET });
span.setAttribute(SEMATTRS_RPC_GRPC_STATUS_CODE, GRPC_STATUS_CODE_OK);
span.setAttribute(ATTR_RPC_GRPC_STATUS_CODE, GRPC_STATUS_CODE_OK);
}

span.end();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import {
} from '@opentelemetry/sdk-trace-base';
import { assertPropagation, assertSpan } from './utils/assertionUtils';
import {
SEMATTRS_RPC_METHOD,
SEMATTRS_RPC_SERVICE,
} from '@opentelemetry/semantic-conventions';
ATTR_RPC_METHOD,
ATTR_RPC_SERVICE,
} from '@opentelemetry/semantic-conventions/incubating';
import { AttributeValues } from '../src/enums/AttributeValues';

export type SpanAssertionFunction = (
exporter: InMemorySpanExporter,
Expand Down Expand Up @@ -61,10 +62,20 @@ function validateSpans(
);
assertPropagation(serverSpan, clientSpan);

assertSpan('grpc', serverSpan, SpanKind.SERVER, validations);
assertSpan('grpc', clientSpan, SpanKind.CLIENT, validations);
assert.strictEqual(clientSpan.attributes[SEMATTRS_RPC_METHOD], rpcMethod);
assert.strictEqual(clientSpan.attributes[SEMATTRS_RPC_SERVICE], rpcService);
assertSpan(
AttributeValues.RPC_SYSTEM,
serverSpan,
SpanKind.SERVER,
validations
);
assertSpan(
AttributeValues.RPC_SYSTEM,
clientSpan,
SpanKind.CLIENT,
validations
);
assert.strictEqual(clientSpan.attributes[ATTR_RPC_METHOD], rpcMethod);
assert.strictEqual(clientSpan.attributes[ATTR_RPC_SERVICE], rpcService);
}

export function assertNoSpansExported(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import {
hrTimeToMicroseconds,
} from '@opentelemetry/core';
import {
SEMATTRS_NET_PEER_NAME,
SEMATTRS_NET_PEER_PORT,
SEMATTRS_RPC_GRPC_STATUS_CODE,
} from '@opentelemetry/semantic-conventions';
ATTR_NET_PEER_NAME,
ATTR_NET_PEER_PORT,
ATTR_RPC_GRPC_STATUS_CODE,
} from '@opentelemetry/semantic-conventions/incubating';

export const grpcStatusCodeToOpenTelemetryStatusCode = (
status: GrpcStatus
Expand Down Expand Up @@ -70,11 +70,11 @@ export const assertSpan = (
validations.netPeerPort !== undefined
) {
assert.strictEqual(
span.attributes[SEMATTRS_NET_PEER_NAME],
span.attributes[ATTR_NET_PEER_NAME],
validations.netPeerName
);
assert.strictEqual(
span.attributes[SEMATTRS_NET_PEER_PORT],
span.attributes[ATTR_NET_PEER_PORT],
validations.netPeerPort
);
}
Expand All @@ -86,7 +86,7 @@ export const assertSpan = (
grpcStatusCodeToOpenTelemetryStatusCode(validations.status)
);
assert.strictEqual(
span.attributes[SEMATTRS_RPC_GRPC_STATUS_CODE],
span.attributes[ATTR_RPC_GRPC_STATUS_CODE],
validations.status
);
};
Expand Down