otlp – go.opentelemetry.io/otel/exporters/otlp Index | Examples | Files | Directories
Deprecated: Use exporters/otlp/otlptrace or exporters/otlp/otlpmetric instead.

package otlp

import "go.opentelemetry.io/otel/exporters/otlp"

Deprecated: This package was moved to exporters/otlp/otlptrace and exporters/otlp/otlpmetric.

Index

Examples

Constants

const (
	// DefaultCollectorPort is the port the Exporter will attempt connect to
	// if no collector port is provided.
	DefaultCollectorPort uint16 = 4317
	// DefaultCollectorHost is the host address the Exporter will attempt
	// connect to if no collector address is provided.
	DefaultCollectorHost string = "localhost"
)

Types

type Compression

type Compression int

Compression describes the compression used for payloads sent to the collector.

const (
	// NoCompression tells the driver to send payloads without
	// compression.
	NoCompression Compression = iota
	// GzipCompression tells the driver to send payloads after
	// compressing them with gzip.
	GzipCompression
)

type Exporter

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

Exporter is an OpenTelemetry exporter. It exports both traces and metrics from OpenTelemetry instrumented to code using OpenTelemetry protocol buffers to a configurable receiver.

func InstallNewPipeline

func InstallNewPipeline(ctx context.Context, driver ProtocolDriver, exporterOpts ...ExporterOption) (*Exporter,
	*sdktrace.TracerProvider, *basic.Controller, error)

InstallNewPipeline instantiates a NewExportPipeline with the recommended configuration and registers it globally.

func NewExportPipeline

func NewExportPipeline(ctx context.Context, driver ProtocolDriver, exporterOpts ...ExporterOption) (*Exporter,
	*sdktrace.TracerProvider, *basic.Controller, error)

NewExportPipeline sets up a complete export pipeline with the recommended TracerProvider setup.

func NewExporter

func NewExporter(ctx context.Context, driver ProtocolDriver, opts ...ExporterOption) (*Exporter, error)

NewExporter constructs a new Exporter and starts it.

Example

Code:play 

package main

import (
	"context"
	"log"

	"go.opentelemetry.io/otel/exporters/otlp"

	"go.opentelemetry.io/otel"
	"go.opentelemetry.io/otel/exporters/otlp/otlpgrpc"

	sdktrace "go.opentelemetry.io/otel/sdk/trace"
)

func main() {
	ctx := context.Background()

	// Set different endpoints for the metrics and traces collectors
	metricsDriver := otlpgrpc.NewDriver(
	// Configure metrics driver here
	)
	tracesDriver := otlpgrpc.NewDriver(
	// Configure traces driver here
	)
	config := otlp.SplitConfig{
		ForMetrics: metricsDriver,
		ForTraces:  tracesDriver,
	}
	driver := otlp.NewSplitDriver(config)
	exporter, err := otlp.NewExporter(ctx, driver) // Configure as needed.
	if err != nil {
		log.Fatalf("failed to create exporter: %v", err)
	}
	defer func() {
		err := exporter.Shutdown(ctx)
		if err != nil {
			log.Fatalf("failed to stop exporter: %v", err)
		}
	}()

	tracerProvider := sdktrace.NewTracerProvider(sdktrace.WithBatcher(exporter))
	otel.SetTracerProvider(tracerProvider)
}

func NewUnstartedExporter

func NewUnstartedExporter(driver ProtocolDriver, opts ...ExporterOption) *Exporter

NewUnstartedExporter constructs a new Exporter and does not start it.

func (*Exporter) Export

func (e *Exporter) Export(parent context.Context, cps metricsdk.CheckpointSet) error

Export transforms and batches metric Records into OTLP Metrics and transmits them to the configured collector.

func (*Exporter) ExportKindFor

func (e *Exporter) ExportKindFor(desc *metric.Descriptor, kind aggregation.Kind) metricsdk.ExportKind

ExportKindFor reports back to the OpenTelemetry SDK sending this Exporter metric telemetry that it needs to be provided in a configured format.

