1 // Copyright 2018, OpenCensus Authors
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
20 "go.opencensus.io/trace/internal"
23 // Config represents the global tracing configuration.
25 // DefaultSampler is the default sampler used when creating new spans.
26 DefaultSampler Sampler
28 // IDGenerator is for internal use only.
29 IDGenerator internal.IDGenerator
31 // MaxAnnotationEventsPerSpan is max number of annotation events per span
32 MaxAnnotationEventsPerSpan int
34 // MaxMessageEventsPerSpan is max number of message events per span
35 MaxMessageEventsPerSpan int
37 // MaxAnnotationEventsPerSpan is max number of attributes per span
38 MaxAttributesPerSpan int
40 // MaxLinksPerSpan is max number of links per span
44 var configWriteMu sync.Mutex
47 // DefaultMaxAnnotationEventsPerSpan is default max number of annotation events per span
48 DefaultMaxAnnotationEventsPerSpan = 32
50 // DefaultMaxMessageEventsPerSpan is default max number of message events per span
51 DefaultMaxMessageEventsPerSpan = 128
53 // DefaultMaxAttributesPerSpan is default max number of attributes per span
54 DefaultMaxAttributesPerSpan = 32
56 // DefaultMaxLinksPerSpan is default max number of links per span
57 DefaultMaxLinksPerSpan = 32
60 // ApplyConfig applies changes to the global tracing configuration.
62 // Fields not provided in the given config are going to be preserved.
63 func ApplyConfig(cfg Config) {
65 defer configWriteMu.Unlock()
66 c := *config.Load().(*Config)
67 if cfg.DefaultSampler != nil {
68 c.DefaultSampler = cfg.DefaultSampler
70 if cfg.IDGenerator != nil {
71 c.IDGenerator = cfg.IDGenerator
73 if cfg.MaxAnnotationEventsPerSpan > 0 {
74 c.MaxAnnotationEventsPerSpan = cfg.MaxAnnotationEventsPerSpan
76 if cfg.MaxMessageEventsPerSpan > 0 {
77 c.MaxMessageEventsPerSpan = cfg.MaxMessageEventsPerSpan
79 if cfg.MaxAttributesPerSpan > 0 {
80 c.MaxAttributesPerSpan = cfg.MaxAttributesPerSpan
82 if cfg.MaxLinksPerSpan > 0 {
83 c.MaxLinksPerSpan = cfg.MaxLinksPerSpan