UNPKG

2.98 kBTypeScriptView Raw
1/**
2 * Copyright 2018, OpenCensus Authors
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/// <reference types="node" />
17import { CoreTracerBase } from './tracer-base';
18import * as types from './types';
19/**
20 * This class represents a tracer with Continuation Local Storage (CLS).
21 *
22 * CLS helps keep tracking the root span over function calls automatically.
23 * It is capable of storing, propagating and retrieving arbitrary
24 * continuation-local data (also called "context").
25 * CLS comes with some performance overhead, you can read more about it here:
26 * https://github.com/othiym23/node-continuation-local-storage/issues/59
27 */
28export declare class CoreTracer extends CoreTracerBase implements types.Tracer {
29 /** Manage context automatic propagation */
30 private contextManager;
31 /** Constructs a new TraceImpl instance. */
32 constructor();
33 /** Gets the current root span. */
34 get currentRootSpan(): types.Span;
35 /** Sets the current root span. */
36 set currentRootSpan(root: types.Span);
37 /** Sets the current root span. */
38 setCurrentRootSpan(root: types.Span): void;
39 /**
40 * Starts a root span.
41 * @param options A TraceOptions object to start a root span.
42 * @param fn A callback function to run after starting a root span.
43 */
44 startRootSpan<T>(options: types.TraceOptions, fn: (root: types.Span) => T): T;
45 /** Notifies listeners of the span start. */
46 onStartSpan(span: types.Span): void;
47 /** Notifies listeners of the span end. */
48 onEndSpan(span: types.Span): void;
49 /** Clears the current root span. */
50 clearCurrentTrace(): void;
51 /**
52 * Starts a span.
53 * @param [options] A SpanOptions object to start a child span.
54 */
55 startChildSpan(options?: types.SpanOptions): types.Span;
56 /**
57 * Binds the trace context to the given function.
58 * This is necessary in order to create child spans correctly in functions
59 * that are called asynchronously (for example, in a network response
60 * handler).
61 * @param fn A function to which to bind the trace context.
62 */
63 wrap<T>(fn: types.Func<T>): types.Func<T>;
64 /**
65 * Binds the trace context to the given event emitter.
66 * This is necessary in order to create child spans correctly in event
67 * handlers.
68 * @param emitter An event emitter whose handlers should have
69 * the trace context binded to them.
70 */
71 wrapEmitter(emitter: NodeJS.EventEmitter): void;
72}