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 options to configure logger by interface #188

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
27 changes: 27 additions & 0 deletions logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2019 The OpenZipkin 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 zipkin

import "log"

// Verify that the Logger interface is implemented by the stdlib logger.
var _ Logger = (*log.Logger)(nil)

// Logger provides an interface defining the needed behavior for
// loggers passed into various components.
type Logger interface {
Print(v ...interface{})
Printf(format string, v ...interface{})
}
9 changes: 8 additions & 1 deletion middleware/http/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type transport struct {
defaultTags map[string]string
errHandler ErrHandler
errResponseReader *ErrResponseReader
logger *log.Logger
logger zipkin.Logger
requestSampler RequestSamplerFunc
remoteEndpoint *model.Endpoint
}
Expand Down Expand Up @@ -115,6 +115,13 @@ func TransportLogger(l *log.Logger) TransportOption {
}
}

// TransportZipkinLogger allows to plug a logger into the transport
func TransportZipkinLogger(l zipkin.Logger) TransportOption {
return func(t *transport) {
t.logger = l
}
}

// TransportRequestSampler allows one to set the sampling decision based on
// the details found in the http.Request. It has preference over the existing
// sampling decision contained in the context. The function returns a *bool,
Expand Down
11 changes: 10 additions & 1 deletion reporter/amqp/amqp.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/streadway/amqp"

"github.com/openzipkin/zipkin-go"
"github.com/openzipkin/zipkin-go/model"
"github.com/openzipkin/zipkin-go/reporter"
)
Expand All @@ -29,7 +30,7 @@ type rmqReporter struct {
conn *amqp.Connection
exchange string
queue string
logger *log.Logger
logger zipkin.Logger
}

// ReporterOption sets a parameter for the rmqReporter
Expand All @@ -43,6 +44,14 @@ func Logger(logger *log.Logger) ReporterOption {
}
}

// GenericLogger sets the logger used to report errors in the collection
// process.
func GenericLogger(logger zipkin.Logger) ReporterOption {
return func(c *rmqReporter) {
c.logger = logger
}
}

// Exchange sets the Exchange used to send messages (
// see https://github.com/openzipkin/zipkin/tree/master/zipkin-collector/rabbitmq
// if want to change default routing key or exchange
Expand Down
9 changes: 8 additions & 1 deletion reporter/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"sync"
"time"

"github.com/openzipkin/zipkin-go"
"github.com/openzipkin/zipkin-go/model"
"github.com/openzipkin/zipkin-go/reporter"
)
Expand All @@ -47,7 +48,7 @@ type HTTPDoer interface {
type httpReporter struct {
url string
client HTTPDoer
logger *log.Logger
logger zipkin.Logger
batchInterval time.Duration
batchSize int
maxBacklog int
Expand Down Expand Up @@ -233,6 +234,12 @@ func Logger(l *log.Logger) ReporterOption {
return func(r *httpReporter) { r.logger = l }
}

// GenericLogger sets the logger used to report errors in the collection
// process.
func GenericLogger(l zipkin.Logger) ReporterOption {
return func(r *httpReporter) { r.logger = l }
}

// Serializer sets the serialization function to use for sending span data to
// Zipkin.
func Serializer(serializer reporter.SpanSerializer) ReporterOption {
Expand Down
11 changes: 10 additions & 1 deletion reporter/kafka/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"os"

"github.com/Shopify/sarama"
"github.com/openzipkin/zipkin-go"
"github.com/openzipkin/zipkin-go/model"
"github.com/openzipkin/zipkin-go/reporter"
)
Expand All @@ -35,7 +36,7 @@ const defaultKafkaTopic = "zipkin"
// broker.
type kafkaReporter struct {
producer sarama.AsyncProducer
logger *log.Logger
logger zipkin.Logger
topic string
serializer reporter.SpanSerializer
}
Expand All @@ -51,6 +52,14 @@ func Logger(logger *log.Logger) ReporterOption {
}
}

// GenericLogger sets the logger used to report errors in the collection
// process.
func GenericLogger(logger zipkin.Logger) ReporterOption {
return func(c *kafkaReporter) {
c.logger = logger
}
}

// Producer sets the producer used to produce to Kafka. For tweaking
// the reporting settings (e.g. reporting timeout or authentication)
// check the sarama.Config struct.
Expand Down