func (*Exporter) ExportSpans

func (e *Exporter) ExportSpans(ctx context.Context, ss []*tracesdk.SpanSnapshot) error

ExportSpans transforms and batches trace SpanSnapshots into OTLP Trace and transmits them to the configured collector.

func (*Exporter) Shutdown

func (e *Exporter) Shutdown(ctx context.Context) error

Shutdown closes all connections and releases resources currently being used by the exporter. If the exporter is not started this does nothing. A shut down exporter can't be started again. Shutting down an already shut down exporter does nothing.

func (*Exporter) Start

func (e *Exporter) Start(ctx context.Context) error

Start establishes connections to the OpenTelemetry collector. Starting an already started exporter returns an error.

type ExporterOption

type ExporterOption func(*config)

ExporterOption are setting options passed to an Exporter on creation.

func WithMetricExportKindSelector

func WithMetricExportKindSelector(selector metricsdk.ExportKindSelector) ExporterOption

WithMetricExportKindSelector defines the ExportKindSelector used for selecting AggregationTemporality (i.e., Cumulative vs. Delta aggregation). If not specified otherwise, exporter will use a cumulative export kind selector.

type Marshaler

type Marshaler int

Marshaler describes the kind of message format sent to the collector

const (
	// MarshalProto tells the driver to send using the protobuf binary format.
	MarshalProto Marshaler = iota
	// MarshalJSON tells the driver to send using json format.
	MarshalJSON
)

type ProtocolDriver

type ProtocolDriver interface {
	// Start should establish connection(s) to endpoint(s). It is
	// called just once by the exporter, so the implementation
	// does not need to worry about idempotence and locking.
	Start(ctx context.Context) error
	// Stop should close the connections. The function is called
	// only once by the exporter, so the implementation does not
	// need to worry about idempotence, but it may be called
	// concurrently with ExportMetrics or ExportTraces, so proper
	// locking is required. The function serves as a
	// synchronization point - after the function returns, the
	// process of closing connections is assumed to be finished.
	Stop(ctx context.Context) error
	// ExportMetrics should transform the passed metrics to the
	// wire format and send it to the collector. May be called
	// concurrently with ExportTraces, so the manager needs to
	// take this into account by doing proper locking.
	ExportMetrics(ctx context.Context, cps metricsdk.CheckpointSet, selector metricsdk.ExportKindSelector) error
	// ExportTraces should transform the passed traces to the wire
	// format and send it to the collector. May be called
	// concurrently with ExportMetrics, so the manager needs to
	// take this into account by doing proper locking.
	ExportTraces(ctx context.Context, ss []*tracesdk.SpanSnapshot) error
}

ProtocolDriver is an interface used by OTLP exporter. It's responsible for connecting to and disconnecting from the collector, and for transforming traces and metrics into wire format and transmitting them to the collector.

func NewSplitDriver

func NewSplitDriver(cfg SplitConfig) ProtocolDriver

NewSplitDriver creates a protocol driver which contains two other protocol drivers and will forward traces to one of them and metrics to another.

type SplitConfig

type SplitConfig struct {
	// ForMetrics driver will be used for sending metrics to the
	// collector.
	ForMetrics ProtocolDriver
	// ForTraces driver will be used for sending spans to the
	// collector.
	ForTraces ProtocolDriver
}

SplitConfig is used to configure a split driver.

Source Files

doc.go options.go optiontypes.go otlp.go protocoldriver.go

Directories

PathSynopsis
internal
otlpgrpcPackage otlpgrpc provides an implementation of otlp.ProtocolDriver that connects to the collector and sends traces and metrics using gRPC.
otlphttpPackage otlphttp implements a protocol driver that sends traces and metrics to the collector using HTTP with binary protobuf payloads.
Version
v0.20.1 (latest)
Published
Mar 9, 2023
Platform
linux/amd64
Imports
11 packages
Last checked
1 week ago

Tools for package owners.