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

Function "update_tags" not working #33

Open
RunzhongHuang opened this issue Oct 21, 2021 · 0 comments
Open

Function "update_tags" not working #33

RunzhongHuang opened this issue Oct 21, 2021 · 0 comments

Comments

@RunzhongHuang
Copy link

Hi,

In the README.md file, there is one part of tutorial is updating the tags to the span (zipkin.update_tags(id=1, user_id=2)). I tried this in two different approach and both returns me errors.

1, AttributeError: 'ZipkinLoggingContext' object has no attribute 'binary_annotations_dict'

I encountered this error while I put the "update_tags" inside the route function as below (function name "index").

from flask import Flask
from flask_zipkin import Zipkin
import requests

app = Flask(__name__)
app.config['ZIPKIN_DISABLE'] = False
app.config['ZIPKIN_DSN'] = "<url>"
zipkin = Zipkin(app)

@app.route('/')
def index():
    headers = {}
    headers.update(zipkin.create_http_headers_for_new_span())
    zipkin.update_tags(id=1, user_id=2)
    r = requests.get('<url>', headers=headers)
    return r.text, 200

# Start the app server
if __name__ == '__main__':
    app.run(debug=True, host='127.0.0.1', threaded=True)

-----------------------------------------------

Traceback (most recent call last):
  File "C:\<path>\venv\lib\site-packages\flask\app.py", line 2091, in __call__
    return self.wsgi_app(environ, start_response)
  File "C:\<path>\venv\lib\site-packages\flask\app.py", line 2076, in wsgi_app
    response = self.handle_exception(e)
  File "C:\<path>\venv\lib\site-packages\flask\app.py", line 2073, in wsgi_app
    response = self.full_dispatch_request()
  File "C:\<path>\venv\lib\site-packages\flask\app.py", line 1518, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "C:\<path>\venv\lib\site-packages\flask\app.py", line 1516, in full_dispatch_request
    rv = self.dispatch_request()
  File "C:\<path>\venv\lib\site-packages\flask\app.py", line 1502, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "C:\<path>\flask-zipkin-test.py", line 26, in index
    zipkin.update_tags(id=1, user_id=2)
  File "C:\<path>\venv\lib\site-packages\flask_zipkin.py", line 152, in update_tags
    g._zipkin_span.logging_context.binary_annotations_dict.update(
AttributeError: 'ZipkinLoggingContext' object has no attribute 'binary_annotations_dict'

2, RuntimeError: Working outside of application context.

This error is triggered if I put the "update_tag" function right after initialize Zipkin object.

from flask import Flask
from flask_zipkin import Zipkin
import requests

app = Flask(__name__)
app.config['ZIPKIN_DISABLE'] = False
app.config['ZIPKIN_DSN'] = "<URL>"
zipkin = Zipkin(app)
zipkin.update_tags(id=1, user_id=2)

@app.route('/')
def index():
    headers = {}
    headers.update(zipkin.create_http_headers_for_new_span())
    r = requests.get('<URL>', headers=headers)
    return r.text, 200

# Start the app server
if __name__ == '__main__':
    app.run(debug=True, host='127.0.0.1', threaded=True)

---------------------------------------------------

Traceback (most recent call last):
  File "C:/<path>/flask-zipkin-test.py", line 10, in <module>
    zipkin.update_tags(id=1, user_id=2)
  File "C:\<path>\venv\lib\site-packages\flask_zipkin.py", line 149, in update_tags
    if all([hasattr(g, '_zipkin_span'),
  File "C:\<path>\venv\lib\site-packages\werkzeug\local.py", line 422, in __get__
    obj = instance._get_current_object()
  File "C:\<path>\venv\lib\site-packages\werkzeug\local.py", line 544, in _get_current_object
    return self.__local()  # type: ignore
  File "C:\<path>\venv\lib\site-packages\flask\globals.py", line 40, in _lookup_app_object
    raise RuntimeError(_app_ctx_err_msg)
RuntimeError: Working outside of application context.

I am not sure if I use the method in a wrong way, if yes, please let me know which part I did it wrong.

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

1 participant