kafka

package module
v0.0.0-...-9c471c1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2018 License: Apache-2.0 Imports: 17 Imported by: 1

README

OpenCensus Go Kafka

Build Status GoDoc

Provides OpenCensus exporter support for sending trace to kafka, Base on stackdriver exporter code

Installation

$ go get -u github.com/yancl/opencensus-go-exporter-kafka

Documentation

Overview

Package kafka contains the OpenCensus exporters for Tracing.

This exporter can be used to send traces to kafka brokers.

Most of the codes base on https://github.com/census-ecosystem/opencensus-go-exporter-stackdriver.git

Example (Defaults)
exporter, err := kafka.NewExporter(
	kafka.Options{
		Brokers: []string{"127.0.0.1:9092"},
		Topic:   "oc-kafka",
	})

if err != nil {
	log.Fatal(err)
}

// Export to Kafka Trace.
trace.RegisterExporter(exporter)

// Use default B3 format header to outgoing requests:
client := &http.Client{
	Transport: &ochttp.Transport{},
}
_ = client // use client

// All outgoing requests from client will include a B3(default) Trace header.
// See the ochttp package for how to handle incoming requests.
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Exporter

type Exporter struct {
	// contains filtered or unexported fields
}

Exporter is a trace.Exporter implementation that uploads data to Kafka.

func NewExporter

func NewExporter(o Options) (*Exporter, error)

NewExporter creates a new Exporter that implements trace.Exporter.

func (*Exporter) ExportSpan

func (e *Exporter) ExportSpan(sd *trace.SpanData)

ExportSpan exports a SpanData to Kafka.

func (*Exporter) Flush

func (e *Exporter) Flush()

Flush waits for exported data to be uploaded.

This is useful if your program is ending and you do not want to lose recent stats or spans.

type Options

type Options struct {
	// Brokers is the addresses of the kafka brokers
	// Required
	Brokers []string

	// Topic is the topic of kafka to send spans to
	// Required
	Topic string

	// OnError is the hook to be called when there is
	// an error uploading the tracing data.
	// If no custom hook is set, errors are logged.
	// Optional.
	OnError func(err error)

	// BundleDelayThreshold determines the max amount of time
	// the exporter can wait before uploading view data to
	// the backend.
	// Optional.
	BundleDelayThreshold time.Duration

	// BundleCountThreshold determines how many view data events
	// can be buffered before batch uploading them to the backend.
	// Optional.
	BundleCountThreshold int

	// DefaultTraceAttributes will be appended to every span that is exported to
	// Kafka Trace.
	DefaultTraceAttributes map[string]interface{}

	// Context allows users to provide a custom context for API calls.
	//
	// This context will be used several times: first, to create Kafka
	// trace and metric clients, and then every time a new batch of traces or
	// stats needs to be uploaded.
	//
	// If unset, context.Background() will be used.
	Context context.Context
	// contains filtered or unexported fields
}

Options contains options for configuring the exporter.

Directories

Path Synopsis
gen-go
internal
testpb
Package testpb is a generated protocol buffer package.
Package testpb is a generated protocol buffer package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL