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

aiohttp instrumentation: Function create_trace_config has no span_name argument. #848

Closed
Olegt0rr opened this issue Jan 9, 2022 · 7 comments · Fixed by #857
Closed

aiohttp instrumentation: Function create_trace_config has no span_name argument. #848

Olegt0rr opened this issue Jan 9, 2022 · 7 comments · Fixed by #857
Labels
bug Something isn't working instrumentation

Comments

@Olegt0rr
Copy link
Contributor

Olegt0rr commented Jan 9, 2022

Docs usage example

Ref: https://opentelemetry-python-contrib.readthedocs.io/en/latest/instrumentation/aiohttp_client/aiohttp_client.html#usage

import aiohttp
from opentelemetry.instrumentation.aiohttp_client import (
    create_trace_config,
    url_path_span_name
)
import yarl

def strip_query_params(url: yarl.URL) -> str:
    return str(url.with_query(None))

async with aiohttp.ClientSession(trace_configs=[create_trace_config(
        # Remove all query params from the URL attribute on the span.
        url_filter=strip_query_params,
        # Use the URL's path as the span name.
        span_name=url_path_span_name
)]) as session:
    async with session.get(url) as response:
        await response.text()

Bug

Function create_trace_config has no span_name argument.

def create_trace_config(
    url_filter: _UrlFilterT = None,
    request_hook: _RequestHookT = None,
    response_hook: _ResponseHookT = None,
    tracer_provider: TracerProvider = None,
) -> aiohttp.TraceConfig:
    ...
@Olegt0rr Olegt0rr added the bug Something isn't working label Jan 9, 2022
@Olegt0rr
Copy link
Contributor Author

Olegt0rr commented Jan 9, 2022

Also looks weird that current solution starts span with name f"HTTP {http_method}" and then prompts to change it through request_hook callback

http_method = params.method.upper()
request_span_name = f"HTTP {http_method}"
trace_config_ctx.span = trace_config_ctx.tracer.start_span(
request_span_name,
kind=SpanKind.CLIENT,
)
if callable(request_hook):
request_hook(trace_config_ctx.span, params)

It would be nice to add span_name (as it described in the docs).

def create_trace_config(
    ...
    span_name: Optional[str] = None,
) -> aiohttp.TraceConfig:
    ...
    request_span_name = f"HTTP {http_method}" if span_name is None else span_name

@Olegt0rr Olegt0rr changed the title Bad docs example for aiohttp-client instrumentation Custom span name for aiohttp-client instrumentation Jan 9, 2022
@owais owais changed the title Custom span name for aiohttp-client instrumentation aiohttp instrumentation: Function create_trace_config has no span_name argument. Jan 10, 2022
@owais
Copy link
Contributor

owais commented Jan 10, 2022

Proposed patch looks good to me. Happy to merge a PR if one is sent :)

Olegt0rr added a commit to Olegt0rr/opentelemetry-python-contrib that referenced this issue Jan 11, 2022
Param `span_name` already used in the docs! So let it works! ;)

open-telemetry#848
@lzchen
Copy link
Contributor

lzchen commented Jan 11, 2022

@owais
I thought we were trying to move away from using a span name callback and utilize the request/response hooks instead?

Like here: #409

@owais
Copy link
Contributor

owais commented Jan 11, 2022

@lzchen This isn't a callback and since it is documented, it looked like a mistake but you're right, we already support request/response hooks which solve this problem. May be we should just update the docs instead.

@Olegt0rr
Copy link
Contributor Author

Olegt0rr commented Jan 15, 2022

Okay, I'll revert changes and update the docs.

Should I remove url_path_span_name since it's not usable anymore?

@lzchen
Copy link
Contributor

lzchen commented Jan 18, 2022

@Olegt0rr

Yes it doesn't seem like url_path_span_name is used so feel free to remove it. I think updating the docs to remove span_name is enough for this issue.

@Olegt0rr
Copy link
Contributor Author

@lzchen, ready :)

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

Successfully merging a pull request may close this issue.

3 participants