opentelemetry

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: MIT Imports: 27 Imported by: 0

README

OpenTelemetry

This package provides effective observability to the flamingo ecosystem using the OpenTelemetry instrumentation library. With the OpenTelemetry module, your application automatically exports telemetry data such as metrics and traces. This makes it easy to analyze your application's behavior and collect statistics about load and performance. It provides exporters for the most common tools, i.e. Jaeger, Prometheus and OTLP components.

The metrics endpoint is provided under the systemendpoint. Once the module is activate you can access them via http://localhost:13210/metrics

Module configuration

Config Default Value Description
flamingo.opentelemetry.serviceName flamingo serviceName is automatically added to all traces as service.name attribute
flamingo.opentelemetry.jaeger.enable false enables the jaeger exporter
ℹ With Jaeger v1.35 they officially support the OpenTelemetry Protocol, so you can use the OTLP exporter instead.
flamingo.opentelemetry.jaeger.endpoint http://localhost:14268/api/traces URL to the jaeger instance
flamingo.opentelemetry.zipkin.enable false enables the zipkin exporter
flamingo.opentelemetry.zipkin.endpoint http://localhost:9411/api/v2/spans URL to the zipkin instance
flamingo.opentelemetry.otlp.http.enable false enables the OTLP HTTP exporter
flamingo.opentelemetry.otlp.http.endpoint http://localhost:4318/v1/traces URL to the OTLP collector
flamingo.opentelemetry.otlp.grpc.enable false enables the OTLP gRPC exporter
flamingo.opentelemetry.otlp.grpc.endpoint grpc://localhost:4317/v1/traces URL to the OTLP collector
flamingo.opentelemetry.tracing.sampler.allowlist [] list of URL paths that are sampled; if empty, all paths are allowed
flamingo.opentelemetry.tracing.sampler.blocklist [] list of URL paths that are never sampled
flamingo.opentelemetry.tracing.sampler.allowParentTrace true if true, we will follow sampling decisions of the parent span

Adding your own tracing information

Before you can create your own spans, you have to initialize a tracer:

tracer := otel.Tracer("my-app")

Now you can create a span based on a context.Context. This will automatically attach all tracing-relevant information (e.g. trace-ID) to the span.

func doSomething(ctx context.Context) {
    ctx, span := tracer.Start(ctx, "my-span")
    defer span.End()
    
    // do some work to track with my-span	
}

To add further attributes to the span, please refer to the official OpenTelemetry documentation.

Adding your own metrics

To collect your own metrics, you have to initialize a meter:

meter := otel.Meter("my-app")

Now you can create a new metric, e.g. a counter:

counter, _ := meter.Int64Counter("my.count",
    metric.WithDescription("count of something"),
)

counter.Add(ctx, 1)

For more information about the kinds of metrics and how to use them, please refer to the official OpenTelemetry documentation.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SemVersion

func SemVersion() string

SemVersion is the semantic version to be supplied to tracer/meter creation.

func URLPrefixSampler

func URLPrefixSampler(allowed, blocked []string, allowParentTrace bool) otelhttp.Filter

func Version

func Version() string

Types

type ConfiguredURLPrefixSampler

type ConfiguredURLPrefixSampler struct {
	Allowlist        config.Slice
	Blocklist        config.Slice
	AllowParentTrace bool
}

func (*ConfiguredURLPrefixSampler) GetFilterOption

func (c *ConfiguredURLPrefixSampler) GetFilterOption() otelhttp.Filter

func (*ConfiguredURLPrefixSampler) Inject

func (c *ConfiguredURLPrefixSampler) Inject(
	cfg *struct {
		Allowlist        config.Slice `inject:"config:flamingo.opentelemetry.tracing.sampler.allowlist,optional"`
		Blocklist        config.Slice `inject:"config:flamingo.opentelemetry.tracing.sampler.blocklist,optional"`
		AllowParentTrace bool         `inject:"config:flamingo.opentelemetry.tracing.sampler.allowParentTrace,optional"`
	},
) *ConfiguredURLPrefixSampler

Inject dependencies

type Module

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

func (*Module) Configure

func (m *Module) Configure(injector *dingo.Injector)

func (*Module) CueConfig

func (m *Module) CueConfig() string

func (*Module) Depends

func (m *Module) Depends() []dingo.Module

func (*Module) Inject

func (m *Module) Inject(
	cfg *struct {
		ServiceName      string `inject:"config:flamingo.opentelemetry.serviceName"`
		JaegerEnable     bool   `inject:"config:flamingo.opentelemetry.jaeger.enable"`
		JaegerEndpoint   string `inject:"config:flamingo.opentelemetry.jaeger.endpoint"`
		ZipkinEnable     bool   `inject:"config:flamingo.opentelemetry.zipkin.enable"`
		ZipkinEndpoint   string `inject:"config:flamingo.opentelemetry.zipkin.endpoint"`
		OTLPEnableHTTP   bool   `inject:"config:flamingo.opentelemetry.otlp.http.enable"`
		OTLPEndpointHTTP string `inject:"config:flamingo.opentelemetry.otlp.http.endpoint"`
		OTLPEnableGRPC   bool   `inject:"config:flamingo.opentelemetry.otlp.grpc.enable"`
		OTLPEndpointGRPC string `inject:"config:flamingo.opentelemetry.otlp.grpc.endpoint"`
	},
) *Module

Jump to

Keyboard shortcuts

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