Skip to content

Commit 14e3f6b

Browse files
authored
Add otlploghttp exporter skeleton (#5138)
1 parent afb6af0 commit 14e3f6b

File tree

12 files changed

+370
-0
lines changed

12 files changed

+370
-0
lines changed

.github/dependabot.yml

+9
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,15 @@ updates:
127127
schedule:
128128
interval: weekly
129129
day: sunday
130+
- package-ecosystem: gomod
131+
directory: /exporters/otlp/otlplog/otlploghttp
132+
labels:
133+
- dependencies
134+
- go
135+
- Skip Changelog
136+
schedule:
137+
interval: weekly
138+
day: sunday
130139
- package-ecosystem: gomod
131140
directory: /exporters/otlp/otlpmetric/otlpmetricgrpc
132141
labels:

exporters/otlp/otlplog/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# OTLP Log Exporters
2+
3+
[![PkgGoDev](https://pkg.go.dev/badge/go.opentelemetry.io/otel/exporters/otlp/otlplog)](https://pkg.go.dev/go.opentelemetry.io/otel/exporters/otlp/otlplog)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# OTLP Log HTTP Exporter
2+
3+
[![PkgGoDev](https://pkg.go.dev/badge/go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp)](https://pkg.go.dev/go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package otlploghttp // import "go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp"
5+
6+
type client struct {
7+
// TODO: implement.
8+
}
9+
10+
// newClient creates a new HTTP log client.
11+
func newClient(cfg config) (*client, error) {
12+
// TODO: implement.
13+
return &client{}, nil
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package otlploghttp // import "go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp"
5+
6+
import (
7+
"crypto/tls"
8+
"net/http"
9+
"net/url"
10+
"time"
11+
)
12+
13+
// Option applies an option to the Exporter.
14+
type Option interface {
15+
applyHTTPOption(config) config
16+
}
17+
18+
type config struct {
19+
// TODO: implement.
20+
}
21+
22+
func newConfig(options []Option) config {
23+
var c config
24+
for _, opt := range options {
25+
c = opt.applyHTTPOption(c)
26+
}
27+
return c
28+
}
29+
30+
// WithEndpoint sets the target endpoint the Exporter will connect to. This
31+
// endpoint is specified as a host and optional port, no path or scheme should
32+
// be included (see WithInsecure and WithURLPath).
33+
//
34+
// If the OTEL_EXPORTER_OTLP_ENDPOINT or OTEL_EXPORTER_OTLP_LOGS_ENDPOINT
35+
// environment variable is set, and this option is not passed, that variable
36+
// value will be used. If both are set, OTEL_EXPORTER_OTLP_LOGS_ENDPOINT
37+
// will take precedence.
38+
//
39+
// By default, if an environment variable is not set, and this option is not
40+
// passed, "localhost:4318" will be used.
41+
func WithEndpoint(endpoint string) Option {
42+
// TODO: implement.
43+
return nil
44+
}
45+
46+
// WithEndpointURL sets the target endpoint URL the Exporter will connect to.
47+
//
48+
// If the OTEL_EXPORTER_OTLP_ENDPOINT or OTEL_EXPORTER_OTLP_LOGS_ENDPOINT
49+
// environment variable is set, and this option is not passed, that variable
50+
// value will be used. If both are set, OTEL_EXPORTER_OTLP_LOGS_ENDPOINT
51+
// will take precedence.
52+
//
53+
// If both this option and WithEndpoint are used, the last used option will
54+
// take precedence.
55+
//
56+
// If an invalid URL is provided, the default value will be kept.
57+
//
58+
// By default, if an environment variable is not set, and this option is not
59+
// passed, "localhost:4318" will be used.
60+
func WithEndpointURL(u string) Option {
61+
// TODO: implement.
62+
return nil
63+
}
64+
65+
// Compression describes the compression used for payloads sent to the
66+
// collector.
67+
type Compression int
68+
69+
// WithCompression sets the compression strategy the Exporter will use to
70+
// compress the HTTP body.
71+
//
72+
// If the OTEL_EXPORTER_OTLP_COMPRESSION or
73+
// OTEL_EXPORTER_OTLP_LOGS_COMPRESSION environment variable is set, and
74+
// this option is not passed, that variable value will be used. That value can
75+
// be either "none" or "gzip". If both are set,
76+
// OTEL_EXPORTER_OTLP_LOGS_COMPRESSION will take precedence.
77+
//
78+
// By default, if an environment variable is not set, and this option is not
79+
// passed, no compression strategy will be used.
80+
func WithCompression(compression Compression) Option {
81+
// TODO: implement.
82+
return nil
83+
}
84+
85+
// WithURLPath sets the URL path the Exporter will send requests to.
86+
//
87+
// If the OTEL_EXPORTER_OTLP_ENDPOINT or OTEL_EXPORTER_OTLP_LOGS_ENDPOINT
88+
// environment variable is set, and this option is not passed, the path
89+
// contained in that variable value will be used. If both are set,
90+
// OTEL_EXPORTER_OTLP_LOGS_ENDPOINT will take precedence.
91+
//
92+
// By default, if an environment variable is not set, and this option is not
93+
// passed, "/v1/logs" will be used.
94+
func WithURLPath(urlPath string) Option {
95+
// TODO: implement.
96+
return nil
97+
}
98+
99+
// WithTLSClientConfig sets the TLS configuration the Exporter will use for
100+
// HTTP requests.
101+
//
102+
// If the OTEL_EXPORTER_OTLP_CERTIFICATE or
103+
// OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE environment variable is set, and
104+
// this option is not passed, that variable value will be used. The value will
105+
// be parsed the filepath of the TLS certificate chain to use. If both are
106+
// set, OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE will take precedence.
107+
//
108+
// By default, if an environment variable is not set, and this option is not
109+
// passed, the system default configuration is used.
110+
func WithTLSClientConfig(tlsCfg *tls.Config) Option {
111+
// TODO: implement.
112+
return nil
113+
}
114+
115+
// WithInsecure disables client transport security for the Exporter's HTTP
116+
// connection.
117+
//
118+
// If the OTEL_EXPORTER_OTLP_ENDPOINT or OTEL_EXPORTER_OTLP_LOGS_ENDPOINT
119+
// environment variable is set, and this option is not passed, that variable
120+
// value will be used to determine client security. If the endpoint has a
121+
// scheme of "http" or "unix" client security will be disabled. If both are
122+
// set, OTEL_EXPORTER_OTLP_LOGS_ENDPOINT will take precedence.
123+
//
124+
// By default, if an environment variable is not set, and this option is not
125+
// passed, client security will be used.
126+
func WithInsecure() Option {
127+
// TODO: implement.
128+
return nil
129+
}
130+
131+
// WithHeaders will send the provided headers with each HTTP requests.
132+
//
133+
// If the OTEL_EXPORTER_OTLP_HEADERS or OTEL_EXPORTER_OTLP_LOGS_HEADERS
134+
// environment variable is set, and this option is not passed, that variable
135+
// value will be used. The value will be parsed as a list of key value pairs.
136+
// These pairs are expected to be in the W3C Correlation-Context format
137+
// without additional semi-colon delimited metadata (i.e. "k1=v1,k2=v2"). If
138+
// both are set, OTEL_EXPORTER_OTLP_LOGS_HEADERS will take precedence.
139+
//
140+
// By default, if an environment variable is not set, and this option is not
141+
// passed, no user headers will be set.
142+
func WithHeaders(headers map[string]string) Option {
143+
// TODO: implement.
144+
return nil
145+
}
146+
147+
// WithTimeout sets the max amount of time an Exporter will attempt an export.
148+
//
149+
// This takes precedence over any retry settings defined by WithRetry. Once
150+
// this time limit has been reached the export is abandoned and the log data is
151+
// dropped.
152+
//
153+
// If the OTEL_EXPORTER_OTLP_TIMEOUT or OTEL_EXPORTER_OTLP_LOGS_TIMEOUT
154+
// environment variable is set, and this option is not passed, that variable
155+
// value will be used. The value will be parsed as an integer representing the
156+
// timeout in milliseconds. If both are set,
157+
// OTEL_EXPORTER_OTLP_LOGS_TIMEOUT will take precedence.
158+
//
159+
// By default, if an environment variable is not set, and this option is not
160+
// passed, a timeout of 10 seconds will be used.
161+
func WithTimeout(duration time.Duration) Option {
162+
// TODO: implement.
163+
return nil
164+
}
165+
166+
// RetryConfig defines configuration for retrying the export of log data that
167+
// failed.
168+
type RetryConfig struct {
169+
// TODO: implement.
170+
}
171+
172+
// WithRetry sets the retry policy for transient retryable errors that are
173+
// returned by the target endpoint.
174+
//
175+
// If the target endpoint responds with not only a retryable error, but
176+
// explicitly returns a backoff time in the response, that time will take
177+
// precedence over these settings.
178+
//
179+
// If unset, the default retry policy will be used. It will retry the export
180+
// 5 seconds after receiving a retryable error and increase exponentially
181+
// after each error for no more than a total time of 1 minute.
182+
func WithRetry(rc RetryConfig) Option {
183+
// TODO: implement.
184+
return nil
185+
}
186+
187+
// HTTPTransportProxyFunc is a function that resolves which URL to use as proxy
188+
// for a given request. This type is compatible with http.Transport.Proxy and
189+
// can be used to set a custom proxy function to the OTLP HTTP client.
190+
type HTTPTransportProxyFunc func(*http.Request) (*url.URL, error)
191+
192+
// WithProxy sets the Proxy function the client will use to determine the
193+
// proxy to use for an HTTP request. If this option is not used, the client
194+
// will use [http.ProxyFromEnvironment].
195+
func WithProxy(pf HTTPTransportProxyFunc) Option {
196+
// TODO: implement.
197+
return nil
198+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
// Package otlploghttp provides an OTLP log exporter. The exporter uses HTTP to
5+
// transport OTLP protobuf payloads.
6+
package otlploghttp // import "go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package otlploghttp // import "go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp"
5+
6+
import (
7+
"context"
8+
9+
"go.opentelemetry.io/otel/sdk/log"
10+
)
11+
12+
// Exporter is a OpenTelemetry log Exporter. It transports log data encoded as
13+
// OTLP protobufs using HTTP.
14+
type Exporter struct {
15+
// TODO: implement.
16+
}
17+
18+
// Compile-time check Exporter implements [log.Exporter].
19+
var _ log.Exporter = (*Exporter)(nil)
20+
21+
// New returns a new [Exporter].
22+
func New(_ context.Context, options ...Option) (*Exporter, error) {
23+
cfg := newConfig(options)
24+
c, err := newClient(cfg)
25+
if err != nil {
26+
return nil, err
27+
}
28+
return newExporter(c, cfg)
29+
}
30+
31+
func newExporter(*client, config) (*Exporter, error) {
32+
// TODO: implement
33+
return &Exporter{}, nil
34+
}
35+
36+
// Export transforms and transmits log records to an OTLP receiver.
37+
func (e *Exporter) Export(ctx context.Context, records []log.Record) error {
38+
// TODO: implement.
39+
return nil
40+
}
41+
42+
// Shutdown shuts down the Exporter. Calls to Export or ForceFlush will perform
43+
// no operation after this is called.
44+
func (e *Exporter) Shutdown(ctx context.Context) error {
45+
// TODO: implement.
46+
return nil
47+
}
48+
49+
// ForceFlush does nothing. The Exporter holds no state.
50+
func (e *Exporter) ForceFlush(ctx context.Context) error {
51+
// TODO: implement.
52+
return nil
53+
}
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp
2+
3+
go 1.21
4+
5+
require (
6+
github.com/stretchr/testify v1.9.0
7+
go.opentelemetry.io/otel/sdk/log v0.0.0-20240403115316-6c6e1e7416e9
8+
)
9+
10+
require (
11+
github.com/davecgh/go-spew v1.1.1 // indirect
12+
github.com/go-logr/logr v1.4.1 // indirect
13+
github.com/go-logr/stdr v1.2.2 // indirect
14+
github.com/pmezard/go-difflib v1.0.0 // indirect
15+
go.opentelemetry.io/otel v1.24.0 // indirect
16+
go.opentelemetry.io/otel/log v0.0.1-alpha // indirect
17+
go.opentelemetry.io/otel/metric v1.24.0 // indirect
18+
go.opentelemetry.io/otel/sdk v1.24.0 // indirect
19+
go.opentelemetry.io/otel/trace v1.24.0 // indirect
20+
golang.org/x/sys v0.18.0 // indirect
21+
gopkg.in/yaml.v3 v3.0.1 // indirect
22+
)
23+
24+
replace go.opentelemetry.io/otel => ../../../..
25+
26+
replace go.opentelemetry.io/otel/sdk/log => ../../../../sdk/log
27+
28+
replace go.opentelemetry.io/otel/trace => ../../../../trace
29+
30+
replace go.opentelemetry.io/otel/sdk => ../../../../sdk
31+
32+
replace go.opentelemetry.io/otel/metric => ../../../../metric
33+
34+
replace go.opentelemetry.io/otel/log => ../../../../log
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
4+
github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
5+
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
6+
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
7+
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
8+
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
9+
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
10+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
11+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
12+
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
13+
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
14+
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
15+
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
16+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
17+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
18+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
19+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package otlploghttp // import "go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp"
5+
6+
// Version is the current release version of the OpenTelemetry OTLP over HTTP/protobuf logs exporter in use.
7+
func Version() string {
8+
return "0.0.0"
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package otlploghttp
5+
6+
import (
7+
"regexp"
8+
"testing"
9+
10+
"github.com/stretchr/testify/assert"
11+
)
12+
13+
// regex taken from https://github.com/Masterminds/semver/tree/v3.1.1
14+
var versionRegex = regexp.MustCompile(`^v?([0-9]+)(\.[0-9]+)?(\.[0-9]+)?` +
15+
`(-([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?` +
16+
`(\+([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?$`)
17+
18+
func TestVersionSemver(t *testing.T) {
19+
v := Version()
20+
assert.NotNil(t, versionRegex.FindStringSubmatch(v), "version is not semver: %s", v)
21+
}

versions.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@ module-sets:
4444
excluded-modules:
4545
- go.opentelemetry.io/otel/internal/tools
4646
- go.opentelemetry.io/otel/sdk/log
47+
- go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp

0 commit comments

Comments
 (0)