github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/tracing/otlp.go (about)

     1  package tracing
     2  
     3  import (
     4  	"go.opentelemetry.io/otel/exporters/otlp"
     5  	export "go.opentelemetry.io/otel/sdk/export/trace"
     6  	"google.golang.org/grpc/credentials"
     7  )
     8  
     9  // OTLP service to export traces to
    10  type OTLP struct {
    11  	Address string            `long:"otlp-address" description:"otlp address to send traces to"`
    12  	Headers map[string]string `long:"otlp-header" description:"headers to attach to each tracing message"`
    13  	UseTLS  bool              `long:"otlp-use-tls" description:"whether to use tls or not"`
    14  }
    15  
    16  // IsConfigured identifies if an Address has been set
    17  func (s OTLP) IsConfigured() bool {
    18  	return s.Address != ""
    19  }
    20  
    21  func (s OTLP) security() otlp.ExporterOption {
    22  	if s.UseTLS {
    23  		return otlp.WithTLSCredentials(credentials.NewClientTLSFromCert(nil, ""))
    24  	}
    25  
    26  	return otlp.WithInsecure()
    27  }
    28  
    29  // Exporter returns a SpanExporter to sync spans to OTLP
    30  func (s OTLP) Exporter() (export.SpanSyncer, error) {
    31  	options := []otlp.ExporterOption{
    32  		otlp.WithAddress(s.Address),
    33  		otlp.WithHeaders(s.Headers),
    34  		s.security(),
    35  	}
    36  
    37  	exporter, err := otlp.NewExporter(options...)
    38  
    39  	if err != nil {
    40  		return nil, err
    41  	}
    42  
    43  	return exporter, nil
    44  }