Discover Packages
github.com/xmlking/toolkit/telemetry
package
module
Version:
v0.5.2
Opens a new window with list of versions in this module.
Published: Aug 8, 2023
License: MIT
Opens a new window with license information.
Imports: 1
Opens a new window with list of imports.
Imported by: ? modules, 0 packages
The first number is the count of modules that contain a package that imports this one.
The module count is a better indicator of popularity than the package count.
A module with 100 importing packages is counted only once instead of 100 times,
reflecting the fact that the choice to use the package was likely made only once,
not 100 times.
A '?' means that the value hasn't been computed yet.
Opens a new window with list of known importers.
README
README
¶
Telemetry
OpenTelemetry initialization helpers
Usage
Optional environment variables
export OTEL_RESOURCE_ATTRIBUTES=key=value,rk5=7
export OTEL_SERVICE_NAME=play-service
# enable metrics and tracking
export CONFY_FEATURES_METRICS_ENABLED=true
export CONFY_FEATURES_TRACING_ENABLED=true
# enable metrics target: `prometheus` and tracing target: `stdout`
export CONFY_FEATURES_METRICS_TARGET=prometheus
export CONFY_FEATURES_TRACING_TARGET=stdout
# when using with target: `gcp`
export GOOGLE_CLOUD_PROJECT=xyz
export GOOGLE_APPLICATION_CREDENTIALS=../../../Apps/micro-starter-kit.json
import (
"go.opentelemetry.io/otel/api/global"
"go.opentelemetry.io/otel/instrumentation/grpctrace"
"github.com/xmlking/toolkit/telemetry/metrics"
"github.com/xmlking/toolkit/telemetry/tracing"
)
func main() {
cfg := config.GetConfig()
if cfg.Features.Tracing.Enabled {
closeFn := tracing.InitTracing(ctx, cfg.Features.Tracing)
defer closeFn()
}
if cfg.Features.Metrics.Enabled {
closeFn := metrics.InitMetrics(ctx, cfg.Features.Metrics)
defer closeFn()
}
lis, err := net.Listen("tcp", port)
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
s := grpc.NewServer(
grpc.UnaryInterceptor(grpctrace.UnaryServerInterceptor(global.Tracer(""))),
grpc.StreamInterceptor(grpctrace.StreamServerInterceptor(global.Tracer(""))),
)
api.RegisterHelloServiceServer(s, &server{})
if err := s.Serve(lis); err != nil {
log.Fatalf("failed to serve: %v", err)
}
}
Examples
Integrated GCP observability
gRPC tracking
Metrics:
Expand ▾
Collapse ▴
Documentation
¶
View Source
const (
GCP = "gcp"
PROMETHEUS = "prometheus"
STDOUT = "stdout"
)
type MetricsConfig struct {
Enabled bool `yaml:",omitempty" default:"false"`
Backend string `yaml:",omitempty" validate:"oneof=gcp prometheus stdout" default:"stdout"`
Endpoint string `yaml:"endpoint,omitempty"`
SamplingFraction float64 `yaml:"sampling_fraction,omitempty" default:"1.0"`
CollectPeriod time .Duration `yaml:"collect_period,omitempty" default:"10s"`
HistogramDistribution []float64 `yaml:"histogram_distribution,omitempty" validate:"omitempty,gt=0,dive,min=0,max=10"`
}
MetricsConfig struct
type TracingConfig struct {
Enabled bool `yaml:",omitempty" default:"false"`
Backend string `yaml:",omitempty" validate:"oneof=gcp stdout" default:"stdout"`
Endpoint string `yaml:"endpoint,omitempty"`
SamplingFraction float64 `yaml:"sampling_fraction,omitempty" default:"1.0"`
}
TracingConfig struct
Source Files
¶
Directories
¶
Click to show internal directories.
Click to hide internal directories.