Skip to content

Commit

Permalink
Add OTLP HTTP exporter (#10)
Browse files Browse the repository at this point in the history
* Add OTLP HTTP exporter

* Increase lint timeout

* Add suggestions
  • Loading branch information
mapno authored Jan 18, 2023
1 parent 77bde55 commit 599b8ec
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 7 deletions.
1 change: 1 addition & 0 deletions examples/param/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ services:
- "14268:14268"
- "55678-55679:55678-55679"
- "4317:4317"
- "4318:4318"
- "9411:9411"
1 change: 1 addition & 0 deletions examples/shared/collector-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ receivers:
otlp:
protocols:
grpc:
http:
jaeger:
protocols:
grpc:
Expand Down
1 change: 1 addition & 0 deletions examples/template/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ services:
- "14268:14268"
- "55678-55679:55678-55679"
- "4317:4317"
- "4318:4318"
- "9411:9411"
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dlclark/regexp2 v1.7.0 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-sourcemap/sourcemap v2.1.4-0.20211119122758-180fcef48034+incompatible // indirect
Expand All @@ -47,6 +48,7 @@ require (
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rs/cors v1.8.2 // indirect
github.com/serenize/snaker v0.0.0-20201027110005-a7ad2135616e // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/spf13/afero v1.8.2 // indirect
Expand All @@ -55,6 +57,7 @@ require (
go.opencensus.io v0.23.0 // indirect
go.opentelemetry.io/collector/semconv v0.62.1 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.36.1 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.36.1 // indirect
go.opentelemetry.io/otel v1.11.1 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBdXk=
github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/frankban/quicktest v1.14.0/go.mod h1:NeW+ay9A/U67EYXNFA1nPE8e/tnQv/09mUdL/ijj8og=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=
Expand Down Expand Up @@ -384,6 +386,8 @@ github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6L
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.6.2 h1:aIihoIOHCiLZHxyoNQ+ABL4NKhFTgKLBdMLyEAh98m0=
github.com/rs/cors v1.8.2 h1:KCooALfAYGs415Cwu5ABvv9n9509fSiG5SQJn/AQo4U=
github.com/rs/cors v1.8.2/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
Expand Down Expand Up @@ -444,6 +448,8 @@ go.opentelemetry.io/collector/semconv v0.62.1 h1:tfld9R7V/aMYyq0VJ8uwaMDL+WCJr6Q
go.opentelemetry.io/collector/semconv v0.62.1/go.mod h1:aRkHuJ/OshtDFYluKEtnG5nkKTsy1HZuvZVHmakx+Vo=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.36.1 h1:RQxI9u7XGv+E9x35YWa3jZhdpsphaV7VvBArNSiDtMw=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.36.1/go.mod h1:ylJH0hLC6Bp40dYp8rctk9HIuEM/xQRbV05d9HGTktQ=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.36.1 h1:ledXJmnPfXGbE/gO4/PWSBsJGonnq6czWLrdHfQxeTU=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.36.1/go.mod h1:W6/Lb2w3nD2K/l+4SzaqJUr2Ibj2uHA+PdFZlO5cWus=
go.opentelemetry.io/otel v1.11.1 h1:4WLLAmcfkmDk2ukNXJyq3/kiz/3UzCaYq6PskJsaou4=
go.opentelemetry.io/otel v1.11.1/go.mod h1:1nNhXBbWSD0nsL38H6btgnFN2k4i0sNLHNNMZMSbUGE=
go.opentelemetry.io/otel/metric v0.32.1 h1:ftff5LSBCIDwL0UkhBuDg8j9NNxx2IusvJ18q9h6RC4=
Expand Down
2 changes: 2 additions & 0 deletions golangci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
run:
timeout: 2m

issues-exit-code: 1
tests: true

Expand Down
30 changes: 23 additions & 7 deletions tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ import (
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configgrpc"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/config/configtls"
"go.opentelemetry.io/collector/exporter/otlpexporter"
"go.opentelemetry.io/collector/exporter/otlphttpexporter"
"go.opentelemetry.io/collector/pdata/ptrace"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/trace"
Expand All @@ -29,9 +31,10 @@ import (
type exporterType string

const (
exporterNone exporterType = ""
exporterOTLP exporterType = "otlp"
exporterJaeger exporterType = "jaeger"
exporterNone exporterType = ""
exporterOTLP exporterType = "otlp"
exporterOTLPHTTP exporterType = "otlphttp"
exporterJaeger exporterType = "jaeger"
)

var (
Expand Down Expand Up @@ -66,10 +69,11 @@ func (ct *TracingModule) Exports() modules.Exports {
return modules.Exports{
Named: map[string]interface{}{
// constants
"SEMANTICS_HTTP": tracegen.SemanticsHTTP,
"SEMANTICS_DB": tracegen.SemanticsDB,
"EXPORTER_OTLP": exporterOTLP,
"EXPORTER_JAEGER": exporterJaeger,
"SEMANTICS_HTTP": tracegen.SemanticsHTTP,
"SEMANTICS_DB": tracegen.SemanticsDB,
"EXPORTER_OTLP": exporterOTLP,
"EXPORTER_OTLP_HTTP": exporterOTLPHTTP,
"EXPORTER_JAEGER": exporterJaeger,
// constructors
"Client": ct.newClient,
"ParameterizedGenerator": ct.newParameterizedGenerator,
Expand Down Expand Up @@ -188,6 +192,18 @@ func NewClient(cfg *ClientConfig, vu modules.VU) (*Client, error) {
"Authorization": "Basic " + base64.StdEncoding.EncodeToString([]byte(cfg.Authentication.User+":"+cfg.Authentication.Password)),
}, cfg.Headers),
}
case exporterOTLPHTTP:
factory = otlphttpexporter.NewFactory()
exporterCfg = factory.CreateDefaultConfig()
exporterCfg.(*otlphttpexporter.Config).HTTPClientSettings = confighttp.HTTPClientSettings{
Endpoint: cfg.Endpoint,
TLSSetting: configtls.TLSClientSetting{
Insecure: cfg.Insecure,
},
Headers: util.MergeMaps(map[string]string{
"Authorization": "Basic " + base64.StdEncoding.EncodeToString([]byte(cfg.Authentication.User+":"+cfg.Authentication.Password)),
}, cfg.Headers),
}
default:
return nil, errors.Errorf("failed to init exporter: unknown exporter type %s", cfg.Exporter)
}
Expand Down

0 comments on commit 599b8ec

Please sign in to comment.