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

Commit 7491376

Browse files
committed
chord: merge commit
2 parents bf33d9c + 0790f49 commit 7491376

11 files changed

Lines changed: 4039 additions & 47 deletions

File tree

packages/opencensus-core/package-lock.json

Lines changed: 3931 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/opencensus-core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"continuation-local-storage": "^3.2.1",
4747
"debug": "^3.1.0",
4848
"end-of-stream": "^1.4.1",
49+
"npm": "^5.7.1",
4950
"require-in-the-middle": "^2.2.1",
5051
"semver": "^5.5.0",
5152
"shimmer": "^1.2.0",
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
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+
118
export interface ExporterOptions {
219

320
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,17 @@ export class Clock {
2828
}
2929

3030
public end(): void {
31-
if (this._ended) return
31+
if (this._ended){
32+
return
33+
}
3234
this.diff = process.hrtime(this._hrtime)
3335
this._ended = true
3436
}
3537

3638
public get duration(): number {
37-
if (!this._ended) return null
39+
if (!this._ended){
40+
return null
41+
}
3842
var ns = this.diff[0] * 1e9 + this.diff[1]
3943
return ns / 1e6
4044
}

packages/opencensus-core/src/internal/cls-ah.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2017 Google Inc. All Rights Reserved.
2+
* Copyright 2018 Google Inc. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,10 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
import * as asyncHook from 'async_hooks';
18-
import {Context, Func, Namespace as CLSNamespace} from 'continuation-local-storage';
19-
import {EventEmitter} from 'events';
20-
import * as shimmer from 'shimmer';
17+
import * as asyncHook from 'async_hooks'
18+
import {Context, Func, Namespace as CLSNamespace} from 'continuation-local-storage'
19+
import {EventEmitter} from 'events'
20+
import * as shimmer from 'shimmer'
2121

2222
const wrappedSymbol = Symbol('context_wrapped');
2323
let contexts: {[asyncId: number]: Context;} = {};

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2015 Google Inc. All Rights Reserved.
2+
* Copyright 2018 Google Inc. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,8 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17-
import * as CLS from 'continuation-local-storage';
18-
import * as semver from 'semver';
17+
import * as CLS from 'continuation-local-storage'
18+
import * as semver from 'semver'
1919

2020
export type Namespace = CLS.Namespace;
2121
export type Func<T> = CLS.Func<T>;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17-
import * as crypto from 'crypto';
18-
import * as Debug from "debug";
17+
import * as crypto from 'crypto'
18+
import * as Debug from "debug"
1919

2020
export const debug = Debug("opencensus");
2121

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

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,57 +14,55 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {Clock} from '../../internal/clock';
18-
import {Trace} from './trace';
17+
import {Clock} from '../../internal/clock'
18+
import {Trace} from './trace'
1919
import {debug, randomSpanId} from '../../internal/util'
2020
import {TraceBaseModel} from '../types/tracetypes'
2121

2222

2323
export class Span extends TraceBaseModel {
2424

2525
private trace: TraceBaseModel;
26-
private _parentSpanId: string;
26+
// private _parentSpanId: string;
2727

2828
constructor(trace: TraceBaseModel) {
2929
super()
3030
this.trace = trace;
31-
this.setId(randomSpanId());
3231
}
3332

3433
public get traceId() : string {
35-
return this.trace.id;
36-
}
37-
38-
public set parentSpanId(parentSpanId : string) {
39-
this._parentSpanId = parentSpanId;
34+
return this.trace.traceId;
4035
}
4136

4237
public get parentSpanId() : string {
43-
return this._parentSpanId;
38+
return this.trace.id;
4439
}
4540

4641
public get traceContext() {
4742
return {
48-
traceId: this.trace.id.toString(),
43+
traceId: this.traceId.toString(),
4944
spanId: this.id.toString(),
5045
options: 1 // always traced
5146
};
5247
}
5348

5449
public start() {
5550
super.start();
56-
debug('starting span %o', {id: this.id, traceId: this.traceId, name: this.name })
51+
debug('starting span %o',
52+
{id: this.id,
53+
traceId: this.traceId,
54+
name: this.name})
5755
}
5856

5957
public end(): void {
6058
super.end();
6159
debug('ending span %o',
62-
{spanId: this.id,
63-
traceId: this.trace.id,
64-
name: this.name ,
65-
startTime: this.startTime,
66-
endTime: this.endTime,
67-
duration: this.duration}
60+
{spanId: this.id,
61+
traceId: this.trace.id,
62+
name: this.name ,
63+
startTime: this.startTime,
64+
endTime: this.endTime,
65+
duration: this.duration}
6866
)
6967

7068
}

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

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,34 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {Span} from './span'
17+
import * as uuid from 'uuid'
18+
19+
import {Span} from './span'
1820
import {Clock} from '../../internal/clock'
19-
import * as uuid from 'uuid';
2021
import {debug} from '../../internal/util'
2122
import {TraceBaseModel} from '../types/tracetypes'
2223

2324
export class Trace extends TraceBaseModel {
2425

2526
private spans: Span[] = [];
27+
private _traceId: string;
2628

2729
constructor() {
2830
super()
29-
this.setId((uuid.v4().split('-').join('')));
31+
this._traceId = (uuid.v4().split('-').join(''));
3032
}
31-
33+
34+
public get traceSpans() : Span[] {
35+
return this.spans;
36+
}
37+
38+
public get traceId() : string {
39+
return this._traceId;
40+
}
41+
3242
public start() {
3343
super.start()
34-
debug('starting trace %o', {id: this.id})
44+
debug('starting trace %o', {traceId: this.traceId})
3545
}
3646

3747
public end() {
@@ -44,7 +54,11 @@ export class Trace extends TraceBaseModel {
4454
})
4555

4656
debug('ending trace %o',
47-
{id: this.id, name: this.name, startTime: this.startTime, endTime: this.endTime, duration: this.duration})
57+
{id: this.id,
58+
name: this.name,
59+
startTime: this.startTime,
60+
endTime: this.endTime,
61+
duration: this.duration})
4862
}
4963

5064
public startSpan(name: string, type: string) {

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@
1414
* limitations under the License.
1515
*/
1616

17-
import * as cls from '../../internal/cls';
17+
import * as cls from '../../internal/cls'
1818
import {Trace} from './trace'
1919
import {Span} from './span'
2020
import {debug} from '../../internal/util'
2121
import {Stackdriver} from '../../exporters/stackdriver/stackdriver'
2222
import {StackdriverOptions} from '../../exporters/stackdriver/options'
23-
import { Exporter } from '../../exporters/exporter';
23+
import { Exporter } from '../../exporters/exporter'
2424

2525
export type Func<T> = (...args: any[]) => T;
2626

2727
export class Tracer {
2828

29-
readonly PLUGINS = ['http', 'https', 'mongodb-core', 'express']
29+
readonly PLUGINS = ['http', 'https', 'mongodb-core', 'express'];
3030

3131
private _active: boolean;
3232
private contextManager: cls.Namespace;
@@ -35,10 +35,9 @@ export class Tracer {
3535
//TODO: temp solution
3636
private endedTraces: Trace[] = [];
3737

38-
constructor(exporter:Exporter) {
38+
constructor() {
3939
this._active = false;
4040
this.contextManager = cls.createNamespace();
41-
this.exporter = exporter;
4241
}
4342

4443
public get currentTrace(): Trace {
@@ -66,7 +65,9 @@ export class Tracer {
6665
}
6766

6867
public endTrace(): void {
69-
if (!this.currentTrace) return debug('cannot end trace - no active trace found')
68+
if (!this.currentTrace){
69+
return debug('cannot end trace - no active trace found')
70+
}
7071
this.currentTrace.end();
7172
this.addEndedTrace(this.currentTrace);
7273
//this.clearCurrentTrace();
@@ -81,7 +82,7 @@ export class Tracer {
8182
if (!this.currentTrace) {
8283
debug('no current trace found - cannot start a new span');
8384
} else {
84-
newSpan = this.currentTrace.startSpan(name, type)
85+
newSpan = this.currentTrace.startSpan(name, type);
8586
}
8687
return newSpan;
8788
}
@@ -120,6 +121,10 @@ export class Tracer {
120121
namespace.bindEmitter(emitter);
121122
}
122123

124+
public registerExporter(exporter:Exporter) {
125+
this.exporter = exporter;
126+
}
127+
123128
}
124129

125130

0 commit comments

Comments
 (0)