Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add jaeger grpc exporter #219

Merged
merged 5 commits into from
Aug 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package defaults

import (
"github.com/open-telemetry/opentelemetry-service/exporter"
"github.com/open-telemetry/opentelemetry-service/exporter/jaeger/jaegergrpcexporter"
"github.com/open-telemetry/opentelemetry-service/exporter/loggingexporter"
"github.com/open-telemetry/opentelemetry-service/exporter/opencensusexporter"
"github.com/open-telemetry/opentelemetry-service/exporter/prometheusexporter"
Expand Down Expand Up @@ -60,6 +61,7 @@ func Components() (
&prometheusexporter.Factory{},
&loggingexporter.Factory{},
&zipkinexporter.Factory{},
&jaegergrpcexporter.Factory{},
)
if err != nil {
errs = append(errs, err)
Expand Down
10 changes: 6 additions & 4 deletions defaults/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/stretchr/testify/assert"

"github.com/open-telemetry/opentelemetry-service/exporter"
"github.com/open-telemetry/opentelemetry-service/exporter/jaeger/jaegergrpcexporter"
"github.com/open-telemetry/opentelemetry-service/exporter/loggingexporter"
"github.com/open-telemetry/opentelemetry-service/exporter/opencensusexporter"
"github.com/open-telemetry/opentelemetry-service/exporter/prometheusexporter"
Expand Down Expand Up @@ -55,10 +56,11 @@ func TestDefaultComponents(t *testing.T) {
"batch": &nodebatcher.Factory{},
}
expectedExporters := map[string]exporter.Factory{
"opencensus": &opencensusexporter.Factory{},
"prometheus": &prometheusexporter.Factory{},
"logging": &loggingexporter.Factory{},
"zipkin": &zipkinexporter.Factory{},
"opencensus": &opencensusexporter.Factory{},
"prometheus": &prometheusexporter.Factory{},
"logging": &loggingexporter.Factory{},
"zipkin": &zipkinexporter.Factory{},
"jaeger-grpc": &jaegergrpcexporter.Factory{},
}

receivers, processors, exporters, err := Components()
Expand Down
3 changes: 2 additions & 1 deletion examples/demotrace/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ services:

# Jaeger
jaeger-all-in-one:
image: jaegertracing/all-in-one:1.8
image: jaegertracing/all-in-one:latest
ports:
- "16686:16686"
- "14268"
- "14250"

# Zipkin
zipkin-all-in-one:
Expand Down
14 changes: 4 additions & 10 deletions examples/demotrace/otel-collector-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,12 @@ receivers:

exporters:
logging:

zipkin:
url: "http://zipkin-all-in-one:9411/api/v2/spans"

# TODO: enable jaeger exporter when it is implemented in otelsvc
# jaeger:
# num-workers: 4
# queue-size: 100
# retry-on-failure: true
# sender-type: jaeger-thrift-http
# jaeger-thrift-http:
# collector-endpoint: http://jaeger-all-in-one:14268/api/traces
# timeout: 5s
jaeger-grpc:
endpoint: jaeger-all-in-one:14250

processors:
batch:
Expand All @@ -27,5 +21,5 @@ processors:
pipelines:
traces:
receivers: [opencensus]
exporters: [logging, zipkin]
exporters: [logging, zipkin, jaeger-grpc]
processors: [batch, queued-retry]
31 changes: 28 additions & 3 deletions exporter/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,40 @@
# Exporters

A variety of exporters are available to the OpenTelemetry Service:
Below is the list of exporters directly supported by the OpenTelemetry Service.

* [Jaeger](#jaeger)
* [Logging](#logging)
* [OpenCensus](#opencensus)
* [Prometheus](#prometheus)
* [Zipkin](#zipkin)

The [contributors repository](https://github.com/open-telemetry/opentelemetry-service-contrib)
has more exporters that can be added to custom builds of the service.

## <a name="jaeger"></a>Jaeger
TODO: document settings

Exports trace data to [Jaeger](https://www.jaegertracing.io/) collectors
accepting one of the following protocols:

* [gRPC](#jaeger-grpc)

### Configuration

Each different supported protocol has its own configuration settings.

#### <a name="jaeger-grpc"></a>gRPC

* `endpoint:` target to which the exporter is going to send Jaeger trace data,
using the gRPC protocol. The valid syntax is described at
https://github.com/grpc/grpc/blob/master/doc/naming.md

Example:

```yaml
exporters:
jaeger-grpc:
endpoint: jaeger-all-in-one:14250
```

## <a name="logging"></a>Logging
TODO: document settings
Expand All @@ -21,7 +46,7 @@ TODO: document settings
TODO: document settings

## <a name="zipkin"></a>Zipkin
Exports trace data to a [Zipkin](https://zipkin.io/) endpoint.
Exports trace data to a [Zipkin](https://zipkin.io/) back-end.

### Configuration

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package jaegerexporter
package jaeger

// TODO: Delete me when tests are added.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package jaegerexporter
package jaeger

import (
"bytes"
Expand All @@ -35,29 +35,29 @@ import (
// Default timeout for http request in seconds
const defaultHTTPTimeout = time.Second * 5

// JaegerThriftHTTPSender forwards spans encoded in the jaeger thrift
// ThriftHTTPSender forwards spans encoded in the jaeger thrift
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to pass lint.

// format to a http server
type JaegerThriftHTTPSender struct {
type ThriftHTTPSender struct {
url string
headers map[string]string
client *http.Client
logger *zap.Logger
}

var _ consumer.TraceConsumer = (*JaegerThriftHTTPSender)(nil)
var _ consumer.TraceConsumer = (*ThriftHTTPSender)(nil)

// HTTPOption sets a parameter for the HttpCollector
type HTTPOption func(s *JaegerThriftHTTPSender)
type HTTPOption func(s *ThriftHTTPSender)

// HTTPTimeout sets maximum timeout for http request.
func HTTPTimeout(duration time.Duration) HTTPOption {
return func(s *JaegerThriftHTTPSender) { s.client.Timeout = duration }
return func(s *ThriftHTTPSender) { s.client.Timeout = duration }
}

// HTTPRoundTripper configures the underlying Transport on the *http.Client
// that is used
func HTTPRoundTripper(transport http.RoundTripper) HTTPOption {
return func(s *JaegerThriftHTTPSender) {
return func(s *ThriftHTTPSender) {
s.client.Transport = transport
}
}
Expand All @@ -70,8 +70,8 @@ func NewJaegerThriftHTTPSender(
headers map[string]string,
zlogger *zap.Logger,
options ...HTTPOption,
) *JaegerThriftHTTPSender {
s := &JaegerThriftHTTPSender{
) *ThriftHTTPSender {
s := &ThriftHTTPSender{
url: url,
headers: headers,
client: &http.Client{Timeout: defaultHTTPTimeout},
Expand All @@ -85,7 +85,7 @@ func NewJaegerThriftHTTPSender(
}

// ConsumeTraceData sends the received data to the configured Jaeger Thrift end-point.
func (s *JaegerThriftHTTPSender) ConsumeTraceData(ctx context.Context, td consumerdata.TraceData) error {
func (s *ThriftHTTPSender) ConsumeTraceData(ctx context.Context, td consumerdata.TraceData) error {
// TODO: (@pjanotti) In case of failure the translation to Jaeger Thrift is going to be remade, cache it somehow.
tBatch, err := jaegertranslator.OCProtoToJaegerThrift(td)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package jaegerexporter
package jaeger

import (
"context"
Expand All @@ -26,28 +26,28 @@ import (
jaegertranslator "github.com/open-telemetry/opentelemetry-service/translator/trace/jaeger"
)

// JaegerThriftTChannelSender takes span batches and sends them
// ThriftTChannelSender takes span batches and sends them
// out on tchannel in thrift encoding
type JaegerThriftTChannelSender struct {
type ThriftTChannelSender struct {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to pass lint.

logger *zap.Logger
reporter reporter.Reporter
}

var _ consumer.TraceConsumer = (*JaegerThriftTChannelSender)(nil)
var _ consumer.TraceConsumer = (*ThriftTChannelSender)(nil)

// NewJaegerThriftTChannelSender creates new TChannel-based sender.
func NewJaegerThriftTChannelSender(
reporter reporter.Reporter,
zlogger *zap.Logger,
) *JaegerThriftTChannelSender {
return &JaegerThriftTChannelSender{
) *ThriftTChannelSender {
return &ThriftTChannelSender{
logger: zlogger,
reporter: reporter,
}
}

// ConsumeTraceData sends the received data to the configured Jaeger Thrift end-point.
func (s *JaegerThriftTChannelSender) ConsumeTraceData(ctx context.Context, td consumerdata.TraceData) error {
func (s *ThriftTChannelSender) ConsumeTraceData(ctx context.Context, td consumerdata.TraceData) error {
// TODO: (@pjanotti) In case of failure the translation to Jaeger Thrift is going to be remade, cache it somehow.
tBatch, err := jaegertranslator.OCProtoToJaegerThrift(td)
if err != nil {
Expand Down
25 changes: 25 additions & 0 deletions exporter/jaeger/jaegergrpcexporter/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2019, OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package jaegergrpcexporter

import (
"github.com/open-telemetry/opentelemetry-service/config/configmodels"
)

// Config defines configuration for Jaeger gRPC exporter.
type Config struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we leave a TODO for TLS option in the config?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I will create an issues to track not TLS but also other missing configurations: timeout, headers, and so on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually there is already one issue to TLS to jaeger receiver and exporter: #126

configmodels.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
Endpoint string `mapstructure:"endpoint"`
}
53 changes: 53 additions & 0 deletions exporter/jaeger/jaegergrpcexporter/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright 2019, OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package jaegergrpcexporter

import (
"path"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-service/config"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import ordering.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

)

func TestLoadConfig(t *testing.T) {
receivers, processors, exporters, err := config.ExampleComponents()
assert.Nil(t, err)

factory := &Factory{}
exporters[typeStr] = factory
cfg, err := config.LoadConfigFile(
t, path.Join(".", "testdata", "config.yaml"), receivers, processors, exporters,
)

require.NoError(t, err)
require.NotNil(t, cfg)

e0 := cfg.Exporters["jaeger-grpc"]

// Endpoint doesn't have a default value so set it directly.
defaultCfg := factory.CreateDefaultConfig().(*Config)
defaultCfg.Endpoint = "some.target:55678"
assert.Equal(t, defaultCfg, e0)

e1 := cfg.Exporters["jaeger-grpc/2"]
assert.Equal(t, "jaeger-grpc/2", e1.(*Config).Name())
assert.Equal(t, "a.new.target:1234", e1.(*Config).Endpoint)
_, _, err = factory.CreateTraceExporter(zap.NewNop(), e1)
require.NoError(t, err)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package jaegerexporter contains a specialized Jaeger exporter. Unlike client
// library exporters they do not buffer or attempt to resend failed batches, all
// of that is delegated to the callers of the exporter.
package jaegerexporter
// Package jaegergrpcexporter implements an exporter that sends trace data to
// a Jaeger collector gRPC endpoint.
package jaegergrpcexporter
Loading