Skip to content

Commit 6e92163

Browse files
authored
otlpmetrichttp: Use go.opentelemetry.io/proto/slim/otlp (#5222)
1 parent f885333 commit 6e92163

37 files changed

+282
-2922
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
2929

3030
- Update `go.opentelemetry.io/proto/otlp` from v1.1.0 to v1.2.0. (#5177)
3131
- Improve performance of baggage member character validation in `go.opentelemetry.io/otel/baggage`. (#5214)
32+
- `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp` no longer depends on `google.golang.org/grpc`. (#5222)
3233

3334
## [1.25.0/0.47.0/0.0.8/0.1.0-alpha] 2024-04-05
3435

exporters/otlp/otlpmetric/otlpmetricgrpc/internal/gen.go

+7-12
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,15 @@ package internal // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/o
1212
//go:generate gotmpl --body=../../../../../internal/shared/otlp/envconfig/envconfig.go.tmpl "--data={}" --out=envconfig/envconfig.go
1313
//go:generate gotmpl --body=../../../../../internal/shared/otlp/envconfig/envconfig_test.go.tmpl "--data={}" --out=envconfig/envconfig_test.go
1414

15-
//go:generate gotmpl --body=../../../../../internal/shared/otlp/otlpmetric/oconf/envconfig.go.tmpl "--data={\"envconfigImportPath\": \"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/envconfig\"}" --out=oconf/envconfig.go
16-
//go:generate gotmpl --body=../../../../../internal/shared/otlp/otlpmetric/oconf/envconfig_test.go.tmpl "--data={}" --out=oconf/envconfig_test.go
17-
//go:generate gotmpl --body=../../../../../internal/shared/otlp/otlpmetric/oconf/options.go.tmpl "--data={\"retryImportPath\": \"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/retry\"}" --out=oconf/options.go
18-
//go:generate gotmpl --body=../../../../../internal/shared/otlp/otlpmetric/oconf/options_test.go.tmpl "--data={\"envconfigImportPath\": \"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/envconfig\"}" --out=oconf/options_test.go
1915
//go:generate gotmpl --body=../../../../../internal/shared/otlp/otlpmetric/oconf/optiontypes.go.tmpl "--data={}" --out=oconf/optiontypes.go
2016
//go:generate gotmpl --body=../../../../../internal/shared/otlp/otlpmetric/oconf/tls.go.tmpl "--data={}" --out=oconf/tls.go
2117

22-
//go:generate gotmpl --body=../../../../../internal/shared/otlp/otlpmetric/otest/client.go.tmpl "--data={}" --out=otest/client.go
23-
//go:generate gotmpl --body=../../../../../internal/shared/otlp/otlpmetric/otest/client_test.go.tmpl "--data={\"internalImportPath\": \"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal\"}" --out=otest/client_test.go
24-
//go:generate gotmpl --body=../../../../../internal/shared/otlp/otlpmetric/otest/collector.go.tmpl "--data={\"oconfImportPath\": \"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf\"}" --out=otest/collector.go
18+
//go:generate gotmpl --body=../../../../../internal/shared/otlp/otlpmetric/otest/client.go.tmpl "--data={\"protoImportPrefix\": \"go.opentelemetry.io/proto\"}" --out=otest/client.go
19+
//go:generate gotmpl --body=../../../../../internal/shared/otlp/otlpmetric/otest/client_test.go.tmpl "--data={\"protoImportPrefix\": \"go.opentelemetry.io/proto\", \"internalImportPath\": \"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/internal\"}" --out=otest/client_test.go
2520

26-
//go:generate gotmpl --body=../../../../../internal/shared/otlp/otlpmetric/transform/attribute.go.tmpl "--data={}" --out=transform/attribute.go
27-
//go:generate gotmpl --body=../../../../../internal/shared/otlp/otlpmetric/transform/attribute_test.go.tmpl "--data={}" --out=transform/attribute_test.go
28-
//go:generate gotmpl --body=../../../../../internal/shared/otlp/otlpmetric/transform/error.go.tmpl "--data={}" --out=transform/error.go
21+
//go:generate gotmpl --body=../../../../../internal/shared/otlp/otlpmetric/transform/attribute.go.tmpl "--data={\"protoImportPrefix\": \"go.opentelemetry.io/proto\"}" --out=transform/attribute.go
22+
//go:generate gotmpl --body=../../../../../internal/shared/otlp/otlpmetric/transform/attribute_test.go.tmpl "--data={\"protoImportPrefix\": \"go.opentelemetry.io/proto\"}" --out=transform/attribute_test.go
23+
//go:generate gotmpl --body=../../../../../internal/shared/otlp/otlpmetric/transform/error.go.tmpl "--data={\"protoImportPrefix\": \"go.opentelemetry.io/proto\"}" --out=transform/error.go
2924
//go:generate gotmpl --body=../../../../../internal/shared/otlp/otlpmetric/transform/error_test.go.tmpl "--data={}" --out=transform/error_test.go
30-
//go:generate gotmpl --body=../../../../../internal/shared/otlp/otlpmetric/transform/metricdata.go.tmpl "--data={}" --out=transform/metricdata.go
31-
//go:generate gotmpl --body=../../../../../internal/shared/otlp/otlpmetric/transform/metricdata_test.go.tmpl "--data={}" --out=transform/metricdata_test.go
25+
//go:generate gotmpl --body=../../../../../internal/shared/otlp/otlpmetric/transform/metricdata.go.tmpl "--data={\"protoImportPrefix\": \"go.opentelemetry.io/proto\"}" --out=transform/metricdata.go
26+
//go:generate gotmpl --body=../../../../../internal/shared/otlp/otlpmetric/transform/metricdata_test.go.tmpl "--data={\"protoImportPrefix\": \"go.opentelemetry.io/proto\"}" --out=transform/metricdata_test.go

exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/envconfig.go

+6-37
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Code created by gotmpl. DO NOT MODIFY.
2-
// source: internal/shared/otlp/otlpmetric/oconf/envconfig.go.tmpl
3-
41
// Copyright The OpenTelemetry Authors
52
// SPDX-License-Identifier: Apache-2.0
63

@@ -37,46 +34,18 @@ func ApplyGRPCEnvConfigs(cfg Config) Config {
3734
return cfg
3835
}
3936

40-
// ApplyHTTPEnvConfigs applies the env configurations for HTTP.
41-
func ApplyHTTPEnvConfigs(cfg Config) Config {
42-
opts := getOptionsFromEnv()
43-
for _, opt := range opts {
44-
cfg = opt.ApplyHTTPOption(cfg)
45-
}
46-
return cfg
47-
}
48-
49-
func getOptionsFromEnv() []GenericOption {
50-
opts := []GenericOption{}
37+
func getOptionsFromEnv() []GRPCOption {
38+
opts := []GRPCOption{}
5139

5240
tlsConf := &tls.Config{}
5341
DefaultEnvOptionsReader.Apply(
5442
envconfig.WithURL("ENDPOINT", func(u *url.URL) {
5543
opts = append(opts, withEndpointScheme(u))
56-
opts = append(opts, newSplitOption(func(cfg Config) Config {
57-
cfg.Metrics.Endpoint = u.Host
58-
// For OTLP/HTTP endpoint URLs without a per-signal
59-
// configuration, the passed endpoint is used as a base URL
60-
// and the signals are sent to these paths relative to that.
61-
cfg.Metrics.URLPath = path.Join(u.Path, DefaultMetricsPath)
62-
return cfg
63-
}, withEndpointForGRPC(u)))
44+
opts = append(opts, NewGRPCOption(withEndpointForGRPC(u)))
6445
}),
6546
envconfig.WithURL("METRICS_ENDPOINT", func(u *url.URL) {
6647
opts = append(opts, withEndpointScheme(u))
67-
opts = append(opts, newSplitOption(func(cfg Config) Config {
68-
cfg.Metrics.Endpoint = u.Host
69-
// For endpoint URLs for OTLP/HTTP per-signal variables, the
70-
// URL MUST be used as-is without any modification. The only
71-
// exception is that if an URL contains no path part, the root
72-
// path / MUST be used.
73-
path := u.Path
74-
if path == "" {
75-
path = "/"
76-
}
77-
cfg.Metrics.URLPath = path
78-
return cfg
79-
}, withEndpointForGRPC(u)))
48+
opts = append(opts, NewGRPCOption(withEndpointForGRPC(u)))
8049
}),
8150
envconfig.WithCertPool("CERTIFICATE", func(p *x509.CertPool) { tlsConf.RootCAs = p }),
8251
envconfig.WithCertPool("METRICS_CERTIFICATE", func(p *x509.CertPool) { tlsConf.RootCAs = p }),
@@ -121,7 +90,7 @@ func WithEnvCompression(n string, fn func(Compression)) func(e *envconfig.EnvOpt
12190
}
12291
}
12392

124-
func withEndpointScheme(u *url.URL) GenericOption {
93+
func withEndpointScheme(u *url.URL) GRPCOption {
12594
switch strings.ToLower(u.Scheme) {
12695
case "http", "unix":
12796
return WithInsecure()
@@ -131,7 +100,7 @@ func withEndpointScheme(u *url.URL) GenericOption {
131100
}
132101

133102
// revive:disable-next-line:flag-parameter
134-
func withInsecure(b bool) GenericOption {
103+
func withInsecure(b bool) GRPCOption {
135104
if b {
136105
return WithInsecure()
137106
}

exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/envconfig_test.go

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Code created by gotmpl. DO NOT MODIFY.
2-
// source: internal/shared/otlp/otlpmetric/oconf/envconfig_test.go.tmpl
3-
41
// Copyright The OpenTelemetry Authors
52
// SPDX-License-Identifier: Apache-2.0
63

exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options.go

+35-142
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Code created by gotmpl. DO NOT MODIFY.
2-
// source: internal/shared/otlp/otlpmetric/oconf/options.go.tmpl
3-
41
// Copyright The OpenTelemetry Authors
52
// SPDX-License-Identifier: Apache-2.0
63

@@ -47,6 +44,7 @@ type (
4744
// This type is compatible with `http.Transport.Proxy` and can be used to set a custom proxy function to the OTLP HTTP client.
4845
HTTPTransportProxyFunc func(*http.Request) (*url.URL, error)
4946

47+
// SignalConfig represents signal specific configuration.
5048
SignalConfig struct {
5149
Endpoint string
5250
Insecure bool
@@ -65,8 +63,8 @@ type (
6563
Proxy HTTPTransportProxyFunc
6664
}
6765

66+
// Config represents exporter configuration.
6867
Config struct {
69-
// Signal specific configurations
7068
Metrics SignalConfig
7169

7270
RetryConfig retry.Config
@@ -79,29 +77,6 @@ type (
7977
}
8078
)
8179

82-
// NewHTTPConfig returns a new Config with all settings applied from opts and
83-
// any unset setting using the default HTTP config values.
84-
func NewHTTPConfig(opts ...HTTPOption) Config {
85-
cfg := Config{
86-
Metrics: SignalConfig{
87-
Endpoint: fmt.Sprintf("%s:%d", DefaultCollectorHost, DefaultCollectorHTTPPort),
88-
URLPath: DefaultMetricsPath,
89-
Compression: NoCompression,
90-
Timeout: DefaultTimeout,
91-
92-
TemporalitySelector: metric.DefaultTemporalitySelector,
93-
AggregationSelector: metric.DefaultAggregationSelector,
94-
},
95-
RetryConfig: retry.DefaultConfig,
96-
}
97-
cfg = ApplyHTTPEnvConfigs(cfg)
98-
for _, opt := range opts {
99-
cfg = opt.ApplyHTTPOption(cfg)
100-
}
101-
cfg.Metrics.URLPath = cleanPath(cfg.Metrics.URLPath, DefaultMetricsPath)
102-
return cfg
103-
}
104-
10580
// cleanPath returns a path with all spaces trimmed and all redundancies
10681
// removed. If urlPath is empty or cleaning it results in an empty string,
10782
// defaultPath is returned instead.
@@ -164,93 +139,14 @@ func NewGRPCConfig(opts ...GRPCOption) Config {
164139
return cfg
165140
}
166141

167-
type (
168-
// GenericOption applies an option to the HTTP or gRPC driver.
169-
GenericOption interface {
170-
ApplyHTTPOption(Config) Config
171-
ApplyGRPCOption(Config) Config
172-
173-
// A private method to prevent users implementing the
174-
// interface and so future additions to it will not
175-
// violate compatibility.
176-
private()
177-
}
178-
179-
// HTTPOption applies an option to the HTTP driver.
180-
HTTPOption interface {
181-
ApplyHTTPOption(Config) Config
142+
// GRPCOption applies an option to the gRPC driver.
143+
type GRPCOption interface {
144+
ApplyGRPCOption(Config) Config
182145

183-
// A private method to prevent users implementing the
184-
// interface and so future additions to it will not
185-
// violate compatibility.
186-
private()
187-
}
188-
189-
// GRPCOption applies an option to the gRPC driver.
190-
GRPCOption interface {
191-
ApplyGRPCOption(Config) Config
192-
193-
// A private method to prevent users implementing the
194-
// interface and so future additions to it will not
195-
// violate compatibility.
196-
private()
197-
}
198-
)
199-
200-
// genericOption is an option that applies the same logic
201-
// for both gRPC and HTTP.
202-
type genericOption struct {
203-
fn func(Config) Config
204-
}
205-
206-
func (g *genericOption) ApplyGRPCOption(cfg Config) Config {
207-
return g.fn(cfg)
208-
}
209-
210-
func (g *genericOption) ApplyHTTPOption(cfg Config) Config {
211-
return g.fn(cfg)
212-
}
213-
214-
func (genericOption) private() {}
215-
216-
func newGenericOption(fn func(cfg Config) Config) GenericOption {
217-
return &genericOption{fn: fn}
218-
}
219-
220-
// splitOption is an option that applies different logics
221-
// for gRPC and HTTP.
222-
type splitOption struct {
223-
httpFn func(Config) Config
224-
grpcFn func(Config) Config
225-
}
226-
227-
func (g *splitOption) ApplyGRPCOption(cfg Config) Config {
228-
return g.grpcFn(cfg)
229-
}
230-
231-
func (g *splitOption) ApplyHTTPOption(cfg Config) Config {
232-
return g.httpFn(cfg)
233-
}
234-
235-
func (splitOption) private() {}
236-
237-
func newSplitOption(httpFn func(cfg Config) Config, grpcFn func(cfg Config) Config) GenericOption {
238-
return &splitOption{httpFn: httpFn, grpcFn: grpcFn}
239-
}
240-
241-
// httpOption is an option that is only applied to the HTTP driver.
242-
type httpOption struct {
243-
fn func(Config) Config
244-
}
245-
246-
func (h *httpOption) ApplyHTTPOption(cfg Config) Config {
247-
return h.fn(cfg)
248-
}
249-
250-
func (httpOption) private() {}
251-
252-
func NewHTTPOption(fn func(cfg Config) Config) HTTPOption {
253-
return &httpOption{fn: fn}
146+
// A private method to prevent users implementing the
147+
// interface and so future additions to it will not
148+
// violate compatibility.
149+
private()
254150
}
255151

256152
// grpcOption is an option that is only applied to the gRPC driver.
@@ -270,15 +166,15 @@ func NewGRPCOption(fn func(cfg Config) Config) GRPCOption {
270166

271167
// Generic Options
272168

273-
func WithEndpoint(endpoint string) GenericOption {
274-
return newGenericOption(func(cfg Config) Config {
169+
func WithEndpoint(endpoint string) GRPCOption {
170+
return NewGRPCOption(func(cfg Config) Config {
275171
cfg.Metrics.Endpoint = endpoint
276172
return cfg
277173
})
278174
}
279175

280-
func WithEndpointURL(v string) GenericOption {
281-
return newGenericOption(func(cfg Config) Config {
176+
func WithEndpointURL(v string) GRPCOption {
177+
return NewGRPCOption(func(cfg Config) Config {
282178
u, err := url.Parse(v)
283179
if err != nil {
284180
global.Error(err, "otlpmetric: parse endpoint url", "url", v)
@@ -295,81 +191,78 @@ func WithEndpointURL(v string) GenericOption {
295191
})
296192
}
297193

298-
func WithCompression(compression Compression) GenericOption {
299-
return newGenericOption(func(cfg Config) Config {
194+
func WithCompression(compression Compression) GRPCOption {
195+
return NewGRPCOption(func(cfg Config) Config {
300196
cfg.Metrics.Compression = compression
301197
return cfg
302198
})
303199
}
304200

305-
func WithURLPath(urlPath string) GenericOption {
306-
return newGenericOption(func(cfg Config) Config {
201+
func WithURLPath(urlPath string) GRPCOption {
202+
return NewGRPCOption(func(cfg Config) Config {
307203
cfg.Metrics.URLPath = urlPath
308204
return cfg
309205
})
310206
}
311207

312-
func WithRetry(rc retry.Config) GenericOption {
313-
return newGenericOption(func(cfg Config) Config {
208+
func WithRetry(rc retry.Config) GRPCOption {
209+
return NewGRPCOption(func(cfg Config) Config {
314210
cfg.RetryConfig = rc
315211
return cfg
316212
})
317213
}
318214

319-
func WithTLSClientConfig(tlsCfg *tls.Config) GenericOption {
320-
return newSplitOption(func(cfg Config) Config {
321-
cfg.Metrics.TLSCfg = tlsCfg.Clone()
322-
return cfg
323-
}, func(cfg Config) Config {
215+
func WithTLSClientConfig(tlsCfg *tls.Config) GRPCOption {
216+
return NewGRPCOption(func(cfg Config) Config {
324217
cfg.Metrics.GRPCCredentials = credentials.NewTLS(tlsCfg)
325218
return cfg
326219
})
327220
}
328221

329-
func WithInsecure() GenericOption {
330-
return newGenericOption(func(cfg Config) Config {
222+
func WithInsecure() GRPCOption {
223+
return NewGRPCOption(func(cfg Config) Config {
331224
cfg.Metrics.Insecure = true
332225
return cfg
333226
})
334227
}
335228

336-
func WithSecure() GenericOption {
337-
return newGenericOption(func(cfg Config) Config {
229+
func WithSecure() GRPCOption {
230+
return NewGRPCOption(func(cfg Config) Config {
338231
cfg.Metrics.Insecure = false
339232
return cfg
340233
})
341234
}
342235

343-
func WithHeaders(headers map[string]string) GenericOption {
344-
return newGenericOption(func(cfg Config) Config {
236+
func WithHeaders(headers map[string]string) GRPCOption {
237+
return NewGRPCOption(func(cfg Config) Config {
345238
cfg.Metrics.Headers = headers
346239
return cfg
347240
})
348241
}
349242

350-
func WithTimeout(duration time.Duration) GenericOption {
351-
return newGenericOption(func(cfg Config) Config {
243+
func WithTimeout(duration time.Duration) GRPCOption {
244+
return NewGRPCOption(func(cfg Config) Config {
352245
cfg.Metrics.Timeout = duration
353246
return cfg
354247
})
355248
}
356249

357-
func WithTemporalitySelector(selector metric.TemporalitySelector) GenericOption {
358-
return newGenericOption(func(cfg Config) Config {
250+
func WithTemporalitySelector(selector metric.TemporalitySelector) GRPCOption {
251+
return NewGRPCOption(func(cfg Config) Config {
359252
cfg.Metrics.TemporalitySelector = selector
360253
return cfg
361254
})
362255
}
363256

364-
func WithAggregationSelector(selector metric.AggregationSelector) GenericOption {
365-
return newGenericOption(func(cfg Config) Config {
257+
func WithAggregationSelector(selector metric.AggregationSelector) GRPCOption {
258+
return NewGRPCOption(func(cfg Config) Config {
366259
cfg.Metrics.AggregationSelector = selector
367260
return cfg
368261
})
369262
}
370263

371-
func WithProxy(pf HTTPTransportProxyFunc) GenericOption {
372-
return newGenericOption(func(cfg Config) Config {
264+
func WithProxy(pf HTTPTransportProxyFunc) GRPCOption {
265+
return NewGRPCOption(func(cfg Config) Config {
373266
cfg.Metrics.Proxy = pf
374267
return cfg
375268
})

0 commit comments

Comments
 (0)