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

api.add_hooks(TracingHook()) doesn't work #67

Closed
julianocosta89 opened this issue Mar 15, 2024 · 3 comments
Closed

api.add_hooks(TracingHook()) doesn't work #67

julianocosta89 opened this issue Mar 15, 2024 · 3 comments

Comments

@julianocosta89
Copy link

Hello all,

I was following those steps to add the hook to the OTel demo:
https://github.com/open-feature/python-sdk-contrib/tree/main/hooks/openfeature-hooks-opentelemetry#usage

But when using: api.add_hooks(TracingHook())

I got the following error:

TypeError: can only concatenate list (not "TracingHook") to list
Traceback (most recent call last):
  File "/usr/src/app/recommendation_server.py", line 131, in <module>
    api.add_hooks(TracingHook())
  File "/usr/local/lib/python3.12/site-packages/openfeature/api.py", line 55, in add_hooks
    _hooks = _hooks + hooks
             ~~~~~~~^~~~~~~

Then I've tried using client.add_hooks(TracingHook()) and got the following one:

2024-03-15 11:48:19,126 ERROR [grpc._server] [_server.py:583] [trace_id=0 span_id=0 resource.service.name=recommendationservice trace_sampled=False] - Exception calling application: can only concatenate list (not "TracingHook") to list
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/grpc/_server.py", line 555, in _call_behavior
    response_or_iterator = behavior(argument, context)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/opentelemetry/instrumentation/grpc/_server.py", line 320, in telemetry_interceptor
    raise error
  File "/usr/local/lib/python3.12/site-packages/opentelemetry/instrumentation/grpc/_server.py", line 311, in telemetry_interceptor
    return behavior(request_or_iterator, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/app/recommendation_server.py", line 44, in ListRecommendations
    prod_list = get_product_list(request.product_ids)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/app/recommendation_server.py", line 78, in get_product_list
    if check_feature_flag("recommendationCache"):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/app/recommendation_server.py", line 127, in check_feature_flag
    api.add_hooks(TracingHook())
  File "/usr/local/lib/python3.12/site-packages/openfeature/api.py", line 55, in add_hooks
    _hooks = _hooks + hooks
             ~~~~~~~^~~~~~~
@julianocosta89
Copy link
Author

Also, it seems that the environment variables are not working properly.
I've set FLAGD_HOST and FLAGD_PORT, but when running the service I got the following error:

debug_error_string = "UNKNOWN:Error received from peer  {created_time:"2024-03-15T12:06:02.432495513+00:00", grpc_status:14, grpc_message:"failed to connect to all addresses; last error: UNKNOWN: ipv4:127.0.0.1:8013: Failed to connect to remote host: Connection refused"}"

Looks like it is not using the env vars.

@federicobond
Copy link
Member

Hi @julianocosta89, thanks for the report! This is a mistake in our docs. add_hooks should be called with a list of hooks, like this:

api.add_hooks([TracingHook()])

As for the environment variables in the Flagd, we have not yet released the version that supports them, but we should do so very soon.

@federicobond
Copy link
Member

Opened #68 to fix the docs.

@gruebel gruebel closed this as completed Apr 5, 2024
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

No branches or pull requests

3 participants