Skip to content

Commit 1aecc25

Browse files
committed
add getter methods
1 parent 0361d0a commit 1aecc25

File tree

11 files changed

+209
-233
lines changed

11 files changed

+209
-233
lines changed

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ linters:
8181
rules:
8282
- linters:
8383
- lll
84-
path: provider.go
84+
path: exporter.go
8585

8686
# Which file paths to exclude: they will be analyzed, but issues from them won't be reported.
8787
# "/" will be replaced by the current OS file path separator to properly work on Windows.

example/go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/hasura/gotel/example
22

3-
go 1.25.3
3+
go 1.25.5
44

55
require (
66
github.com/caarlos0/env/v11 v11.3.1
@@ -44,8 +44,8 @@ require (
4444
golang.org/x/net v0.47.0 // indirect
4545
golang.org/x/sys v0.38.0 // indirect
4646
golang.org/x/text v0.31.0 // indirect
47-
google.golang.org/genproto/googleapis/api v0.0.0-20251111163417-95abcf5c77ba // indirect
48-
google.golang.org/genproto/googleapis/rpc v0.0.0-20251111163417-95abcf5c77ba // indirect
47+
google.golang.org/genproto/googleapis/api v0.0.0-20251202230838-ff82c1b0f217 // indirect
48+
google.golang.org/genproto/googleapis/rpc v0.0.0-20251202230838-ff82c1b0f217 // indirect
4949
google.golang.org/grpc v1.77.0 // indirect
5050
google.golang.org/protobuf v1.36.10 // indirect
5151
)

example/go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM=
9797
golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM=
9898
gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk=
9999
gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E=
100-
google.golang.org/genproto/googleapis/api v0.0.0-20251111163417-95abcf5c77ba h1:B14OtaXuMaCQsl2deSvNkyPKIzq3BjfxQp8d00QyWx4=
101-
google.golang.org/genproto/googleapis/api v0.0.0-20251111163417-95abcf5c77ba/go.mod h1:G5IanEx8/PgI9w6CFcYQf7jMtHQhZruvfM1i3qOqk5U=
102-
google.golang.org/genproto/googleapis/rpc v0.0.0-20251111163417-95abcf5c77ba h1:UKgtfRM7Yh93Sya0Fo8ZzhDP4qBckrrxEr2oF5UIVb8=
103-
google.golang.org/genproto/googleapis/rpc v0.0.0-20251111163417-95abcf5c77ba/go.mod h1:7i2o+ce6H/6BluujYR+kqX3GKH+dChPTQU19wjRPiGk=
100+
google.golang.org/genproto/googleapis/api v0.0.0-20251202230838-ff82c1b0f217 h1:fCvbg86sFXwdrl5LgVcTEvNC+2txB5mgROGmRL5mrls=
101+
google.golang.org/genproto/googleapis/api v0.0.0-20251202230838-ff82c1b0f217/go.mod h1:+rXWjjaukWZun3mLfjmVnQi18E1AsFbDN9QdJ5YXLto=
102+
google.golang.org/genproto/googleapis/rpc v0.0.0-20251202230838-ff82c1b0f217 h1:gRkg/vSppuSQoDjxyiGfN4Upv/h/DQmIR10ZU8dh4Ww=
103+
google.golang.org/genproto/googleapis/rpc v0.0.0-20251202230838-ff82c1b0f217/go.mod h1:7i2o+ce6H/6BluujYR+kqX3GKH+dChPTQU19wjRPiGk=
104104
google.golang.org/grpc v1.77.0 h1:wVVY6/8cGA6vvffn+wWK5ToddbgdU3d8MNENr4evgXM=
105105
google.golang.org/grpc v1.77.0/go.mod h1:z0BY1iVj0q8E1uSQCjL9cppRj+gnZjzDnzV0dHhrNig=
106106
google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE=

exporter.go

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
package gotel
2+
3+
import "errors"
4+
5+
// OTLPCompressionType represents the compression type enum for OTLP.
6+
type OTLPCompressionType string
7+
8+
const (
9+
// OTLPCompressionNone is the enum that disables compression.
10+
OTLPCompressionNone OTLPCompressionType = "none"
11+
// OTLPCompressionGzip is the enum that enable compression of gzip algorithm.
12+
OTLPCompressionGzip OTLPCompressionType = "gzip"
13+
)
14+
15+
// OTLPProtocol represents the OTLP protocol enum.
16+
type OTLPProtocol string
17+
18+
const (
19+
// OTLPProtocolGRPC represents the gRPC OTLP protocol enum.
20+
OTLPProtocolGRPC OTLPProtocol = "grpc"
21+
// OTLPProtocolHTTPProtobuf represents the HTTP Protobuf OTLP protocol enum.
22+
OTLPProtocolHTTPProtobuf OTLPProtocol = "http/protobuf"
23+
)
24+
25+
// OTELMetricsExporterType defines the type of OpenTelemetry metrics exporter.
26+
type OTELMetricsExporterType string
27+
28+
const (
29+
// OTELMetricsExporterNone represents a enum that disables the metrics exporter.
30+
OTELMetricsExporterNone OTELMetricsExporterType = "none"
31+
// OTELMetricsExporterOTLP represents a enum that enables the metrics exporter via OTLP protocol.
32+
OTELMetricsExporterOTLP OTELMetricsExporterType = "otlp"
33+
// OTELMetricsExporterPrometheus represents a enum that enables the metrics exporter via Prometheus.
34+
OTELMetricsExporterPrometheus OTELMetricsExporterType = "prometheus"
35+
)
36+
37+
// OTELLogsExporterType defines the type of OpenTelemetry logs exporter.
38+
type OTELLogsExporterType string
39+
40+
const (
41+
// OTELLogsExporterNone represents a enum that disables the logs exporter.
42+
OTELLogsExporterNone OTELLogsExporterType = "none"
43+
// OTELLogsExporterOTLP represents a enum that enables the logs exporter via OTLP protocol.
44+
OTELLogsExporterOTLP OTELLogsExporterType = "otlp"
45+
)
46+
47+
var (
48+
errInvalidOTLPCompressionType = errors.New(
49+
"invalid OTLP compression type, accept none, gzip only",
50+
)
51+
errInvalidOTELMetricExporterType = errors.New("invalid OTEL metrics exporter type")
52+
errInvalidOTLPProtocol = errors.New("invalid OTLP protocol")
53+
errMetricsOTLPEndpointRequired = errors.New("OTLP endpoint is required for metrics exporter")
54+
)
55+
56+
// OTLPConfig contains configuration for OpenTelemetry exporter.
57+
type OTLPConfig struct {
58+
// OpenTelemetry service name.
59+
ServiceName string `json:"serviceName,omitempty" yaml:"serviceName,omitempty" env:"OTEL_SERVICE_NAME" help:"OpenTelemetry service name."`
60+
// OTLP receiver endpoint that is set as default for all types.
61+
OtlpEndpoint string `json:"otlpEndpoint,omitempty" yaml:"otlpEndpoint,omitempty" env:"OTEL_EXPORTER_OTLP_ENDPOINT" help:"OTLP receiver endpoint that is set as default for all types."`
62+
// OTLP receiver endpoint for traces exporter.
63+
OtlpTracesEndpoint string `json:"otlpTracesEndpoint,omitempty" yaml:"otlpTracesEndpoint,omitempty" env:"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" help:"OTLP receiver endpoint for traces."`
64+
// OTLP receiver endpoint for metrics exporter.
65+
OtlpMetricsEndpoint string `json:"otlpMetricsEndpoint,omitempty" yaml:"otlpMetricsEndpoint,omitempty" env:"OTEL_EXPORTER_OTLP_METRICS_ENDPOINT" help:"OTLP receiver endpoint for metrics."`
66+
// OTLP receiver endpoint for logs exporter.
67+
OtlpLogsEndpoint string `json:"otlpLogsEndpoint,omitempty" yaml:"otlpLogsEndpoint,omitempty" env:"OTEL_EXPORTER_OTLP_LOGS_ENDPOINT" help:"OTLP receiver endpoint for logs."`
68+
// Disable TLS for OpenTelemetry exporters.
69+
OtlpInsecure *bool `json:"otlpInsecure,omitempty" yaml:"otlpInsecure,omitempty" env:"OTEL_EXPORTER_OTLP_INSECURE" help:"Disable TLS for OpenTelemetry exporters."`
70+
// Disable TLS for OpenTelemetry traces exporter.
71+
OtlpTracesInsecure *bool `json:"otlpTracesInsecure,omitempty" yaml:"otlpTracesInsecure,omitempty" env:"OTEL_EXPORTER_OTLP_TRACES_INSECURE" help:"Disable TLS for OpenTelemetry traces exporter."`
72+
// Disable TLS for OpenTelemetry metrics exporter.
73+
OtlpMetricsInsecure *bool `json:"otlpMetricsInsecure,omitempty" yaml:"otlpMetricsInsecure,omitempty" env:"OTEL_EXPORTER_OTLP_METRICS_INSECURE" help:"Disable TLS for OpenTelemetry metrics exporter."`
74+
// Disable TLS for OpenTelemetry logs exporter.
75+
OtlpLogsInsecure *bool `json:"otlpLogsInsecure,omitempty" yaml:"otlpLogsInsecure,omitempty" env:"OTEL_EXPORTER_OTLP_LOGS_INSECURE" help:"Disable TLS for OpenTelemetry logs exporter."`
76+
// OTLP receiver protocol for all exporters. Default is grpc.
77+
OtlpProtocol OTLPProtocol `json:"otlpProtocol,omitempty" yaml:"otlpProtocol,omitempty" env:"OTEL_EXPORTER_OTLP_PROTOCOL" enum:"grpc,http/protobuf" jsonschema:"enum=grpc,enum=http/protobuf" help:"OTLP receiver protocol for all exporters. Default is grpc"`
78+
// OTLP receiver protocol for traces.
79+
OtlpTracesProtocol OTLPProtocol `json:"otlpTracesProtocol,omitempty" yaml:"otlpTracesProtocol,omitempty" env:"OTEL_EXPORTER_OTLP_TRACES_PROTOCOL" enum:"grpc,http/protobuf" jsonschema:"enum=grpc,enum=http/protobuf" help:"OTLP receiver protocol for traces."`
80+
// OTLP receiver protocol for metrics.
81+
OtlpMetricsProtocol OTLPProtocol `json:"otlpMetricsProtocol,omitempty" yaml:"otlpMetricsProtocol,omitempty" env:"OTEL_EXPORTER_OTLP_METRICS_PROTOCOL" enum:"grpc,http/protobuf" jsonschema:"enum=grpc,enum=http/protobuf" help:"OTLP receiver protocol for metrics."`
82+
// OTLP receiver protocol for logs.
83+
OtlpLogsProtocol OTLPProtocol `json:"otlpLogsProtocol,omitempty" yaml:"otlpLogsProtocol,omitempty" env:"OTEL_EXPORTER_OTLP_LOGS_PROTOCOL" enum:"grpc,http/protobuf" jsonschema:"enum=grpc,enum=http/protobuf" help:"OTLP receiver protocol for logs."`
84+
// Enable compression for OTLP exporters. Accept: none, gzip
85+
OtlpCompression OTLPCompressionType `json:"otlpCompression,omitempty" yaml:"otlpCompression,omitempty" env:"OTEL_EXPORTER_OTLP_COMPRESSION" default:"gzip" enum:"none,gzip" jsonschema:"enum=none,enum=gzip" help:"Enable compression for OTLP exporters. Accept: none, gzip"`
86+
// Enable compression for OTLP traces exporter. Accept: none, gzip
87+
OtlpTracesCompression OTLPCompressionType `json:"otlpTracesCompression,omitempty" yaml:"otlpTracesCompression,omitempty" env:"OTEL_EXPORTER_OTLP_TRACES_COMPRESSION" enum:"none,gzip" jsonschema:"enum=none,enum=gzip" help:"Enable compression for OTLP traces exporter. Accept: none, gzip"`
88+
// Enable compression for OTLP metrics exporter. Accept: none, gzip
89+
OtlpMetricsCompression OTLPCompressionType `json:"otlpMetricsCompression,omitempty" yaml:"otlpMetricsCompression,omitempty" env:"OTEL_EXPORTER_OTLP_METRICS_COMPRESSION" enum:"none,gzip" jsonschema:"enum=none,enum=gzip" help:"Enable compression for OTLP metrics exporter. Accept: none, gzip"`
90+
// Enable compression for OTLP logs exporter. Accept: none, gzip
91+
OtlpLogsCompression OTLPCompressionType `json:"otlpLogsCompression,omitempty" yaml:"otlpLogsCompression,omitempty" env:"OTEL_EXPORTER_OTLP_LOGS_COMPRESSION" enum:"none,gzip" jsonschema:"enum=none,enum=gzip" help:"Enable compression for OTLP logs exporter. Accept: none, gzip"`
92+
// Metrics export type. Accept: none, otlp, prometheus
93+
MetricsExporter OTELMetricsExporterType `json:"metricsExporter,omitempty" yaml:"metricsExporter,omitempty" env:"OTEL_METRICS_EXPORTER" default:"none" enum:"none,otlp,prometheus" jsonschema:"enum=none,enum=otlp,enum=prometheus" help:"Metrics export type. Accept: none, otlp, prometheus"`
94+
// Logs export type. Accept: none, otlp
95+
LogsExporter OTELLogsExporterType `json:"logsExporter,omitempty" yaml:"logsExporter,omitempty" env:"OTEL_LOGS_EXPORTER" default:"none" enum:"none,otlp" jsonschema:"enum=none,enum=otlp" help:"Logs export type. Accept: none, otlp"`
96+
// Prometheus port for the Prometheus HTTP server. Use /metrics endpoint of the connector server if empty.
97+
PrometheusPort *uint `json:"prometheusPort,omitempty" yaml:"prometheusPort,omitempty" env:"OTEL_EXPORTER_PROMETHEUS_PORT" jsonschema:"minimum=1000,maximum=65535" help:"Prometheus port for the Prometheus HTTP server. Use /metrics endpoint of the connector server if empty"`
98+
// Disable internal Go and process metrics (prometheus exporter only).
99+
DisableGoMetrics *bool `json:"disableGoMetrics,omitempty" yaml:"disableGoMetrics,omitempty" help:"Disable internal Go and process metrics"`
100+
}
101+
102+
// GetOTLPProtocol returns the OTLP protocol for OpenTelemetry exporters. Default is grpc.
103+
func (oc OTLPConfig) GetOTLPProtocol() OTLPProtocol {
104+
if oc.OtlpProtocol == "" {
105+
return OTLPProtocolGRPC
106+
}
107+
108+
return oc.OtlpProtocol
109+
}
110+
111+
// GetOTLPTracesProtocol returns the OTLP protocol for OTEL traces exporter.
112+
func (oc OTLPConfig) GetOTLPTracesProtocol() OTLPProtocol {
113+
if oc.OtlpTracesProtocol != "" {
114+
return oc.OtlpTracesProtocol
115+
}
116+
117+
return oc.GetOTLPProtocol()
118+
}
119+
120+
// GetOTLPMetricsProtocol returns the OTLP protocol for OTEL metrics exporter.
121+
func (oc OTLPConfig) GetOTLPMetricsProtocol() OTLPProtocol {
122+
if oc.OtlpMetricsProtocol != "" {
123+
return oc.OtlpMetricsProtocol
124+
}
125+
126+
return oc.GetOTLPProtocol()
127+
}
128+
129+
// GetOTLPLogsProtocol returns the OTLP protocol for OTEL logs exporter.
130+
func (oc OTLPConfig) GetOTLPLogsProtocol() OTLPProtocol {
131+
if oc.OtlpLogsProtocol != "" {
132+
return oc.OtlpLogsProtocol
133+
}
134+
135+
return oc.GetOTLPProtocol()
136+
}
137+
138+
// GetOTLPCompression returns the OTLP compression type. Default is gzip.
139+
func (oc OTLPConfig) GetOTLPCompression() OTLPCompressionType {
140+
if oc.OtlpCompression == "" {
141+
return OTLPCompressionGzip
142+
}
143+
144+
return oc.OtlpCompression
145+
}
146+
147+
// GetOTLPTracesCompression returns the OTLP traces compression type. Default is the otlpCompression value.
148+
func (oc OTLPConfig) GetOTLPTracesCompression() OTLPCompressionType {
149+
if oc.OtlpTracesCompression != "" {
150+
return oc.OtlpTracesCompression
151+
}
152+
153+
return oc.GetOTLPCompression()
154+
}
155+
156+
// GetOTLPMetricsCompression returns the OTLP metrics compression type. Default is the otlpCompression value.
157+
func (oc OTLPConfig) GetOTLPMetricsCompression() OTLPCompressionType {
158+
if oc.OtlpMetricsCompression != "" {
159+
return oc.OtlpMetricsCompression
160+
}
161+
162+
return oc.GetOTLPCompression()
163+
}
164+
165+
// GetOTLPLogsCompression returns the OTLP logs compression type. Default is the otlpCompression value.
166+
func (oc OTLPConfig) GetOTLPLogsCompression() OTLPCompressionType {
167+
if oc.OtlpLogsCompression != "" {
168+
return oc.OtlpLogsCompression
169+
}
170+
171+
return oc.GetOTLPCompression()
172+
}
173+
174+
// GetMetricsExporter returns the type of metrics exporter. Default is none.
175+
func (oc OTLPConfig) GetMetricsExporter() OTELMetricsExporterType {
176+
if oc.MetricsExporter == "" {
177+
return OTELMetricsExporterNone
178+
}
179+
180+
return oc.MetricsExporter
181+
}
182+
183+
// GetLogsExporter returns the type of logs exporter. Default is none.
184+
func (oc OTLPConfig) GetLogsExporter() OTELLogsExporterType {
185+
if oc.LogsExporter == "" {
186+
return OTELLogsExporterNone
187+
}
188+
189+
return OTELLogsExporterOTLP
190+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/hasura/gotel
22

3-
go 1.25
3+
go 1.25.5
44

55
require (
66
github.com/go-logr/logr v1.4.3

go.sum

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,8 @@ golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM=
9595
golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM=
9696
gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk=
9797
gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E=
98-
google.golang.org/genproto/googleapis/api v0.0.0-20251111163417-95abcf5c77ba h1:B14OtaXuMaCQsl2deSvNkyPKIzq3BjfxQp8d00QyWx4=
99-
google.golang.org/genproto/googleapis/api v0.0.0-20251111163417-95abcf5c77ba/go.mod h1:G5IanEx8/PgI9w6CFcYQf7jMtHQhZruvfM1i3qOqk5U=
10098
google.golang.org/genproto/googleapis/api v0.0.0-20251202230838-ff82c1b0f217 h1:fCvbg86sFXwdrl5LgVcTEvNC+2txB5mgROGmRL5mrls=
10199
google.golang.org/genproto/googleapis/api v0.0.0-20251202230838-ff82c1b0f217/go.mod h1:+rXWjjaukWZun3mLfjmVnQi18E1AsFbDN9QdJ5YXLto=
102-
google.golang.org/genproto/googleapis/rpc v0.0.0-20251111163417-95abcf5c77ba h1:UKgtfRM7Yh93Sya0Fo8ZzhDP4qBckrrxEr2oF5UIVb8=
103-
google.golang.org/genproto/googleapis/rpc v0.0.0-20251111163417-95abcf5c77ba/go.mod h1:7i2o+ce6H/6BluujYR+kqX3GKH+dChPTQU19wjRPiGk=
104100
google.golang.org/genproto/googleapis/rpc v0.0.0-20251202230838-ff82c1b0f217 h1:gRkg/vSppuSQoDjxyiGfN4Upv/h/DQmIR10ZU8dh4Ww=
105101
google.golang.org/genproto/googleapis/rpc v0.0.0-20251202230838-ff82c1b0f217/go.mod h1:7i2o+ce6H/6BluujYR+kqX3GKH+dChPTQU19wjRPiGk=
106102
google.golang.org/grpc v1.77.0 h1:wVVY6/8cGA6vvffn+wWK5ToddbgdU3d8MNENr4evgXM=

logger.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ func newLoggerProvider(
8989

9090
endpoint, protocol, insecure, err := parseOTLPEndpoint(
9191
logsEndpoint,
92-
getDefault(config.OtlpLogsProtocol, config.OtlpProtocol),
92+
config.GetOTLPLogsProtocol(),
9393
getDefaultPtr(config.OtlpLogsInsecure, config.OtlpInsecure),
9494
)
9595
if err != nil {
9696
return nil, fmt.Errorf("failed to parse OTLP logs endpoint: %w", err)
9797
}
9898

9999
compressorStr, compressorInt, err := parseOTLPCompression(
100-
getDefault(config.OtlpLogsCompression, config.OtlpCompression),
100+
config.GetOTLPLogsCompression(),
101101
)
102102
if err != nil {
103103
return nil, fmt.Errorf("failed to parse OTLP logs compression: %w", err)

0 commit comments

Comments
 (0)