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

Commit 6e673b2

Browse files
fabiogomessilvakjin
authored andcommitted
refactor: rename span.type to span.kind (#56)
1 parent 2ddf84f commit 6e673b2

10 files changed

Lines changed: 39 additions & 39 deletions

File tree

packages/opencensus-core/src/trace/model/root-span.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class RootSpan extends SpanBase implements types.RootSpan {
5050
this.parentSpanId = context.spanContext.spanId || '';
5151
}
5252
this.spansLocal = [];
53-
this.type = context && context.type ? context.type : null;
53+
this.kind = context && context.kind ? context.kind : null;
5454
this.logger = tracer.logger || logger.logger();
5555
}
5656

@@ -93,29 +93,29 @@ export class RootSpan extends SpanBase implements types.RootSpan {
9393
/**
9494
* Starts a new child span in the root span.
9595
* @param name Span name.
96-
* @param type Span type.
96+
* @param kind Span kind.
9797
* @param parentSpanId Span parent ID.
9898
*/
99-
startChildSpan(name: string, type: string, parentSpanId?: string):
99+
startChildSpan(name: string, kind: string, parentSpanId?: string):
100100
types.Span {
101101
if (this.ended) {
102102
this.logger.debug(
103103
'calling %s.startSpan() on ended %s %o', this.className,
104-
this.className, {id: this.id, name: this.name, type: this.type});
104+
this.className, {id: this.id, name: this.name, kind: this.kind});
105105
return null;
106106
}
107107
if (!this.started) {
108108
this.logger.debug(
109109
'calling %s.startSpan() on un-started %s %o', this.className,
110-
this.className, {id: this.id, name: this.name, type: this.type});
110+
this.className, {id: this.id, name: this.name, kind: this.kind});
111111
return null;
112112
}
113113
const newSpan = new Span(this);
114114
if (name) {
115115
newSpan.name = name;
116116
}
117-
if (type) {
118-
newSpan.type = type;
117+
if (kind) {
118+
newSpan.kind = kind;
119119
}
120120
newSpan.start();
121121
this.spansLocal.push(newSpan);

packages/opencensus-core/src/trace/model/span-base.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ export abstract class SpanBase implements types.Span {
4949
parentSpanId: string = null;
5050
/** The resource name of the span */
5151
name: string = null;
52-
/** Type of span. Used to specify additional relationships between spans */
53-
type: string = null;
52+
/** Kind of span. */
53+
kind: string = null;
5454
/** A final status for this span */
5555
status: number;
5656

@@ -181,7 +181,7 @@ export abstract class SpanBase implements types.Span {
181181
if (this.started) {
182182
this.logger.debug(
183183
'calling %s.start() on already started %s %o', this.className,
184-
this.className, {id: this.id, name: this.name, type: this.type});
184+
this.className, {id: this.id, name: this.name, type: this.kind});
185185
return;
186186
}
187187
this.clock = new Clock();
@@ -193,13 +193,13 @@ export abstract class SpanBase implements types.Span {
193193
if (this.ended) {
194194
this.logger.debug(
195195
'calling %s.end() on already ended %s %o', this.className,
196-
this.className, {id: this.id, name: this.name, type: this.type});
196+
this.className, {id: this.id, name: this.name, type: this.kind});
197197
return;
198198
}
199199
if (!this.started) {
200200
this.logger.debug(
201201
'calling %s.end() on un-started %s %o', this.className,
202-
this.className, {id: this.id, name: this.name, type: this.type});
202+
this.className, {id: this.id, name: this.name, type: this.kind});
203203
return;
204204
}
205205
this.startedLocal = false;

packages/opencensus-core/src/trace/model/types.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ export interface TraceOptions {
6767
name: string;
6868
/** Trace context */
6969
spanContext?: SpanContext;
70-
/** Span type */
71-
type?: string;
70+
/** Span kind */
71+
kind?: string;
7272
}
7373

7474
/** Defines the span context */
@@ -102,8 +102,8 @@ export interface Span {
102102
/** The resource name of the span */
103103
name: string;
104104

105-
/** Type of span. Used to specify additional relationships between spans */
106-
type: string;
105+
/** Kind of span. */
106+
kind: string;
107107

108108
/** An object to log information to */
109109
logger: loggerTypes.Logger;

packages/opencensus-core/test/test-tracer.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ describe('Tracer', () => {
176176
});
177177

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

182182
it('should create new RootSpan instance, no propagation', () => {
@@ -185,7 +185,7 @@ describe('Tracer', () => {
185185
tracer.startRootSpan(traceOptions, (rootSpan) => {
186186
assert.ok(rootSpan);
187187
assert.strictEqual(rootSpan.name, traceOptions.name);
188-
assert.strictEqual(rootSpan.type, traceOptions.type);
188+
assert.strictEqual(rootSpan.kind, traceOptions.kind);
189189
});
190190
});
191191

@@ -203,7 +203,7 @@ describe('Tracer', () => {
203203
tracer.startRootSpan(traceOptions, (rootSpan) => {
204204
assert.ok(rootSpan);
205205
assert.strictEqual(rootSpan.name, traceOptions.name);
206-
assert.strictEqual(rootSpan.type, traceOptions.type);
206+
assert.strictEqual(rootSpan.kind, traceOptions.kind);
207207
assert.strictEqual(rootSpan.traceId, spanContextPropagated.traceId);
208208
assert.strictEqual(rootSpan.parentSpanId, spanContextPropagated.spanId);
209209
});
@@ -216,7 +216,7 @@ describe('Tracer', () => {
216216
tracer.startRootSpan(traceOptions, (rootSpan) => {
217217
assert.ok(rootSpan);
218218
assert.strictEqual(rootSpan.name, traceOptions.name);
219-
assert.strictEqual(rootSpan.type, traceOptions.type);
219+
assert.strictEqual(rootSpan.kind, traceOptions.kind);
220220
assert.notEqual(rootSpan.traceId, spanContextPropagated.traceId);
221221
assert.notEqual(rootSpan.parentSpanId, spanContextPropagated.spanId);
222222
});
@@ -253,7 +253,7 @@ describe('Tracer', () => {
253253
it('should start a span', () => {
254254
assert.ok(span.started);
255255
assert.strictEqual(span.name, 'spanName');
256-
assert.strictEqual(span.type, 'spanType');
256+
assert.strictEqual(span.kind, 'spanType');
257257
});
258258
});
259259

packages/opencensus-exporter-instana/src/instana.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export class InstanaTraceExporter implements types.Exporter {
103103
// API requires an integer/long
104104
duration: span.duration | 0,
105105
name: span.name,
106-
type: span.type,
106+
type: span.kind,
107107
// No translatable counterpart in OpenCensus as of 2018-06-14
108108
error: false,
109109
data: Object.keys(span.attributes)

packages/opencensus-instrumentation-grpc/src/grpc.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export class GrpcPlugin extends classes.BasePlugin {
172172

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

185185
rootSpan.addAttribute(GrpcPlugin.ATTRIBUTE_GRPC_METHOD, name);
186186
rootSpan.addAttribute(
187-
GrpcPlugin.ATTRIBUTE_GRPC_KIND, traceOptions.type);
187+
GrpcPlugin.ATTRIBUTE_GRPC_KIND, traceOptions.kind);
188188

189189
switch (type) {
190190
case 'unary':
@@ -314,7 +314,7 @@ export class GrpcPlugin extends classes.BasePlugin {
314314
) {
315315
const traceOptions = {
316316
name: `grpc.${original.path.replace('/', '')}`,
317-
type: 'CLIENT',
317+
kind: 'CLIENT',
318318
};
319319
const args = Array.prototype.slice.call(arguments);
320320
// Checks if this remote function call is part of an operation by
@@ -328,7 +328,7 @@ export class GrpcPlugin extends classes.BasePlugin {
328328
plugin.makeGrpcClientRemoteCall(original, args, this, plugin));
329329
} else {
330330
const span = plugin.tracer.startChildSpan(
331-
traceOptions.name, traceOptions.type);
331+
traceOptions.name, traceOptions.kind);
332332
return (plugin.makeGrpcClientRemoteCall(
333333
original, args, this, plugin))(span);
334334
}
@@ -401,7 +401,7 @@ export class GrpcPlugin extends classes.BasePlugin {
401401
}
402402

403403
span.addAttribute(GrpcPlugin.ATTRIBUTE_GRPC_METHOD, original.path);
404-
span.addAttribute(GrpcPlugin.ATTRIBUTE_GRPC_KIND, span.type);
404+
span.addAttribute(GrpcPlugin.ATTRIBUTE_GRPC_KIND, span.kind);
405405

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

packages/opencensus-instrumentation-grpc/test/test-grpc.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,14 +326,14 @@ describe('GrpcPlugin() ', function() {
326326
false;
327327

328328
function assertSpan(
329-
span: types.Span, spanName: string, type: string,
329+
span: types.Span, spanName: string, kind: string,
330330
status: grpcModule.status) {
331331
assert.strictEqual(span.name, spanName);
332-
assert.strictEqual(span.type, type);
332+
assert.strictEqual(span.kind, kind);
333333
assert.strictEqual(
334334
span.status, GrpcPlugin.convertGrpcStatusToSpanStatus(status));
335335

336-
assert.strictEqual(span.attributes[GrpcPlugin.ATTRIBUTE_GRPC_KIND], type);
336+
assert.strictEqual(span.attributes[GrpcPlugin.ATTRIBUTE_GRPC_KIND], kind);
337337
assert.strictEqual(
338338
span.attributes[GrpcPlugin.ATTRIBUTE_GRPC_STATUS_CODE], `${status}`);
339339
assert.ok(span.attributes[GrpcPlugin.ATTRIBUTE_GRPC_METHOD]);

packages/opencensus-instrumentation-http/src/http.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export class HttpPlugin extends classes.BasePlugin {
124124

125125
const traceOptions = {
126126
name: url.parse(request.url).pathname,
127-
type: 'SERVER',
127+
kind: 'SERVER',
128128
spanContext: propagation ? propagation.extract(getter) : null
129129
};
130130

@@ -220,7 +220,7 @@ export class HttpPlugin extends classes.BasePlugin {
220220
const traceOptions = {
221221
name:
222222
`${request.method ? request.method : 'GET'} ${options.pathname}`,
223-
type: 'CLIENT',
223+
kind: 'CLIENT',
224224
};
225225

226226

@@ -236,7 +236,7 @@ export class HttpPlugin extends classes.BasePlugin {
236236
} else {
237237
plugin.logger.debug('outgoingRequest starting a child span');
238238
const span = plugin.tracer.startChildSpan(
239-
traceOptions.name, traceOptions.type);
239+
traceOptions.name, traceOptions.kind);
240240
return (plugin.getMakeRequestTraceFunction(request, options, plugin))(
241241
span);
242242
}

packages/opencensus-instrumentation-http2/src/http2.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export class Http2Plugin extends HttpPlugin {
101101

102102
const traceOptions = {
103103
name: `${headers[':method'] || 'GET'} ${headers[':path']}`,
104-
type: 'CLIENT',
104+
kind: 'CLIENT',
105105
};
106106

107107
// Checks if this outgoing request is part of an operation by checking
@@ -115,7 +115,7 @@ export class Http2Plugin extends HttpPlugin {
115115
request, headers, authority, plugin));
116116
} else {
117117
const span = plugin.tracer.startChildSpan(
118-
traceOptions.name, traceOptions.type);
118+
traceOptions.name, traceOptions.kind);
119119
return (plugin.getMakeHttp2RequestTraceFunction(
120120
request, headers, authority, plugin))(span);
121121
}
@@ -221,7 +221,7 @@ export class Http2Plugin extends HttpPlugin {
221221

222222
const traceOptions = {
223223
name: headers[':path'],
224-
type: 'SERVER',
224+
kind: 'SERVER',
225225
spanContext: propagation ? propagation.extract(getter) : null
226226
} as types.TraceOptions;
227227

packages/opencensus-instrumentation-mongodb/test/test-mongodb.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,17 @@ function accessCollection(url: string, dbName: string, collectionName: string):
6868
* @param rootSpanVerifier An instance of rootSpanVerifier to analyse RootSpan
6969
* instances from.
7070
* @param expectedName The expected name of the first root span.
71-
* @param expectedType The expected type of the first root span.
71+
* @param expectedKind The expected kind of the first root span.
7272
*/
7373
function assertSpan(
7474
rootSpanVerifier: RootSpanVerifier, expectedName: string,
75-
expectedType: string) {
75+
expectedKind: string) {
7676
assert.strictEqual(rootSpanVerifier.endedRootSpans.length, 1);
7777
assert.strictEqual(rootSpanVerifier.endedRootSpans[0].spans.length, 1);
7878
assert.strictEqual(
7979
rootSpanVerifier.endedRootSpans[0].spans[0].name, expectedName);
8080
assert.strictEqual(
81-
rootSpanVerifier.endedRootSpans[0].spans[0].type, expectedType);
81+
rootSpanVerifier.endedRootSpans[0].spans[0].kind, expectedKind);
8282
}
8383

8484
describe('MongoDBPlugin', () => {

0 commit comments

Comments
 (0)