Skip to content

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

@julianocosta89

Description

@julianocosta89

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
             ~~~~~~~^~~~~~~

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions