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

feat!: OTel hook changes for hook interface updates #644

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions hooks/open-telemetry/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/open-feature/go-sdk-contrib/hooks/open-telemetry
go 1.21

require (
github.com/open-feature/go-sdk v1.11.0
github.com/open-feature/go-sdk v1.14.1
go.opentelemetry.io/otel v1.28.0
go.opentelemetry.io/otel/metric v1.28.0
go.opentelemetry.io/otel/sdk v1.28.0
Expand All @@ -15,6 +15,6 @@ require (
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/google/uuid v1.6.0 // indirect
golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3 // indirect
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
golang.org/x/sys v0.21.0 // indirect
)
3 changes: 3 additions & 0 deletions hooks/open-telemetry/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/open-feature/go-sdk v1.11.0 h1:4cp9rXl16ZvlMCef7O+I3vQSXae8DzAF0SfV9mvYInw=
github.com/open-feature/go-sdk v1.11.0/go.mod h1:+rkJhLBtYsJ5PZNddAgFILhRAAxwrJ32aU7UEUm4zQI=
github.com/open-feature/go-sdk v1.14.1 h1:jcxjCIG5Up3XkgYwWN5Y/WWfc6XobOhqrIwjyDBsoQo=
github.com/open-feature/go-sdk v1.14.1/go.mod h1:t337k0VB/t/YxJ9S0prT30ISUHwYmUd/jhUZgFcOvGg=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
Expand All @@ -29,6 +31,7 @@ go.opentelemetry.io/otel/trace v1.28.0 h1:GhQ9cUuQGmNDd5BTCP2dAvv75RdMxEfTmYejp+
go.opentelemetry.io/otel/trace v1.28.0/go.mod h1:jPyXzNPg6da9+38HEwElrQiHlVMTnVfM3/yv2OlIHaI=
golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3 h1:/RIbNt/Zr7rVhIkQhooTxCxFcdWLGIKnZA4IXNFSrvo=
golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3/go.mod h1:idGWGoKP1toJGkd5/ig9ZLuPcZBC3ewk7SzmH0uou08=
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
Expand Down
2 changes: 1 addition & 1 deletion hooks/open-telemetry/pkg/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
attributeMapperCallback func(openfeature.FlagMetadata) []attribute.KeyValue
}

var _ openfeature.Hook = &MetricsHook{}

Check failure on line 32 in hooks/open-telemetry/pkg/metrics.go

View workflow job for this annotation

GitHub Actions / lint

cannot use &MetricsHook{} (value of type *MetricsHook) as openfeature.Hook value in variable declaration: *MetricsHook does not implement openfeature.Hook (wrong type for method Finally)

Check failure on line 32 in hooks/open-telemetry/pkg/metrics.go

View workflow job for this annotation

GitHub Actions / test

cannot use &MetricsHook{} (value of type *MetricsHook) as openfeature.Hook value in variable declaration: *MetricsHook does not implement openfeature.Hook (wrong type for method Finally)

// NewMetricsHook builds a metric hook backed by a globally set metric.MeterProvider.
// Use otel.SetMeterProvider to set the global provider or use NewMetricsHookForProvider.
Expand Down Expand Up @@ -122,7 +122,7 @@
attribute.String(semconv.ExceptionEventName, err.Error())))
}

func (h *MetricsHook) Finally(ctx context.Context, hCtx openfeature.HookContext, hint openfeature.HookHints) {
func (h *MetricsHook) Finally(ctx context.Context, hCtx openfeature.HookContext, evalCtx openfeature.InterfaceEvaluationDetails, hint openfeature.HookHints) {
h.activeCounter.Add(ctx, -1, api.WithAttributes(semconv.FeatureFlagKey(hCtx.FlagKey())))
}

Expand Down
22 changes: 20 additions & 2 deletions hooks/open-telemetry/pkg/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,15 @@ func TestMetricsHook_FinallyStage(t *testing.T) {

ctx := context.Background()

evalDetails := openfeature.InterfaceEvaluationDetails{
Value: true,
EvaluationDetails: openfeature.EvaluationDetails{
FlagKey: "flagA",
FlagType: openfeature.Boolean,
ResolutionDetail: openfeature.ResolutionDetail{},
},
}

hookContext := hookContext()
hookHints := openfeature.NewHookHints(map[string]interface{}{})

Expand All @@ -180,7 +189,7 @@ func TestMetricsHook_FinallyStage(t *testing.T) {
}

// when
metricsHook.Finally(ctx, hookContext, hookHints)
metricsHook.Finally(ctx, hookContext, evalDetails, hookHints)

// then
var data metricdata.ResourceMetrics
Expand Down Expand Up @@ -214,6 +223,15 @@ func TestMetricsHook_ActiveCounterShouldBeZero(t *testing.T) {

ctx := context.Background()

evalDetails := openfeature.InterfaceEvaluationDetails{
Value: true,
EvaluationDetails: openfeature.EvaluationDetails{
FlagKey: "flagA",
FlagType: openfeature.Boolean,
ResolutionDetail: openfeature.ResolutionDetail{},
},
}

hookContext := hookContext()
hookHints := openfeature.NewHookHints(map[string]interface{}{})

Expand All @@ -230,7 +248,7 @@ func TestMetricsHook_ActiveCounterShouldBeZero(t *testing.T) {
return
}

metricsHook.Finally(ctx, hookContext, hookHints)
metricsHook.Finally(ctx, hookContext, evalDetails, hookHints)

// then
var data metricdata.ResourceMetrics
Expand Down
Loading