receiver

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2019 License: Apache-2.0 Imports: 3 Imported by: 1

README

A variety of receivers are available to the OpenCensus Service (both Agent and Collector)

Currently there are some inconsistencies between Agent and Collector configuration, those will be addressed by issue #135.

OpenCensus

This receiver receives spans from OpenCensus instrumented applications and translates them into the internal span types that are then sent to the collector/exporters.

Its address can be configured in the YAML configuration file under section "receivers", subsection "opencensus" and field "address". The syntax of the field "address" is [address|host]:<port-number>.

For example:

receivers:
  opencensus:
    address: "localhost:55678"

Collector Differences

(To be fixed via #135)

By default this receiver is ALWAYS started on the OpenCensus Collector, it can be disabled via command-line by using --receive-oc-trace=false. On the Collector only the port can be configured, example:

receivers:
  opencensus:
    port: 55678

Jaeger

This receiver receives spans from Jaeger collector HTTP and Thrift uploads and translates them into the internal span types that are then sent to the collector/exporters.

Its address can be configured in the YAML configuration file under section "receivers", subsection "jaeger" and fields "collector_http_port", "collector_thrift_port".

For example:

receivers:
  jaeger:
    collector_thrift_port: 14267
    collector_http_port: 14268

Collector Differences

(To be fixed via #135)

On the Collector Jaeger reception at the default ports can be enabled via command-line --receive-jaeger, and the name of the fields is slightly different:

receivers:
  jaeger:
    jaeger-thrift-tchannel-port: 14267
    jaeger-thrift-http-port: 14268

Zipkin

This receiver receives spans from Zipkin (V1 and V2) HTTP uploads and translates them into the internal span types that are then sent to the collector/exporters.

Its address can be configured in the YAML configuration file under section "receivers", subsection "zipkin" and field "address". The syntax of the field "address" is [address|host]:<port-number>.

For example:

receivers:
  zipkin:
    address: "localhost:9411"

Collector Differences

(To be fixed via #135)

On the Collector Zipkin reception at the port 9411 can be enabled via command-line --receive-zipkin. On the Collector only the port can be configured, example:

receivers:
  zipkin:
    port: 9411

Documentation

Overview

Example (EndToEnd)
package main

import (
	"context"
	"encoding/json"
	"log"
	"time"

	"contrib.go.opencensus.io/exporter/ocagent"
	"go.opencensus.io/trace"

	"github.com/census-instrumentation/opencensus-service/data"
	"github.com/census-instrumentation/opencensus-service/receiver"
	"github.com/census-instrumentation/opencensus-service/receiver/opencensus"
)

func main() {
	// This is what the cmd/ocagent code would look like this.
	// A trace receiver as per the trace receiver
	// configs that have been parsed.
	tr, err := opencensus.New("localhost:55678")
	if err != nil {
		log.Fatalf("Failed to create trace receiver: %v", err)
	}

	// The agent will combine all trace receivers like this.
	trl := []receiver.TraceReceiver{tr}

	// Once we have the span receiver which will connect to the
	// various exporter pipeline i.e. *tracepb.Span->OpenCensus.SpanData
	lsr := new(logSpanSink)
	for _, tr := range trl {
		if err := tr.StartTraceReception(context.Background(), lsr); err != nil {
			log.Fatalf("Failed to start trace receiver: %v", err)
		}
	}

	// Before exiting, stop all the trace receivers
	defer func() {
		for _, tr := range trl {
			_ = tr.StopTraceReception(context.Background())
		}
	}()
	log.Println("Done starting the trace receiver")
	// We are done with the agent-core

	// Now this code would exist in the client application e.g. client code.
	// Create the agent exporter
	oce, err := ocagent.NewExporter(ocagent.WithInsecure())
	if err != nil {
		log.Fatalf("Failed to create ocagent exporter: %v", err)
	}
	defer oce.Stop()

	// Register it as a trace exporter
	trace.RegisterExporter(oce)
	// For demo purposes we are always sampling
	trace.ApplyConfig(trace.Config{DefaultSampler: trace.AlwaysSample()})

	log.Println("Starting loop")
	ctx, span := trace.StartSpan(context.Background(), "ClientLibrarySpan")
	for i := 0; i < 10; i++ {
		_, span := trace.StartSpan(ctx, "ChildSpan")
		span.Annotatef([]trace.Attribute{
			trace.StringAttribute("type", "Child"),
			trace.Int64Attribute("i", int64(i)),
		}, "This is an annotation")
		<-time.After(100 * time.Millisecond)
		span.End()
		oce.Flush()
	}
	span.End()

	<-time.After(400 * time.Millisecond)
	oce.Flush()
	<-time.After(5 * time.Second)
}

type logSpanSink int

var _ receiver.TraceReceiverSink = (*logSpanSink)(nil)

func (lsr *logSpanSink) ReceiveTraceData(ctx context.Context, td data.TraceData) (*receiver.TraceReceiverAcknowledgement, error) {
	spansBlob, _ := json.MarshalIndent(td.Spans, " ", "  ")
	log.Printf("\n****\nNode: %#v\nSpans: %s\n****\n", td.Node, spansBlob)

	return &receiver.TraceReceiverAcknowledgement{SavedSpans: uint64(len(td.Spans))}, nil
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MetricsReceiver

type MetricsReceiver interface {
	StartMetricsReception(ctx context.Context, destination MetricsReceiverSink) error
	StopMetricsReception(ctx context.Context) error
}

A MetricsReceiver is an "arbitrary data"-to-"metric proto" converter. Its purpose is to translate data from the wild into metric proto accompanied by a *commonpb.Node to uniquely identify where that data comes from. MetricsReceiver feeds a MetricsReceiverSink with data.

For example it could be Prometheus data source which translates Prometheus metrics into *metricpb.Metric-s.

func MultiMetricsReceiver added in v0.0.3

func MultiMetricsReceiver(mrs ...MetricsReceiver) MetricsReceiver

MultiMetricsReceiver wraps multiple metrics receivers in a single one.

type MetricsReceiverAcknowledgement added in v0.0.3

type MetricsReceiverAcknowledgement struct {
	SavedMetrics   uint64
	DroppedMetrics uint64
}

MetricsReceiverAcknowledgement struct reports the number of saved and dropped metrics in a ReceiveMetricsData call.

type MetricsReceiverSink added in v0.0.3

type MetricsReceiverSink interface {
	ReceiveMetricsData(ctx context.Context, metricsdata data.MetricsData) (*MetricsReceiverAcknowledgement, error)
}

MetricsReceiverSink is an interface that receives MetricsData.

type TraceReceiver

type TraceReceiver interface {
	StartTraceReception(ctx context.Context, destination TraceReceiverSink) error
	StopTraceReception(ctx context.Context) error
}

A TraceReceiver is an "arbitrary data"-to-"trace proto span" converter. Its purpose is to translate data from the wild into trace proto accompanied by a *commonpb.Node to uniquely identify where that data comes from. TraceReceiver feeds a TraceReceiverSink with data.

For example it could be Zipkin data source which translates Zipkin spans into *tracepb.Span-s.

StartTraceReception tells the receiver to start its processing.

StopTraceReception tells the receiver that should stop reception, giving it a chance to perform any necessary clean-up.

func MultiTraceReceiver added in v0.0.3

func MultiTraceReceiver(trs ...TraceReceiver) TraceReceiver

MultiTraceReceiver wraps multiple trace receivers in a single one.

type TraceReceiverAcknowledgement added in v0.0.3

type TraceReceiverAcknowledgement struct {
	SavedSpans   uint64
	DroppedSpans uint64
}

TraceReceiverAcknowledgement struct reports the number of saved and dropped spans in a ReceiveTraceData call.

type TraceReceiverSink added in v0.0.3

type TraceReceiverSink interface {
	ReceiveTraceData(ctx context.Context, tracedata data.TraceData) (*TraceReceiverAcknowledgement, error)
}

TraceReceiverSink is an interface that receives TraceData.

Directories

Path Synopsis
ocmetrics
Package ocmetrics is the logic for receiving OpenCensus metrics proto from already instrumented applications and then passing them onto a metricsink instance.
Package ocmetrics is the logic for receiving OpenCensus metrics proto from already instrumented applications and then passing them onto a metricsink instance.
octrace
Package octrace is the logic for receiving OpenCensus trace protobuf defined spans from already instrumented applications and then passing them onto a TraceReceiverSink instance.
Package octrace is the logic for receiving OpenCensus trace protobuf defined spans from already instrumented applications and then passing them onto a TraceReceiverSink instance.
Package prometheus has the logic for scraping Prometheus metrics from already instrumented applications and then passing them onto a metricsink instance.
Package prometheus has the logic for scraping Prometheus metrics from already instrumented applications and then passing them onto a metricsink instance.

Jump to

Keyboard shortcuts

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