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

Commit 74c614a

Browse files
committed
refactor: rework after review
1 parent 05cee77 commit 74c614a

21 files changed

Lines changed: 127 additions & 101 deletions

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {Logger} from '../common/types';
2323
import {Exporter} from './types';
2424
import {Config, BufferConfig} from '../trace/config/types';
2525

26-
import * as logger from '../common/consolelogger';
26+
import * as logger from '../common/console-logger';
2727

2828

2929
/** Controls the sending of traces to exporters. */

packages/opencensus-core/src/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,25 @@
1919
export * from './trace/types';
2020
export * from './trace/model/types';
2121
export * from './trace/config/types';
22+
export * from './trace/sampler/types';
2223
export * from './trace/instrumentation/types';
2324
export * from './exporters/types';
2425
export * from './common/types';
2526

2627
// domain models impls
27-
export * from './trace/model/rootspan';
28+
export * from './trace/model/root-span';
2829
export * from './trace/model/span';
2930
export * from './trace/model/tracer';
3031

3132
// sampler impl
32-
export * from './trace/config/sampler';
33+
export * from './trace/sampler/sampler';
3334

3435
// base instrumetation class
35-
export * from './trace/instrumentation/baseplugin';
36+
export * from './trace/instrumentation/base-plugin';
3637

3738
// console exporter and buffer impls
3839
export * from './exporters/buffer';
39-
export * from './exporters/consolelog-exporter';
40+
export * from './exporters/console-exporter';
4041

4142
// util
4243
export * from './internal/util';

packages/opencensus-core/src/internal/clock.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,6 @@ export class Clock {
4949
return ns / 1e6;
5050
}
5151

52-
/**
53-
* Compares clock with another one.
54-
* @param timer A clock object to compare.
55-
*/
56-
offset(timer: Clock): number {
57-
const a = timer.hrtime;
58-
const b = this.hrtime;
59-
const ns = (b[0] - a[0]) * 1e9 + (b[1] - a[1]);
60-
return ns / 1e6;
61-
}
62-
63-
/** Gets the time in high definition. */
64-
get hrtime(): [number, number] {
65-
return this.hrtimeLocal;
66-
}
6752

