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

Commit

Permalink
refactor: rename span.type to span.kind (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiogomessilva authored and kjin committed Jun 20, 2018
1 parent 2ddf84f commit 6e673b2
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 39 deletions.
14 changes: 7 additions & 7 deletions packages/opencensus-core/src/trace/model/root-span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class RootSpan extends SpanBase implements types.RootSpan {
this.parentSpanId = context.spanContext.spanId || '';
}
this.spansLocal = [];
this.type = context && context.type ? context.type : null;
this.kind = context && context.kind ? context.kind : null;
this.logger = tracer.logger || logger.logger();
}

Expand Down Expand Up @@ -93,29 +93,29 @@ export class RootSpan extends SpanBase implements types.RootSpan {
/**
* Starts a new child span in the root span.
* @param name Span name.
* @param type Span type.
* @param kind Span kind.
* @param parentSpanId Span parent ID.
*/
startChildSpan(name: string, type: string, parentSpanId?: string):
startChildSpan(name: string, kind: string, parentSpanId?: string):
types.Span {
if (this.ended) {
this.logger.debug(
'calling %s.startSpan() on ended %s %o', this.className,
this.className, {id: this.id, name: this.name, type: this.type});
this.className, {id: this.id, name: this.name, kind: this.kind});
return null;
}
if (!this.started) {
this.logger.debug(
'calling %s.startSpan() on un-started %s %o', this.className,
this.className, {id: this.id, name: this.name, type: this.type});
this.className, {id: this.id, name: this.name, kind: this.kind});
return null;
}
const newSpan = new Span(this);
if (name) {
newSpan.name = name;
}
if (type) {
newSpan.type = type;
if (kind) {
newSpan.kind = kind;
}
newSpan.start();
this.spansLocal.push(newSpan);
Expand Down
10 changes: 5 additions & 5 deletions packages/opencensus-core/src/trace/model/span-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export abstract class SpanBase implements types.Span {
parentSpanId: string = null;
/** The resource name of the span */
name: string = null;
/** Type of span. Used to specify additional relationships between spans */
type: string = null;
/** Kind of span. */
kind: string = null;
/** A final status for this span */
status: number;

Expand Down Expand Up @@ -181,7 +181,7 @@ export abstract class SpanBase implements types.Span {
if (this.started) {
this.logger.debug(
'calling %s.start() on already started %s %o', this.className,
this.className, {id: this.id, name: this.name, type: this.type});
this.className, {id: this.id, name: this.name, type: this.kind});
return;
}
this.clock = new Clock();
Expand All @@ -193,13 +193,13 @@ export abstract class SpanBase implements types.Span {
if (this.ended) {
this.logger.debug(
'calling %s.end() on already ended %s %o', this.className,
this.className, {id: this.id, name: this.name, type: this.type});
this.className, {id: this.id, name: this.name, type: this.kind});
return;
}
if (!this.started) {
this.logger.debug(
'calling %s.end() on un-started %s %o', this.className,
this.className, {id: this.id, name: this.name, type: this.type});
this.className, {id: this.id, name: this.name, type: this.kind});
return;
}
this.startedLocal = false;
Expand Down
8 changes: 4 additions & 4 deletions packages/opencensus-core/src/trace/model/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ export interface TraceOptions {
name: string;
/** Trace context */
spanContext?: SpanContext;
/** Span type */
type?: string;
/** Span kind */
kind?: string;
}

/** Defines the span context */
Expand Down Expand Up @@ -102,8 +102,8 @@ export interface Span {
/** The resource name of the span */
name: string;

/** Type of span. Used to specify additional relationships between spans */
type: string;
/** Kind of span. */
kind: string;

/** An object to log information to */
logger: loggerTypes.Logger;
Expand Down
10 changes: 5 additions & 5 deletions packages/opencensus-core/test/test-tracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ describe('Tracer', () => {
});

describe('startRootSpan() with context propagation', () => {
const traceOptions = {name: 'rootName', type: 'spanType'} as
const traceOptions = {name: 'rootName', kind: 'spanType'} as
types.TraceOptions;

it('should create new RootSpan instance, no propagation', () => {
Expand All @@ -185,7 +185,7 @@ describe('Tracer', () => {
tracer.startRootSpan(traceOptions, (rootSpan) => {
assert.ok(rootSpan);
assert.strictEqual(rootSpan.name, traceOptions.name);
assert.strictEqual(rootSpan.type, traceOptions.type);
assert.strictEqual(rootSpan.kind, traceOptions.kind);
});
});

Expand All @@ -203,7 +203,7 @@ describe('Tracer', () => {
tracer.startRootSpan(traceOptions, (rootSpan) => {
assert.ok(rootSpan);
assert.strictEqual(rootSpan.name, traceOptions.name);
assert.strictEqual(rootSpan.type, traceOptions.type);
assert.strictEqual(rootSpan.kind, traceOptions.kind);
assert.strictEqual(rootSpan.traceId, spanContextPropagated.traceId);
assert.strictEqual(rootSpan.parentSpanId, spanContextPropagated.spanId);
});
Expand All @@ -216,7 +216,7 @@ describe('Tracer', () => {
tracer.startRootSpan(traceOptions, (rootSpan) => {
assert.ok(rootSpan);
assert.strictEqual(rootSpan.name, traceOptions.name);
assert.strictEqual(rootSpan.type, traceOptions.type);
assert.strictEqual(rootSpan.kind, traceOptions.kind);
assert.notEqual(rootSpan.traceId, spanContextPropagated.traceId);
assert.notEqual(rootSpan.parentSpanId, spanContextPropagated.spanId);
});
Expand Down Expand Up @@ -253,7 +253,7 @@ describe('Tracer', () => {
it('should start a span', () => {
assert.ok(span.started);
assert.strictEqual(span.name, 'spanName');
assert.strictEqual(span.type, 'spanType');
assert.strictEqual(span.kind, 'spanType');
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/opencensus-exporter-instana/src/instana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class InstanaTraceExporter implements types.Exporter {
// API requires an integer/long
duration: span.duration | 0,
name: span.name,
type: span.type,
type: span.kind,
// No translatable counterpart in OpenCensus as of 2018-06-14
error: false,
data: Object.keys(span.attributes)
Expand Down
10 changes: 5 additions & 5 deletions packages/opencensus-instrumentation-grpc/src/grpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export class GrpcPlugin extends classes.BasePlugin {

const traceOptions = {
name: `grpc.${name.replace('/', '')}`,
type: 'SERVER',
kind: 'SERVER',
spanContext: propagation ? propagation.extract(getter) : null
};
plugin.logger.debug('path func: %s', traceOptions.name);
Expand All @@ -184,7 +184,7 @@ export class GrpcPlugin extends classes.BasePlugin {

rootSpan.addAttribute(GrpcPlugin.ATTRIBUTE_GRPC_METHOD, name);
rootSpan.addAttribute(
GrpcPlugin.ATTRIBUTE_GRPC_KIND, traceOptions.type);
GrpcPlugin.ATTRIBUTE_GRPC_KIND, traceOptions.kind);

switch (type) {
case 'unary':
Expand Down Expand Up @@ -314,7 +314,7 @@ export class GrpcPlugin extends classes.BasePlugin {
) {
const traceOptions = {
name: `grpc.${original.path.replace('/', '')}`,
type: 'CLIENT',
kind: 'CLIENT',
};
const args = Array.prototype.slice.call(arguments);
// Checks if this remote function call is part of an operation by
Expand All @@ -328,7 +328,7 @@ export class GrpcPlugin extends classes.BasePlugin {
plugin.makeGrpcClientRemoteCall(original, args, this, plugin));
} else {
const span = plugin.tracer.startChildSpan(
traceOptions.name, traceOptions.type);
traceOptions.name, traceOptions.kind);
return (plugin.makeGrpcClientRemoteCall(
original, args, this, plugin))(span);
}
Expand Down Expand Up @@ -401,7 +401,7 @@ export class GrpcPlugin extends classes.BasePlugin {
}

span.addAttribute(GrpcPlugin.ATTRIBUTE_GRPC_METHOD, original.path);
span.addAttribute(GrpcPlugin.ATTRIBUTE_GRPC_KIND, span.type);
span.addAttribute(GrpcPlugin.ATTRIBUTE_GRPC_KIND, span.kind);

const call = original.apply(self, args);

Expand Down
6 changes: 3 additions & 3 deletions packages/opencensus-instrumentation-grpc/test/test-grpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,14 +326,14 @@ describe('GrpcPlugin() ', function() {
false;

function assertSpan(
span: types.Span, spanName: string, type: string,
span: types.Span, spanName: string, kind: string,
status: grpcModule.status) {
assert.strictEqual(span.name, spanName);
assert.strictEqual(span.type, type);
assert.strictEqual(span.kind, kind);
assert.strictEqual(
span.status, GrpcPlugin.convertGrpcStatusToSpanStatus(status));

assert.strictEqual(span.attributes[GrpcPlugin.ATTRIBUTE_GRPC_KIND], type);
assert.strictEqual(span.attributes[GrpcPlugin.ATTRIBUTE_GRPC_KIND], kind);
assert.strictEqual(
span.attributes[GrpcPlugin.ATTRIBUTE_GRPC_STATUS_CODE], `${status}`);
assert.ok(span.attributes[GrpcPlugin.ATTRIBUTE_GRPC_METHOD]);
Expand Down
6 changes: 3 additions & 3 deletions packages/opencensus-instrumentation-http/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class HttpPlugin extends classes.BasePlugin {

const traceOptions = {
name: url.parse(request.url).pathname,
type: 'SERVER',
kind: 'SERVER',
spanContext: propagation ? propagation.extract(getter) : null
};

Expand Down Expand Up @@ -220,7 +220,7 @@ export class HttpPlugin extends classes.BasePlugin {
const traceOptions = {
name:
`${request.method ? request.method : 'GET'} ${options.pathname}`,
type: 'CLIENT',
kind: 'CLIENT',
};


Expand All @@ -236,7 +236,7 @@ export class HttpPlugin extends classes.BasePlugin {
} else {
plugin.logger.debug('outgoingRequest starting a child span');
const span = plugin.tracer.startChildSpan(
traceOptions.name, traceOptions.type);
traceOptions.name, traceOptions.kind);
return (plugin.getMakeRequestTraceFunction(request, options, plugin))(
span);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/opencensus-instrumentation-http2/src/http2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class Http2Plugin extends HttpPlugin {

const traceOptions = {
name: `${headers[':method'] || 'GET'} ${headers[':path']}`,
type: 'CLIENT',
kind: 'CLIENT',
};

// Checks if this outgoing request is part of an operation by checking
Expand All @@ -115,7 +115,7 @@ export class Http2Plugin extends HttpPlugin {
request, headers, authority, plugin));
} else {
const span = plugin.tracer.startChildSpan(
traceOptions.name, traceOptions.type);
traceOptions.name, traceOptions.kind);
return (plugin.getMakeHttp2RequestTraceFunction(
request, headers, authority, plugin))(span);
}
Expand Down Expand Up @@ -221,7 +221,7 @@ export class Http2Plugin extends HttpPlugin {

const traceOptions = {
name: headers[':path'],
type: 'SERVER',
kind: 'SERVER',
spanContext: propagation ? propagation.extract(getter) : null
} as types.TraceOptions;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@ function accessCollection(url: string, dbName: string, collectionName: string):
* @param rootSpanVerifier An instance of rootSpanVerifier to analyse RootSpan
* instances from.
* @param expectedName The expected name of the first root span.
* @param expectedType The expected type of the first root span.
* @param expectedKind The expected kind of the first root span.
*/
function assertSpan(
rootSpanVerifier: RootSpanVerifier, expectedName: string,
expectedType: string) {
expectedKind: string) {
assert.strictEqual(rootSpanVerifier.endedRootSpans.length, 1);
assert.strictEqual(rootSpanVerifier.endedRootSpans[0].spans.length, 1);
assert.strictEqual(
rootSpanVerifier.endedRootSpans[0].spans[0].name, expectedName);
assert.strictEqual(
rootSpanVerifier.endedRootSpans[0].spans[0].type, expectedType);
rootSpanVerifier.endedRootSpans[0].spans[0].kind, expectedKind);
}

describe('MongoDBPlugin', () => {
Expand Down

0 comments on commit 6e673b2

Please sign in to comment.