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

logexporters.NewOTLP   A

Complexity

Conditions 4

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 13
nop 4
dl 0
loc 22
rs 9.75
c 0
b 0
f 0
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