Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Commit

Permalink
Add with headers option to agent exporter (#43)
Browse files Browse the repository at this point in the history
The WithHeaders option adds the ability to send metadata headers at the
beginning of each gRPC stream connection for exporting spans.
  • Loading branch information
Steven Karis authored Feb 14, 2019
1 parent 531677e commit b04e1cc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ocagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"google.golang.org/api/support/bundler"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"

"go.opencensus.io/resource"
"go.opencensus.io/stats/view"
Expand Down Expand Up @@ -67,6 +68,7 @@ type Exporter struct {
reconnectionPeriod time.Duration
resource *resourcepb.Resource
compressor string
headers map[string]string

startOnce sync.Once
stopCh chan bool
Expand Down Expand Up @@ -191,7 +193,11 @@ func (ae *Exporter) enableConnectionStreams(cc *grpc.ClientConn) error {
func (ae *Exporter) createTraceServiceConnection(cc *grpc.ClientConn, node *commonpb.Node) error {
// Initiate the trace service by sending over node identifier info.
traceSvcClient := agenttracepb.NewTraceServiceClient(cc)
traceExporter, err := traceSvcClient.Export(context.Background())
ctx := context.Background()
if len(ae.headers) > 0 {
ctx = metadata.NewOutgoingContext(ctx, metadata.New(ae.headers))
}
traceExporter, err := traceSvcClient.Export(ctx)
if err != nil {
return fmt.Errorf("Exporter.Start:: TraceServiceClient: %v", err)
}
Expand Down
12 changes: 12 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,15 @@ func (c compressorSetter) withExporter(e *Exporter) {
func UseCompressor(compressorName string) ExporterOption {
return compressorSetter(compressorName)
}

type headerSetter map[string]string

func (h headerSetter) withExporter(e *Exporter) {
e.headers = map[string]string(h)
}

// WithHeaders will send the provided headers when the gRPC stream connection
// is instantiated
func WithHeaders(headers map[string]string) ExporterOption {
return headerSetter(headers)
}

0 comments on commit b04e1cc

Please sign in to comment.