safer code
This commit is contained in:
@@ -128,15 +128,13 @@ func (s Service) getInMemoryServiceUser() proto.Account {
|
||||
// the query contains account properties
|
||||
func (s Service) ListAccounts(ctx context.Context, in *proto.ListAccountsRequest, out *proto.ListAccountsResponse) (err error) {
|
||||
var span trace.Span
|
||||
if s.Config.Tracing.Enabled {
|
||||
ctx, span = accTracing.TraceProvider.Tracer("accounts").Start(ctx, "Accounts.ListAccounts")
|
||||
defer span.End()
|
||||
ctx, span = accTracing.TraceProvider.Tracer("accounts").Start(ctx, "Accounts.ListAccounts")
|
||||
defer span.End()
|
||||
|
||||
span.SetAttributes(
|
||||
attribute.KeyValue{Key: "page_size", Value: attribute.Int64Value(int64(in.PageSize))},
|
||||
attribute.KeyValue{Key: "page_token", Value: attribute.StringValue(in.PageToken)},
|
||||
)
|
||||
}
|
||||
span.SetAttributes(
|
||||
attribute.KeyValue{Key: "page_size", Value: attribute.Int64Value(int64(in.PageSize))},
|
||||
attribute.KeyValue{Key: "page_token", Value: attribute.StringValue(in.PageToken)},
|
||||
)
|
||||
|
||||
hasSelf := s.hasSelfManagementPermissions(ctx)
|
||||
hasManagement := s.hasAccountManagementPermissions(ctx)
|
||||
@@ -284,14 +282,13 @@ func (s Service) findAccountsByQuery(ctx context.Context, query string) ([]strin
|
||||
// GetAccount implements the AccountsServiceHandler interface
|
||||
func (s Service) GetAccount(ctx context.Context, in *proto.GetAccountRequest, out *proto.Account) (err error) {
|
||||
var span trace.Span
|
||||
if s.Config.Tracing.Enabled {
|
||||
ctx, span = accTracing.TraceProvider.Tracer("accounts").Start(ctx, "Accounts.GetAccount")
|
||||
defer span.End()
|
||||
|
||||
span.SetAttributes(
|
||||
attribute.KeyValue{Key: "account_id", Value: attribute.StringValue(in.Id)},
|
||||
)
|
||||
}
|
||||
ctx, span = accTracing.TraceProvider.Tracer("accounts").Start(ctx, "Accounts.GetAccount")
|
||||
defer span.End()
|
||||
|
||||
span.SetAttributes(
|
||||
attribute.KeyValue{Key: "account_id", Value: attribute.StringValue(in.Id)},
|
||||
)
|
||||
|
||||
hasSelf := s.hasSelfManagementPermissions(ctx)
|
||||
hasManagement := s.hasAccountManagementPermissions(ctx)
|
||||
@@ -342,14 +339,13 @@ func (s Service) GetAccount(ctx context.Context, in *proto.GetAccountRequest, ou
|
||||
// CreateAccount implements the AccountsServiceHandler interface
|
||||
func (s Service) CreateAccount(ctx context.Context, in *proto.CreateAccountRequest, out *proto.Account) (err error) {
|
||||
var span trace.Span
|
||||
if s.Config.Tracing.Enabled {
|
||||
ctx, span = accTracing.TraceProvider.Tracer("accounts").Start(ctx, "Accounts.CreateAccount")
|
||||
defer span.End()
|
||||
|
||||
span.SetAttributes(
|
||||
attribute.KeyValue{Key: "account", Value: attribute.StringValue(in.Account.String())},
|
||||
)
|
||||
}
|
||||
ctx, span = accTracing.TraceProvider.Tracer("accounts").Start(ctx, "Accounts.CreateAccount")
|
||||
defer span.End()
|
||||
|
||||
span.SetAttributes(
|
||||
attribute.KeyValue{Key: "account", Value: attribute.StringValue(in.Account.String())},
|
||||
)
|
||||
|
||||
if !s.hasAccountManagementPermissions(ctx) {
|
||||
return merrors.Forbidden(s.id, "no permission for CreateAccount")
|
||||
@@ -484,14 +480,13 @@ func (s Service) rollbackCreateAccount(ctx context.Context, acc *proto.Account)
|
||||
// TODO how can we unset specific values? using the update mask
|
||||
func (s Service) UpdateAccount(ctx context.Context, in *proto.UpdateAccountRequest, out *proto.Account) (err error) {
|
||||
var span trace.Span
|
||||
if s.Config.Tracing.Enabled {
|
||||
ctx, span = accTracing.TraceProvider.Tracer("accounts").Start(ctx, "Accounts.UpdateAccount")
|
||||
defer span.End()
|
||||
|
||||
span.SetAttributes(
|
||||
attribute.KeyValue{Key: "account", Value: attribute.StringValue(in.Account.String())},
|
||||
)
|
||||
}
|
||||
ctx, span = accTracing.TraceProvider.Tracer("accounts").Start(ctx, "Accounts.UpdateAccount")
|
||||
defer span.End()
|
||||
|
||||
span.SetAttributes(
|
||||
attribute.KeyValue{Key: "account", Value: attribute.StringValue(in.Account.String())},
|
||||
)
|
||||
|
||||
hasSelf := s.hasSelfManagementPermissions(ctx)
|
||||
hasManagement := s.hasAccountManagementPermissions(ctx)
|
||||
@@ -660,10 +655,9 @@ var updatableAccountPaths = map[string]struct{}{
|
||||
// DeleteAccount implements the AccountsServiceHandler interface
|
||||
func (s Service) DeleteAccount(ctx context.Context, in *proto.DeleteAccountRequest, out *empty.Empty) (err error) {
|
||||
var span trace.Span
|
||||
if s.Config.Tracing.Enabled {
|
||||
ctx, span = accTracing.TraceProvider.Tracer("accounts").Start(ctx, "Accounts.DeleteAccount")
|
||||
defer span.End()
|
||||
}
|
||||
|
||||
ctx, span = accTracing.TraceProvider.Tracer("accounts").Start(ctx, "Accounts.DeleteAccount")
|
||||
defer span.End()
|
||||
|
||||
if !s.hasAccountManagementPermissions(ctx) {
|
||||
return merrors.Forbidden(s.id, "no permission for DeleteAccount")
|
||||
|
||||
@@ -3,12 +3,12 @@ package tracing
|
||||
import (
|
||||
"github.com/owncloud/ocis/accounts/pkg/config"
|
||||
pkgtrace "github.com/owncloud/ocis/ocis-pkg/tracing"
|
||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
var (
|
||||
// TraceProvider is the global trace provider for the proxy service.
|
||||
TraceProvider *sdktrace.TracerProvider
|
||||
TraceProvider = trace.NewNoopTracerProvider()
|
||||
)
|
||||
|
||||
func Configure(cfg *config.Config) error {
|
||||
|
||||
@@ -3,12 +3,12 @@ package tracing
|
||||
import (
|
||||
"github.com/owncloud/ocis/glauth/pkg/config"
|
||||
pkgtrace "github.com/owncloud/ocis/ocis-pkg/tracing"
|
||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
var (
|
||||
// TraceProvider is the global trace provider for the glauth service.
|
||||
TraceProvider *sdktrace.TracerProvider
|
||||
TraceProvider = trace.NewNoopTracerProvider()
|
||||
)
|
||||
|
||||
func Configure(cfg *config.Config) error {
|
||||
|
||||
@@ -3,12 +3,12 @@ package tracing
|
||||
import (
|
||||
"github.com/owncloud/ocis/graph-explorer/pkg/config"
|
||||
pkgtrace "github.com/owncloud/ocis/ocis-pkg/tracing"
|
||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
var (
|
||||
// TraceProvider is the global trace provider for the proxy service.
|
||||
TraceProvider *sdktrace.TracerProvider
|
||||
TraceProvider = trace.NewNoopTracerProvider()
|
||||
)
|
||||
|
||||
func Configure(cfg *config.Config) error {
|
||||
|
||||
@@ -3,12 +3,12 @@ package tracing
|
||||
import (
|
||||
"github.com/owncloud/ocis/graph/pkg/config"
|
||||
pkgtrace "github.com/owncloud/ocis/ocis-pkg/tracing"
|
||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
var (
|
||||
// TraceProvider is the global trace provider for the graph service.
|
||||
TraceProvider *sdktrace.TracerProvider
|
||||
TraceProvider = trace.NewNoopTracerProvider()
|
||||
)
|
||||
|
||||
func Configure(cfg *config.Config) error {
|
||||
|
||||
@@ -3,12 +3,12 @@ package tracing
|
||||
import (
|
||||
"github.com/owncloud/ocis/idp/pkg/config"
|
||||
pkgtrace "github.com/owncloud/ocis/ocis-pkg/tracing"
|
||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
var (
|
||||
// TraceProvider is the global trace provider for the idp service.
|
||||
TraceProvider *sdktrace.TracerProvider
|
||||
TraceProvider = trace.NewNoopTracerProvider()
|
||||
)
|
||||
|
||||
func Configure(cfg *config.Config) error {
|
||||
|
||||
@@ -33,14 +33,12 @@ func (o Ocs) ListUserGroups(w http.ResponseWriter, r *http.Request) {
|
||||
// the OCS API is a REST API and it uses the username to look for groups. If the id from the user in the context
|
||||
// differs from that of the url we can assume we are an admin because we are past the selfOrAdmin middleware.
|
||||
|
||||
if o.config.Tracing.Enabled {
|
||||
_, span := ocstracing.TraceProvider.
|
||||
Tracer("ocs").
|
||||
Start(r.Context(), "ListUserGroups")
|
||||
defer span.End()
|
||||
_, span := ocstracing.TraceProvider.
|
||||
Tracer("ocs").
|
||||
Start(r.Context(), "ListUserGroups")
|
||||
defer span.End()
|
||||
|
||||
span.SetAttributes(attribute.Any("groups", u.Groups))
|
||||
}
|
||||
span.SetAttributes(attribute.Any("groups", u.Groups))
|
||||
|
||||
if len(u.Groups) > 0 {
|
||||
mustNotFail(render.Render(w, r, response.DataRender(&data.Groups{Groups: u.Groups})))
|
||||
@@ -93,14 +91,12 @@ func (o Ocs) ListUserGroups(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
o.logger.Error().Err(err).Int("count", len(groups)).Str("userid", account.Id).Msg("listing groups for user")
|
||||
|
||||
if o.config.Tracing.Enabled {
|
||||
_, span := ocstracing.TraceProvider.
|
||||
Tracer("ocs").
|
||||
Start(r.Context(), "ListUserGroups")
|
||||
defer span.End()
|
||||
_, span := ocstracing.TraceProvider.
|
||||
Tracer("ocs").
|
||||
Start(r.Context(), "ListUserGroups")
|
||||
defer span.End()
|
||||
|
||||
span.SetAttributes(attribute.Any("groups", groups))
|
||||
}
|
||||
span.SetAttributes(attribute.Any("groups", groups))
|
||||
|
||||
mustNotFail(render.Render(w, r, response.DataRender(&data.Groups{Groups: groups})))
|
||||
}
|
||||
@@ -265,14 +261,12 @@ func (o Ocs) ListGroups(w http.ResponseWriter, r *http.Request) {
|
||||
groups = append(groups, res.Groups[i].OnPremisesSamAccountName)
|
||||
}
|
||||
|
||||
if o.config.Tracing.Enabled {
|
||||
_, span := ocstracing.TraceProvider.
|
||||
Tracer("ocs").
|
||||
Start(r.Context(), "ListGroups")
|
||||
defer span.End()
|
||||
_, span := ocstracing.TraceProvider.
|
||||
Tracer("ocs").
|
||||
Start(r.Context(), "ListGroups")
|
||||
defer span.End()
|
||||
|
||||
span.SetAttributes(attribute.Any("groups", groups))
|
||||
}
|
||||
span.SetAttributes(attribute.Any("groups", groups))
|
||||
|
||||
mustNotFail(render.Render(w, r, response.DataRender(&data.Groups{Groups: groups})))
|
||||
}
|
||||
|
||||
@@ -148,14 +148,12 @@ func (o Ocs) GetUser(w http.ResponseWriter, r *http.Request) {
|
||||
},
|
||||
}
|
||||
|
||||
if o.config.Tracing.Enabled {
|
||||
_, span := ocstracing.TraceProvider.
|
||||
Tracer("ocs").
|
||||
Start(r.Context(), "GetUser")
|
||||
defer span.End()
|
||||
_, span := ocstracing.TraceProvider.
|
||||
Tracer("ocs").
|
||||
Start(r.Context(), "GetUser")
|
||||
defer span.End()
|
||||
|
||||
span.SetAttributes(attribute.Any("user", d))
|
||||
}
|
||||
span.SetAttributes(attribute.Any("user", d))
|
||||
|
||||
mustNotFail(render.Render(w, r, response.DataRender(d)))
|
||||
}
|
||||
|
||||
@@ -3,12 +3,12 @@ package tracing
|
||||
import (
|
||||
pkgtrace "github.com/owncloud/ocis/ocis-pkg/tracing"
|
||||
"github.com/owncloud/ocis/ocs/pkg/config"
|
||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
var (
|
||||
// TraceProvider is the global trace provider for the ocs service.
|
||||
TraceProvider *sdktrace.TracerProvider
|
||||
TraceProvider = trace.NewNoopTracerProvider()
|
||||
)
|
||||
|
||||
func Configure(cfg *config.Config) error {
|
||||
|
||||
@@ -3,12 +3,12 @@ package tracing
|
||||
import (
|
||||
pkgtrace "github.com/owncloud/ocis/ocis-pkg/tracing"
|
||||
"github.com/owncloud/ocis/onlyoffice/pkg/config"
|
||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
var (
|
||||
// TraceProvider is the global trace provider for the onlyoffice service.
|
||||
TraceProvider *sdktrace.TracerProvider
|
||||
TraceProvider = trace.NewNoopTracerProvider()
|
||||
)
|
||||
|
||||
func Configure(cfg *config.Config) error {
|
||||
|
||||
@@ -222,10 +222,11 @@ func (p *MultiHostReverseProxy) ServeHTTP(w http.ResponseWriter, r *http.Request
|
||||
span trace.Span
|
||||
)
|
||||
|
||||
tracer := proxytracing.TraceProvider.Tracer("proxy")
|
||||
ctx, span = tracer.Start(ctx, fmt.Sprintf("%s %v", r.Method, r.URL.Path))
|
||||
defer span.End()
|
||||
|
||||
if p.config.Tracing.Enabled {
|
||||
tracer := proxytracing.TraceProvider.Tracer("proxy")
|
||||
ctx, span = tracer.Start(ctx, fmt.Sprintf("%s %v", r.Method, r.URL.Path))
|
||||
defer span.End()
|
||||
pkgtrace.Propagator.Inject(ctx, propagation.HeaderCarrier(r.Header))
|
||||
}
|
||||
|
||||
|
||||
@@ -3,12 +3,12 @@ package tracing
|
||||
import (
|
||||
pkgtrace "github.com/owncloud/ocis/ocis-pkg/tracing"
|
||||
"github.com/owncloud/ocis/proxy/pkg/config"
|
||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
var (
|
||||
// TraceProvider is the global trace provider for the proxy service.
|
||||
TraceProvider *sdktrace.TracerProvider
|
||||
TraceProvider = trace.NewNoopTracerProvider()
|
||||
)
|
||||
|
||||
func Configure(cfg *config.Config) error {
|
||||
|
||||
@@ -3,12 +3,12 @@ package tracing
|
||||
import (
|
||||
pkgtrace "github.com/owncloud/ocis/ocis-pkg/tracing"
|
||||
"github.com/owncloud/ocis/settings/pkg/config"
|
||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
var (
|
||||
// TraceProvider is the global trace provider for the settings service.
|
||||
TraceProvider *sdktrace.TracerProvider
|
||||
TraceProvider = trace.NewNoopTracerProvider()
|
||||
)
|
||||
|
||||
func Configure(cfg *config.Config) error {
|
||||
|
||||
@@ -3,12 +3,12 @@ package tracing
|
||||
import (
|
||||
pkgtrace "github.com/owncloud/ocis/ocis-pkg/tracing"
|
||||
"github.com/owncloud/ocis/store/pkg/config"
|
||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
var (
|
||||
// TraceProvider is the global trace provider for the store service.
|
||||
TraceProvider *sdktrace.TracerProvider
|
||||
TraceProvider = trace.NewNoopTracerProvider()
|
||||
)
|
||||
|
||||
func Configure(cfg *config.Config) error {
|
||||
|
||||
@@ -3,12 +3,12 @@ package tracing
|
||||
import (
|
||||
pkgtrace "github.com/owncloud/ocis/ocis-pkg/tracing"
|
||||
"github.com/owncloud/ocis/thumbnails/pkg/config"
|
||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
var (
|
||||
// TraceProvider is the global trace provider for the thumbnails service.
|
||||
TraceProvider *sdktrace.TracerProvider
|
||||
TraceProvider = trace.NewNoopTracerProvider()
|
||||
)
|
||||
|
||||
func Configure(cfg *config.Config) error {
|
||||
|
||||
@@ -3,12 +3,12 @@ package tracing
|
||||
import (
|
||||
pkgtrace "github.com/owncloud/ocis/ocis-pkg/tracing"
|
||||
"github.com/owncloud/ocis/web/pkg/config"
|
||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
var (
|
||||
// TraceProvider is the global trace provider for the web service.
|
||||
TraceProvider *sdktrace.TracerProvider
|
||||
TraceProvider = trace.NewNoopTracerProvider()
|
||||
)
|
||||
|
||||
func Configure(cfg *config.Config) error {
|
||||
|
||||
@@ -3,12 +3,12 @@ package tracing
|
||||
import (
|
||||
pkgtrace "github.com/owncloud/ocis/ocis-pkg/tracing"
|
||||
"github.com/owncloud/ocis/webdav/pkg/config"
|
||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
var (
|
||||
// TraceProvider is the global trace provider for the proxy service.
|
||||
TraceProvider *sdktrace.TracerProvider
|
||||
TraceProvider = trace.NewNoopTracerProvider()
|
||||
)
|
||||
|
||||
func Configure(cfg *config.Config) error {
|
||||
|
||||
Reference in New Issue
Block a user