Skip to content

Commit

Permalink
fix linter error
Browse files Browse the repository at this point in the history
  • Loading branch information
pulak-opti committed Jan 15, 2024
1 parent ab92186 commit 384109e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
1 change: 1 addition & 0 deletions pkg/client/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ func WithNotificationCenter(nc notification.Center) OptionFunc {
}
}

// WithTracer allows user to pass in their own implementation of the Tracer interface
func WithTracer(tracer tracing.Tracer) OptionFunc {
return func(f *OptimizelyFactory) {
f.tracer = tracer
Expand Down
12 changes: 6 additions & 6 deletions pkg/client/optimizely_user_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,27 +160,27 @@ func (o *OptimizelyUserContext) TrackEvent(eventKey string, eventTags map[string

// SetForcedDecision sets the forced decision (variation key) for a given decision context (flag key and optional rule key).
// returns true if the forced decision has been set successfully.
func (o *OptimizelyUserContext) SetForcedDecision(context pkgDecision.OptimizelyDecisionContext, decision pkgDecision.OptimizelyForcedDecision) bool {
func (o *OptimizelyUserContext) SetForcedDecision(ctx pkgDecision.OptimizelyDecisionContext, decision pkgDecision.OptimizelyForcedDecision) bool {
if o.forcedDecisionService == nil {
o.forcedDecisionService = pkgDecision.NewForcedDecisionService(o.GetUserID())
}
return o.forcedDecisionService.SetForcedDecision(context, decision)
return o.forcedDecisionService.SetForcedDecision(ctx, decision)
}

// GetForcedDecision returns the forced decision for a given flag and an optional rule
func (o *OptimizelyUserContext) GetForcedDecision(context pkgDecision.OptimizelyDecisionContext) (pkgDecision.OptimizelyForcedDecision, error) {
func (o *OptimizelyUserContext) GetForcedDecision(ctx pkgDecision.OptimizelyDecisionContext) (pkgDecision.OptimizelyForcedDecision, error) {
if o.forcedDecisionService == nil {
return pkgDecision.OptimizelyForcedDecision{}, errors.New("decision not found")
}
return o.forcedDecisionService.GetForcedDecision(context)
return o.forcedDecisionService.GetForcedDecision(ctx)
}

// RemoveForcedDecision removes the forced decision for a given flag and an optional rule.
func (o *OptimizelyUserContext) RemoveForcedDecision(context pkgDecision.OptimizelyDecisionContext) bool {
func (o *OptimizelyUserContext) RemoveForcedDecision(ctx pkgDecision.OptimizelyDecisionContext) bool {
if o.forcedDecisionService == nil {
return false
}
return o.forcedDecisionService.RemoveForcedDecision(context)
return o.forcedDecisionService.RemoveForcedDecision(ctx)
}

// RemoveAllForcedDecisions removes all forced decisions bound to this user context.
Expand Down
31 changes: 29 additions & 2 deletions pkg/tracing/opentelemetry.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/****************************************************************************
* Copyright 2023 Optimizely, Inc. and contributors *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
***************************************************************************/

// Package tracing //
package tracing

import (
Expand Down Expand Up @@ -26,12 +43,14 @@ type otelTracer struct {
enabled bool
}

// NewOtelTracer returns a new instance of Tracer
func NewOtelTracer(t trace.Tracer) Tracer {
return &otelTracer{
enabled: true,
}
}

// StartSpan starts a trace span. Span can be a parent or child span based on the passed context.
func (t *otelTracer) StartSpan(pctx context.Context, tracerName, spanName string) (context.Context, Span) {
ctx, span := otel.Tracer(tracerName).Start(pctx, spanName)
return ctx, &otelSpan{
Expand All @@ -44,24 +63,32 @@ type otelSpan struct {
span trace.Span
}

// SetAttibutes sets the attributes for the span
func (s *otelSpan) SetAttibutes(key string, value interface{}) {
s.span.SetAttributes(attribute.KeyValue{
Key: attribute.Key(key),
Value: attribute.StringValue(value.(string)),
})
}

// End ends the span
func (s *otelSpan) End() {
s.span.End()
}

// NoopTracer is a no-op implementation of Tracer
type NoopTracer struct{}

func (t *NoopTracer) StartSpan(ctx context.Context, tracerName string, spanName string) (context.Context, Span) {
// StartSpan returns a new instance of NoopTracer
func (t *NoopTracer) StartSpan(ctx context.Context, tracerName, spanName string) (context.Context, Span) {
return ctx, &NoopSpan{}
}

// NoopSpan is a no-op implementation of Span
type NoopSpan struct{}

// SetAttibutes sets the attributes for the noop-span
func (s *NoopSpan) SetAttibutes(key string, value interface{}) {}
func (s *NoopSpan) End() {}

// End ends the noop-span
func (s *NoopSpan) End() {}

0 comments on commit 384109e

Please sign in to comment.