Documentation
¶
Overview ¶
Example (EndToEnd) ¶
package main import ( "context" "log" "time" "contrib.go.opencensus.io/exporter/ocagent" "go.opencensus.io/trace" "go.uber.org/zap" "github.com/open-telemetry/opentelemetry-service/config/configmodels" "github.com/open-telemetry/opentelemetry-service/exporter/loggingexporter" "github.com/open-telemetry/opentelemetry-service/receiver" "github.com/open-telemetry/opentelemetry-service/receiver/opencensusreceiver" ) 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. lte, err := loggingexporter.NewTraceExporter(&configmodels.ExporterSettings{}, zap.NewNop()) if err != nil { log.Fatalf("Failed to create logging exporter: %v", err) } tr, err := opencensusreceiver.New("localhost:55678", lte, nil) 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 for _, tr := range trl { if err := tr.StartTraceReception(nil); 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() } }() 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) }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CustomUnmarshaler ¶
CustomUnmarshaler is a function that un-marshals a viper data into a config struct in a custom way.
type Factory ¶
type Factory interface { // Type gets the type of the Receiver created by this factory. Type() string // CreateDefaultConfig creates the default configuration for the Receiver. CreateDefaultConfig() configmodels.Receiver // CustomUnmarshaler returns a custom unmarshaler for the configuration or nil if // there is no need for custom unmarshaling. This is typically used if viper.Unmarshal() // is not sufficient to unmarshal correctly. CustomUnmarshaler() CustomUnmarshaler // CreateTraceReceiver creates a trace receiver based on this config. // If the receiver type does not support tracing or if the config is not valid // error will be returned instead. CreateTraceReceiver(ctx context.Context, logger *zap.Logger, cfg configmodels.Receiver, nextConsumer consumer.TraceConsumer) (TraceReceiver, error) // CreateMetricsReceiver creates a metrics receiver based on this config. // If the receiver type does not support metrics or if the config is not valid // error will be returned instead. CreateMetricsReceiver(logger *zap.Logger, cfg configmodels.Receiver, consumer consumer.MetricsConsumer) (MetricsReceiver, error) }
Factory is factory interface for receivers.
type Host ¶
type Host interface { // Context returns a context provided by the host to be used on the receiver // operations. Context() context.Context // ReportFatalError is used to report to the host that the receiver encountered // a fatal error (i.e.: an error that the instance can't recover from) after // its start function has already returned. ReportFatalError(err error) }
Host represents the entity where the receiver is being hosted. It is used to allow communication between the receiver and its host.
type MetricsReceiver ¶
type MetricsReceiver interface { // MetricsSource returns the name of the metrics data source. MetricsSource() string // StartMetricsReception tells the receiver to start its processing. // By convention the consumer of the data received is set at creation time. StartMetricsReception(host Host) error // StopMetricsReception tells the receiver that should stop reception, // giving it a chance to perform any necessary clean-up. StopMetricsReception() 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 consumer.MetricsConsumer with data.
For example it could be Prometheus data source which translates Prometheus metrics into *metricpb.Metric-s.
type SecureReceiverSettings ¶ added in v0.0.2
type SecureReceiverSettings struct { configmodels.ReceiverSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct // Configures the receiver to use TLS. // The default value is nil, which will cause the receiver to not use TLS. TLSCredentials *TLSCredentials `mapstructure:"tls-credentials, omitempty"` }
SecureReceiverSettings defines common settings for receivers that use Transport Layer Security (TLS)
type TLSCredentials ¶ added in v0.0.2
type TLSCredentials struct { // CertFile is the file path containing the TLS certificate. CertFile string `mapstructure:"cert-file"` // KeyFile is the file path containing the TLS key. KeyFile string `mapstructure:"key-file"` }
TLSCredentials contains path information for a certificate and key to be used for TLS
func (*TLSCredentials) ToGrpcServerOption ¶ added in v0.0.2
func (tlsCreds *TLSCredentials) ToGrpcServerOption() (opt grpc.ServerOption, err error)
ToGrpcServerOption creates a gRPC ServerOption from TLSCredentials. If TLSCredentials is nil, returns empty option.
type TraceReceiver ¶
type TraceReceiver interface { // TraceSource returns the name of the trace data source. TraceSource() string // StartTraceReception tells the receiver to start its processing. // By convention the consumer of the data received is set at creation time. StartTraceReception(host Host) error // StopTraceReception tells the receiver that should stop reception, // giving it a chance to perform any necessary clean-up. StopTraceReception() 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 consumer.TraceConsumer with data.
For example it could be Zipkin data source which translates Zipkin spans into *tracepb.Span-s.
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 prometheusreceiver has the logic for scraping Prometheus metrics from already instrumented applications and then passing them onto a metricsink instance.
|
Package prometheusreceiver has the logic for scraping Prometheus metrics from already instrumented applications and then passing them onto a metricsink instance. |
Package receivertest define types and functions used to help test packages implementing the receiver package interfaces.
|
Package receivertest define types and functions used to help test packages implementing the receiver package interfaces. |
Package vmmetricsreceiver has the logic for scraping VM metrics and then passing them onto a metric consumer instance.
|
Package vmmetricsreceiver has the logic for scraping VM metrics and then passing them onto a metric consumer instance. |