Skip to content

Commit

Permalink
Add a jaeger service and the ability to report stats to it.
Browse files Browse the repository at this point in the history
  • Loading branch information
jakedt committed Apr 14, 2021
1 parent d7ef928 commit 67f7026
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 26 deletions.
19 changes: 11 additions & 8 deletions cmd/spicedb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ import (
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/trace/jaeger"
"go.opentelemetry.io/otel/sdk/resource"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/semconv"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/keepalive"
Expand All @@ -35,10 +40,6 @@ import (
"github.com/authzed/spicedb/internal/services"
api "github.com/authzed/spicedb/pkg/REDACTEDapi/api"
health "github.com/authzed/spicedb/pkg/REDACTEDapi/healthcheck"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/stdout"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
)

func main() {
Expand Down Expand Up @@ -260,7 +261,7 @@ func persistentPreRunE(cmd *cobra.Command, args []string) error {
case "none":
// Nothing.

case "stdout":
case "jaeger":
initTracer()
default:
return errors.New("unknown tracing")
Expand All @@ -271,16 +272,18 @@ func persistentPreRunE(cmd *cobra.Command, args []string) error {
}

func initTracer() {
var err error
exp, err := stdout.NewExporter(stdout.WithPrettyPrint())
exp, err := jaeger.NewRawExporter(jaeger.WithCollectorEndpoint("http://jaeger:14268/api/traces"))
if err != nil {
log.Fatal().Err(err).Msg("failed to initialize stdout exporter")
log.Fatal().Err(err).Msg("failed to initialize jaeger exporter")
return
}
bsp := sdktrace.NewBatchSpanProcessor(exp)
tp := sdktrace.NewTracerProvider(
sdktrace.WithSampler(sdktrace.AlwaysSample()),
sdktrace.WithSpanProcessor(bsp),
sdktrace.WithResource(resource.NewWithAttributes(semconv.ServiceNameKey.String("spicedb"))),
)
otel.SetTracerProvider(tp)

log.Info().Msg("jaeger tracing enabled")
}
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect
github.com/containerd/continuity v0.0.0-20210315143101-93e15499afd5 // indirect
github.com/dgraph-io/ristretto v0.0.3
github.com/dlmiddlecote/sqlstats v1.0.2
github.com/envoyproxy/protoc-gen-validate v0.1.0
github.com/golang-migrate/migrate/v4 v4.14.1
github.com/golang/protobuf v1.4.3
Expand All @@ -21,17 +22,17 @@ require (
github.com/jmoiron/sqlx v1.3.1
github.com/jzelinskie/cobrautil v0.0.0-20210330205530-45d5fbfe45dd
github.com/lib/pq v1.9.0
github.com/ngrok/sqlmw v0.0.0-20200129213757-d5c93a81bec6
github.com/opencontainers/runc v0.1.1 // indirect
github.com/ory/dockertest v3.3.5+incompatible
github.com/prometheus/client_golang v1.9.0
github.com/rs/zerolog v1.20.0
github.com/spf13/cobra v1.1.3
github.com/stretchr/testify v1.7.0
go.opentelemetry.io/otel v0.19.0
go.opentelemetry.io/otel/exporters/stdout v0.19.0
go.opentelemetry.io/otel/exporters/trace/jaeger v0.19.0
go.opentelemetry.io/otel/sdk v0.19.0
go.opentelemetry.io/otel/trace v0.19.0
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb // indirect
google.golang.org/grpc v1.36.0
google.golang.org/grpc/examples v0.0.0-20210316215007-967933baf52a // indirect
google.golang.org/protobuf v1.25.0
Expand Down
Loading

0 comments on commit 67f7026

Please sign in to comment.