Skip to content

Commit

Permalink
fix: net instrumentation - change span kind of connect to internal (o…
Browse files Browse the repository at this point in the history
…pen-telemetry#394)

Co-authored-by: Valentin Marchaud <[email protected]>
  • Loading branch information
seemk and vmarchaud authored Mar 24, 2021
1 parent 21af6e7 commit 92656a3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
8 changes: 2 additions & 6 deletions plugins/node/opentelemetry-instrumentation-net/src/net.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { diag, Span, SpanKind, SpanStatusCode } from '@opentelemetry/api';
import { diag, Span, SpanStatusCode } from '@opentelemetry/api';
import {
InstrumentationBase,
InstrumentationConfig,
Expand Down Expand Up @@ -91,9 +91,7 @@ export class NetInstrumentation extends InstrumentationBase<Net> {

/* It might still be useful to pick up errors due to invalid connect arguments. */
private _startGenericSpan(socket: Socket) {
const span = this.tracer.startSpan('connect', {
kind: SpanKind.CLIENT,
});
const span = this.tracer.startSpan('connect');

registerListeners(socket, span);

Expand All @@ -102,7 +100,6 @@ export class NetInstrumentation extends InstrumentationBase<Net> {

private _startIpcSpan(options: NormalizedOptions, socket: Socket) {
const span = this.tracer.startSpan('ipc.connect', {
kind: SpanKind.CLIENT,
attributes: {
[GeneralAttribute.NET_TRANSPORT]: IPC_TRANSPORT,
[GeneralAttribute.NET_PEER_NAME]: options.path,
Expand All @@ -116,7 +113,6 @@ export class NetInstrumentation extends InstrumentationBase<Net> {

private _startTcpSpan(options: NormalizedOptions, socket: Socket) {
const span = this.tracer.startSpan('tcp.connect', {
kind: SpanKind.CLIENT,
attributes: {
[GeneralAttribute.NET_TRANSPORT]: GeneralAttribute.IP_TCP,
[GeneralAttribute.NET_PEER_NAME]: options.host,
Expand Down
8 changes: 4 additions & 4 deletions plugins/node/opentelemetry-instrumentation-net/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const HOST = 'localhost';
export const IPC_PATH = path.join(os.tmpdir(), 'otel-js-net-test-ipc');

export function assertTcpSpan(span: ReadableSpan, socket: Socket) {
assertClientSpan(span);
assertSpanKind(span);
assertAttrib(span, GeneralAttribute.NET_TRANSPORT, GeneralAttribute.IP_TCP);
assertAttrib(span, GeneralAttribute.NET_PEER_NAME, HOST);
assertAttrib(span, GeneralAttribute.NET_PEER_PORT, PORT);
Expand All @@ -37,13 +37,13 @@ export function assertTcpSpan(span: ReadableSpan, socket: Socket) {
}

export function assertIpcSpan(span: ReadableSpan) {
assertClientSpan(span);
assertSpanKind(span);
assertAttrib(span, GeneralAttribute.NET_TRANSPORT, IPC_TRANSPORT);
assertAttrib(span, GeneralAttribute.NET_PEER_NAME, IPC_PATH);
}

export function assertClientSpan(span: ReadableSpan) {
assert.strictEqual(span.kind, SpanKind.CLIENT);
export function assertSpanKind(span: ReadableSpan) {
assert.strictEqual(span.kind, SpanKind.INTERNAL);
}

export function assertAttrib(span: ReadableSpan, attrib: string, value: any) {
Expand Down

0 comments on commit 92656a3

Please sign in to comment.