Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changelog/4719.changed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
opentelemetry-instrumentation-requests: remove multiple calls to sanitize_method
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pytest-benchmark==4.0.0
-e opentelemetry-instrumentation
-e util/opentelemetry-util-http
-e instrumentation/opentelemetry-instrumentation-requests
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

import pytest
import requests
from requests.adapters import BaseAdapter
from requests.models import Response

from opentelemetry.instrumentation.requests import RequestsInstrumentor
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
from opentelemetry.sdk.trace.export.in_memory_span_exporter import (
InMemorySpanExporter,
)

_URL = "http://mock/status/200"


class _FakeAdapter(BaseAdapter):
def __init__(self):
super().__init__()
resp = Response()
resp.status_code = 200
self._response = resp

def send(self, *args, **kwargs):
return self._response

def close(self):
pass


@pytest.fixture(name="http_session")
def _http_session_fixture():
exporter = InMemorySpanExporter()
provider = TracerProvider()
provider.add_span_processor(SimpleSpanProcessor(exporter))
RequestsInstrumentor().instrument(tracer_provider=provider)
session = requests.Session()
session.mount("http://", _FakeAdapter())
yield session
RequestsInstrumentor().uninstrument()


def test_instrumented_send(benchmark, http_session: requests.Session):
benchmark(http_session.get, _URL)
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,16 @@ def get_or_create_headers():
# See
# https://github.com/open-telemetry/semantic-conventions/blob/main/docs/http/http-spans.md#http-client
method = request.method
span_name = get_default_span_name(method)
sanitized_method = sanitize_method(method.strip())
span_name = get_default_span_name(sanitized_method)

url = redact_url(request.url)

span_attributes = {}
_set_http_method(
span_attributes,
method,
sanitize_method(method),
sanitized_method,
sem_conv_opt_in_mode,
)
_set_http_url(span_attributes, url, sem_conv_opt_in_mode)
Expand All @@ -363,7 +364,7 @@ def get_or_create_headers():
_set_http_method(
metric_labels,
method,
sanitize_method(method),
sanitized_method,
sem_conv_opt_in_mode,
)

Expand Down Expand Up @@ -532,7 +533,6 @@ def get_default_span_name(method: str) -> str:
Returns:
span name
"""
method = sanitize_method(method.strip())
if method == "_OTHER":
return "HTTP"
return method
Expand Down
3 changes: 3 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ envlist =
pypy3-test-instrumentation-logging
lint-instrumentation-logging
benchmark-instrumentation-logging
benchmark-instrumentation-requests

; opentelemetry-exporter-richconsole
py3{10,11,12,13,14}-test-exporter-richconsole
Expand Down Expand Up @@ -691,6 +692,7 @@ deps =
logging: {[testenv]test_deps}
logging: -r {toxinidir}/instrumentation/opentelemetry-instrumentation-logging/test-requirements.txt
benchmark-instrumentation-logging: -r {toxinidir}/instrumentation/opentelemetry-instrumentation-logging/benchmark-requirements.txt
benchmark-instrumentation-requests: -r {toxinidir}/instrumentation/opentelemetry-instrumentation-requests/benchmark-requirements.txt

aiohttp-client: {[testenv]test_deps}
aiohttp-client: -r {toxinidir}/instrumentation/opentelemetry-instrumentation-aiohttp-client/test-requirements.txt
Expand Down Expand Up @@ -893,6 +895,7 @@ commands =
test-instrumentation-logging: pytest {toxinidir}/instrumentation/opentelemetry-instrumentation-logging/tests {posargs}
lint-instrumentation-logging: sh -c "cd instrumentation && pylint --rcfile ../.pylintrc opentelemetry-instrumentation-logging"
benchmark-instrumentation-logging: pytest {toxinidir}/instrumentation/opentelemetry-instrumentation-logging/benchmarks {posargs} --benchmark-json=instrumentation-logging-benchmark.json
benchmark-instrumentation-requests: pytest {toxinidir}/instrumentation/opentelemetry-instrumentation-requests/benchmarks {posargs} --benchmark-json=instrumentation-requests-benchmark.json

test-instrumentation-mysql: pytest {toxinidir}/instrumentation/opentelemetry-instrumentation-mysql/tests {posargs}
lint-instrumentation-mysql: sh -c "cd instrumentation && pylint --rcfile ../.pylintrc opentelemetry-instrumentation-mysql"
Expand Down
Loading