Skip to content

Commit

Permalink
Refactor moving suppress key to instrumentation package
Browse files Browse the repository at this point in the history
  • Loading branch information
euniceek committed May 31, 2021
1 parent b4c0f0e commit e1b84bb
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
import typing

from opentelemetry.context import Context, attach, detach, set_value
from opentelemetry.instrumentation.utils import _SUPPRESS_INSTRUMENTATION_KEY
from opentelemetry.instrumentation.utils import get_suppress_instrumentation_key
from opentelemetry.sdk.trace import Span, SpanProcessor
from opentelemetry.sdk.trace.export import SpanExporter
from opentelemetry.trace import INVALID_TRACE_ID
from opentelemetry.util._time import _time_ns

_SUPPRESS_INSTRUMENTATION_KEY = get_suppress_instrumentation_key()
logger = logging.getLogger(__name__)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def strip_query_params(url: yarl.URL) -> str:
from opentelemetry.instrumentation.aiohttp_client.version import __version__
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
from opentelemetry.instrumentation.utils import (
_SUPPRESS_INSTRUMENTATION_KEY,
get_suppress_instrumentation_key,
http_status_to_status_code,
unwrap,
)
Expand All @@ -88,6 +88,7 @@ def strip_query_params(url: yarl.URL) -> str:
_SpanNameT = typing.Optional[
typing.Union[typing.Callable[[aiohttp.TraceRequestStartParams], str], str]
]
_SUPPRESS_INSTRUMENTATION_KEY = get_suppress_instrumentation_key()


def url_path_span_name(params: aiohttp.TraceRequestStartParams) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
from opentelemetry.instrumentation.aiohttp_client import (
AioHttpClientInstrumentor,
)
from opentelemetry.instrumentation.utils import _SUPPRESS_INSTRUMENTATION_KEY
from opentelemetry.instrumentation.utils import get_suppress_instrumentation_key
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.test.test_base import TestBase
from opentelemetry.trace import StatusCode

_SUPPRESS_INSTRUMENTATION_KEY = get_suppress_instrumentation_key()