6853
/** Starts the clock. */
6954
get startTime(): Date {

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

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,23 @@
1-
import {Exporter} from '../../exporters/types';
1+
/**
2+
* Copyright 2018 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import {Exporter} from '../../exporters/types';
218
import {PluginNames} from '../instrumentation/types';
319
import {Logger} from '../../common/types';
420

5-
/** This interface represent the probability of a tracer. */
6-
export interface Sampler {
7-
/**
8-
* Sets idUpperBound with MAX_NUMBER that is equivalent the probability be 1.
9-
* @returns a Sampler object.
10-
*/
11-
always(): Sampler;
12-
13-
/**
14-
* Sets idUpperBound with MIN_NUMBER that is equivalent the probability be 0.
15-
* @returns a Sampler object.
16-
*/
17-
never(): Sampler;
18-
19-
/**
20-
* Sets idUpperBound with the probability. If probability
21-
* parameter is bigger then 1 set always. If probability parameter less
22-
* than 0, set never.
23-
* @param probability probability between 0 and 1.
24-
* @returns a Sampler object.
25-
*/
26-
probability(probability: number): Sampler;
27-
28-
/**
29-
* Checks if trace belong the sample.
30-
* @param traceId Used to check the probability.
31-
* @returns a boolean. True if the traceId is in probability
32-
* False if the traceId is not in probability.
33-
*/
34-
shouldSample(traceId: string): boolean;
35-
}
36-
3721
/** Interface configuration for a buffer. */
3822
export interface BufferConfig {
3923
bufferSize?: number;

packages/opencensus-core/src/trace/instrumentation/base-plugin.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,20 @@
1414
* limitations under the License.
1515
*/
1616
import * as shimmer from 'shimmer';
17+
import {Plugin} from './types';
1718
import {Tracer} from '../model/types';
1819

1920
/** This class represent the base to patch plugin. */
20-
export abstract class BasePlugin {
21+
export abstract class BasePlugin implements Plugin {
2122
/** The service to send the collected traces */
2223
// tslint:disable:no-any
23-
exporter: any;
24+
protected exporter: any;
2425
/** The module name */
25-
moduleName: string;
26+
protected moduleName: string;
2627
/** A tracer object. */
27-
tracer: Tracer;
28+
protected tracer: Tracer;
2829
/** The module version. */
29-
version: string;
30+
protected version: string;
3031

3132
/**
3233
* Constructs a new BasePlugin instance.
@@ -87,4 +88,11 @@ export abstract class BasePlugin {
8788
shimmer.massUnwrap(nodule, names);
8889
}
8990

91+
// tslint:disable:no-any
92+
applyPatch(exporter: any, tracer: Tracer, version: string): any{
93+
this.setPluginContext(exporter, tracer, version);
94+
}
95+
96+
abstract applyUnpatch(): void;
97+
9098
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {Tracer} from "../model/types";
1919
/** Interface Plugin to apply patch. */
2020
export interface Plugin {
2121
// tslint:disable:no-any
22-
applyPatch(module: {}, tracer: Tracer, version: string): any;
22+
applyPatch(exporter: any, tracer: Tracer, version: string): any;
2323
applyUnpatch(): void;
2424
}
2525

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ import {Clock} from '../../internal/clock';
2020
import {debug} from '../../internal/util';
2121

2222
import {SpanImpl} from './span';
23-
import {SpanBaseModel} from './spanbasemodel';
23+
import {SpanBaseModel} from './span-base-model';
2424
import {TracerImpl} from './tracer';
2525
import {OnEndSpanEventListener, RootSpan, Span, TraceContext, TraceOptions, Tracer} from './types';
2626

27-
import * as logger from '../../common/consolelogger';
27+
import * as logger from '../../common/console-logger';
2828

2929
/** Defines a root span */
3030
export class RootSpanImpl extends SpanBaseModel implements RootSpan {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import {Clock} from '../../internal/clock';
1818
import {debug, randomSpanId} from '../../internal/util';
19-
import {Sampler} from '../config/types';
19+
import {Sampler} from '../sampler/types';
2020

2121
import {Annotation, Attributes, Link, MessageEvent, Span, TraceContext} from './types';
2222
import {Logger} from '../../common/types';
@@ -128,7 +128,7 @@ export abstract class SpanBaseModel implements Span {
128128
* @param key Describes the value added.
129129
* @param value The result of an operation.
130130
*/
131-
addAtribute(key: string, value: string|number|boolean) {
131+
addAttribute(key: string, value: string|number|boolean) {
132132
this.attributes[key] = value;
133133
}
134134

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616

1717
import {debug, randomSpanId} from '../../internal/util';
1818

19-
import {RootSpanImpl} from './rootspan';
20-
import {SpanBaseModel} from './spanbasemodel';
19+
import {RootSpanImpl} from './root-span';
20+
import {SpanBaseModel} from './span-base-model';
2121
import {RootSpan, Span, TraceContext} from './types';
2222

23-
import * as logger from '../../common/consolelogger';
23+
import * as logger from '../../common/console-logger';
2424

2525
/** Defines a Span. */
2626
export class SpanImpl extends SpanBaseModel implements Span {

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,20 @@
1616

1717
import * as cls from '../../internal/cls';
1818
import {debug} from '../../internal/util';
19-
import {SamplerImpl} from '../config/sampler';
20-
import {Sampler, TracerConfig} from '../config/types';
19+
import {SamplerImpl} from '../sampler/sampler';
20+
import {TracerConfig} from '../config/types';
21+
import {Sampler} from '../sampler/types';
22+
2123
import {Config} from '../config/types';
2224

23-
import {RootSpanImpl} from './rootspan';
25+
import {RootSpanImpl} from './root-span';
2426
import {SpanImpl} from './span';
2527
import {RootSpan, Span} from './types';
2628
import {TraceOptions, Tracer} from './types';
2729
import {Func, OnEndSpanEventListener} from './types';
2830
import {Logger} from '../../common/types';
2931

30-
import * as logger from '../../common/consolelogger';
32+
import * as logger from '../../common/console-logger';
3133

3234
/**
3335
* This class represent a tracer.
@@ -181,7 +183,7 @@ export class TracerImpl implements Tracer {
181183
}
182184

183185
// This is safe because isActive checks the value of this.namespace.
184-
const namespace = this.contextManager as cls.Namespace;
186+
const namespace = this.contextManager;
185187
return namespace.bind<T>(fn);
186188
}
187189

@@ -195,7 +197,7 @@ export class TracerImpl implements Tracer {
195197
}
196198

197199
// This is safe because isActive checks the value of this.namespace.
198-
const namespace = this.contextManager as cls.Namespace;
200+
const namespace = this.contextManager;
199201
namespace.bindEmitter(emitter);
200202
}
201203
}

0 commit comments

Comments
 (0)