Skip to content

Commit ce5d255

Browse files
committed
feat: Documenation
1 parent 9a6c949 commit ce5d255

File tree

5 files changed

+75
-48
lines changed

5 files changed

+75
-48
lines changed

packages/browser/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"extends": "./tsconfig.build.json",
3-
"include": ["src/**/*", "test/**/*", "../opentracing/src/sessiontracking.ts"],
3+
"include": ["src/**/*", "test/**/*"],
44
"exclude": ["dist"],
55
"compilerOptions": {
66
"rootDir": ".",

packages/opentracing/src/opentracingintegration.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,27 @@ export class OpenTracingIntegration implements Integration {
1919
* Constructor for OpenTracingIntegration
2020
*
2121
* @param traceId Optional TraceId that should be set into the integration.
22-
* @param tracer Optional custom tracer that should be used.
22+
* @param _tracer Optional custom tracer that should be used.
2323
*/
24-
public constructor(traceId?: string, private readonly tracer: Tracer = new Tracer()) {
25-
tracer.setTraceId(traceId);
24+
public constructor(traceId?: string, private readonly _tracer: Tracer = new Tracer()) {
25+
_tracer.setTraceId(traceId);
2626
}
2727

2828
/**
2929
* @inheritDoc
3030
*/
3131
public setupOnce(): void {
32-
const span = this.tracer.startSpan('sdk.init');
32+
const span = this._tracer.startSpan('sdk.init');
3333
span.finish();
3434
setTimeout(() => {
35-
this.tracer.flush();
35+
this._tracer.flush();
3636
});
3737
}
3838

3939
/**
4040
* Returns the Tracer which can be used as the parent.
4141
*/
4242
public getTracer(): Tracer {
43-
return this.tracer;
43+
return this._tracer;
4444
}
4545
}

packages/opentracing/src/span.ts

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,25 @@ import * as opentracing from 'opentracing';
33
import { SpanContext } from './spancontext';
44
import { Tracer } from './tracer';
55

6-
/** JSDoc */
6+
/**
7+
* Interface for log entries.
8+
*/
79
interface Log {
810
data: { [key: string]: any };
911
timestamp?: number;
1012
}
1113

12-
/** JSDoc */
14+
/**
15+
* Span represents a logical unit of work as part of a broader Trace. Examples
16+
* of span might include remote procedure calls or a in-process function calls
17+
* to sub-components. A Trace has a single, top-level "root" Span that in turn
18+
* may have zero or more child Spans, which in turn may have children.
19+
*/
1320
export class Span extends opentracing.Span implements SpanInterface {
14-
private flushed: boolean = false;
15-
private finishTime: number = 0;
21+
private _flushed: boolean = false;
22+
private _finishTime: number = 0;
1623

17-
private readonly logs: Log[] = [];
24+
private readonly _logs: Log[] = [];
1825

1926
public tags: {
2027
[key: string]: string;
@@ -25,11 +32,11 @@ export class Span extends opentracing.Span implements SpanInterface {
2532
} = {};
2633

2734
public constructor(
28-
private readonly usedTracer: Tracer,
29-
private operation: string,
30-
private readonly spanContext: SpanContext,
31-
private readonly references?: opentracing.Reference[],
32-
private readonly startTime: number = Date.now(),
35+
private readonly _usedTracer: Tracer,
36+
private _operation: string,
37+
private readonly _spanContext: SpanContext,
38+
private readonly _references?: opentracing.Reference[],
39+
private readonly _startTime: number = Date.now(),
3340
) {
3441
super();
3542
}
@@ -38,29 +45,33 @@ export class Span extends opentracing.Span implements SpanInterface {
3845
* Returns the context.
3946
*/
4047
protected _context(): SpanContext {
41-
return this.spanContext;
48+
return this._spanContext;
4249
}
4350

4451
/**
4552
* Returns the tracer passed to the span.
4653
*/
4754
protected _tracer(): Tracer {
48-
return this.usedTracer;
55+
return this._usedTracer;
4956
}
5057

5158
/**
5259
* Sets the operation name.
5360
*/
5461
protected _setOperationName(name: string): void {
55-
this.operation = name;
62+
this._operation = name;
5663
}
5764

58-
/** JSDoc */
65+
/**
66+
* Implementation for {@link setBaggageItem}
67+
*/
5968
protected _setBaggageItem(key: string, value: string): void {
6069
this.baggage[key] = value;
6170
}
6271

63-
/** JSDoc */
72+
/**
73+
* Implementation for {@link getBaggageItem}
74+
*/
6475
protected _getBaggageItem(key: string): string | undefined {
6576
return this.baggage[key];
6677
}
@@ -78,69 +89,69 @@ export class Span extends opentracing.Span implements SpanInterface {
7889
/**
7990
* Store log entry.
8091
*/
81-
protected _log(data: { [key: string]: any }, timestamp?: number): void {
82-
this.logs.push({
92+
protected _log(data: { [key: string]: any }, timestamp: number = Date.now() / 1000): void {
93+
this._logs.push({
8394
data,
8495
timestamp,
8596
});
8697
}
8798

8899
/**
89-
* JSDoc
100+
* Implementation for {@link finish}
90101
*/
91-
protected _finish(finishTime?: number): void {
92-
this.finishTime = finishTime || Date.now();
102+
protected _finish(finishTime: number = Date.now()): void {
103+
this._finishTime = finishTime;
93104
}
94105

95106
/**
96107
* Returns the operationName.
97108
*/
98109
public getOperationName(): string {
99-
return this.operation;
110+
return this._operation;
100111
}
101112

102113
/**
103114
* Returns the duration of the span.
104115
*/
105116
public duration(): number {
106-
return this.finishTime - this.startTime;
117+
return this._finishTime - this._startTime;
107118
}
108119

109120
/**
110121
* Returns wether the span has been finished.
111122
*/
112123
public isFinished(): boolean {
113-
return this.finishTime > 0;
124+
return this._finishTime > 0;
114125
}
115126

116127
/**
117128
* Marks the span as flushed.
118129
*/
119130
public flush(): this {
120-
this.flushed = true;
131+
this._flushed = true;
121132
return this;
122133
}
123134

124135
/**
125136
* Returns wether the span has already be flushed.
126137
*/
127138
public isFlushed(): boolean {
128-
return this.flushed;
139+
return this._flushed;
129140
}
130141

131142
/**
132143
* @inheritdoc
133144
*/
134145
public toJSON(): object {
135146
return {
136-
finish_time: (this.finishTime && this.finishTime / 1000) || undefined,
137-
logs: this.logs.length === 0 ? undefined : this.logs,
138-
operation: this.operation,
139-
references: this.references && this.references,
140-
span_id: this.spanContext.spanId,
141-
start_time: this.startTime / 1000,
147+
finish_time: (this._finishTime && this._finishTime / 1000) || undefined,
148+
logs: this._logs.length === 0 ? undefined : this._logs,
149+
operation: this._operation,
150+
references: this._references && this._references,
151+
span_id: this._spanContext.spanId,
152+
start_time: this._startTime / 1000,
142153
tags: Object.keys(this.tags).length === 0 ? undefined : this.tags,
143-
trace_id: this.spanContext.traceId,
154+
trace_id: this._spanContext.traceId,
144155
};
145156
}
146157
}

packages/opentracing/src/spancontext.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import { uuid4 } from '@sentry/utils/misc';
2+
23
/**
3-
* JSDoc
4+
* SpanContext represents Span state that must propagate to descendant Spans
5+
* and across process boundaries.
6+
*
7+
* SpanContext is logically divided into two pieces: the user-level "Baggage"
8+
* (see setBaggageItem and getBaggageItem) that propagates across Span
9+
* boundaries and any Tracer-implementation-specific fields that are needed to
10+
* identify or otherwise contextualize the associated Span instance (e.g., a
11+
* <trace_id, span_id, sampled> tuple).
412
*/
513
export class SpanContext {
614
public constructor(

packages/opentracing/src/tracer.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,28 @@ import { Span } from './span';
44
import { SpanContext } from './spancontext';
55

66
/**
7-
* JSDoc
7+
* Tracer is the entry-point between the instrumentation API and the tracing
8+
* implementation.
9+
*
10+
* The default object acts as a no-op implementation.
11+
*
12+
* Note to implementators: derived classes can choose to directly implement the
13+
* methods in the "OpenTracing API methods" section, or optionally the subset of
14+
* underscore-prefixed methods to pick up the argument checking and handling
15+
* automatically from the base class.
816
*/
917
export class Tracer extends opentracing.Tracer {
10-
private traceId?: string = undefined;
11-
private readonly spans: Span[] = [];
18+
private _traceId?: string = undefined;
19+
private readonly _spans: Span[] = [];
1220

1321
/**
1422
* Called by public method startSpan
1523
* @param name Name of the operation
1624
* @param fields Options for the span {@link opentracing.SpanOptions}
1725
*/
1826
protected _startSpan(name: string, fields: opentracing.SpanOptions): Span {
19-
const span = new Span(this, name, new SpanContext(this.traceId), fields.references, fields.startTime);
20-
this.spans.push(span);
27+
const span = new Span(this, name, new SpanContext(this._traceId), fields.references, fields.startTime);
28+
this._spans.push(span);
2129
return span;
2230
}
2331

@@ -34,18 +42,18 @@ export class Tracer extends opentracing.Tracer {
3442
* @param traceId A string representing the traceId
3543
*/
3644
public setTraceId(traceId?: string): void {
37-
this.traceId = traceId;
45+
this._traceId = traceId;
3846
}
3947

4048
/**
4149
* Flushes all spans and sends an event
4250
*/
4351
public flush(): void {
44-
const finishedSpans = this.spans.filter((span: Span) => span.isFinished() && !span.isFlushed());
52+
const finishedSpans = this._spans.filter((span: Span) => span.isFinished() && !span.isFlushed());
4553
if (finishedSpans.length) {
4654
getCurrentHub().captureEvent({
4755
spans: finishedSpans.map((span: Span) => span.flush()),
48-
type: 'none',
56+
type: 'none', // This ensures a Sentry event will not be created on the server
4957
});
5058
}
5159
}

0 commit comments

Comments
 (0)