def run_with_test_server(
runnable: typing.Callable, url: str, handler: typing.Callable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,14 @@
from opentelemetry.instrumentation.botocore.version import __version__
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
from opentelemetry.instrumentation.utils import (
_SUPPRESS_INSTRUMENTATION_KEY,
get_suppress_instrumentation_key,
unwrap,
)
from opentelemetry.propagate import inject
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.trace import SpanKind, get_tracer

_SUPPRESS_INSTRUMENTATION_KEY = get_suppress_instrumentation_key()
logger = logging.getLogger(__name__)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@
from opentelemetry import trace as trace_api
from opentelemetry.context import attach, detach, set_value
from opentelemetry.instrumentation.botocore import BotocoreInstrumentor
from opentelemetry.instrumentation.utils import _SUPPRESS_INSTRUMENTATION_KEY
from opentelemetry.instrumentation.utils import get_suppress_instrumentation_key
from opentelemetry.propagate import get_global_textmap, set_global_textmap
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.test.mock_textmap import MockTextMapPropagator
from opentelemetry.test.test_base import TestBase

_SUPPRESS_INSTRUMENTATION_KEY = get_suppress_instrumentation_key()


def get_as_zip_file(file_name, content):
zip_output = io.BytesIO()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from opentelemetry.instrumentation.requests.package import _instruments
from opentelemetry.instrumentation.requests.version import __version__
from opentelemetry.instrumentation.utils import (
_SUPPRESS_INSTRUMENTATION_KEY,
get_suppress_instrumentation_key,
http_status_to_status_code,
)
from opentelemetry.propagate import inject
Expand All @@ -59,6 +59,7 @@
_SUPPRESS_HTTP_INSTRUMENTATION_KEY = context.create_key(
"suppress_http_instrumentation"
)
_SUPPRESS_INSTRUMENTATION_KEY = get_suppress_instrumentation_key()


# pylint: disable=unused-argument
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@
import opentelemetry.instrumentation.requests
from opentelemetry import context, trace
from opentelemetry.instrumentation.requests import RequestsInstrumentor
from opentelemetry.instrumentation.utils import _SUPPRESS_INSTRUMENTATION_KEY
from opentelemetry.instrumentation.utils import get_suppress_instrumentation_key
from opentelemetry.propagate import get_global_textmap, set_global_textmap
from opentelemetry.sdk import resources
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.test.mock_textmap import MockTextMapPropagator
from opentelemetry.test.test_base import TestBase
from opentelemetry.trace import StatusCode

_SUPPRESS_INSTRUMENTATION_KEY = get_suppress_instrumentation_key()


class InvalidResponseObjectException(Exception):
def __init__(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
__version__,
)
from opentelemetry.instrumentation.utils import (
_SUPPRESS_INSTRUMENTATION_KEY,
get_suppress_instrumentation_key,
http_status_to_status_code,
)
from opentelemetry.propagate import inject
Expand All @@ -63,6 +63,7 @@
_SUPPRESS_HTTP_INSTRUMENTATION_KEY = context.create_key(
"suppress_http_instrumentation"
)
_SUPPRESS_INSTRUMENTATION_KEY = get_suppress_instrumentation_key()


class URLLibInstrumentor(BaseInstrumentor):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@
from opentelemetry.instrumentation.urllib import ( # pylint: disable=no-name-in-module,import-error
URLLibInstrumentor,
)
from opentelemetry.instrumentation.utils import _SUPPRESS_INSTRUMENTATION_KEY
from opentelemetry.instrumentation.utils import get_suppress_instrumentation_key
from opentelemetry.propagate import get_global_textmap, set_global_textmap
from opentelemetry.sdk import resources
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.test.mock_textmap import MockTextMapPropagator
from opentelemetry.test.test_base import TestBase
from opentelemetry.trace import StatusCode

_SUPPRESS_INSTRUMENTATION_KEY = get_suppress_instrumentation_key()


class RequestsIntegrationTestBase(abc.ABC):
# pylint: disable=no-member
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def span_name_callback(method: str, url: str, headers):
from opentelemetry.instrumentation.urllib3.package import _instruments
from opentelemetry.instrumentation.urllib3.version import __version__
from opentelemetry.instrumentation.utils import (
_SUPPRESS_INSTRUMENTATION_KEY,
get_suppress_instrumentation_key,
http_status_to_status_code,
unwrap,
)
Expand All @@ -70,6 +70,7 @@ def span_name_callback(method: str, url: str, headers):
_SUPPRESS_HTTP_INSTRUMENTATION_KEY = context.create_key(
"suppress_http_instrumentation"
)
_SUPPRESS_INSTRUMENTATION_KEY = get_suppress_instrumentation_key()

_UrlFilterT = typing.Optional[typing.Callable[[str], str]]
_SpanNameT = typing.Optional[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@
_SUPPRESS_HTTP_INSTRUMENTATION_KEY,
URLLib3Instrumentor,
)
from opentelemetry.instrumentation.utils import _SUPPRESS_INSTRUMENTATION_KEY
from opentelemetry.instrumentation.utils import get_suppress_instrumentation_key
from opentelemetry.propagate import get_global_textmap, set_global_textmap
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.test.mock_textmap import MockTextMapPropagator
from opentelemetry.test.test_base import TestBase

# pylint: disable=too-many-public-methods
_SUPPRESS_INSTRUMENTATION_KEY = get_suppress_instrumentation_key()


class TestURLLib3Instrumentor(TestBase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,6 @@ def unwrap(obj, attr: str):
func = getattr(obj, attr, None)
if func and isinstance(func, ObjectProxy) and hasattr(func, "__wrapped__"):
setattr(obj, attr, func.__wrapped__)

def get_suppress_instrumentation_key():
return _SUPPRESS_INSTRUMENTATION_KEY

0 comments on commit e1b84bb

Please sign in to comment.