1 | ;
|
2 | /**
|
3 | * Copyright 2018, OpenCensus Authors
|
4 | *
|
5 | * Licensed under the Apache License, Version 2.0 (the "License");
|
6 | * you may not use this file except in compliance with the License.
|
7 | * You may obtain a copy of the License at
|
8 | *
|
9 | * http://www.apache.org/licenses/LICENSE-2.0
|
10 | *
|
11 | * Unless required by applicable law or agreed to in writing, software
|
12 | * distributed under the License is distributed on an "AS IS" BASIS,
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14 | * See the License for the specific language governing permissions and
|
15 | * limitations under the License.
|
16 | */
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.ConsoleStatsExporter = exports.ConsoleExporter = exports.NoopExporter = void 0;
|
19 | const exporter_buffer_1 = require("./exporter-buffer");
|
20 | const logger = require("../common/console-logger");
|
21 | /** Do not send span data */
|
22 | class NoopExporter {
|
23 | onStartSpan(span) { }
|
24 | onEndSpan(span) { }
|
25 | publish(spans) {
|
26 | return Promise.resolve();
|
27 | }
|
28 | }
|
29 | exports.NoopExporter = NoopExporter;
|
30 | /** Format and sends span data to the console. */
|
31 | class ConsoleExporter {
|
32 | /**
|
33 | * Constructs a new ConsoleExporter instance.
|
34 | * @param config Exporter configuration object to create a console log
|
35 | * exporter.
|
36 | */
|
37 | constructor(config) {
|
38 | this.buffer = new exporter_buffer_1.ExporterBuffer(this, config);
|
39 | this.logger = config.logger || logger.logger();
|
40 | }
|
41 | onStartSpan(span) { }
|
42 | /**
|
43 | * Event called when a span is ended.
|
44 | * @param span Ended span.
|
45 | */
|
46 | onEndSpan(span) {
|
47 | // Add spans of a trace together when root is ended, skip non root spans.
|
48 | // publish function will extract child spans from root.
|
49 | if (!span.isRootSpan())
|
50 | return;
|
51 | this.buffer.addToBuffer(span);
|
52 | }
|
53 | /**
|
54 | * Sends the spans information to the console.
|
55 | * @param spans A list of spans to publish.
|
56 | */
|
57 | publish(spans) {
|
58 | spans.map(span => {
|
59 | const ROOT_STR = `RootSpan: {traceId: ${span.traceId}, spanId: ${span.id}, name: ${span.name} }`;
|
60 | const SPANS_STR = span.spans.map(child => [`\t\t{spanId: ${child.id}, name: ${child.name}}`].join('\n'));
|
61 | const result = [];
|
62 | result.push(ROOT_STR + '\n\tChildSpans:\n' + `${SPANS_STR.join('\n')}`);
|
63 | console.log(`${result}`);
|
64 | });
|
65 | return Promise.resolve();
|
66 | }
|
67 | }
|
68 | exports.ConsoleExporter = ConsoleExporter;
|
69 | /** Exporter that receives stats data and shows in the log console. */
|
70 | class ConsoleStatsExporter {
|
71 | /**
|
72 | * Event called when a view is registered
|
73 | * @param view registered view
|
74 | */
|
75 | onRegisterView(view) {
|
76 | console.log(`View registered: ${view.name}, Measure registered: ${view.measure.name}`);
|
77 | }
|
78 | /**
|
79 | * Event called when a measurement is recorded
|
80 | * @param view recorded view from measurement
|
81 | * @param measurement recorded measurement
|
82 | * @param tags The tags to which the value is applied
|
83 | */
|
84 | onRecord(views, measurement, tags) {
|
85 | console.log(`Measurement recorded: ${measurement.measure.name}`);
|
86 | }
|
87 | /**
|
88 | * Starts the Console exporter that polls Metric from Metrics library and
|
89 | * shows in the log console..
|
90 | */
|
91 | start() {
|
92 | // TODO(mayurkale): dependency with PR#253.
|
93 | }
|
94 | /** Stops the exporter. */
|
95 | stop() { }
|
96 | }
|
97 | exports.ConsoleStatsExporter = ConsoleStatsExporter;
|
98 | //# sourceMappingURL=console-exporter.js.map |
\ | No newline at end of file |