Skip to content

Commit

Permalink
Merge pull request #190 from foomo/feature/otel-update
Browse files Browse the repository at this point in the history
feat(telemetry): update otel
  • Loading branch information
franklinkim authored Mar 25, 2024
2 parents 25e94fc + f791248 commit 9f78c0f
Show file tree
Hide file tree
Showing 17 changed files with 318 additions and 606 deletions.
45 changes: 34 additions & 11 deletions examples/telemetry/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,27 @@ package main
import (
"math/rand"
"net/http"
"time"

"github.com/foomo/keel/service"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric/instrument"

"github.com/foomo/keel"
"github.com/foomo/keel/log"
"github.com/foomo/keel/net/http/middleware"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/trace"
)

var metricRequestLatency = promauto.NewHistogram(prometheus.HistogramOpts{
Namespace: "demo",
Name: "request_latency_seconds",
Help: "Request Latency",
Buckets: prometheus.ExponentialBuckets(.0001, 2, 50),
})

func main() {
// Run this example with the following env vars:
//
Expand Down Expand Up @@ -48,14 +57,14 @@ func main() {
svs := http.NewServeMux()

{ // counter
counter, err := meter.SyncInt64().Counter(
counter, err := meter.Int64Counter(
"a.counter",
instrument.WithDescription("Count things"),
metric.WithDescription("Count things"),
)
log.Must(l, err, "failed to create counter meter")

svs.HandleFunc("/count", func(w http.ResponseWriter, r *http.Request) {
counter.Add(r.Context(), 1, attribute.String("key", "value"))
counter.Add(r.Context(), 1, metric.WithAttributes(attribute.String("key", "value")))
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte("OK!"))
})
Expand All @@ -70,33 +79,47 @@ func main() {
})

{ // up down
upDown, err := meter.SyncInt64().UpDownCounter(
upDown, err := meter.Int64UpDownCounter(
"a.updown",
instrument.WithDescription("Up down values"),
metric.WithDescription("Up down values"),
)
log.Must(l, err, "failed to create up down meter")

svs.HandleFunc("/up", func(w http.ResponseWriter, r *http.Request) {
upDown.Add(r.Context(), 1, attribute.String("key", "value"))
upDown.Add(r.Context(), 1, metric.WithAttributes(attribute.String("key", "value")))
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte("OK!"))
})
svs.HandleFunc("/down", func(w http.ResponseWriter, r *http.Request) {
upDown.Add(r.Context(), -1, attribute.String("key", "value"))
upDown.Add(r.Context(), -1, metric.WithAttributes(attribute.String("key", "value")))
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte("OK!"))
})
}

{ // histogram
histogram, err := meter.SyncInt64().Histogram(
histogram, err := meter.Int64Histogram(
"a.histogram",
instrument.WithDescription("Up down values"),
metric.WithDescription("Up down values"),
metric.WithUnit("ms"),
)
log.Must(l, err, "failed to create up down meter")

svs.HandleFunc("/histogram", func(w http.ResponseWriter, r *http.Request) {
histogram.Record(r.Context(), int64(rand.Int()), attribute.String("key", "value"))
start := time.Now()
time.Sleep(time.Second)
traceID := trace.SpanContextFromContext(r.Context())
histogram.Record(r.Context(), int64(rand.Int()),
metric.WithAttributes(
attribute.String("key", "value"),
attribute.String("traceID", traceID.TraceID().String()),
),
)

metricRequestLatency.(prometheus.ExemplarObserver).ObserveWithExemplar(
time.Since(start).Seconds(), prometheus.Labels{"traceID": traceID.TraceID().String()},
)

w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte("OK!"))
})
Expand Down
63 changes: 31 additions & 32 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ require (
github.com/tidwall/pretty v1.2.1
github.com/tinylib/msgp v1.1.9
go.mongodb.org/mongo-driver v1.14.0
go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo v0.32.0
go.opentelemetry.io/contrib/instrumentation/host v0.32.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.32.0
go.opentelemetry.io/contrib/instrumentation/runtime v0.32.0
go.opentelemetry.io/otel v1.7.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.7.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.7.0
go.opentelemetry.io/otel/exporters/prometheus v0.30.0
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v0.30.0
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.7.0
go.opentelemetry.io/otel/metric v0.30.0
go.opentelemetry.io/otel/sdk v1.7.0
go.opentelemetry.io/otel/sdk/metric v0.30.0
go.opentelemetry.io/otel/trace v1.7.0
go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo v0.49.0
go.opentelemetry.io/contrib/instrumentation/host v0.49.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0
go.opentelemetry.io/contrib/instrumentation/runtime v0.49.0
go.opentelemetry.io/otel v1.24.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.24.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.24.0
go.opentelemetry.io/otel/exporters/prometheus v0.46.0
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.24.0
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.24.0
go.opentelemetry.io/otel/metric v1.24.0
go.opentelemetry.io/otel/sdk v1.24.0
go.opentelemetry.io/otel/sdk/metric v1.24.0
go.opentelemetry.io/otel/trace v1.24.0
go.temporal.io/api v1.8.0
go.temporal.io/sdk v1.15.0
go.temporal.io/sdk/contrib/opentelemetry v0.1.0
Expand All @@ -44,20 +44,20 @@ require (
)

require (
cloud.google.com/go v0.110.10 // indirect
cloud.google.com/go v0.111.0 // indirect
cloud.google.com/go/compute v1.23.3 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/firestore v1.14.0 // indirect
cloud.google.com/go/longrunning v0.5.4 // indirect
github.com/armon/go-metrics v0.4.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a // indirect
github.com/fatih/color v1.14.1 // indirect
github.com/felixge/httpsnoop v1.0.2 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
Expand All @@ -72,7 +72,7 @@ require (
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0 // indirect
github.com/hashicorp/consul/api v1.25.1 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
Expand All @@ -99,36 +99,36 @@ require (
github.com/philhofer/fwd v1.1.2 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/client_model v0.6.0 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/robfig/cron v1.2.0 // indirect
github.com/sagikazarmark/crypt v0.17.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/shirou/gopsutil/v3 v3.22.3 // indirect
github.com/shirou/gopsutil/v3 v3.24.1 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/tklauser/go-sysconf v0.3.10 // indirect
github.com/tklauser/numcpus v0.4.0 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.etcd.io/etcd/api/v3 v3.5.10 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.10 // indirect
go.etcd.io/etcd/client/v2 v2.305.10 // indirect
go.etcd.io/etcd/client/v3 v3.5.10 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.7.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.7.0 // indirect
go.opentelemetry.io/proto/otlp v0.16.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0 // indirect
go.opentelemetry.io/proto/otlp v1.1.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
Expand All @@ -139,13 +139,12 @@ require (
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.14.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.153.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20231212172506-995d672761c0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240102182953-50ed04b92917 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240102182953-50ed04b92917 // indirect
google.golang.org/grpc v1.61.1 // indirect
google.golang.org/protobuf v1.32.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
Loading

0 comments on commit 9f78c0f

Please sign in to comment.