Passed
Push — master ( 8dc111...68a08a )
by Tolga
02:45 queued 16s
created

meterexporters.NewOTLPGrpc   A

Complexity

Conditions 3

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 11
nop 2
dl 0
loc 17
rs 9.85
c 0
b 0
f 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