...

Source file src/go.opencensus.io/trace/config.go

Documentation: go.opencensus.io/trace

     1  // Copyright 2018, OpenCensus Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package trace
    16  
    17  import (
    18  	"sync"
    19  
    20  	"go.opencensus.io/trace/internal"
    21  )
    22  
    23  // Config represents the global tracing configuration.
    24  type Config struct {
    25  	// DefaultSampler is the default sampler used when creating new spans.
    26  	DefaultSampler Sampler
    27  
    28  	// IDGenerator is for internal use only.
    29  	IDGenerator internal.IDGenerator
    30  
    31  	// MaxAnnotationEventsPerSpan is max number of annotation events per span
    32  	MaxAnnotationEventsPerSpan int
    33  
    34  	// MaxMessageEventsPerSpan is max number of message events per span
    35  	MaxMessageEventsPerSpan int
    36  
    37  	// MaxAnnotationEventsPerSpan is max number of attributes per span
    38  	MaxAttributesPerSpan int
    39  
    40  	// MaxLinksPerSpan is max number of links per span
    41  	MaxLinksPerSpan int
    42  }
    43  
    44  var configWriteMu sync.Mutex
    45  
    46  const (
    47  	// DefaultMaxAnnotationEventsPerSpan is default max number of annotation events per span
    48  	DefaultMaxAnnotationEventsPerSpan = 32
    49  
    50  	// DefaultMaxMessageEventsPerSpan is default max number of message events per span
    51  	DefaultMaxMessageEventsPerSpan = 128
    52  
    53  	// DefaultMaxAttributesPerSpan is default max number of attributes per span
    54  	DefaultMaxAttributesPerSpan = 32
    55  
    56  	// DefaultMaxLinksPerSpan is default max number of links per span
    57  	DefaultMaxLinksPerSpan = 32
    58  )
    59  
    60  // ApplyConfig applies changes to the global tracing configuration.
    61  //
    62  // Fields not provided in the given config are going to be preserved.
    63  func ApplyConfig(cfg Config) {
    64  	configWriteMu.Lock()
    65  	defer configWriteMu.Unlock()
    66  	c := *config.Load().(*Config)
    67  	if cfg.DefaultSampler != nil {
    68  		c.DefaultSampler = cfg.DefaultSampler
    69  	}
    70  	if cfg.IDGenerator != nil {
    71  		c.IDGenerator = cfg.IDGenerator
    72  	}
    73  	if cfg.MaxAnnotationEventsPerSpan > 0 {
    74  		c.MaxAnnotationEventsPerSpan = cfg.MaxAnnotationEventsPerSpan
    75  	}
    76  	if cfg.MaxMessageEventsPerSpan > 0 {
    77  		c.MaxMessageEventsPerSpan = cfg.MaxMessageEventsPerSpan
    78  	}
    79  	if cfg.MaxAttributesPerSpan > 0 {
    80  		c.MaxAttributesPerSpan = cfg.MaxAttributesPerSpan
    81  	}
    82  	if cfg.MaxLinksPerSpan > 0 {
    83  		c.MaxLinksPerSpan = cfg.MaxLinksPerSpan
    84  	}
    85  	config.Store(&c)
    86  }
    87  

View as plain text