Skip to content

Commit

Permalink
update interface and changelog
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Ye <ben.ye@bytedance.com>
  • Loading branch information
Ben Ye committed Jan 3, 2022
1 parent 793824f commit 7d0eb4f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 34 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased]

### Added

- Support `OTEL_EXPORTER_ZIPKIN_ENDPOINT` env to specify zipkin collector endpoint.

### Deprecated

- Deprecate module `"go.opentelemetry.io/otel/sdk/export/metric"`, new functionality available in "go.opentelemetry.io/otel/sdk/metric" module:
Expand Down
2 changes: 1 addition & 1 deletion example/zipkin/main.go
Expand Up @@ -41,7 +41,7 @@ func initTracer(url string) func() {
// configure the sampler to a trace.ParentBased(trace.TraceIDRatioBased) set at the desired
// ratio.
exporter, err := zipkin.New(
zipkin.WithEndpoint(url),
url,
zipkin.WithLogger(logger),
)
if err != nil {
Expand Down
37 changes: 12 additions & 25 deletions exporters/zipkin/zipkin.go
Expand Up @@ -51,7 +51,6 @@ var (
type config struct {
client *http.Client
logger *log.Logger
url string
}

// Option defines a function that configures the exporter.
Expand All @@ -65,13 +64,6 @@ func (fn optionFunc) apply(cfg *config) {
fn(cfg)
}

// WithEndpoint configures the exporter to use the passed collector endpoint.
func WithEndpoint(endpoint string) Option {
return optionFunc(func(cfg *config) {
cfg.url = endpoint
})
}

// WithLogger configures the exporter to use the passed logger.
func WithLogger(logger *log.Logger) Option {
return optionFunc(func(cfg *config) {
Expand All @@ -87,34 +79,29 @@ func WithClient(client *http.Client) Option {
}

// New creates a new Zipkin exporter.
func New(opts ...Option) (*Exporter, error) {
var (
err error
u *url.URL
)

cfg := config{}
for _, opt := range opts {
opt.apply(&cfg)
}

if cfg.url == "" {
func New(collectorURL string, opts ...Option) (*Exporter, error) {
if collectorURL == "" {
// Use endpoint from env var or default collector URL.
cfg.url = envOr(envEndpoint, defaultCollectorURL)
collectorURL = envOr(envEndpoint, defaultCollectorURL)
}
u, err = url.Parse(cfg.url)
u, err := url.Parse(collectorURL)
if err != nil {
return nil, fmt.Errorf("invalid collector URL %q: %v", cfg.url, err)
return nil, fmt.Errorf("invalid collector URL %q: %v", collectorURL, err)
}
if u.Scheme == "" || u.Host == "" {
return nil, fmt.Errorf("invalid collector URL %q: no scheme or host", cfg.url)
return nil, fmt.Errorf("invalid collector URL %q: no scheme or host", collectorURL)
}

cfg := config{}
for _, opt := range opts {
opt.apply(&cfg)
}

if cfg.client == nil {
cfg.client = http.DefaultClient
}
return &Exporter{
url: cfg.url,
url: collectorURL,
client: cfg.client,
logger: cfg.logger,
}, nil
Expand Down
16 changes: 8 additions & 8 deletions exporters/zipkin/zipkin_test.go
Expand Up @@ -41,7 +41,7 @@ import (

func TestNewRawExporter(t *testing.T) {
_, err := New(
WithEndpoint(defaultCollectorURL),
defaultCollectorURL,
)

assert.NoError(t, err)
Expand All @@ -55,7 +55,7 @@ func TestNewRawExporterShouldFailInvalidCollectorURL(t *testing.T) {

// invalid URL
exp, err = New(
WithEndpoint("localhost"),
"localhost",
)

assert.Error(t, err)
Expand All @@ -70,7 +70,7 @@ func TestNewRawExporterEmptyDefaultCollectorURL(t *testing.T) {
)

// use default collector URL if not specified
exp, err = New()
exp, err = New("")

assert.NoError(t, err)
assert.Equal(t, defaultCollectorURL, exp.url)
Expand All @@ -91,7 +91,7 @@ func TestNewRawExporterCollectorURLFromEnv(t *testing.T) {
require.NoError(t, envStore.Restore())
}()

exp, err = New()
exp, err = New("")

assert.NoError(t, err)
assert.Equal(t, expectedEndpoint, exp.url)
Expand Down Expand Up @@ -306,7 +306,7 @@ func TestExportSpans(t *testing.T) {
defer collector.Close()
ls := &logStore{T: t}
logger := logStoreLogger(ls)
exporter, err := New(WithEndpoint(collector.url), WithLogger(logger))
exporter, err := New(collector.url, WithLogger(logger))
require.NoError(t, err)
ctx := context.Background()
require.Len(t, ls.Messages, 0)
Expand All @@ -331,7 +331,7 @@ func TestExporterShutdownHonorsTimeout(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
defer cancel()

exp, err := New()
exp, err := New("")
require.NoError(t, err)

innerCtx, innerCancel := context.WithTimeout(ctx, time.Nanosecond)
Expand All @@ -344,7 +344,7 @@ func TestExporterShutdownHonorsCancel(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
defer cancel()

exp, err := New()
exp, err := New("")
require.NoError(t, err)

innerCtx, innerCancel := context.WithCancel(ctx)
Expand All @@ -353,7 +353,7 @@ func TestExporterShutdownHonorsCancel(t *testing.T) {
}

func TestErrorOnExportShutdownExporter(t *testing.T) {
exp, err := New()
exp, err := New("")
require.NoError(t, err)
assert.NoError(t, exp.Shutdown(context.Background()))
assert.NoError(t, exp.ExportSpans(context.Background(), nil))
Expand Down

0 comments on commit 7d0eb4f

Please sign in to comment.