/
noOpSpan.ts
78 lines (69 loc) · 1.67 KB
/
noOpSpan.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { Span, SpanContext, Attributes, Status, TraceFlags } from "@opentelemetry/api";
/**
* A no-op implementation of Span that can safely be used without side-effects.
*/
export class NoOpSpan implements Span {
/**
* Returns the SpanContext associated with this Span.
*/
context(): SpanContext {
return {
spanId: "",
traceId: "",
traceFlags: TraceFlags.NONE
};
}
/**
* Marks the end of Span execution.
* @param _endTime The time to use as the Span's end time. Defaults to
* the current time.
*/
end(_endTime?: number): void {
/* Noop */
}
/**
* Sets an attribute on the Span
* @param _key the attribute key
* @param _value the attribute value
*/
setAttribute(_key: string, _value: unknown): this {
return this;
}
/**
* Sets attributes on the Span
* @param _attributes the attributes to add
*/
setAttributes(_attributes: Attributes): this {
return this;
}
/**
* Adds an event to the Span
* @param _name The name of the event
* @param _attributes The associated attributes to add for this event
*/
addEvent(_name: string, _attributes?: Attributes): this {
return this;
}
/**
* Sets a status on the span. Overrides the default of CanonicalCode.OK.
* @param _status The status to set.
*/
setStatus(_status: Status): this {
return this;
}
/**
* Updates the name of the Span
* @param _name the new Span name
*/
updateName(_name: string): this {
return this;
}
/**
* Returns whether this span will be recorded
*/
isRecording(): boolean {
return false;
}
}