opentelemetry-python-contrib icon indicating copy to clipboard operation
opentelemetry-python-contrib copied to clipboard

opentelemetry-instrumentation-asgi: do not set `url.full` attribute for server spans

Open emdneto opened this issue 7 months ago • 7 comments

Describe your environment

instrumentation-asgi: 0.47b0.dev

What happened?

asgi instrumentation is emitting url.full attribute in server spans

Steps to Reproduce

Run any example of asgi instrumentation with new semconv opt-in enabled

import fastapi
import os
import logging
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider, sampling
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace.export import (
    BatchSpanProcessor,
    ConsoleSpanExporter,
)
# Specify "http", "http/dup" or ""
os.environ["OTEL_SEMCONV_STABILITY_OPT_IN"] = "http"
logging.basicConfig(level=logging.DEBUG)

provider = TracerProvider()
processor = BatchSpanProcessor(ConsoleSpanExporter())
provider.add_span_processor(processor)
trace.set_tracer_provider(provider)
tracer = trace.get_tracer(__name__)

app = fastapi.FastAPI()

@app.get("/foobar")
async def foobar():
    return {"message": "hello world"}

FastAPIInstrumentor.instrument_app(app)

Expected Result

"attributes": {
        "url.scheme": "http",
        "server.address": "127.0.0.1:8000",
        "server.port": 8000,
        "network.protocol.version": "1.1",
        "url.path": "/foobar",
        "http.request.method": "GET",
        "user_agent.original": "curl/7.68.0",
        "client.address": "127.0.0.1",
        "client.port": 45854,
        "http.route": "/foobar",
        "http.response.status_code": 200
    },

Actual Result

Server span Attributes with url.full which isn't necessary for server span:

"attributes": {
        "url.scheme": "http",
        "server.address": "127.0.0.1:8000",
        "server.port": 8000,
        "network.protocol.version": "1.1",
        "url.path": "/foobar",
        "url.full": "http://127.0.0.1:8000/foobar",
        "http.request.method": "GET",
        "user_agent.original": "curl/7.68.0",
        "client.address": "127.0.0.1",
        "client.port": 45854,
        "http.route": "/foobar",
        "http.response.status_code": 200
    },

Additional context

Seems we are setting http.url (for old semconv) since always but isn't really necessary anymore

https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2682#issuecomment-2223277707

https://github.com/open-telemetry/opentelemetry-specification/blob/v1.11.0/specification/trace/semantic_conventions/http.md#http-server-semantic-conventions

Would you like to implement a fix?

None

emdneto avatar Jul 11 '24 19:07 emdneto