1 // Copyright 2017, 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.
23 // Exporter is a type for functions that receive sampled trace spans.
25 // The ExportSpan method should be safe for concurrent use and should return
26 // quickly; if an Exporter takes a significant amount of time to process a
27 // SpanData, that work should be done on another goroutine.
29 // The SpanData should not be modified, but a pointer to it can be kept.
30 type Exporter interface {
31 ExportSpan(s *SpanData)
34 type exportersMap map[Exporter]struct{}
38 exporters atomic.Value
41 // RegisterExporter adds to the list of Exporters that will receive sampled
44 // Binaries can register exporters, libraries shouldn't register exporters.
45 func RegisterExporter(e Exporter) {
47 new := make(exportersMap)
48 if old, ok := exporters.Load().(exportersMap); ok {
49 for k, v := range old {
58 // UnregisterExporter removes from the list of Exporters the Exporter that was
59 // registered with the given name.
60 func UnregisterExporter(e Exporter) {
62 new := make(exportersMap)
63 if old, ok := exporters.Load().(exportersMap); ok {
64 for k, v := range old {
73 // SpanData contains all the information collected by a Span.
74 type SpanData struct {
80 // The wall clock time of EndTime will be adjusted to always be offset
81 // from StartTime by the duration of the span.
83 // The values of Attributes each have type string, bool, or int64.
84 Attributes map[string]interface{}
85 Annotations []Annotation
86 MessageEvents []MessageEvent
90 DroppedAttributeCount int
91 DroppedAnnotationCount int
92 DroppedMessageEventCount int
95 // ChildSpanCount holds the number of child span created for this span.