Skip to content

Commit

Permalink
chore: e2e-telemetry-correlation-poc
Browse files Browse the repository at this point in the history
  • Loading branch information
Blinkuu committed Dec 5, 2024
1 parent 59d44ef commit 7a4fef8
Show file tree
Hide file tree
Showing 501 changed files with 61,618 additions and 4,125 deletions.
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ ARG PUBLIC_BACKEND_WS_ENDPOINT=""
ENV PUBLIC_BACKEND_WS_ENDPOINT=${PUBLIC_BACKEND_WS_ENDPOINT}

RUN npm install && \
npm run build
npm run build

FROM golang:1.21-bullseye AS builder
FROM golang:1.23-bullseye AS builder

WORKDIR /app
COPY . ./
COPY --from=fe-builder /app/pkg/web/build /app/pkg/web/build
RUN go generate pkg/web/web.go && \
CGO_ENABLED=0 go build -o /bin/quickpizza ./cmd
CGO_ENABLED=0 go build -o /bin/quickpizza ./cmd

FROM gcr.io/distroless/static-debian11

Expand Down
45 changes: 34 additions & 11 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,55 @@ package main

import (
"context"
"log/slog"
http "net/http"
"os"
"runtime"
"strconv"
"strings"
"time"

"log/slog"

"github.com/grafana/pyroscope-go"
"github.com/grafana/quickpizza/pkg/database"
qpgrpc "github.com/grafana/quickpizza/pkg/grpc"
qphttp "github.com/grafana/quickpizza/pkg/http"
qpotel "github.com/grafana/quickpizza/pkg/otel"
"github.com/hashicorp/go-retryablehttp"
slogmulti "github.com/samber/slog-multi"
"go.opentelemetry.io/contrib/bridges/otelslog"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"go.opentelemetry.io/otel/propagation"
)

func main() {
// write logs as logfmt
slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{
slogStdErr := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{
Level: getLogLevel(),
})))
}))
slog.SetDefault(slogStdErr)

prov := qpotel.Noop()
if otlpEndpoint, otlpEnabled := os.LookupEnv("OTEL_EXPORTER_OTLP_ENDPOINT"); otlpEnabled {
newProv, shutdown, err := qpotel.Setup(context.Background(), otlpEndpoint)
if err != nil {
slog.Error("failed to setup otel", "err", err)
os.Exit(1)
}

defer shutdown(context.Background())

prov = newProv

otelLogger := otelslog.NewLogger("quickpizza", otelslog.WithLoggerProvider(prov.LoggerProvider()))

slog.SetDefault(
slog.New(
slogmulti.Fanout(
slogStdErr.Handler(),
otelLogger.Handler(),
),
),
)
}

// Create an HTTP client configured from env vars.
// If no specific env vars are set, this will return a http client that does not perform any retries.
Expand All @@ -36,11 +62,8 @@ func main() {
os.Exit(1)
}

