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

Commit f7a6019

Browse files
committed
refactor: update interface types
1 parent 3d59c94 commit f7a6019

6 files changed

Lines changed: 79 additions & 34 deletions

File tree

packages/opencensus-core/src/exporters/buffer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
import * as uuidv4 from 'uuid/v4';
1818

1919
import {debug} from '../internal/util';
20-
import {RootSpan} from '../trace/model/rootspan';
21-
import {OnEndSpanEventListener} from '../trace/types/tracetypes';
20+
import {RootSpan} from '../trace/types';
21+
import {OnEndSpanEventListener} from '../trace/types';
2222

2323
import {Exporter} from './exporter';
2424
import {ExporterOptions} from './exporterOptions';

packages/opencensus-core/src/exporters/exporter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*/
1616

1717

18-
import {RootSpan} from '../trace/model/rootspan';
19-
import {OnEndSpanEventListener} from '../trace/types/tracetypes';
18+
import {RootSpan} from '../trace/types';
19+
import {OnEndSpanEventListener} from '../trace/types';
2020
import {ExporterOptions} from './exporterOptions';
2121

2222
export interface Exporter { publish(rootSpans: RootSpan[]); }

packages/opencensus-core/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ export * from './exporters/exporterOptions';
2121
export * from './internal/clock';
2222
export * from './internal/util';
2323
export * from './trace/config/sampler';
24-
export * from './trace/instrumentation/plugingtypes';
24+
export * from './trace/instrumentation/types';
2525
export * from './trace/model/rootspan';
2626
export * from './trace/model/span';
2727
export * from './trace/model/tracer';
28-
export * from './trace/types/tracetypes';
28+
export * from './trace/types';
2929

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { Clock } from '../../internal/clock';
22
import { debug, randomSpanId } from '../../internal/util';
33
import { Sampler } from '../config/sampler';
4-
import { TraceContext } from '../types';
4+
import { TraceContext, Span } from '../types';
55

66
export interface MapLabels { [propName: string]: string; }
77
export interface MapObjects { [propName: string]: any; }
88

9-
export abstract class SpanBaseModel {
9+
export abstract class SpanBaseModel implements Span {
1010
protected className: string;
1111
/** The clock used to mesure the beginning and ending of a span */
1212
private clock: Clock = null;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ import { RootSpanImpl } from './rootspan';
1919
import { SpanImpl } from './span';
2020
import { debug } from '../../internal/util';
2121
import { Sampler } from '../config/sampler';
22-
import { TraceOptions, TracerConfig, defaultConfig, Tracer, OnEndSpanEventListener } from '../types';
22+
import { TraceOptions, TracerConfig, defaultConfig, Tracer, OnEndSpanEventListener, Func } from '../types';
2323

24-
export type Func<T> = (...args: any[]) => T;
24+
//ßexport type Func<T> = (...args: any[]) => T;
2525

2626
export class TracerImpl implements Tracer {
2727

packages/opencensus-core/src/trace/types/tracetypes.ts renamed to packages/opencensus-core/src/trace/types.ts

Lines changed: 69 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616

1717
import { Sampler } from './config/sampler';
18-
import { SpanBaseModel } from './model/spanbasemodel';
1918

2019
/** Default type for functions */
2120
export type Func<T> = (...args: any[]) => T;
@@ -63,11 +62,6 @@ export interface TraceOptions {
6362
type?: string;
6463
}
6564

66-
/** Defines an end span event listener */
67-
export interface OnEndSpanEventListener {
68-
/** Happens when a span is ended */
69-
onEndSpan(span: SpanBaseModel): void;
70-
}
7165

7266
/** Defines the span data */
7367
export interface SpanData {
@@ -81,32 +75,83 @@ export interface SpanData {
8175
parentSpanId?: string;
8276
}
8377

84-
/** Interface for RootSpan */
85-
export interface RootSpan {
86-
/** Get the span list from RootSpan instance */
87-
readonly spans: Span[];
88-
89-
/** Start the RootSpan instance */
90-
start(): void;
91-
/** End the RootSpan instance */
92-
end(): void;
93-
/** Start a new Span instance in the RootSpan instance */
94-
startSpan(name: string, type: string, parentSpanId?: string): Span;
95-
}
9678

9779
/** Interface for Span */
9880
export interface Span {
99-
/** Gets the traceId from span instance */
81+
82+
/** The Span ID of this span */
83+
readonly id: string;
84+
remoteParent: string;
85+
/** The span ID of this span's parent. If it's a root span, must be empty */
86+
parentSpanId: string;
87+
/** The resource name of the span */
88+
name: string;
89+
/** Type of span. Used to specify additional relationships between spans */
90+
type: string;
91+
/** A final status for this span */
92+
status: number;
93+
/** A sampler that will decide if the span will be sampled or not */
94+
sampler: Sampler;
95+
/** Constructs a new SpanBaseModel instance. */
10096
readonly traceId: string;
101-
/** Gets the parentSpanId from span instance */
102-
readonly parentSpanId: string;
103-
/** Gets the traceContext from span instance */
97+
/** Indicates if span was started. */
98+
readonly started: boolean;
99+
/** Indicates if span was ended. */
100+
readonly ended: boolean;
101+
/**
102+
* Gives a timestap that indicates the span's start time in RFC3339 UTC
103+
* "Zulu" format.
104+
*/
105+
readonly startTime: Date;
106+
/**
107+
* Gives a timestap that indicates the span's end time in RFC3339 UTC
108+
* "Zulu" format.
109+
*/
110+
readonly endTime: Date;
111+
/**
112+
* Gives a timestap that indicates the span's duration in RFC3339 UTC
113+
* "Zulu" format.
114+
*/
115+
readonly duration: number;
116+
/** Gives the TraceContext of the span. */
104117
readonly traceContext: TraceContext;
105-
106-
/** Starts a span instance. */
118+
/**
119+
* Adds an atribute to the span.
120+
* @param key Describes the value added.
121+
* @param value The result of an operation.
122+
*/
123+
addAtribute(key: string, value: string): void;
124+
/**
125+
* Adds an annotation to the span.
126+
* @param key Describes the value added.
127+
* @param value The result of an operation.
128+
*/
129+
addAnotation(key: string, value: string | number | boolean): void;
130+
/** Starts a span. */
107131
start(): void;
108132
/** Ends a span. */
109133
end(): void;
134+
/** Forces to end a span. */
135+
truncate(): void;
136+
}
137+
138+
/** Interface for RootSpan */
139+
export interface RootSpan extends Span {
140+
/** Get the span list from RootSpan instance */
141+
readonly spans: Span[];
142+
143+
/** Start the RootSpan instance */
144+
start(): void;
145+
/** End the RootSpan instance */
146+
end(): void;
147+
/** Start a new Span instance in the RootSpan instance */
148+
startSpan(name: string, type: string, parentSpanId?: string): Span;
149+
}
150+
151+
/** Defines an end span event listener */
152+
export interface OnEndSpanEventListener {
153+
/** Happens when a span is ended */
154+
onEndSpan(span: Span): void;
110155
}
111156

112157
/** Interface for Tracer */

0 commit comments

Comments
 (0)