/**
 * Copyright 2018, OpenCensus Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */ import * as loggerTypes from '../common/types' ; import { Measurement , View } from '../stats/types' ; import { TagKey , TagValue } from '../tags/types' ; import * as modelTypes from '../trace/model/types' ; import { ExporterBuffer } from './exporter-buffer' ; import * as logger from '../common/console-logger' ; import { Exporter , ExporterConfig , StatsEventListener } from './types' ; /** Do not send span data */ export class NoopExporter implements Exporter { logger ? : loggerTypes . Logger ; onStartSpan ( span ) { } onEndSpan ( span ) { } publish ( spans ) { return Promise . resolve ( ) ; } } /** Format and sends span data to the console. */ export class ConsoleExporter implements Exporter { /** Buffer object to store the spans. */ logger : loggerTypes . Logger ; private buffer : ExporterBuffer ; param config constructor ( config ) { this . buffer = new ExporterBuffer ( this , config ) ; this . logger = config . logger || logger . logger ( ) ; } onStartSpan ( span ) { } param span onEndSpan ( span ) { if ( ! span . isRootSpan ( ) ) return ; this . buffer . addToBuffer ( span ) ; } param spans publish ( spans ) { spans . map ( span => { const ROOT_STR = `RootSpan: {traceId: ${ span . traceId }, spanId: ${ span . id }, name: ${ span . name } }` ; const SPANS_STR = span . spans . map ( child => [ `\t\t{spanId: ${ child . id }, name: ${ child . name }}` ] . join ( '\n' ) ) ; const result = [ ] ; result . push ( ROOT_STR + '\n\tChildSpans:\n' + `${ SPANS_STR . join ( '\n' ) }` ) ; console . log ( `${ result }` ) ; } ) ; return Promise . resolve ( ) ; } } /** Exporter that receives stats data and shows in the log console. */ export class ConsoleStatsExporter implements StatsEventListener { param view onRegisterView ( view ) { console . log ( `View registered: ${ view . name }, Measure registered: ${ view . measure . name }` ) ; } param view param measurement param tags onRecord ( views , measurement , tags ) { console . log ( `Measurement recorded: ${ measurement . measure . name }` ) ; } /**
     * Starts the Console exporter that polls Metric from Metrics library and
     * shows in the log console..
     */ start ( ) { } /** Stops the exporter. */ stop ( ) { } }