otlp

package module
v3.0.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2025 License: MIT Imports: 24 Imported by: 0

README

OTLP Configuration

This package provides a configuration for the OpenTelemetry Protocol (OTLP) exporter.

Usage Example

package main

import (
	"context"

	"go.opentelemetry.io/otel/attribute"

	"github.com/go-kratos-ecosystem/components/v2/otel/otlp"
)

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

	// transport
	transport := otlp.NewGRPCTransport("localhost:4317", otlp.WithGRPCTransportInsecure(true))

	// client
	client := otlp.NewClient(
		otlp.WithServiceName("service-name"),
		otlp.WithDeploymentEnvironment("development"),
		otlp.WithAttributes(
			attribute.String("key", "value"),
			// ...
		),
		otlp.WithTransport(transport),
	)

	if err := client.Configure(ctx); err != nil {
		panic(err)
	}

	defer client.Shutdown(ctx)

	// do something
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultHooks = []Hook{
	&RuntimeMetricsHook{},
	&HostMetricsHook{},
}

DefaultHooks are the hooks that are enabled by default.

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(opts ...Option) *Client

func (*Client) Configure

func (c *Client) Configure(ctx context.Context) error

func (*Client) RegisterResource

func (c *Client) RegisterResource(resource *sdkresource.Resource)

func (*Client) Shutdown

func (c *Client) Shutdown(ctx context.Context) (err error)

type GRPCTransport

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

func NewGRPCTransport

func NewGRPCTransport(endpoint string, opts ...GRPCTransportOption) *GRPCTransport

func (*GRPCTransport) GetLogExporter

func (t *GRPCTransport) GetLogExporter(ctx context.Context) (log.Exporter, error)

func (*GRPCTransport) GetMetricExporter

func (t *GRPCTransport) GetMetricExporter(ctx context.Context) (metric.Exporter, error)

func (*GRPCTransport) GetTraceSpanExporter

func (t *GRPCTransport) GetTraceSpanExporter(ctx context.Context) (trace.SpanExporter, error)

type GRPCTransportOption

type GRPCTransportOption func(*GRPCTransport)

func WithGRPCTransportInsecure

func WithGRPCTransportInsecure(insecure bool) GRPCTransportOption

type Hook

type Hook interface {
	// Configured is called after the client is fully configured.
	Configured(ctx context.Context, client *Client) error
}

type HostMetricsHook

type HostMetricsHook struct{}

HostMetricsHook is a hook that starts the host metrics collection.

func (*HostMetricsHook) Configured

func (h *HostMetricsHook) Configured(context.Context, *Client) error

type Option

type Option func(*Client)

func WithAttributes

func WithAttributes(attributes ...attribute.KeyValue) Option

func WithDeploymentEnvironment

func WithDeploymentEnvironment(deploymentEnvironment string) Option

func WithHook

func WithHook(hooks ...Hook) Option

func WithLoggerProvider

func WithLoggerProvider(provider log.LoggerProvider) Option

func WithMeterProvider

func WithMeterProvider(provider metric.MeterProvider) Option

func WithPropagator

func WithPropagator(propagator propagation.TextMapPropagator) Option

func WithResource

func WithResource(resource *sdkresource.Resource) Option

func WithServiceName

func WithServiceName(serviceName string) Option

func WithTraceSampler

func WithTraceSampler(sampler sdktrace.Sampler) Option

func WithTracerProvider

func WithTracerProvider(provider trace.TracerProvider) Option

func WithTransport

func WithTransport(transport Transport) Option

type Provider

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

func NewProvider

func NewProvider(client *Client) *Provider

func (*Provider) Bootstrap

func (p *Provider) Bootstrap(ctx context.Context) (context.Context, error)

func (*Provider) Terminate

func (p *Provider) Terminate(ctx context.Context) (context.Context, error)

type RuntimeMetricsHook

type RuntimeMetricsHook struct{}

RuntimeMetricsHook is a hook that starts the runtime metrics collection.

func (*RuntimeMetricsHook) Configured

func (r *RuntimeMetricsHook) Configured(context.Context, *Client) error

type Transport

type Transport interface {
	GetTraceSpanExporter(ctx context.Context) (trace.SpanExporter, error)
	GetMetricExporter(ctx context.Context) (metric.Exporter, error)
	GetLogExporter(ctx context.Context) (log.Exporter, error)
}

Jump to

Keyboard shortcuts

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