Passed
Push — master ( 5fb140...f50c84 )
by Tolga
01:04 queued 13s
created

pkg/telemetry/logexporters/otlp.go   A

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 18
dl 0
loc 32
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A logexporters.NewOTLP 0 22 4
1
package logexporters
2
3
import (
4
	"context"
5
6
	"github.com/agoda-com/opentelemetry-logs-go/exporters/otlp/otlplogs"
7
	"github.com/agoda-com/opentelemetry-logs-go/exporters/otlp/otlplogs/otlplogshttp"
8
)
9
10
// NewOTLP - Creates new OTLP exporter using HTTP protocol.
11
func NewOTLP(endpoint string, insecure bool, urlpath string, headers map[string]string) (*otlplogs.Exporter, error) {
12
	options := []otlplogshttp.Option{
13
		otlplogshttp.WithCompression(otlplogshttp.GzipCompression),
14
		otlplogshttp.WithEndpoint(endpoint),
15
	}
16
17
	if urlpath != "" {
18
		options = append(options, otlplogshttp.WithURLPath(urlpath))
19
	}
20
21
	if insecure {
22
		options = append(options, otlplogshttp.WithInsecure())
23
	}
24
25
	exporter, err := otlplogs.NewExporter(context.Background(), otlplogs.WithClient(
26
		otlplogshttp.NewClient(options...),
27
	))
28
	if err != nil {
29
		return nil, err
30
	}
31
32
	return exporter, nil
33
}
34