1 /* 2 * Copyright 2017, 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 17 package io.opencensus.trace.config; 18 19 /** 20 * Global configuration of the trace service. This allows users to change configs for the default 21 * sampler, maximum events to be kept, etc. (see {@link TraceParams} for details). 22 * 23 * @since 0.5 24 */ 25 public abstract class TraceConfig { 26 private static final NoopTraceConfig NOOP_TRACE_CONFIG = new NoopTraceConfig(); 27 28 /** 29 * Returns the active {@code TraceParams}. 30 * 31 * @return the active {@code TraceParams}. 32 * @since 0.5 33 */ getActiveTraceParams()34 public abstract TraceParams getActiveTraceParams(); 35 36 /** 37 * Updates the active {@link TraceParams}. 38 * 39 * @param traceParams the new active {@code TraceParams}. 40 * @since 0.5 41 */ updateActiveTraceParams(TraceParams traceParams)42 public abstract void updateActiveTraceParams(TraceParams traceParams); 43 44 /** 45 * Returns the no-op implementation of the {@code TraceConfig}. 46 * 47 * @return the no-op implementation of the {@code TraceConfig}. 48 * @since 0.5 49 */ getNoopTraceConfig()50 public static TraceConfig getNoopTraceConfig() { 51 return NOOP_TRACE_CONFIG; 52 } 53 54 private static final class NoopTraceConfig extends TraceConfig { 55 56 @Override getActiveTraceParams()57 public TraceParams getActiveTraceParams() { 58 return TraceParams.DEFAULT; 59 } 60 61 @Override updateActiveTraceParams(TraceParams traceParams)62 public void updateActiveTraceParams(TraceParams traceParams) {} 63 } 64 } 65