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

telemetry.NewLog   A

Complexity

Conditions 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
package telemetry
2
3
import (
4
	"os"
5
	"runtime"
6
7
	"go.opentelemetry.io/otel/attribute"
8
9
	sdk "github.com/agoda-com/opentelemetry-logs-go/sdk/logs"
10
11
	"go.opentelemetry.io/otel/sdk/resource"
12
	semconv "go.opentelemetry.io/otel/semconv/v1.10.0"
13
14
	"github.com/Permify/permify/internal"
15
)
16
17
// NewLog - Creates new log
18
func NewLog(exporter sdk.LogRecordExporter) *sdk.LoggerProvider {
19
	// Create a logger provider with the exporter and resource
20
	lp := sdk.NewLoggerProvider(
21
		sdk.WithBatcher(exporter),
22
		sdk.WithResource(newResource()),
23
	)
24
25
	// Return the logger provider
26
	return lp
27
}
28
29
func newResource() *resource.Resource {
30
	hostName, _ := os.Hostname()
31
	return resource.NewWithAttributes(
32
		semconv.SchemaURL,
33
		semconv.ServiceNameKey.String("permify"),
34
		semconv.HostNameKey.String(hostName),
35
		attribute.String("id", internal.Identifier),
36
		attribute.String("project.id", internal.Identifier),
37
		attribute.String("version", internal.Version),
38
		attribute.String("host_name", hostName),
39
		attribute.String("os", runtime.GOOS),
40
		attribute.String("arch", runtime.GOARCH),
41
	)
42
}
43