UNPKG

2.93 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 /** Sets the current root span. */
35 currentRootSpan: types.Span;
36 /** Sets the current root span. */
37 setCurrentRootSpan(root: types.Span): void;
38 /**
39 * Starts a root span.
40 * @param options A TraceOptions object to start a root span.
41 * @param fn A callback function to run after starting a root span.
42 */
43 startRootSpan<T>(options: types.TraceOptions, fn: (root: types.Span) => T): T;
44 /** Notifies listeners of the span start. */
45 onStartSpan(span: types.Span): void;
46 /** Notifies listeners of the span end. */
47 onEndSpan(span: types.Span): void;
48 /** Clears the current root span. */
49 clearCurrentTrace(): void;
50 /**
51 * Starts a span.
52 * @param [options] A SpanOptions object to start a child span.
53 */
54 startChildSpan(options?: types.SpanOptions): types.Span;
55 /**
56 * Binds the trace context to the given function.
57 * This is necessary in order to create child spans correctly in functions
58 * that are called asynchronously (for example, in a network response
59 * handler).
60 * @param fn A function to which to bind the trace context.
61 */
62 wrap<T>(fn: types.Func<T>): types.Func<T>;
63 /**
64 * Binds the trace context to the given event emitter.
65 * This is necessary in order to create child spans correctly in event
66 * handlers.
67 * @param emitter An event emitter whose handlers should have
68 * the trace context binded to them.
69 */
70 wrapEmitter(emitter: NodeJS.EventEmitter): void;
71}