Skip to content

WSGI request spans don't have both http.target and http.url attributes #2156

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

Open
alexmojaki opened this issue Feb 7, 2024 · 7 comments
Open
Labels
bug Something isn't working

Comments

@alexmojaki
Copy link
Contributor

Steps to reproduce

Example code:

from flask import Flask
from opentelemetry.instrumentation.flask import FlaskInstrumentor
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor
from opentelemetry.semconv.trace import SpanAttributes

tracer_provider = TracerProvider()
processor = SimpleSpanProcessor(
    ConsoleSpanExporter(
        formatter=lambda span: str(
            (
                span.attributes.get(SpanAttributes.HTTP_TARGET),
                span.attributes.get(SpanAttributes.HTTP_URL),
            )
        )
    )
)
tracer_provider.add_span_processor(processor)

app = Flask(__name__)
FlaskInstrumentor().instrument_app(app, tracer_provider=tracer_provider)


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


app.run()

Then visit http://localhost:5000/hello

What is the expected behavior?

('/hello', 'http://localhost:5000/hello')

What is the actual behavior?

('/hello', None)

Additional context

The current code looks like this:

if target is not None:
result[SpanAttributes.HTTP_TARGET] = target
else:
result[SpanAttributes.HTTP_URL] = remove_url_credentials(
wsgiref_util.request_uri(environ)
)

The first commit of the file shows essentially the same:

if target is not None:
result["http.target"] = target
else:
result["http.url"] = wsgiref_util.request_uri(environ)

I don't know under what circumstances the target is missing and the full URL is present instead, but I don't understand why only one or the other is included instead of both.

By comparison, the ASGI instrumentation happily includes both:

SpanAttributes.HTTP_TARGET: scope.get("path"),
SpanAttributes.HTTP_URL: remove_url_credentials(http_url),

@alexmojaki alexmojaki added the bug Something isn't working label Feb 7, 2024
@qiuge615
Copy link
Contributor

qiuge615 commented Aug 6, 2024

Hi @xrmx, regarding this issue, shall I add http_url for only new semconv as below PR's changes for asgi http_url?
#2735

Makes changes locally and the span is like below. Please review and if this makes sense I will create PR with changes, thanks.
('/hello', 'http://127.0.0.1:5000/hello')

@emdneto
Copy link
Member

emdneto commented Aug 6, 2024

@qiuge615 In that case, the PR is removing the url.full attribute, which isn't required in server spans in new semantic conventions. Probably, this implementation is due to http.scheme, http.host and http.target being set, and it would be redundant to have http.url. These separate values are preferred, but if, for some reason, the URL is available, but the other values are not, the URL can replace the set of attributes: http.scheme, http.host, and http.target.

@qiuge615
Copy link
Contributor

qiuge615 commented Aug 7, 2024

@emdneto Thanks for your help, url.full is not required in new semantic conventions. One question is regarding the old version of semantic conventions, http.url is required, as below doc, does that make sense to add it in old version of semantic conventions?
https://github.com/open-telemetry/opentelemetry-specification/blob/v1.20.0/specification/trace/semantic_conventions/http.md#http-client

@emdneto
Copy link
Member

emdneto commented Aug 7, 2024

@qiuge615 http.url is required for http client instrumentations, which isn't the case here. Also, we are discouraging new changes that pertain to old semconv other than the transitions using the opt-in strategy. See, https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/CONTRIBUTING.md#guideline-for-instrumentations

@qiuge615
Copy link
Contributor

qiuge615 commented Aug 8, 2024

@emdneto well received, thank your for your explanations.

@Kludex
Copy link
Contributor

Kludex commented Sep 30, 2024

So... The ASGI adding the http.url is wrong?

@emdneto
Copy link
Member

emdneto commented Sep 30, 2024

@Kludex the attribute isn't wrong. it's redundant for server spans in the new version of semconv (so, it is unnecessary to have it)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants