Skip to content

Conversation

@Kavindu-Dodan
Copy link
Contributor

@Kavindu-Dodan Kavindu-Dodan commented Apr 19, 2023

This PR

Fulfill the sdk-side implementation of issue open-feature/flagd#620

Introduce option to enable disable otel interceptor for flagd connection from flagd go-sdk

SDK configuration - openfeature.SetProvider(flagd.NewProvider(flagd.WithOtelInterceptor(true)))

This option combined with open telemetry configurations at sdk usage component (ex:- application), allows distributed tracing for flagd

How to test

Write a simple code with otel traces and propagator, and use flagd with the option flagd.WithOtelInterceptor(true)

Related PR - open-feature/flagd#624

@Kavindu-Dodan Kavindu-Dodan requested a review from a team as a code owner April 19, 2023 20:46
@Kavindu-Dodan Kavindu-Dodan changed the title Feat/otel interceptor feat: otel interceptor for flagd go-sdk Apr 19, 2023
@open-feature open-feature deleted a comment from github-actions bot Apr 19, 2023
@@ -1,64 +0,0 @@
// Code generated by MockGen. DO NOT EDIT.
Copy link
Contributor Author

@Kavindu-Dodan Kavindu-Dodan Apr 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed as we do not use this anymore

mockgen:
mockgen -source=pkg/service/iservice.go -destination=internal/mock/service_mock_test.go -package=mock
mockgen -source=pkg/service/client.go -destination=pkg/service/client_mock_test.go -package=service_test
mockgen -source=pkg/service/iservice.go -destination=internal/mock/service_mock.go -package=mock
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a correction which we missed to update

Signed-off-by: Kavindu Dodanduwa <[email protected]>
Signed-off-by: Kavindu Dodanduwa <[email protected]>
Signed-off-by: Kavindu Dodanduwa <[email protected]>
Signed-off-by: Kavindu Dodanduwa <[email protected]>
@Kavindu-Dodan Kavindu-Dodan force-pushed the feat/otel-interceptor branch from 0bd3d48 to 71d7785 Compare April 24, 2023 16:17
flagd.WithLRUCache(1000) // enables LRU caching (see configuring caching section)
flagd.WithBasicInMemoryCache() // enables basic in memory cache (see configuring caching section)
flagd.WithLogger(logger) // sets a custom logger (see logging section)
flagd.WithOtelInterceptor(bool) // enable or disable OpenTelemetry interceptor for flagd communication
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would the impact be of having this enabled by default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interceptor uses no-op implementations and yields nothing

The idea here was to allow sdk users to manually opt-in for telemetry interception. Because this is only needed if the sdk user (i.e- application developer) has a proper telemetry configuration for the application. Setup includes exporter configuration (ex:- console, otel exporter ...) and related services up and running (ex:- otel collector).

So for simple usage as well as to exclude the performance impact of including no-op interceptors, it's best to make this an opt-in configuration.

"google.golang.org/protobuf/types/known/structpb"
)

type ServiceConfiguration struct {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to client.go where this is properly used

Comment on lines 42 to 48
c.mu.Lock()
defer c.mu.Unlock()

if c.client != nil {
return c.client
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can do the nil check first, and only lock if c.client is nil while we create it. That way, we only bother doing any locking if the c.client has not been created. Setting it is atomic, I think... so once it's been set and we unlock I guess we can never worry about locking again.

As is, this will lock with every access, which might not be needed. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After a second look at the code, I think the lock is an overkill. I will try to refactor the code to be bit nicer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@toddbaert toddbaert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved, see my thought here.

Signed-off-by: Kavindu Dodanduwa <[email protected]>
@Kavindu-Dodan Kavindu-Dodan merged commit 17e5ab7 into open-feature:main Apr 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants