otlpmetrichttp

package module
Version: v0.33.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2022 License: Apache-2.0 Imports: 20 Imported by: 14

Documentation

Overview

Package otlpmetrichttp provides an otlpmetric.Exporter that communicates with an OTLP receiving endpoint using protobuf encoded metric data over HTTP.

Example
package main

import (
	"context"

	"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp"
	"go.opentelemetry.io/otel/metric/global"
	"go.opentelemetry.io/otel/sdk/metric"
)

func main() {
	ctx := context.Background()
	exp, err := otlpmetrichttp.New(ctx)
	if err != nil {
		panic(err)
	}

	meterProvider := metric.NewMeterProvider(metric.WithReader(metric.NewPeriodicReader(exp)))
	defer func() {
		if err := meterProvider.Shutdown(ctx); err != nil {
			panic(err)
		}
	}()
	global.SetMeterProvider(meterProvider)

	// From here, the meterProvider can be used by instrumentation to collect
	// telemetry.
}
Output:

Index

Examples

Constants

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

Variables

This section is empty.

Functions

func New

func New(_ context.Context, opts ...Option) (metric.Exporter, error)

New returns an OpenTelemetry metric Exporter. The Exporter can be used with a PeriodicReader to export OpenTelemetry metric data to an OTLP receiving endpoint using protobufs over HTTP.

Types

type Compression

type Compression oconf.Compression

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

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option applies an option to the Exporter.

func WithCompression

func WithCompression(compression Compression) Option

WithCompression sets the compression strategy the Exporter will use to compress the HTTP body.

If the OTEL_EXPORTER_OTLP_COMPRESSION or OTEL_EXPORTER_OTLP_METRICS_COMPRESSION environment variable is set, and this option is not passed, that variable value will be used. That value can be either "none" or "gzip". If both are set, OTEL_EXPORTER_OTLP_METRICS_COMPRESSION will take precedence.

By default, if an environment variable is not set, and this option is not passed, no compression strategy will be used.

func WithEndpoint

func WithEndpoint(endpoint string) Option

WithEndpoint sets the target endpoint the Exporter will connect to. This endpoint is specified as a host and optional port, no path or scheme should be included (see WithInsecure and WithURLPath).

If the OTEL_EXPORTER_OTLP_ENDPOINT or OTEL_EXPORTER_OTLP_METRICS_ENDPOINT environment variable is set, and this option is not passed, that variable value will be used. If both are set, OTEL_EXPORTER_OTLP_METRICS_ENDPOINT will take precedence.

By default, if an environment variable is not set, and this option is not passed, "localhost:4318" will be used.

func WithHeaders

func WithHeaders(headers map[string]string) Option

WithHeaders will send the provided headers with each HTTP requests.

If the OTEL_EXPORTER_OTLP_HEADERS or OTEL_EXPORTER_OTLP_METRICS_HEADERS environment variable is set, and this option is not passed, that variable value will be used. The value will be parsed as a list of key value pairs. These pairs are expected to be in the W3C Correlation-Context format without additional semi-colon delimited metadata (i.e. "k1=v1,k2=v2"). If both are set, OTEL_EXPORTER_OTLP_METRICS_HEADERS will take precedence.

By default, if an environment variable is not set, and this option is not passed, no user headers will be set.

func WithInsecure

func WithInsecure() Option

WithInsecure disables client transport security for the Exporter's HTTP connection.

If the OTEL_EXPORTER_OTLP_ENDPOINT or OTEL_EXPORTER_OTLP_METRICS_ENDPOINT environment variable is set, and this option is not passed, that variable value will be used to determine client security. If the endpoint has a scheme of "http" or "unix" client security will be disabled. If both are set, OTEL_EXPORTER_OTLP_METRICS_ENDPOINT will take precedence.

By default, if an environment variable is not set, and this option is not passed, client security will be used.

func WithRetry added in v0.26.0

func WithRetry(rc RetryConfig) Option

WithRetry sets the retry policy for transient retryable errors that are returned by the target endpoint.

If the target endpoint responds with not only a retryable error, but explicitly returns a backoff time in the response, that time will take precedence over these settings.

If unset, the default retry policy will be used. It will retry the export 5 seconds after receiving a retryable error and increase exponentially after each error for no more than a total time of 1 minute.

func WithTLSClientConfig

func WithTLSClientConfig(tlsCfg *tls.Config) Option

WithTLSClientConfig sets the TLS configuration the Exporter will use for HTTP requests.

If the OTEL_EXPORTER_OTLP_CERTIFICATE or OTEL_EXPORTER_OTLP_METRICS_CERTIFICATE environment variable is set, and this option is not passed, that variable value will be used. The value will be parsed the filepath of the TLS certificate chain to use. If both are set, OTEL_EXPORTER_OTLP_METRICS_CERTIFICATE will take precedence.

By default, if an environment variable is not set, and this option is not passed, the system default configuration is used.

func WithTimeout

func WithTimeout(duration time.Duration) Option

WithTimeout sets the max amount of time an Exporter will attempt an export.

This takes precedence over any retry settings defined by WithRetry. Once this time limit has been reached the export is abandoned and the metric data is dropped.

If the OTEL_EXPORTER_OTLP_TIMEOUT or OTEL_EXPORTER_OTLP_METRICS_TIMEOUT environment variable is set, and this option is not passed, that variable value will be used. The value will be parsed as an integer representing the timeout in milliseconds. If both are set, OTEL_EXPORTER_OTLP_METRICS_TIMEOUT will take precedence.

By default, if an environment variable is not set, and this option is not passed, a timeout of 10 seconds will be used.

func WithURLPath

func WithURLPath(urlPath string) Option

WithURLPath sets the URL path the Exporter will send requests to.

If the OTEL_EXPORTER_OTLP_ENDPOINT or OTEL_EXPORTER_OTLP_METRICS_ENDPOINT environment variable is set, and this option is not passed, the path contained in that variable value will be used. If both are set, OTEL_EXPORTER_OTLP_METRICS_ENDPOINT will take precedence.

By default, if an environment variable is not set, and this option is not passed, "/v1/metrics" will be used.

type RetryConfig added in v0.26.0

type RetryConfig retry.Config

RetryConfig defines configuration for retrying the export of metric data that failed.

Jump to

Keyboard shortcuts

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