Skip to content

Commit

Permalink
Merge pull request #38 from FachschaftMathPhysInfo/35-export-otel-tra…
Browse files Browse the repository at this point in the history
…ces-from-backend

35 export otel traces from backend
  • Loading branch information
dheidemann authored Jul 11, 2024
2 parents a57bf1f + f6f6a5d commit 0ed7204
Show file tree
Hide file tree
Showing 9 changed files with 226 additions and 42 deletions.
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ services:
volumes:
- data:/var/lib/postgresql/data
env_file: .env.local

otel-collector:
image: otel/opentelemetry-collector-contrib
volumes:
- ./otel-collector-config.yaml:/etc/otelcol-contrib/config.yaml

server:
build:
context: ./server
Expand All @@ -19,6 +25,8 @@ services:
- 8080:8080
depends_on:
- postgres
- otel-collector

frontend:
build:
context: ./frontend
Expand Down
18 changes: 18 additions & 0 deletions otel-collector-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
receivers:
otlp:
protocols:
grpc:
endpoint: "0.0.0.0:4317"
processors:
exporters:
debug:
verbosity: detailed
sampling_initial: 5
sampling_thereafter: 200

service:
pipelines:
traces:
receivers: [otlp]
processors: []
exporters: [debug]
1 change: 1 addition & 0 deletions server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ COPY models ./models
COPY db ./db
COPY email ./email
COPY maintenance ./maintenance
COPY tracing ./tracing

RUN CGO_ENABLED=0 go build -a -o graphql-server server.go

Expand Down
10 changes: 7 additions & 3 deletions server/db/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (
"github.com/uptrace/bun"
"github.com/uptrace/bun/dialect/pgdialect"
"github.com/uptrace/bun/driver/pgdriver"
"github.com/uptrace/bun/extra/bundebug"
"github.com/uptrace/bun/extra/bunotel"
"go.opentelemetry.io/otel/sdk/trace"
)

func Init(ctx context.Context) (*bun.DB, *sql.DB, error) {
func Init(ctx context.Context, tracer *trace.TracerProvider) (*bun.DB, *sql.DB, error) {
db_user := os.Getenv("POSTGRES_USER")
db_pw := os.Getenv("POSTGRES_PASSWORD")
db_db := os.Getenv("POSTGRES_DB")
Expand All @@ -26,7 +27,10 @@ func Init(ctx context.Context) (*bun.DB, *sql.DB, error) {

db := bun.NewDB(sqldb, pgdialect.New())

db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose(true)))
db.AddQueryHook(bunotel.NewQueryHook(
bunotel.WithFormattedQueries(true),
bunotel.WithTracerProvider(tracer),
))

relations := []interface{}{
(*models.EventToTutor)(nil),
Expand Down
30 changes: 24 additions & 6 deletions server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,24 @@ go 1.22.4

require (
github.com/99designs/gqlgen v0.17.49
github.com/go-chi/chi/v5 v5.0.14
github.com/go-chi/chi/v5 v5.1.0
github.com/matcornic/hermes/v2 v2.1.0
github.com/ravilushqa/otelgqlgen v0.16.0
github.com/riandyrn/otelchi v0.9.0
github.com/robfig/cron/v3 v3.0.1
github.com/rs/cors v1.11.0
github.com/uptrace/bun v1.2.1
github.com/uptrace/bun/dialect/pgdialect v1.2.1
github.com/uptrace/bun/driver/pgdriver v1.2.1
github.com/uptrace/bun/extra/bundebug v1.2.1
github.com/uptrace/bun/extra/bunotel v1.2.1
github.com/vektah/gqlparser/v2 v2.5.16
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.53.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0
go.opentelemetry.io/otel v1.28.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.28.0
go.opentelemetry.io/otel/sdk v1.28.0
go.opentelemetry.io/otel/trace v1.28.0
google.golang.org/grpc v1.65.0
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
)

Expand All @@ -23,19 +32,20 @@ require (
github.com/PuerkitoBio/goquery v1.9.2 // indirect
github.com/agnivade/levenshtein v1.1.1 // indirect
github.com/andybalholm/cascadia v1.3.2 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/css v1.0.1 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/huandu/xstrings v1.5.0 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/jaytaylor/html2text v0.0.0-20230321000545-74c2419ad056 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
Expand All @@ -46,19 +56,27 @@ require (
github.com/sosodev/duration v1.3.1 // indirect
github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf // indirect
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect
github.com/uptrace/opentelemetry-go-extra/otelsql v0.2.4 // indirect
github.com/urfave/cli/v2 v2.27.2 // indirect
github.com/vanng822/css v1.0.1 // indirect
github.com/vanng822/go-premailer v1.21.0 // indirect
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect
go.opentelemetry.io/contrib v1.27.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 // indirect
go.opentelemetry.io/otel/metric v1.28.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/tools v0.22.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240701130421-f6361c86f094 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
mellium.im/sasl v0.3.1 // indirect
Expand Down
Loading

0 comments on commit 0ed7204

Please sign in to comment.