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