Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add otel tracing to authorino #380

Merged
merged 11 commits into from
Mar 1, 2023
Prev Previous commit
Next Next commit
made changes as per review request
Signed-off-by: ROHITH RAJU <rohithraju488@gmail.com>
  • Loading branch information
Rohith-Raju committed Feb 19, 2023
commit fbb33cdba42f748e6c883e04dfa1283cf578f75a
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ require (
github.com/spf13/cobra v1.5.0
github.com/spf13/pflag v1.0.5
github.com/tidwall/gjson v1.14.0
go.opentelemetry.io/otel v1.13.0
go.opentelemetry.io/otel/exporters/jaeger v1.13.0
go.opentelemetry.io/otel/sdk v1.13.0
go.uber.org/zap v1.19.1
golang.org/x/net v0.7.0
golang.org/x/oauth2 v0.5.0
Expand Down Expand Up @@ -60,7 +63,7 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.2.0 // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
Expand All @@ -84,16 +87,13 @@ require (
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/stretchr/testify v1.8.0 // indirect
github.com/stretchr/testify v1.8.1 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/vektah/gqlparser/v2 v2.4.6 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/yashtewari/glob-intersection v0.1.0 // indirect
go.opentelemetry.io/otel v1.13.0 // indirect
go.opentelemetry.io/otel/exporters/jaeger v1.13.0 // indirect
go.opentelemetry.io/otel/sdk v1.13.0 // indirect
go.opentelemetry.io/otel/trace v1.13.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
Expand Down
5 changes: 3 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,8 @@ github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-containerregistry v0.5.1/go.mod h1:Ct15B4yir3PLOP5jsy0GNeYVaIZs/MK/Jz5any1wFW0=
github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
Expand Down Expand Up @@ -1068,6 +1068,7 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v0.0.0-20151208002404-e3a8ff8ce365/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v0.0.0-20180303142811-b89eecf5ca5d/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
Expand Down
14 changes: 10 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ var (
healthProbeAddr string
enableLeaderElection bool
maxHttpRequestBodySize int64
enableTrace bool
observabilityServiceEndpoint string

scheme = runtime.NewScheme()

Expand Down Expand Up @@ -129,7 +129,7 @@ func main() {
cmdServer.PersistentFlags().StringVar(&healthProbeAddr, "health-probe-addr", ":8081", "The network address the health probe endpoint binds to")
cmdServer.PersistentFlags().BoolVar(&enableLeaderElection, "enable-leader-election", false, "Enable leader election for status updater - ensures only one instance of Authorino tries to update the status of reconciled resources")
cmdServer.PersistentFlags().Int64Var(&maxHttpRequestBodySize, "max-http-request-body-size", utils.EnvVar("MAX_HTTP_REQUEST_BODY_SIZE", int64(8192)), "Maximum size of the body of requests accepted in the raw HTTP interface of the authorization server - in bytes")
cmdServer.PersistentFlags().BoolVar(&enableTrace, "enable-trace", true, "Enables tracing")
cmdServer.PersistentFlags().StringVar(&observabilityServiceEndpoint, "observability-service-endpoint", "", "Enable Otel Tracing by providing an endpoint URL")
guicassolato marked this conversation as resolved.
Show resolved Hide resolved

cmdVersion := &cobra.Command{
Use: "version",
Expand Down Expand Up @@ -174,8 +174,14 @@ func run(cmd *cobra.Command, _ []string) {
managerOptions.Namespace = watchNamespace
}

tp := trace.CreateTraceProvider("http://localhost:14268/api/authorino")
otel.SetTracerProvider(tp)
if observabilityServiceEndpoint != "" {
tp, err := trace.CreateTraceProvider(observabilityServiceEndpoint, version)
Rohith-Raju marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
logger.Error(err, "unable to create traceprovider")
os.Exit(1)
}
otel.SetTracerProvider(tp)
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), managerOptions)
if err != nil {
Expand Down
24 changes: 10 additions & 14 deletions pkg/trace/exporter.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package trace

import (
"fmt"
"os"

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/exporters/jaeger"
"go.opentelemetry.io/otel/sdk/resource"
Expand All @@ -12,35 +9,34 @@ import (
)

// NewExporter returns a Jaeger Exporter
func NewExporter(url string) (*jaeger.Exporter, error) {
endPoint := jaeger.WithEndpoint(url)
collector := jaeger.WithCollectorEndpoint(endPoint)
func newExporter(url string) (*jaeger.Exporter, error) {
endpoint := jaeger.WithEndpoint(url)
collector := jaeger.WithCollectorEndpoint(endpoint)
jagerEndpoint, err := jaeger.New(collector)
return jagerEndpoint, err
}

func NewResource() *resource.Resource {
func newResource(version string) *resource.Resource {
r, _ := resource.Merge(
resource.Default(),
resource.NewWithAttributes(
semconv.SchemaURL,
semconv.ServiceNameKey.String("authorino"),
semconv.ServiceVersionKey.String("v0.1.0"),
semconv.ServiceVersionKey.String(version),
attribute.String("environment", "demo"),
Rohith-Raju marked this conversation as resolved.
Show resolved Hide resolved
),
)
return r
}

func CreateTraceProvider(url string) *trace.TracerProvider {
exp, err := NewExporter(url)
func CreateTraceProvider(url string, version string) (*trace.TracerProvider, error) {
exp, err := newExporter(url)
if err != nil {
fmt.Println("error: ", err)
os.Exit(1)
return nil, err
}
tp := trace.NewTracerProvider(
trace.WithBatcher(exp),
trace.WithResource(NewResource()),
trace.WithResource(newResource(version)),
)
return tp
return tp, nil
}