Total Lines | 31 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package tracerexporters |
||
2 | |||
3 | import ( |
||
4 | "context" |
||
5 | |||
6 | "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc" |
||
7 | "go.opentelemetry.io/otel/sdk/trace" |
||
8 | "google.golang.org/grpc/credentials" |
||
9 | ) |
||
10 | |||
11 | // NewOTLPGrpc - Creates new OTLP exporter using GRPC protocol. |
||
12 | func NewOTLPGrpc(endpoint string, insecure bool) (trace.SpanExporter, error) { |
||
13 | var exporter trace.SpanExporter |
||
14 | var err error |
||
15 | |||
16 | opts := []otlptracegrpc.Option{ |
||
17 | otlptracegrpc.WithEndpoint(endpoint), |
||
18 | } |
||
19 | |||
20 | if insecure { |
||
21 | opts = append(opts, otlptracegrpc.WithInsecure()) |
||
22 | } else { |
||
23 | opts = append(opts, otlptracegrpc.WithTLSCredentials(credentials.NewClientTLSFromCert(nil, ""))) |
||
24 | } |
||
25 | |||
26 | exporter, err = otlptracegrpc.New(context.Background(), opts...) |
||
27 | if err != nil { |
||
28 | return nil, err |
||
29 | } |
||
30 | |||
31 | return exporter, nil |
||
32 | } |
||
33 |