Categorygithub.com/go-faster/sdk
module
0.15.1
Repository: https://github.com/go-faster/sdk.git
Documentation: pkg.go.dev

# README

sdk Go Reference codecov alpha

SDK for go-faster applications. Implements automatic setup of observability and daemonization based on environment variables.

Packages

PackageDescription
autometerAutomatic OpenTelemetry MeterProvider from environment
autotracerAutomatic OpenTelemetry TracerProvider from environment
profilerExplicit pprof routes
zctxcontext.Context and tracing support for zap
goldGolden files in tests
appAutomatic setup observability and run daemon

Environment variables

[!WARNING] The pprof listener is disabled by default and should be explicitly enabled by PPROF_ADDR.

[!IMPORTANT]
For configuring OpenTelemetry exporters, see OpenTelemetry exporters documentation.

Metrics and pprof can be served from same address if needed, set both addresses to the same value.

NameDescriptionExampleDefault
AUTOMAXPROCSUse automaxprocs01
AUTOMAXPROCS_MINMinimum GOMAXPROCS to use21
OTEL_RESOURCE_ATTRIBUTESOTEL Resource attributesservice.name=app
OTEL_SERVICE_NAMEOTEL Service nameappunknown_service
OTEL_EXPORTER_OTLP_PROTOCOLOTLP protocol to usehttpgrpc
OTEL_PROPAGATORSOTEL Propagatorsnonetracecontext,baggage
PPROF_ROUTESList of enabled pprof routescmdline,profileSee below
PPROF_ADDREnable pprof and listen on addr0.0.0.0:9010N/A
OTEL_LOG_LEVELLog leveldebuginfo
METRICS_ADDRPrometheus addr (fallback)localhost:9464Prometheus addr
OTEL_METRICS_EXPORTERMetrics exporter to useprometheusotlp
OTEL_EXPORTER_OTLP_METRICS_PROTOCOLMetrics OTLP protocol to usehttpgrpc
OTEL_EXPORTER_PROMETHEUS_HOSTHost of prometheus addr0.0.0.0localhost
OTEL_EXPORTER_PROMETHEUS_PORTPort of prometheus addr90909464
OTEL_TRACES_EXPORTERTraces exporter to useotlpotlp
OTEL_EXPORTER_OTLP_TRACES_PROTOCOLTraces OTLP protocol to usehttpgrpc

Metrics exporters

ValueDescription
otlpOTLP exporter (default)
prometheusPrometheus exporter
noneNo exporter

Trace exporters

ValueDescription
otlpOTLP exporter (default)
noneNo exporter

Defaults

By default, OpenTelemetry SDK tries localhost:4318 OTLP endpoint, assuming collector is running on the localhost.

If that is not true, following errors can be seen in the logs:

{"error": "failed to upload metrics: Post \"https://localhost:4318/v1/metrics\": dial tcp 127.0.0.1:4318: connect: connection refused"}
{"error": "failed to upload traces: Post \"https://localhost:4318/v1/traces\": dial tcp 127.0.0.1:4318: connect: connection refused"}

To fix that, configure exporters accordingly. For example, this will disable both metrics and traces exporters:

export OTEL_TRACES_EXPORTER="none"
export OTEL_METRICS_EXPORTER="none"

To enable Prometheus exporter, set OTEL_METRICS_EXPORTER=prometheus and OTEL_EXPORTER_PROMETHEUS_HOST and OTEL_EXPORTER_PROMETHEUS_PORT accordingly.

export OTEL_METRICS_EXPORTER="prometheus"
export OTEL_EXPORTER_PROMETHEUS_HOST="0.0.0.0"
export OTEL_EXPORTER_PROMETHEUS_PORT="9090"

Routes for pprof

List of enabled pprof routes

Name: PPROF_ROUTES

Default: profile,symbol,trace,goroutine,heap,threadcreate,block

TODO

  • Use slog
  • Pyroscope compat

Code coverage

codecov

# Packages

Package app implements OTEL, prometheus, graceful shutdown and other common application features for go-faster projects.
No description provided by the author
Package autometer provides an OpenTelemetry MeterProvider creation function.
Package autotracer provides an OpenTelemetry TracerProvider creation function.
No description provided by the author
Package gold implements golden files.
Package otelenv provides helpers for working with OTEL_RESOURCE_ATTRIBUTES.
Package profiler implements pprof routes.
Package zapotel provides OpenTelemetry logs exporter zap core implementation.
Package zctx is a context-aware zap logger.