From ebf27451ca5fb75e188034d53232a7d9441e3198 Mon Sep 17 00:00:00 2001 From: saba Date: Tue, 2 Apr 2024 18:55:51 +0200 Subject: [PATCH] Add trace to all methods --- api/api.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/api/api.go b/api/api.go index 989a9ca3..e52d157f 100644 --- a/api/api.go +++ b/api/api.go @@ -5,7 +5,6 @@ package api import ( "context" "encoding/json" - sdkPlugin "github.com/gatewayd-io/gatewayd-plugin-sdk/plugin" v1 "github.com/gatewayd-io/gatewayd/api/v1" "github.com/gatewayd-io/gatewayd/config" @@ -102,7 +101,9 @@ func (a *API) GetGlobalConfig(ctx context.Context, group *v1.Group) (*structpb.S } // GetPluginConfig returns the plugin configuration of the GatewayD. -func (a *API) GetPluginConfig(context.Context, *emptypb.Empty) (*structpb.Struct, error) { +func (a *API) GetPluginConfig(ctx context.Context, empty *emptypb.Empty) (*structpb.Struct, error) { + _, span := otel.Tracer(config.TracerName).Start(ctx, "Get Plugin Config") + defer span.End() jsonData, err := json.Marshal(a.Config.Plugin) if err != nil { metrics.APIRequestsErrors.WithLabelValues( @@ -134,7 +135,9 @@ func (a *API) GetPluginConfig(context.Context, *emptypb.Empty) (*structpb.Struct } // GetPlugins returns the active plugin configuration of the GatewayD. -func (a *API) GetPlugins(context.Context, *emptypb.Empty) (*v1.PluginConfigs, error) { +func (a *API) GetPlugins(ctx context.Context, empty *emptypb.Empty) (*v1.PluginConfigs, error) { + _, span := otel.Tracer(config.TracerName).Start(ctx, "Get Plugins") + defer span.End() plugins := make([]*v1.PluginConfig, 0) a.PluginRegistry.ForEach( func(pluginID sdkPlugin.Identifier, plugIn *plugin.Plugin) { @@ -177,7 +180,9 @@ func (a *API) GetPlugins(context.Context, *emptypb.Empty) (*v1.PluginConfigs, er } // GetPools returns the pool configuration of the GatewayD. -func (a *API) GetPools(context.Context, *emptypb.Empty) (*structpb.Struct, error) { +func (a *API) GetPools(ctx context.Context, empty *emptypb.Empty) (*structpb.Struct, error) { + _, span := otel.Tracer(config.TracerName).Start(ctx, "Get Pools") + defer span.End() pools := make(map[string]interface{}, 0) for name, p := range a.Pools { pools[name] = map[string]interface{}{ @@ -199,7 +204,9 @@ func (a *API) GetPools(context.Context, *emptypb.Empty) (*structpb.Struct, error } // GetProxies returns the proxy configuration of the GatewayD. -func (a *API) GetProxies(context.Context, *emptypb.Empty) (*structpb.Struct, error) { +func (a *API) GetProxies(ctx context.Context, empty *emptypb.Empty) (*structpb.Struct, error) { + _, span := otel.Tracer(config.TracerName).Start(ctx, "Get Proxies") + defer span.End() proxies := make(map[string]interface{}, 0) for name, proxy := range a.Proxies { available := make([]interface{}, 0) @@ -232,7 +239,9 @@ func (a *API) GetProxies(context.Context, *emptypb.Empty) (*structpb.Struct, err } // GetServers returns the server configuration of the GatewayD. -func (a *API) GetServers(context.Context, *emptypb.Empty) (*structpb.Struct, error) { +func (a *API) GetServers(ctx context.Context, empty *emptypb.Empty) (*structpb.Struct, error) { + _, span := otel.Tracer(config.TracerName).Start(ctx, "Get Servers") + defer span.End() servers := make(map[string]interface{}, 0) for name, server := range a.Servers { servers[name] = map[string]interface{}{