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

Add line-specific filter to catch warning #3164

Merged
merged 4 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import math
ocelotl marked this conversation as resolved.
Show resolved Hide resolved
import os
from abc import ABC, abstractmethod
from enum import Enum
Expand All @@ -23,7 +24,6 @@
from typing import IO, Callable, Dict, Iterable, Optional

from typing_extensions import final
import math

# This kind of import is needed to avoid Sphinx errors.
import opentelemetry.sdk.metrics._internal
Expand Down
24 changes: 19 additions & 5 deletions opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
Type,
Union,
)
from warnings import filterwarnings

from deprecated import deprecated

Expand Down Expand Up @@ -1167,16 +1168,29 @@ def get_tracer(
logger.error("get_tracer called with missing module name.")
if instrumenting_library_version is None:
instrumenting_library_version = ""

filterwarnings(
"ignore",
message=(
r"Call to deprecated method __init__. \(You should use "
r"InstrumentationScope\) -- Deprecated since version 1.11.1."
),
category=DeprecationWarning,
module="opentelemetry.sdk.trace",
)

instrumentation_info = InstrumentationInfo(
instrumenting_module_name,
instrumenting_library_version,
schema_url,
)

return Tracer(
self.sampler,
self.resource,
self._active_span_processor,
self.id_generator,
InstrumentationInfo(
instrumenting_module_name,
instrumenting_library_version,
schema_url,
),
instrumentation_info,
ocelotl marked this conversation as resolved.
Show resolved Hide resolved
self._span_limits,
InstrumentationScope(
instrumenting_module_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import math
from time import sleep, time_ns
from typing import Sequence
from unittest.mock import Mock

from flaky import flaky
import math

from opentelemetry.sdk.metrics import Counter
from opentelemetry.sdk.metrics._internal import _Counter
Expand Down Expand Up @@ -139,7 +139,9 @@ def test_ticker_not_called_on_infinity(self):
collect_mock = Mock()
exporter = FakeMetricsExporter()
exporter.export = Mock()
pmr = PeriodicExportingMetricReader(exporter, export_interval_millis=math.inf)
pmr = PeriodicExportingMetricReader(
ocelotl marked this conversation as resolved.
Show resolved Hide resolved
exporter, export_interval_millis=math.inf
)
pmr._set_collect_callback(collect_mock)
sleep(0.1)
self.assertTrue(collect_mock.assert_not_called)
Expand All @@ -149,16 +151,20 @@ def test_ticker_value_exception_on_zero(self):
exporter = FakeMetricsExporter()
exporter.export = Mock()
self.assertRaises(
ValueError, PeriodicExportingMetricReader,
exporter, export_interval_millis=0
ValueError,
ocelotl marked this conversation as resolved.
Show resolved Hide resolved
PeriodicExportingMetricReader,
exporter,
export_interval_millis=0,
)

def test_ticker_value_exception_on_negative(self):
exporter = FakeMetricsExporter()
exporter.export = Mock()
self.assertRaises(
ValueError, PeriodicExportingMetricReader,
exporter, export_interval_millis=-100
ValueError,
ocelotl marked this conversation as resolved.
Show resolved Hide resolved
PeriodicExportingMetricReader,
exporter,
export_interval_millis=-100,
)

@flaky(max_runs=3, min_passes=1)
Expand Down
16 changes: 14 additions & 2 deletions opentelemetry-sdk/tests/trace/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from time import time_ns
from typing import Optional
from unittest import mock
from unittest.mock import Mock

from opentelemetry import trace as trace_api
from opentelemetry.context import Context
Expand All @@ -39,7 +40,7 @@
OTEL_TRACES_SAMPLER,
OTEL_TRACES_SAMPLER_ARG,
)
from opentelemetry.sdk.trace import Resource
from opentelemetry.sdk.trace import Resource, TracerProvider
from opentelemetry.sdk.trace.id_generator import RandomIdGenerator
from opentelemetry.sdk.trace.sampling import (
ALWAYS_OFF,
Expand All @@ -48,7 +49,7 @@
ParentBased,
StaticSampler,
)
from opentelemetry.sdk.util import ns_to_iso_str
from opentelemetry.sdk.util import BoundedDict, ns_to_iso_str
from opentelemetry.sdk.util.instrumentation import InstrumentationInfo
from opentelemetry.test.spantestutil import (
get_span_with_dropped_attributes_events_links,
Expand All @@ -58,6 +59,17 @@


class TestTracer(unittest.TestCase):
def test_no_deprecated_warning(self):
with self.assertRaises(AssertionError):
with self.assertWarns(DeprecationWarning):
TracerProvider(Mock(), Mock()).get_tracer(Mock(), Mock())

# This is being added here to make sure the filter on
# InstrumentationInfo does not affect other DeprecationWarnings that
# may be raised.
with self.assertWarns(DeprecationWarning):
BoundedDict(0)

def test_extends_api(self):
tracer = new_tracer()
self.assertIsInstance(tracer, trace.Tracer)
Expand Down