This repository was archived by the owner on Oct 3, 2023. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -81,6 +81,9 @@ type Options struct {
8181 // MetricPrefix overrides the OpenCensus prefix of a stackdriver metric.
8282 // Optional.
8383 MetricPrefix string
84+
85+ // DefaultTraceAttributes will be appended to every span that is exported.
86+ DefaultTraceAttributes map [string ]interface {}
8487}
8588
8689// Exporter is a stats.Exporter and trace.Exporter
@@ -125,9 +128,24 @@ func (e *Exporter) ExportView(vd *view.Data) {
125128
126129// ExportSpan exports a SpanData to Stackdriver Trace.
127130func (e * Exporter ) ExportSpan (sd * trace.SpanData ) {
131+ if len (e .traceExporter .o .DefaultTraceAttributes ) > 0 {
132+ sd = e .sdWithDefaultTraceAttributes (sd )
133+ }
128134 e .traceExporter .ExportSpan (sd )
129135}
130136
137+ func (e * Exporter ) sdWithDefaultTraceAttributes (sd * trace.SpanData ) * trace.SpanData {
138+ newSD := * sd
139+ newSD .Attributes = make (map [string ]interface {})
140+ for k , v := range e .traceExporter .o .DefaultTraceAttributes {
141+ newSD .Attributes [k ] = v
142+ }
143+ for k , v := range sd .Attributes {
144+ newSD .Attributes [k ] = v
145+ }
146+ return & newSD
147+ }
148+
131149// Flush waits for exported data to be uploaded.
132150//
133151// This is useful if your program is ending and you do not
You can’t perform that action at this time.
0 commit comments