python-flask icon indicating copy to clipboard operation
python-flask copied to clipboard

Status code tag is not added to spans when using @trace decorator

Open Fortiz2305 opened this issue 5 years ago • 0 comments

How to reproduce the issue

Let's use whatever tracer (I used jaeger for this example) and use the trace decorator. Ex.:

from flask import Flask
from flask_opentracing import FlaskTracer

app = Flask(__name__)


def initialize_tracer():
    config = Config(
        config={
            'sampler': {'type': 'const', 'param': 1}
        },
        service_name='hello-world'
    )
    return config.initialize_tracer()


flask_tracer = FlaskTracer(initialize_tracer)


@app.route('/')
@flask_tracer.trace()
def hello():
    return 'Hello'

In the resulting span, the HTTP_STATUS_CODE tag should not be present.

Possible cause

Looking at the code, it seems the response is not being passed to the _after_request_fn method when using the trace decorator.

https://github.com/opentracing-contrib/python-flask/blob/master/flask_opentracing/tracing.py#L83

Possible fix

I attached a PR with one possible solution.

Fortiz2305 avatar Nov 14 '19 18:11 Fortiz2305