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

Refactored zipkin exporter for the upcoming ToClient confighttp API changes. #3290

Merged
merged 3 commits into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions exporter/zipkinexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func createTracesExporter(
zc,
params.Logger,
ze.pushTraceData,
exporterhelper.WithStart(ze.start),
// explicitly disable since we rely on http.Client timeout logic.
exporterhelper.WithTimeout(exporterhelper.TimeoutSettings{Timeout: 0}),
exporterhelper.WithQueue(zc.QueueSettings),
Expand Down
27 changes: 18 additions & 9 deletions exporter/zipkinexporter/zipkin.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"github.com/openzipkin/zipkin-go/proto/zipkin_proto3"
zipkinreporter "github.com/openzipkin/zipkin-go/reporter"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/consumer/consumererror"
"go.opentelemetry.io/collector/consumer/pdata"
"go.opentelemetry.io/collector/translator/trace/zipkin"
Expand All @@ -36,21 +38,18 @@ import (
type zipkinExporter struct {
defaultServiceName string

url string
client *http.Client
serializer zipkinreporter.SpanSerializer
url string
client *http.Client
serializer zipkinreporter.SpanSerializer
clientSettings *confighttp.HTTPClientSettings
}

func createZipkinExporter(cfg *Config) (*zipkinExporter, error) {
client, err := cfg.HTTPClientSettings.ToClient()
if err != nil {
return nil, err
}

ze := &zipkinExporter{
defaultServiceName: cfg.DefaultServiceName,
url: cfg.Endpoint,
client: client,
clientSettings: &cfg.HTTPClientSettings,
client: nil,
}

switch cfg.Format {
Expand All @@ -65,6 +64,16 @@ func createZipkinExporter(cfg *Config) (*zipkinExporter, error) {
return ze, nil
}

// start creates the http client
func (ze *zipkinExporter) start(_ context.Context, _ component.Host) error {
client, err := ze.clientSettings.ToClient()
if err != nil {
return err
}
ze.client = client
return nil
pavankrish123 marked this conversation as resolved.
Show resolved Hide resolved
}

func (ze *zipkinExporter) pushTraceData(ctx context.Context, td pdata.Traces) error {
tbatch, err := zipkin.InternalTracesToZipkinSpans(td)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions exporter/zipkinexporter/zipkin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ func TestZipkinExporter_roundtripJSON(t *testing.T) {
assert.NoError(t, err)
require.NotNil(t, zexp)

require.NoError(t, zexp.Start(context.Background(), componenttest.NewNopHost()))

// The test requires the spans from zipkinSpansJSONJavaLibrary to be sent in a single batch, use
// a mock to ensure that this happens as intended.
mzr := newMockZipkinReporter(cst.URL)
Expand Down Expand Up @@ -314,6 +316,8 @@ func TestZipkinExporter_roundtripProto(t *testing.T) {
zexp, err := NewFactory().CreateTracesExporter(context.Background(), component.ExporterCreateParams{Logger: zap.NewNop()}, cfg)
require.NoError(t, err)

require.NoError(t, zexp.Start(context.Background(), componenttest.NewNopHost()))

// The test requires the spans from zipkinSpansJSONJavaLibrary to be sent in a single batch, use
// a mock to ensure that this happens as intended.
mzr := newMockZipkinReporter(cst.URL)
Expand Down