Skip to content

Commit 599b8ec

Browse files
authored
Add OTLP HTTP exporter (#10)
* Add OTLP HTTP exporter * Increase lint timeout * Add suggestions
1 parent 77bde55 commit 599b8ec

File tree

7 files changed

+37
-7
lines changed

7 files changed

+37
-7
lines changed

examples/param/docker-compose.yml

+1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ services:
2424
- "14268:14268"
2525
- "55678-55679:55678-55679"
2626
- "4317:4317"
27+
- "4318:4318"
2728
- "9411:9411"

examples/shared/collector-config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ receivers:
22
otlp:
33
protocols:
44
grpc:
5+
http:
56
jaeger:
67
protocols:
78
grpc:

examples/template/docker-compose.yml

+1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ services:
2424
- "14268:14268"
2525
- "55678-55679:55678-55679"
2626
- "4317:4317"
27+
- "4318:4318"
2728
- "9411:9411"

go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ require (
2121
github.com/davecgh/go-spew v1.1.1 // indirect
2222
github.com/dlclark/regexp2 v1.7.0 // indirect
2323
github.com/fatih/color v1.13.0 // indirect
24+
github.com/felixge/httpsnoop v1.0.3 // indirect
2425
github.com/go-logr/logr v1.2.3 // indirect
2526
github.com/go-logr/stdr v1.2.2 // indirect
2627
github.com/go-sourcemap/sourcemap v2.1.4-0.20211119122758-180fcef48034+incompatible // indirect
@@ -47,6 +48,7 @@ require (
4748
github.com/opentracing/opentracing-go v1.2.0 // indirect
4849
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect
4950
github.com/pmezard/go-difflib v1.0.0 // indirect
51+
github.com/rs/cors v1.8.2 // indirect
5052
github.com/serenize/snaker v0.0.0-20201027110005-a7ad2135616e // indirect
5153
github.com/sirupsen/logrus v1.9.0 // indirect
5254
github.com/spf13/afero v1.8.2 // indirect
@@ -55,6 +57,7 @@ require (
5557
go.opencensus.io v0.23.0 // indirect
5658
go.opentelemetry.io/collector/semconv v0.62.1 // indirect
5759
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.36.1 // indirect
60+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.36.1 // indirect
5861
go.opentelemetry.io/otel v1.11.1 // indirect
5962
go.uber.org/atomic v1.10.0 // indirect
6063
go.uber.org/multierr v1.8.0 // indirect

go.sum

+6
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL
111111
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
112112
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
113113
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
114+
github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBdXk=
115+
github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
114116
github.com/frankban/quicktest v1.14.0/go.mod h1:NeW+ay9A/U67EYXNFA1nPE8e/tnQv/09mUdL/ijj8og=
115117
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
116118
github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=
@@ -384,6 +386,8 @@ github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6L
384386
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
385387
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
386388
github.com/rogpeppe/go-internal v1.6.2 h1:aIihoIOHCiLZHxyoNQ+ABL4NKhFTgKLBdMLyEAh98m0=
389+
github.com/rs/cors v1.8.2 h1:KCooALfAYGs415Cwu5ABvv9n9509fSiG5SQJn/AQo4U=
390+
github.com/rs/cors v1.8.2/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
387391
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
388392
github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
389393
github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
@@ -444,6 +448,8 @@ go.opentelemetry.io/collector/semconv v0.62.1 h1:tfld9R7V/aMYyq0VJ8uwaMDL+WCJr6Q
444448
go.opentelemetry.io/collector/semconv v0.62.1/go.mod h1:aRkHuJ/OshtDFYluKEtnG5nkKTsy1HZuvZVHmakx+Vo=
445449
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.36.1 h1:RQxI9u7XGv+E9x35YWa3jZhdpsphaV7VvBArNSiDtMw=
446450
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.36.1/go.mod h1:ylJH0hLC6Bp40dYp8rctk9HIuEM/xQRbV05d9HGTktQ=
451+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.36.1 h1:ledXJmnPfXGbE/gO4/PWSBsJGonnq6czWLrdHfQxeTU=
452+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.36.1/go.mod h1:W6/Lb2w3nD2K/l+4SzaqJUr2Ibj2uHA+PdFZlO5cWus=
447453
go.opentelemetry.io/otel v1.11.1 h1:4WLLAmcfkmDk2ukNXJyq3/kiz/3UzCaYq6PskJsaou4=
448454
go.opentelemetry.io/otel v1.11.1/go.mod h1:1nNhXBbWSD0nsL38H6btgnFN2k4i0sNLHNNMZMSbUGE=
449455
go.opentelemetry.io/otel/metric v0.32.1 h1:ftff5LSBCIDwL0UkhBuDg8j9NNxx2IusvJ18q9h6RC4=

golangci.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
run:
2+
timeout: 2m
3+
24
issues-exit-code: 1
35
tests: true
46

tracing.go

+23-7
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ import (
1717
"go.opentelemetry.io/collector/component/componenttest"
1818
"go.opentelemetry.io/collector/config"
1919
"go.opentelemetry.io/collector/config/configgrpc"
20+
"go.opentelemetry.io/collector/config/confighttp"
2021
"go.opentelemetry.io/collector/config/configtls"
2122
"go.opentelemetry.io/collector/exporter/otlpexporter"
23+
"go.opentelemetry.io/collector/exporter/otlphttpexporter"
2224
"go.opentelemetry.io/collector/pdata/ptrace"
2325
"go.opentelemetry.io/otel/metric"
2426
"go.opentelemetry.io/otel/trace"
@@ -29,9 +31,10 @@ import (
2931
type exporterType string
3032

3133
const (
32-
exporterNone exporterType = ""
33-
exporterOTLP exporterType = "otlp"
34-
exporterJaeger exporterType = "jaeger"
34+
exporterNone exporterType = ""
35+
exporterOTLP exporterType = "otlp"
36+
exporterOTLPHTTP exporterType = "otlphttp"
37+
exporterJaeger exporterType = "jaeger"
3538
)
3639

3740
var (
@@ -66,10 +69,11 @@ func (ct *TracingModule) Exports() modules.Exports {
6669
return modules.Exports{
6770
Named: map[string]interface{}{
6871
// constants
69-
"SEMANTICS_HTTP": tracegen.SemanticsHTTP,
70-
"SEMANTICS_DB": tracegen.SemanticsDB,
71-
"EXPORTER_OTLP": exporterOTLP,
72-
"EXPORTER_JAEGER": exporterJaeger,
72+
"SEMANTICS_HTTP": tracegen.SemanticsHTTP,
73+
"SEMANTICS_DB": tracegen.SemanticsDB,
74+
"EXPORTER_OTLP": exporterOTLP,
75+
"EXPORTER_OTLP_HTTP": exporterOTLPHTTP,
76+
"EXPORTER_JAEGER": exporterJaeger,
7377
// constructors
7478
"Client": ct.newClient,
7579
"ParameterizedGenerator": ct.newParameterizedGenerator,
@@ -188,6 +192,18 @@ func NewClient(cfg *ClientConfig, vu modules.VU) (*Client, error) {
188192
"Authorization": "Basic " + base64.StdEncoding.EncodeToString([]byte(cfg.Authentication.User+":"+cfg.Authentication.Password)),
189193
}, cfg.Headers),
190194
}
195+
case exporterOTLPHTTP:
196+
factory = otlphttpexporter.NewFactory()
197+
exporterCfg = factory.CreateDefaultConfig()
198+
exporterCfg.(*otlphttpexporter.Config).HTTPClientSettings = confighttp.HTTPClientSettings{
199+
Endpoint: cfg.Endpoint,
200+
TLSSetting: configtls.TLSClientSetting{
201+
Insecure: cfg.Insecure,
202+
},
203+
Headers: util.MergeMaps(map[string]string{
204+
"Authorization": "Basic " + base64.StdEncoding.EncodeToString([]byte(cfg.Authentication.User+":"+cfg.Authentication.Password)),
205+
}, cfg.Headers),
206+
}
191207
default:
192208
return nil, errors.Errorf("failed to init exporter: unknown exporter type %s", cfg.Exporter)
193209
}

0 commit comments

Comments
 (0)