This repository was archived by the owner on Nov 10, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +34
-4
lines changed Expand file tree Collapse file tree 3 files changed +34
-4
lines changed Original file line number Diff line number Diff line change 14
14
* limitations under the License.
15
15
*/
16
16
17
- import { ProxyTracerProvider } from '../trace/ProxyTracerProvider' ;
18
- import { Tracer } from '../trace/tracer' ;
19
- import { TracerProvider } from '../trace/tracer_provider' ;
20
- import { isSpanContextValid } from '../trace/spancontext-utils' ;
21
17
import {
22
18
getGlobal ,
23
19
registerGlobal ,
24
20
unregisterGlobal ,
25
21
} from '../internal/global-utils' ;
22
+ import { ProxyTracerProvider } from '../trace/ProxyTracerProvider' ;
23
+ import {
24
+ isSpanContextValid ,
25
+ wrapSpanContext ,
26
+ } from '../trace/spancontext-utils' ;
27
+ import { Tracer } from '../trace/tracer' ;
28
+ import { TracerProvider } from '../trace/tracer_provider' ;
26
29
27
30
const API_NAME = 'trace' ;
28
31
@@ -76,5 +79,7 @@ export class TraceAPI {
76
79
this . _proxyTracerProvider = new ProxyTracerProvider ( ) ;
77
80
}
78
81
82
+ public wrapSpanContext = wrapSpanContext ;
83
+
79
84
public isSpanContextValid = isSpanContextValid ;
80
85
}
Original file line number Diff line number Diff line change 13
13
* See the License for the specific language governing permissions and
14
14
* limitations under the License.
15
15
*/
16
+ import { NonRecordingSpan } from './NonRecordingSpan' ;
17
+ import { Span } from './span' ;
16
18
import { SpanContext } from './span_context' ;
17
19
import { TraceFlags } from './trace_flags' ;
18
20
@@ -43,3 +45,13 @@ export function isSpanContextValid(spanContext: SpanContext): boolean {
43
45
isValidTraceId ( spanContext . traceId ) && isValidSpanId ( spanContext . spanId )
44
46
) ;
45
47
}
48
+
49
+ /**
50
+ * Wrap the given {@link SpanContext} in a new non-recording {@link Span}
51
+ *
52
+ * @param spanContext span context to be wrapped
53
+ * @returns a new non-recording {@link Span} with the provided context
54
+ */
55
+ export function wrapSpanContext ( spanContext : SpanContext ) : Span {
56
+ return new NonRecordingSpan ( spanContext ) ;
57
+ }
Original file line number Diff line number Diff line change @@ -54,4 +54,17 @@ describe('spancontext-utils', () => {
54
54
} ;
55
55
assert . ok ( ! context . isSpanContextValid ( spanContext ) ) ;
56
56
} ) ;
57
+
58
+ it ( 'should wrap a SpanContext in a non-recording span' , ( ) => {
59
+ const spanContext = {
60
+ traceId : 'd4cda95b652f4a1592b449d5929fda1b' ,
61
+ spanId : '6e0c63257de34c92' ,
62
+ traceFlags : TraceFlags . NONE ,
63
+ } ;
64
+
65
+ const span = context . wrapSpanContext ( spanContext ) ;
66
+
67
+ assert . deepStrictEqual ( span . spanContext ( ) , spanContext ) ;
68
+ assert . strictEqual ( span . isRecording ( ) , false ) ;
69
+ } ) ;
57
70
} ) ;
You can’t perform that action at this time.
0 commit comments