if otlpEndpoint, tracingEnabled := os.LookupEnv("QUICKPIZZA_OTLP_ENDPOINT"); tracingEnabled {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

installer, err := qphttp.NewTraceInstaller(ctx, otlpEndpoint)
if _, tracingEnabled := os.LookupEnv("OTEL_EXPORTER_OTLP_ENDPOINT"); tracingEnabled {
installer, err := qphttp.NewTraceInstaller(prov)
if err != nil {
slog.Error("creating otlp trace installer", "err", err)
os.Exit(1)
Expand Down Expand Up @@ -157,7 +180,7 @@ func clientFromEnv() *http.Client {
Transport: otelhttp.NewTransport(
nil, // Default transport.
// Propagator will retrieve the tracer used in the server from memory.
otelhttp.WithPropagators(propagation.TraceContext{}),
// otelhttp.WithPropagators(propagation.TraceContext{}),
),
}

Expand Down
19 changes: 19 additions & 0 deletions docker-compose-cloud-serverless.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: "3.8"

services:
quickpizza:
# The QUICKPIZZA_IMAGE env. variable enables the use of a locally built image,
# created with `docker build -t image_name .`
image: ${QUICKPIZZA_IMAGE:-ghcr.io/grafana/quickpizza-local:latest}
ports:
- "3333:3333"
environment:
QUICKPIZZA_TRUST_CLIENT_TRACEID: 1
# must be set with an .env file
QUICKPIZZA_CONF_FARO_URL: "${QUICKPIZZA_CONF_FARO_URL}"
QUICKPIZZA_PYROSCOPE_ENDPOINT: "${QUICKPIZZA_CONF_PYROSCOPE_ENDPOINT}"
QUICKPIZZA_GRAFANA_CLOUD_USER: "${QUICKPIZZA_GRAFANA_CLOUD_USER}"
QUICKPIZZA_GRAFANA_CLOUD_PASSWORD: "${GRAFANA_CLOUD_TOKEN}"
OTEL_EXPORTER_OTLP_PROTOCOL: "${OTEL_EXPORTER_OTLP_PROTOCOL}"
OTEL_EXPORTER_OTLP_ENDPOINT: "${OTEL_EXPORTER_OTLP_ENDPOINT}"
OTEL_EXPORTER_OTLP_HEADERS: "${OTEL_EXPORTER_OTLP_HEADERS}"
5 changes: 4 additions & 1 deletion docker-compose-cloud.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ services:
ports:
- "3333:3333"
environment:
QUICKPIZZA_OTLP_ENDPOINT: http://agent:4318
OTEL_EXPORTER_OTLP_INSECURE: true
OTEL_EXPORTER_OTLP_ENDPOINT: http://agent:4318
QUICKPIZZA_TRUST_CLIENT_TRACEID: 1
# must be set with an .env file
QUICKPIZZA_CONF_FARO_URL: "${QUICKPIZZA_CONF_FARO_URL}"
QUICKPIZZA_PYROSCOPE_ENDPOINT: "${QUICKPIZZA_CONF_PYROSCOPE_ENDPOINT}"
QUICKPIZZA_GRAFANA_CLOUD_USER: "${QUICKPIZZA_GRAFANA_CLOUD_USER}"
QUICKPIZZA_GRAFANA_CLOUD_PASSWORD: "${GRAFANA_CLOUD_TOKEN}"

agent:
image: grafana/agent:latest
Expand Down
3 changes: 2 additions & 1 deletion docker-compose-local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ services:
ports:
- "3333:3333"
environment:
QUICKPIZZA_OTLP_ENDPOINT: http://agent:4318
OTEL_EXPORTER_OTLP_INSECURE: true
OTEL_EXPORTER_OTLP_ENDPOINT: http://agent:4318
QUICKPIZZA_TRUST_CLIENT_TRACEID: 1
QUICKPIZZA_PYROSCOPE_ENDPOINT: http://pyroscope:4040

Expand Down
47 changes: 29 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module github.com/grafana/quickpizza

go 1.21
go 1.22

toolchain go1.22.4
toolchain go1.23.3

require (
github.com/go-chi/chi v1.5.4
Expand All @@ -13,25 +13,35 @@ require (
github.com/olahol/melody v1.1.3
github.com/prometheus/client_golang v1.14.1-0.20221122130035-8b6e68085b10
github.com/rs/xid v1.4.0
github.com/samber/slog-multi v1.2.4
github.com/uptrace/bun v1.1.14
github.com/uptrace/bun/dbfixture v1.1.14
github.com/uptrace/bun/dialect/pgdialect v1.1.14
github.com/uptrace/bun/dialect/sqlitedialect v1.1.14
github.com/uptrace/bun/driver/pgdriver v1.1.14
github.com/uptrace/bun/driver/sqliteshim v1.1.14
github.com/uptrace/bun/extra/bunotel v1.1.14
go.opentelemetry.io/contrib/bridges/otelslog v0.7.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.42.0
go.opentelemetry.io/otel v1.28.0
go.opentelemetry.io/contrib/processors/baggagecopy v0.5.0
go.opentelemetry.io/otel v1.32.0
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.8.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.28.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.28.0
go.opentelemetry.io/otel/sdk v1.28.0
go.opentelemetry.io/otel/trace v1.28.0
golang.org/x/net v0.26.0
google.golang.org/grpc v1.65.0
google.golang.org/protobuf v1.34.2
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.32.0
go.opentelemetry.io/otel/log v0.8.0
go.opentelemetry.io/otel/sdk v1.32.0
go.opentelemetry.io/otel/sdk/log v0.8.0
go.opentelemetry.io/otel/sdk/metric v1.32.0
go.opentelemetry.io/otel/trace v1.32.0
golang.org/x/net v0.30.0
google.golang.org/grpc v1.67.1
google.golang.org/protobuf v1.35.1
)

require github.com/samber/lo v1.47.0 // indirect

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
Expand All @@ -44,7 +54,7 @@ require (
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grafana/pyroscope-go/godeltaprof v0.1.7 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.23.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
Expand All @@ -60,16 +70,17 @@ require (
github.com/uptrace/opentelemetry-go-extra/otelsql v0.2.1 // indirect
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
go.opentelemetry.io/otel/metric v1.28.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.8.0
go.opentelemetry.io/otel/metric v1.32.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/mod v0.17.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.21.1-0.20240508182429-e35e4ccd0d2d // 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
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/sync v0.9.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/text v0.20.0 // indirect
golang.org/x/tools v0.22.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/uint128 v1.3.0 // indirect
mellium.im/sasl v0.3.1 // indirect
Expand Down
Loading

0 comments on commit 7a4fef8

Please sign in to comment.