open-telemetry / open-telemetry/opentelemetry-python-contrib

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

Open
#2,156 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
1.1k
Forks
1.1k
Avg merge
4d 15h
Merged PRs (30d)
16

Description

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:

https://github.com/open-telemetry/opentelemetry-python-contrib/blob/47caeab7aff47070c565cd90536a39ec5eb06f34/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py#L320-L325

The first commit of the file shows essentially the same:

https://github.com/open-telemetry/opentelemetry-python-contrib/blob/d19b464a0a23a4a66d5df635634e7d6315cb54db/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py#L108-L111

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:

https://github.com/open-telemetry/opentelemetry-python-contrib/blob/47caeab7aff47070c565cd90536a39ec5eb06f34/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py#L311-L312

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/init.py at the linked lines, then compare the corresponding ASGI instrumentation. Run the Flask reproduction to inspect both attributes; done means the WSGI span reports http.target as /hello and http.url as the full URL.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, python
Domain
observability-sre
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.