From daecd34648fdc52057bfc6b5949a00a4b4bad75e Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Tue, 13 Apr 2021 08:55:07 -0700 Subject: [PATCH 1/7] initial commit for fix for issue 1747 --- .../opentelemetry/exporter/otlp/proto/grpc/exporter.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py index e3a42a24c53..6d6092187c4 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py @@ -194,9 +194,15 @@ def __init__( super().__init__() endpoint = endpoint or environ.get( - OTEL_EXPORTER_OTLP_ENDPOINT, "localhost:4317" + OTEL_EXPORTER_OTLP_ENDPOINT, "http://localhost:4317" ) + if endpoint.startswith("http://"): + insecure = True + + # strip the scheme before using endpoint + endpoint = endpoint.split("://")[-1] + self._headers = headers or environ.get(OTEL_EXPORTER_OTLP_HEADERS) if isinstance(self._headers, str): self._headers = tuple( From fbbba384b2c00082b1154a0008e46792bd84d25e Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Wed, 14 Apr 2021 08:37:56 -0700 Subject: [PATCH 2/7] update changelog --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc3b62b6117..d0b27b17290 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added ProxyTracerProvider and ProxyTracer implementations to allow fetching provider and tracer instances before a global provider is set up. ([#1726](https://github.com/open-telemetry/opentelemetry-python/pull/1726)) - +- OTLP Exporter now uses the scheme in the endpoint to determine whether to establish + a secure connection or not. + ([#1771](https://github.com/open-telemetry/opentelemetry-python/pull/1771)) ## [1.0.0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.0.0) - 2021-03-26 ### Added From fcab0e4b1f0a15070be238d61b7acff411b28506 Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Thu, 15 Apr 2021 15:03:48 -0700 Subject: [PATCH 3/7] use urlparse and update tests --- docs/examples/fork-process-model/README.rst | 4 ++-- .../flask-gunicorn/gunicorn.config.py | 2 +- .../examples/fork-process-model/flask-uwsgi/app.py | 2 +- .../exporter/otlp/proto/grpc/__init__.py | 2 +- .../exporter/otlp/proto/grpc/exporter.py | 14 ++++++++++---- .../tests/test_otlp_trace_exporter.py | 4 +++- 6 files changed, 18 insertions(+), 10 deletions(-) diff --git a/docs/examples/fork-process-model/README.rst b/docs/examples/fork-process-model/README.rst index 2bd0c9ecbcd..2f33bcf500a 100644 --- a/docs/examples/fork-process-model/README.rst +++ b/docs/examples/fork-process-model/README.rst @@ -31,7 +31,7 @@ Gunicorn post_fork hook trace.set_tracer_provider(TracerProvider(resource=resource)) span_processor = BatchSpanProcessor( - OTLPSpanExporter(endpoint="localhost:4317") + OTLPSpanExporter(endpoint="http://localhost:4317") ) trace.get_tracer_provider().add_span_processor(span_processor) @@ -58,7 +58,7 @@ uWSGI postfork decorator trace.set_tracer_provider(TracerProvider(resource=resource)) span_processor = BatchSpanProcessor( - OTLPSpanExporter(endpoint="localhost:4317") + OTLPSpanExporter(endpoint="http://localhost:4317") ) trace.get_tracer_provider().add_span_processor(span_processor) diff --git a/docs/examples/fork-process-model/flask-gunicorn/gunicorn.config.py b/docs/examples/fork-process-model/flask-gunicorn/gunicorn.config.py index eaf67773929..902a0133e3b 100644 --- a/docs/examples/fork-process-model/flask-gunicorn/gunicorn.config.py +++ b/docs/examples/fork-process-model/flask-gunicorn/gunicorn.config.py @@ -47,6 +47,6 @@ def post_fork(server, worker): # This uses insecure connection for the purpose of example. Please see the # OTLP Exporter documentation for other options. span_processor = BatchSpanProcessor( - OTLPSpanExporter(endpoint="localhost:4317", insecure=True) + OTLPSpanExporter(endpoint="http://localhost:4317", insecure=True) ) trace.get_tracer_provider().add_span_processor(span_processor) diff --git a/docs/examples/fork-process-model/flask-uwsgi/app.py b/docs/examples/fork-process-model/flask-uwsgi/app.py index adcf52691f9..fb56037c06e 100644 --- a/docs/examples/fork-process-model/flask-uwsgi/app.py +++ b/docs/examples/fork-process-model/flask-uwsgi/app.py @@ -38,7 +38,7 @@ def init_tracing(): # This uses insecure connection for the purpose of example. Please see the # OTLP Exporter documentation for other options. span_processor = BatchSpanProcessor( - OTLPSpanExporter(endpoint="localhost:4317", insecure=True) + OTLPSpanExporter(endpoint="http://localhost:4317", insecure=True) ) trace.get_tracer_provider().add_span_processor(span_processor) diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/__init__.py index c4c96b76c0f..0a33b6325ad 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/__init__.py @@ -57,7 +57,7 @@ trace.set_tracer_provider(TracerProvider(resource=resource)) tracer = trace.get_tracer(__name__) - otlp_exporter = OTLPSpanExporter(endpoint="localhost:4317", insecure=True) + otlp_exporter = OTLPSpanExporter(endpoint="http://localhost:4317", insecure=True) span_processor = BatchSpanProcessor(otlp_exporter) diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py index 6d6092187c4..b76e41f9347 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py @@ -22,6 +22,8 @@ from typing import Any, Callable, Dict, Generic, List, Optional from typing import Sequence as TypingSequence from typing import Text, TypeVar +from urllib import parse +from urllib.parse import urlparse from backoff import expo from google.rpc.error_details_pb2 import RetryInfo @@ -197,11 +199,15 @@ def __init__( OTEL_EXPORTER_OTLP_ENDPOINT, "http://localhost:4317" ) - if endpoint.startswith("http://"): - insecure = True + parsed_url = urlparse(endpoint) - # strip the scheme before using endpoint - endpoint = endpoint.split("://")[-1] + if endpoint is None: + if parsed_url.scheme == "https": + insecure = False + else: + insecure = True + + endpoint = parsed_url.netloc self._headers = headers or environ.get(OTEL_EXPORTER_OTLP_HEADERS) if isinstance(self._headers, str): diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_trace_exporter.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_trace_exporter.py index ed22cbdbea1..53d9a9b8351 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_trace_exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_trace_exporter.py @@ -208,8 +208,10 @@ def test_env_variables(self, mock_exporter_mixin): def test_no_credentials_error( self, mock_ssl_channel, mock_secure, mock_stub ): - OTLPSpanExporter(insecure=False) + OTLPSpanExporter(endpoint="https://localhost:4317") self.assertTrue(mock_ssl_channel.called) + self.assertTrue(mock_secure.called) + self.assertTrue("localhost:4317" in mock_secure.call_args[0]) @patch.dict( "os.environ", From 9f6f1ba0fabce73b64721990c724afbe7d0b900e Mon Sep 17 00:00:00 2001 From: Michael Stella Date: Fri, 16 Apr 2021 11:29:03 -0400 Subject: [PATCH 4/7] Add __contains__ to TraceState (#1773) --- CHANGELOG.md | 2 ++ .../src/opentelemetry/trace/span.py | 7 +++++-- opentelemetry-api/tests/trace/test_tracestate.py | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e915587acd7..81d9644b1da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added ProxyTracerProvider and ProxyTracer implementations to allow fetching provider and tracer instances before a global provider is set up. ([#1726](https://github.com/open-telemetry/opentelemetry-python/pull/1726)) +- Added `__contains__` to `opentelementry.trace.span.TraceState`. + ([#1773](https://github.com/open-telemetry/opentelemetry-python/pull/1773)) - OTLP Exporter now uses the scheme in the endpoint to determine whether to establish a secure connection or not. ([#1771](https://github.com/open-telemetry/opentelemetry-python/pull/1771)) diff --git a/opentelemetry-api/src/opentelemetry/trace/span.py b/opentelemetry-api/src/opentelemetry/trace/span.py index d04cdfa49dd..c4c713cf3e7 100644 --- a/opentelemetry-api/src/opentelemetry/trace/span.py +++ b/opentelemetry-api/src/opentelemetry/trace/span.py @@ -231,8 +231,11 @@ def __init__( "Invalid key/value pair (%s, %s) found.", key, value ) - def __getitem__(self, key: str) -> typing.Optional[str]: # type: ignore - return self._dict.get(key) + def __contains__(self, item: object) -> bool: + return item in self._dict + + def __getitem__(self, key: str) -> str: + return self._dict[key] def __iter__(self) -> typing.Iterator[str]: return iter(self._dict) diff --git a/opentelemetry-api/tests/trace/test_tracestate.py b/opentelemetry-api/tests/trace/test_tracestate.py index 6665dd612dd..625b260d548 100644 --- a/opentelemetry-api/tests/trace/test_tracestate.py +++ b/opentelemetry-api/tests/trace/test_tracestate.py @@ -96,3 +96,19 @@ def test_tracestate_order_changed(self): foo_place = entries.index(("foo", "bar33")) # type: ignore prev_first_place = entries.index(("1a-2f@foo", "bar1")) # type: ignore self.assertLessEqual(foo_place, prev_first_place) + + def test_trace_contains(self): + entries = [ + "1a-2f@foo=bar1", + "1a-_*/2b@foo=bar2", + "foo=bar3", + "foo-_*/bar=bar4", + ] + header_list = [",".join(entries)] + state = TraceState.from_header(header_list) + + self.assertTrue("foo" in state) + self.assertFalse("bar" in state) + self.assertIsNone(state.get("bar")) + with self.assertRaises(KeyError): + state["bar"] # pylint:disable=W0104 From c845f1530a0948e7889e8be1732d55c62503c8ea Mon Sep 17 00:00:00 2001 From: Owais Lone Date: Fri, 16 Apr 2021 21:19:02 +0530 Subject: [PATCH 5/7] Upgraded black and isort (#1777) --- dev-requirements.txt | 4 +-- docs/conf.py | 25 +++++++++++++++---- docs/examples/opentracing/main.py | 5 +++- docs/getting_started/jaeger_example.py | 5 +++- docs/getting_started/tests/test_flask.py | 3 ++- .../examples/jaeger_exporter_example.py | 3 ++- .../jaeger/proto/grpc/translate/__init__.py | 8 ++++-- .../tests/test_jaeger_exporter_protobuf.py | 15 +++++++---- .../tests/test_jaeger_exporter_thrift.py | 7 ++++-- .../opencensus/trace_exporter/__init__.py | 5 +++- .../tests/test_otcollector_trace_exporter.py | 15 ++++++++--- .../proto/grpc/trace_exporter/__init__.py | 10 +++++--- .../test_benchmark_trace_exporter.py | 11 +++++--- .../tests/test_otlp_exporter_mixin.py | 4 ++- .../tests/test_otlp_trace_exporter.py | 9 ++++--- opentelemetry-api/setup.py | 4 ++- .../src/opentelemetry/propagate/__init__.py | 7 ++++-- .../src/opentelemetry/trace/__init__.py | 8 +++--- .../src/opentelemetry/util/_providers.py | 5 +++- .../tests/baggage/test_baggage.py | 3 ++- .../tests/context/test_contextvars_context.py | 4 ++- opentelemetry-distro/setup.py | 4 ++- .../src/opentelemetry/distro/__init__.py | 4 ++- opentelemetry-instrumentation/setup.py | 4 ++- .../tests/test_bootstrap.py | 5 +++- .../tests/test_utils.py | 20 ++++++++++++--- opentelemetry-proto/setup.py | 4 ++- opentelemetry-sdk/setup.py | 4 ++- .../sdk/trace/export/__init__.py | 8 +++--- .../src/opentelemetry/sdk/trace/sampling.py | 19 +++++++------- .../profile_resource_usage_batch_export.py | 3 ++- .../profile_resource_usage_simple_export.py | 3 ++- .../tests/trace/export/test_export.py | 11 +++++--- .../tests/trace/test_sampling.py | 15 +++++++---- .../opentelemetry/propagators/b3/__init__.py | 4 ++- .../tests/test_jaeger_propagator.py | 12 ++++++--- scripts/eachdist.py | 9 +++++-- shim/opentelemetry-opentracing-shim/setup.py | 7 +++++- .../tests/test_shim.py | 6 +++-- .../test_asyncio.py | 3 ++- 40 files changed, 215 insertions(+), 90 deletions(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index 87dc7adc59f..bcbc90148c1 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,7 +1,7 @@ pylint==2.6.0 flake8~=3.7 -isort~=5.6 -black>=19.3b0,==19.* +isort~=5.8 +black~=20.8b1 httpretty~=1.0 mypy==0.812 sphinx~=2.1 diff --git a/docs/conf.py b/docs/conf.py index 61dc1a82540..0f1a69503f0 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -101,12 +101,27 @@ # Even if wrapt is added to intersphinx_mapping, sphinx keeps failing # with "class reference target not found: ObjectProxy". ("py:class", "ObjectProxy"), - ("py:class", "opentelemetry.trace._LinkBase",), + ( + "py:class", + "opentelemetry.trace._LinkBase", + ), # TODO: Understand why sphinx is not able to find this local class - ("py:class", "opentelemetry.propagators.textmap.TextMapPropagator",), - ("py:class", "opentelemetry.propagators.textmap.DefaultGetter",), - ("any", "opentelemetry.propagators.textmap.TextMapPropagator.extract",), - ("any", "opentelemetry.propagators.textmap.TextMapPropagator.inject",), + ( + "py:class", + "opentelemetry.propagators.textmap.TextMapPropagator", + ), + ( + "py:class", + "opentelemetry.propagators.textmap.DefaultGetter", + ), + ( + "any", + "opentelemetry.propagators.textmap.TextMapPropagator.extract", + ), + ( + "any", + "opentelemetry.propagators.textmap.TextMapPropagator.inject", + ), ] # Add any paths that contain templates here, relative to this directory. diff --git a/docs/examples/opentracing/main.py b/docs/examples/opentracing/main.py index 09ff51465c3..9c6252ff8c1 100755 --- a/docs/examples/opentracing/main.py +++ b/docs/examples/opentracing/main.py @@ -13,7 +13,10 @@ tracer_provider = trace.get_tracer_provider() # Configure the tracer to export traces to Jaeger -jaeger_exporter = JaegerExporter(agent_host_name="localhost", agent_port=6831,) +jaeger_exporter = JaegerExporter( + agent_host_name="localhost", + agent_port=6831, +) span_processor = SimpleSpanProcessor(jaeger_exporter) tracer_provider.add_span_processor(span_processor) diff --git a/docs/getting_started/jaeger_example.py b/docs/getting_started/jaeger_example.py index 77fea2585d2..3d31b18fb93 100644 --- a/docs/getting_started/jaeger_example.py +++ b/docs/getting_started/jaeger_example.py @@ -25,7 +25,10 @@ ) ) -jaeger_exporter = JaegerExporter(agent_host_name="localhost", agent_port=6831,) +jaeger_exporter = JaegerExporter( + agent_host_name="localhost", + agent_port=6831, +) trace.get_tracer_provider().add_span_processor( BatchSpanProcessor(jaeger_exporter) diff --git a/docs/getting_started/tests/test_flask.py b/docs/getting_started/tests/test_flask.py index fdd5cb330ab..d1475133f95 100644 --- a/docs/getting_started/tests/test_flask.py +++ b/docs/getting_started/tests/test_flask.py @@ -27,7 +27,8 @@ def test_flask(self): dirpath = os.path.dirname(os.path.realpath(__file__)) server_script = "{}/../flask_example.py".format(dirpath) server = subprocess.Popen( - [sys.executable, server_script], stdout=subprocess.PIPE, + [sys.executable, server_script], + stdout=subprocess.PIPE, ) retry_strategy = Retry(total=10, backoff_factor=1) adapter = HTTPAdapter(max_retries=retry_strategy) diff --git a/exporter/opentelemetry-exporter-jaeger-proto-grpc/examples/jaeger_exporter_example.py b/exporter/opentelemetry-exporter-jaeger-proto-grpc/examples/jaeger_exporter_example.py index d8c017e5b0f..dc3c539e753 100644 --- a/exporter/opentelemetry-exporter-jaeger-proto-grpc/examples/jaeger_exporter_example.py +++ b/exporter/opentelemetry-exporter-jaeger-proto-grpc/examples/jaeger_exporter_example.py @@ -15,7 +15,8 @@ # `EXPORTER_JAEGER_CERTIFICATE` with file containing creds. jaeger_exporter = grpc.JaegerExporter( - collector_endpoint="localhost:14250", insecure=True, + collector_endpoint="localhost:14250", + insecure=True, ) # create a BatchSpanProcessor and add the exporter to it diff --git a/exporter/opentelemetry-exporter-jaeger-proto-grpc/src/opentelemetry/exporter/jaeger/proto/grpc/translate/__init__.py b/exporter/opentelemetry-exporter-jaeger-proto-grpc/src/opentelemetry/exporter/jaeger/proto/grpc/translate/__init__.py index 5d11e14f602..778296a917c 100644 --- a/exporter/opentelemetry-exporter-jaeger-proto-grpc/src/opentelemetry/exporter/jaeger/proto/grpc/translate/__init__.py +++ b/exporter/opentelemetry-exporter-jaeger-proto-grpc/src/opentelemetry/exporter/jaeger/proto/grpc/translate/__init__.py @@ -195,7 +195,8 @@ def _duration_from_two_time_stamps( See https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#duration """ duration = Duration( - seconds=end.seconds - start.seconds, nanos=end.nanos - start.nanos, + seconds=end.seconds - start.seconds, + nanos=end.nanos - start.nanos, ) # pylint: disable=chained-comparison if duration.seconds < 0 and duration.nanos > 0: @@ -350,7 +351,10 @@ def _extract_logs( fields.append(tag) fields.append( - _get_string_key_value(key="message", value=event.name,) + _get_string_key_value( + key="message", + value=event.name, + ) ) event_ts = _proto_timestamp_from_epoch_nanos(event.timestamp) logs.append(model_pb2.Log(timestamp=event_ts, fields=fields)) diff --git a/exporter/opentelemetry-exporter-jaeger-proto-grpc/tests/test_jaeger_exporter_protobuf.py b/exporter/opentelemetry-exporter-jaeger-proto-grpc/tests/test_jaeger_exporter_protobuf.py index 96bccaef4a7..99b3f093cb8 100644 --- a/exporter/opentelemetry-exporter-jaeger-proto-grpc/tests/test_jaeger_exporter_protobuf.py +++ b/exporter/opentelemetry-exporter-jaeger-proto-grpc/tests/test_jaeger_exporter_protobuf.py @@ -126,8 +126,8 @@ def test_translate_to_jaeger(self): event_timestamp = base_time + 50 * 10 ** 6 # pylint:disable=protected-access - event_timestamp_proto = pb_translator._proto_timestamp_from_epoch_nanos( - event_timestamp + event_timestamp_proto = ( + pb_translator._proto_timestamp_from_epoch_nanos(event_timestamp) ) event = trace.Event( @@ -339,7 +339,9 @@ def test_translate_to_jaeger(self): duration=span2_duration, flags=0, tags=default_tags, - process=model_pb2.Process(service_name="svc",), + process=model_pb2.Process( + service_name="svc", + ), ), model_pb2.Span( operation_name=span_names[2], @@ -370,7 +372,9 @@ def test_translate_to_jaeger(self): v_str="version", ), ], - process=model_pb2.Process(service_name="svc",), + process=model_pb2.Process( + service_name="svc", + ), ), ] @@ -378,7 +382,8 @@ def test_translate_to_jaeger(self): # (attributes) in otel is not important but in jeager it is # pylint: disable=no-member self.assertCountEqual( - spans[0].logs[0].fields, expected_spans[0].logs[0].fields, + spans[0].logs[0].fields, + expected_spans[0].logs[0].fields, ) self.assertEqual(spans, expected_spans) diff --git a/exporter/opentelemetry-exporter-jaeger-thrift/tests/test_jaeger_exporter_thrift.py b/exporter/opentelemetry-exporter-jaeger-thrift/tests/test_jaeger_exporter_thrift.py index 4cf06b04a5f..9c1773d4fad 100644 --- a/exporter/opentelemetry-exporter-jaeger-thrift/tests/test_jaeger_exporter_thrift.py +++ b/exporter/opentelemetry-exporter-jaeger-thrift/tests/test_jaeger_exporter_thrift.py @@ -258,7 +258,9 @@ def test_translate_to_jaeger(self): default_tags = [ jaeger.Tag( - key="span.kind", vType=jaeger.TagType.STRING, vStr="internal", + key="span.kind", + vType=jaeger.TagType.STRING, + vStr="internal", ), ] @@ -522,7 +524,8 @@ def test_agent_client(self): spans = translate._translate(ThriftTranslator()) batch = jaeger.Batch( - spans=spans, process=jaeger.Process(serviceName="xxx"), + spans=spans, + process=jaeger.Process(serviceName="xxx"), ) agent_client.emit(batch) diff --git a/exporter/opentelemetry-exporter-opencensus/src/opentelemetry/exporter/opencensus/trace_exporter/__init__.py b/exporter/opentelemetry-exporter-opencensus/src/opentelemetry/exporter/opencensus/trace_exporter/__init__.py index 4bea1af1565..b20084888f0 100644 --- a/exporter/opentelemetry-exporter-opencensus/src/opentelemetry/exporter/opencensus/trace_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-opencensus/src/opentelemetry/exporter/opencensus/trace_exporter/__init__.py @@ -46,7 +46,10 @@ class OpenCensusSpanExporter(SpanExporter): """ def __init__( - self, endpoint=DEFAULT_ENDPOINT, host_name=None, client=None, + self, + endpoint=DEFAULT_ENDPOINT, + host_name=None, + client=None, ): tracer_provider = trace.get_tracer_provider() service_name = ( diff --git a/exporter/opentelemetry-exporter-opencensus/tests/test_otcollector_trace_exporter.py b/exporter/opentelemetry-exporter-opencensus/tests/test_otcollector_trace_exporter.py index ab8a3a2eb6e..222a94d60b3 100644 --- a/exporter/opentelemetry-exporter-opencensus/tests/test_otcollector_trace_exporter.py +++ b/exporter/opentelemetry-exporter-opencensus/tests/test_otcollector_trace_exporter.py @@ -51,7 +51,9 @@ def test_constructor(self): endpoint = "testEndpoint" with patch: exporter = OpenCensusSpanExporter( - host_name=host_name, endpoint=endpoint, client=client, + host_name=host_name, + endpoint=endpoint, + client=client, ) self.assertIs(exporter.client, client) @@ -154,7 +156,10 @@ def test_translate_to_collector(self): otel_spans[0].end(end_time=end_times[0]) otel_spans[1].start(start_time=start_times[1]) otel_spans[1].set_status( - trace_api.Status(trace_api.StatusCode.ERROR, {"test", "val"},) + trace_api.Status( + trace_api.StatusCode.ERROR, + {"test", "val"}, + ) ) otel_spans[1].end(end_time=end_times[1]) otel_spans[2].start(start_time=start_times[2]) @@ -194,7 +199,8 @@ def test_translate_to_collector(self): output_spans[2].parent_span_id, b"\x11\x11\x11\x11\x11\x11\x11\x11" ) self.assertEqual( - output_spans[0].status.code, trace_api.StatusCode.OK.value, + output_spans[0].status.code, + trace_api.StatusCode.OK.value, ) self.assertEqual(len(output_spans[0].tracestate.entries), 1) self.assertEqual(output_spans[0].tracestate.entries[0].key, "testkey") @@ -264,7 +270,8 @@ def test_translate_to_collector(self): trace_pb2.Span.Link.Type.TYPE_UNSPECIFIED, ) self.assertEqual( - output_spans[1].status.code, trace_api.StatusCode.ERROR.value, + output_spans[1].status.code, + trace_api.StatusCode.ERROR.value, ) self.assertEqual( output_spans[2].links.link[0].type, diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/trace_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/trace_exporter/__init__.py index 518fc5551f0..e7f54c1ac31 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/trace_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/trace_exporter/__init__.py @@ -241,10 +241,12 @@ def _translate_data( sdk_resource_instrumentation_library_spans.keys() ): if sdk_span.instrumentation_info is not None: - instrumentation_library_spans = InstrumentationLibrarySpans( - instrumentation_library=InstrumentationLibrary( - name=sdk_span.instrumentation_info.name, - version=sdk_span.instrumentation_info.version, + instrumentation_library_spans = ( + InstrumentationLibrarySpans( + instrumentation_library=InstrumentationLibrary( + name=sdk_span.instrumentation_info.name, + version=sdk_span.instrumentation_info.version, + ) ) ) diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/performance/benchmarks/test_benchmark_trace_exporter.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/performance/benchmarks/test_benchmark_trace_exporter.py index 201a29fe7c1..da292d02adc 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/performance/benchmarks/test_benchmark_trace_exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/performance/benchmarks/test_benchmark_trace_exporter.py @@ -27,7 +27,8 @@ def get_tracer_with_processor(span_processor_class): span_processor = span_processor_class(OTLPSpanExporter()) tracer = TracerProvider( - active_span_processor=span_processor, sampler=sampling.DEFAULT_ON, + active_span_processor=span_processor, + sampler=sampling.DEFAULT_ON, ).get_tracer("pipeline_benchmark_tracer") return tracer @@ -45,7 +46,9 @@ def test_simple_span_processor(benchmark): tracer = get_tracer_with_processor(SimpleSpanProcessor) def create_spans_to_be_exported(): - span = tracer.start_span("benchmarkedSpan",) + span = tracer.start_span( + "benchmarkedSpan", + ) for i in range(10): span.set_attribute( "benchmarkAttribute_{}".format(i), @@ -71,7 +74,9 @@ def test_batch_span_processor(benchmark): tracer = get_tracer_with_processor(BatchSpanProcessor) def create_spans_to_be_exported(): - span = tracer.start_span("benchmarkedSpan",) + span = tracer.start_span( + "benchmarkedSpan", + ) for i in range(10): span.set_attribute( "benchmarkAttribute_{}".format(i), diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_exporter_mixin.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_exporter_mixin.py index 7ea53ddc069..a7627b237c9 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_exporter_mixin.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_exporter_mixin.py @@ -42,6 +42,8 @@ def test_environ_to_compression(self): ), Compression.Gzip, ) - self.assertIsNone(environ_to_compression("missing_key"),) + self.assertIsNone( + environ_to_compression("missing_key"), + ) with self.assertRaises(InvalidCompressionValueException): environ_to_compression("test_invalid") diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_trace_exporter.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_trace_exporter.py index 53d9a9b8351..cc6293f974d 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_trace_exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_trace_exporter.py @@ -273,7 +273,8 @@ def test_otlp_exporter_otlp_compression_unspecified( # pylint: disable=no-self-use @patch("opentelemetry.exporter.otlp.proto.grpc.exporter.insecure_channel") @patch.dict( - "os.environ", {OTEL_EXPORTER_OTLP_TRACES_COMPRESSION: "gzip"}, + "os.environ", + {OTEL_EXPORTER_OTLP_TRACES_COMPRESSION: "gzip"}, ) def test_otlp_exporter_otlp_compression_precendence( self, mock_insecure_channel @@ -457,10 +458,12 @@ def _check_translated_status( ) self.assertEqual( - status.code, code_expected, + status.code, + code_expected, ) self.assertEqual( - status.deprecated_code, deprecated_code_expected, + status.deprecated_code, + deprecated_code_expected, ) def test_span_status_translate(self): diff --git a/opentelemetry-api/setup.py b/opentelemetry-api/setup.py index 75d213ae4eb..1bd85cb4103 100644 --- a/opentelemetry-api/setup.py +++ b/opentelemetry-api/setup.py @@ -22,4 +22,6 @@ with open(VERSION_FILENAME) as f: exec(f.read(), PACKAGE_INFO) -setuptools.setup(version=PACKAGE_INFO["__version__"],) +setuptools.setup( + version=PACKAGE_INFO["__version__"], +) diff --git a/opentelemetry-api/src/opentelemetry/propagate/__init__.py b/opentelemetry-api/src/opentelemetry/propagate/__init__.py index 091b5b8d44e..6c63edec3cb 100644 --- a/opentelemetry-api/src/opentelemetry/propagate/__init__.py +++ b/opentelemetry-api/src/opentelemetry/propagate/__init__.py @@ -127,7 +127,8 @@ def inject( # Single use variable here to hack black and make lint pass environ_propagators = environ.get( - OTEL_PROPAGATORS, "tracecontext,baggage", + OTEL_PROPAGATORS, + "tracecontext,baggage", ) for propagator in environ_propagators.split(","): @@ -148,6 +149,8 @@ def get_global_textmap() -> textmap.TextMapPropagator: return _HTTP_TEXT_FORMAT -def set_global_textmap(http_text_format: textmap.TextMapPropagator,) -> None: +def set_global_textmap( + http_text_format: textmap.TextMapPropagator, +) -> None: global _HTTP_TEXT_FORMAT # pylint:disable=global-statement _HTTP_TEXT_FORMAT = http_text_format # type: ignore diff --git a/opentelemetry-api/src/opentelemetry/trace/__init__.py b/opentelemetry-api/src/opentelemetry/trace/__init__.py index d06a09c20a2..cae50a5b472 100644 --- a/opentelemetry-api/src/opentelemetry/trace/__init__.py +++ b/opentelemetry-api/src/opentelemetry/trace/__init__.py @@ -134,7 +134,9 @@ class Link(_LinkBase): """ def __init__( - self, context: "SpanContext", attributes: types.Attributes = None, + self, + context: "SpanContext", + attributes: types.Attributes = None, ) -> None: super().__init__(context) self._attributes = attributes @@ -393,9 +395,7 @@ def _tracer(self) -> Tracer: def start_span(self, *args, **kwargs) -> Span: # type: ignore return self._tracer.start_span(*args, **kwargs) # type: ignore - def start_as_current_span( # type: ignore - self, *args, **kwargs - ) -> Span: + def start_as_current_span(self, *args, **kwargs) -> Span: # type: ignore return self._tracer.start_as_current_span(*args, **kwargs) # type: ignore diff --git a/opentelemetry-api/src/opentelemetry/util/_providers.py b/opentelemetry-api/src/opentelemetry/util/_providers.py index 8388f6d8e9c..0e31f702ba6 100644 --- a/opentelemetry-api/src/opentelemetry/util/_providers.py +++ b/opentelemetry-api/src/opentelemetry/util/_providers.py @@ -42,7 +42,10 @@ def _load_provider( ), ) ) - return cast(Provider, entry_point.load()(),) + return cast( + Provider, + entry_point.load()(), + ) except Exception: # pylint: disable=broad-except logger.error("Failed to load configured provider %s", provider) raise diff --git a/opentelemetry-api/tests/baggage/test_baggage.py b/opentelemetry-api/tests/baggage/test_baggage.py index 62f3fb77d5d..223b9b2ff2a 100644 --- a/opentelemetry-api/tests/baggage/test_baggage.py +++ b/opentelemetry-api/tests/baggage/test_baggage.py @@ -41,7 +41,8 @@ def test_set_multiple_baggage_entries(self): self.assertEqual(baggage.get_baggage("test", context=ctx), "value") self.assertEqual(baggage.get_baggage("test2", context=ctx), "value2") self.assertEqual( - baggage.get_all(context=ctx), {"test": "value", "test2": "value2"}, + baggage.get_all(context=ctx), + {"test": "value", "test2": "value2"}, ) def test_modifying_baggage(self): diff --git a/opentelemetry-api/tests/context/test_contextvars_context.py b/opentelemetry-api/tests/context/test_contextvars_context.py index 0c2ec1e6c2c..2ac517abb20 100644 --- a/opentelemetry-api/tests/context/test_contextvars_context.py +++ b/opentelemetry-api/tests/context/test_contextvars_context.py @@ -33,7 +33,9 @@ class TestContextVarsContext(ContextTestCases.BaseTest): def setUp(self) -> None: super(TestContextVarsContext, self).setUp() self.mock_runtime = patch.object( - context, "_RUNTIME_CONTEXT", ContextVarsRuntimeContext(), + context, + "_RUNTIME_CONTEXT", + ContextVarsRuntimeContext(), ) self.mock_runtime.start() diff --git a/opentelemetry-distro/setup.py b/opentelemetry-distro/setup.py index da8417d50a5..95af2c4840a 100644 --- a/opentelemetry-distro/setup.py +++ b/opentelemetry-distro/setup.py @@ -24,4 +24,6 @@ with open(VERSION_FILENAME) as f: exec(f.read(), PACKAGE_INFO) -setuptools.setup(version=PACKAGE_INFO["__version__"],) +setuptools.setup( + version=PACKAGE_INFO["__version__"], +) diff --git a/opentelemetry-distro/src/opentelemetry/distro/__init__.py b/opentelemetry-distro/src/opentelemetry/distro/__init__.py index 258bdaddc55..d60bbd208ee 100644 --- a/opentelemetry-distro/src/opentelemetry/distro/__init__.py +++ b/opentelemetry-distro/src/opentelemetry/distro/__init__.py @@ -70,7 +70,9 @@ def _init_tracing( ): # if env var OTEL_RESOURCE_ATTRIBUTES is given, it will read the service_name # from the env variable else defaults to "unknown_service" - provider = TracerProvider(id_generator=id_generator(),) + provider = TracerProvider( + id_generator=id_generator(), + ) trace.set_tracer_provider(provider) for _, exporter_class in exporters.items(): diff --git a/opentelemetry-instrumentation/setup.py b/opentelemetry-instrumentation/setup.py index fb3c8ff9f1d..d4f84f738ba 100644 --- a/opentelemetry-instrumentation/setup.py +++ b/opentelemetry-instrumentation/setup.py @@ -24,4 +24,6 @@ with open(VERSION_FILENAME) as f: exec(f.read(), PACKAGE_INFO) -setuptools.setup(version=PACKAGE_INFO["__version__"],) +setuptools.setup( + version=PACKAGE_INFO["__version__"], +) diff --git a/opentelemetry-instrumentation/tests/test_bootstrap.py b/opentelemetry-instrumentation/tests/test_bootstrap.py index e5a1a86dda5..de978eb6d58 100644 --- a/opentelemetry-instrumentation/tests/test_bootstrap.py +++ b/opentelemetry-instrumentation/tests/test_bootstrap.py @@ -23,7 +23,10 @@ def sample_packages(packages, rate): - sampled = sample(list(packages), int(len(packages) * rate),) + sampled = sample( + list(packages), + int(len(packages) * rate), + ) return {k: v for k, v in packages.items() if k in sampled} diff --git a/opentelemetry-instrumentation/tests/test_utils.py b/opentelemetry-instrumentation/tests/test_utils.py index 273c6f085cc..e5246335c9f 100644 --- a/opentelemetry-instrumentation/tests/test_utils.py +++ b/opentelemetry-instrumentation/tests/test_utils.py @@ -31,12 +31,24 @@ def test_http_status_to_status_code(self): (HTTPStatus.UNAUTHORIZED, StatusCode.ERROR), (HTTPStatus.FORBIDDEN, StatusCode.ERROR), (HTTPStatus.NOT_FOUND, StatusCode.ERROR), - (HTTPStatus.UNPROCESSABLE_ENTITY, StatusCode.ERROR,), - (HTTPStatus.TOO_MANY_REQUESTS, StatusCode.ERROR,), + ( + HTTPStatus.UNPROCESSABLE_ENTITY, + StatusCode.ERROR, + ), + ( + HTTPStatus.TOO_MANY_REQUESTS, + StatusCode.ERROR, + ), (HTTPStatus.NOT_IMPLEMENTED, StatusCode.ERROR), (HTTPStatus.SERVICE_UNAVAILABLE, StatusCode.ERROR), - (HTTPStatus.GATEWAY_TIMEOUT, StatusCode.ERROR,), - (HTTPStatus.HTTP_VERSION_NOT_SUPPORTED, StatusCode.ERROR,), + ( + HTTPStatus.GATEWAY_TIMEOUT, + StatusCode.ERROR, + ), + ( + HTTPStatus.HTTP_VERSION_NOT_SUPPORTED, + StatusCode.ERROR, + ), (600, StatusCode.ERROR), (99, StatusCode.ERROR), ): diff --git a/opentelemetry-proto/setup.py b/opentelemetry-proto/setup.py index 0bb2e6012e0..8daf422ffae 100644 --- a/opentelemetry-proto/setup.py +++ b/opentelemetry-proto/setup.py @@ -24,4 +24,6 @@ with open(VERSION_FILENAME) as f: exec(f.read(), PACKAGE_INFO) -setuptools.setup(version=PACKAGE_INFO["__version__"],) +setuptools.setup( + version=PACKAGE_INFO["__version__"], +) diff --git a/opentelemetry-sdk/setup.py b/opentelemetry-sdk/setup.py index 3ba02ba2459..cf910e40f1d 100644 --- a/opentelemetry-sdk/setup.py +++ b/opentelemetry-sdk/setup.py @@ -24,4 +24,6 @@ with open(VERSION_FILENAME) as f: exec(f.read(), PACKAGE_INFO) -setuptools.setup(version=PACKAGE_INFO["__version__"],) +setuptools.setup( + version=PACKAGE_INFO["__version__"], +) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py index 2e7ab83d61f..457a1ef56ca 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py @@ -258,7 +258,9 @@ def worker(self): self._notify_flush_request_finished(flush_request) self._notify_flush_request_finished(shutdown_flush_request) - def _get_and_unset_flush_request(self,) -> typing.Optional[_FlushRequest]: + def _get_and_unset_flush_request( + self, + ) -> typing.Optional[_FlushRequest]: """Returns the current flush request and makes it invisible to the worker thread for subsequent calls. """ @@ -316,8 +318,8 @@ def _export(self, flush_request: typing.Optional[_FlushRequest]): def _export_batch(self) -> int: """Exports at most max_export_batch_size spans and returns the number of - exported spans. - """ + exported spans. + """ idx = 0 # currently only a single thread acts as consumer, so queue.pop() will # not raise an exception diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/sampling.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/sampling.py index ce71569e72b..833fbc76aad 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/sampling.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/sampling.py @@ -266,7 +266,9 @@ def should_sample( if decision is Decision.DROP: attributes = None return SamplingResult( - decision, attributes, _get_parent_trace_state(parent_context), + decision, + attributes, + _get_parent_trace_state(parent_context), ) def get_description(self) -> str: @@ -341,15 +343,12 @@ def should_sample( ) def get_description(self): - return ( - "ParentBased{{root:{},remoteParentSampled:{},remoteParentNotSampled:{}," - "localParentSampled:{},localParentNotSampled:{}}}".format( - self._root.get_description(), - self._remote_parent_sampled.get_description(), - self._remote_parent_not_sampled.get_description(), - self._local_parent_sampled.get_description(), - self._local_parent_not_sampled.get_description(), - ) + return "ParentBased{{root:{},remoteParentSampled:{},remoteParentNotSampled:{}," "localParentSampled:{},localParentNotSampled:{}}}".format( + self._root.get_description(), + self._remote_parent_sampled.get_description(), + self._remote_parent_not_sampled.get_description(), + self._local_parent_sampled.get_description(), + self._local_parent_not_sampled.get_description(), ) diff --git a/opentelemetry-sdk/tests/performance/resource-usage/trace/profile_resource_usage_batch_export.py b/opentelemetry-sdk/tests/performance/resource-usage/trace/profile_resource_usage_batch_export.py index c4b16dd8de9..178d65b114f 100644 --- a/opentelemetry-sdk/tests/performance/resource-usage/trace/profile_resource_usage_batch_export.py +++ b/opentelemetry-sdk/tests/performance/resource-usage/trace/profile_resource_usage_batch_export.py @@ -35,7 +35,8 @@ def __init__(self, channel): simple_span_processor = BatchSpanProcessor(OTLPSpanExporter()) tracer = TracerProvider( - active_span_processor=simple_span_processor, sampler=sampling.DEFAULT_ON, + active_span_processor=simple_span_processor, + sampler=sampling.DEFAULT_ON, ).get_tracer("resource_usage_tracer") starttime = time.time() diff --git a/opentelemetry-sdk/tests/performance/resource-usage/trace/profile_resource_usage_simple_export.py b/opentelemetry-sdk/tests/performance/resource-usage/trace/profile_resource_usage_simple_export.py index efad1a8407f..b82f133ec4a 100644 --- a/opentelemetry-sdk/tests/performance/resource-usage/trace/profile_resource_usage_simple_export.py +++ b/opentelemetry-sdk/tests/performance/resource-usage/trace/profile_resource_usage_simple_export.py @@ -35,7 +35,8 @@ def __init__(self, channel): simple_span_processor = SimpleSpanProcessor(OTLPSpanExporter()) tracer = TracerProvider( - active_span_processor=simple_span_processor, sampler=sampling.DEFAULT_ON, + active_span_processor=simple_span_processor, + sampler=sampling.DEFAULT_ON, ).get_tracer("resource_usage_tracer") starttime = time.time() diff --git a/opentelemetry-sdk/tests/trace/export/test_export.py b/opentelemetry-sdk/tests/trace/export/test_export.py index 831105b8fff..23f9308e084 100644 --- a/opentelemetry-sdk/tests/trace/export/test_export.py +++ b/opentelemetry-sdk/tests/trace/export/test_export.py @@ -365,7 +365,8 @@ def test_batch_span_processor_scheduled_delay(self): destination=spans_names_list, export_event=export_event ) span_processor = export.BatchSpanProcessor( - my_exporter, schedule_delay_millis=50, + my_exporter, + schedule_delay_millis=50, ) # create single span @@ -391,7 +392,8 @@ def test_batch_span_processor_reset_timeout(self): ) span_processor = export.BatchSpanProcessor( - my_exporter, schedule_delay_millis=50, + my_exporter, + schedule_delay_millis=50, ) with mock.patch.object(span_processor.condition, "wait") as mock_wait: @@ -424,7 +426,10 @@ def test_batch_span_processor_parameters(self): # negative max_queue_size self.assertRaises( - ValueError, export.BatchSpanProcessor, None, max_queue_size=-500, + ValueError, + export.BatchSpanProcessor, + None, + max_queue_size=-500, ) # zero schedule_delay_millis diff --git a/opentelemetry-sdk/tests/trace/test_sampling.py b/opentelemetry-sdk/tests/trace/test_sampling.py index 3e2a66bb90b..808c64499de 100644 --- a/opentelemetry-sdk/tests/trace/test_sampling.py +++ b/opentelemetry-sdk/tests/trace/test_sampling.py @@ -315,7 +315,8 @@ def test_probability_sampler_limits(self): # the highest theoretical sampling rate. If this test fails the test # above is wrong. self.assertLess( - almost_almost_always_on.bound, 0xFFFFFFFFFFFFFFFF, + almost_almost_always_on.bound, + 0xFFFFFFFFFFFFFFFF, ) # pylint:disable=too-many-statements @@ -325,7 +326,8 @@ def exec_parent_based(self, parent_sampling_context): # Check that the sampling decision matches the parent context if given with parent_sampling_context( self._create_parent_span( - trace_flags=TO_DEFAULT, trace_state=trace_state, + trace_flags=TO_DEFAULT, + trace_state=trace_state, ) ) as context: # local, not sampled @@ -342,7 +344,8 @@ def exec_parent_based(self, parent_sampling_context): with parent_sampling_context( self._create_parent_span( - trace_flags=TO_DEFAULT, trace_state=trace_state, + trace_flags=TO_DEFAULT, + trace_state=trace_state, ) ) as context: sampler = sampling.ParentBased( @@ -363,7 +366,8 @@ def exec_parent_based(self, parent_sampling_context): with parent_sampling_context( self._create_parent_span( - trace_flags=TO_SAMPLED, trace_state=trace_state, + trace_flags=TO_SAMPLED, + trace_state=trace_state, ) ) as context: sampler = sampling.ParentBased(sampling.ALWAYS_OFF) @@ -382,7 +386,8 @@ def exec_parent_based(self, parent_sampling_context): with parent_sampling_context( self._create_parent_span( - trace_flags=TO_SAMPLED, trace_state=trace_state, + trace_flags=TO_SAMPLED, + trace_state=trace_state, ) ) as context: sampler = sampling.ParentBased( diff --git a/propagator/opentelemetry-propagator-b3/src/opentelemetry/propagators/b3/__init__.py b/propagator/opentelemetry-propagator-b3/src/opentelemetry/propagators/b3/__init__.py index 2d50ea88dc5..6977bc32c64 100644 --- a/propagator/opentelemetry-propagator-b3/src/opentelemetry/propagators/b3/__init__.py +++ b/propagator/opentelemetry-propagator-b3/src/opentelemetry/propagators/b3/__init__.py @@ -139,7 +139,9 @@ def inject( sampled = (trace.TraceFlags.SAMPLED & span_context.trace_flags) != 0 setter.set( - carrier, self.TRACE_ID_KEY, format_trace_id(span_context.trace_id), + carrier, + self.TRACE_ID_KEY, + format_trace_id(span_context.trace_id), ) setter.set( carrier, self.SPAN_ID_KEY, format_span_id(span_context.span_id) diff --git a/propagator/opentelemetry-propagator-jaeger/tests/test_jaeger_propagator.py b/propagator/opentelemetry-propagator-jaeger/tests/test_jaeger_propagator.py index 003bbfeb49d..12a0a028ddf 100644 --- a/propagator/opentelemetry-propagator-jaeger/tests/test_jaeger_propagator.py +++ b/propagator/opentelemetry-propagator-jaeger/tests/test_jaeger_propagator.py @@ -62,8 +62,10 @@ def setUpClass(cls): cls.trace_id = generator.generate_trace_id() cls.span_id = generator.generate_span_id() cls.parent_span_id = generator.generate_span_id() - cls.serialized_uber_trace_id = jaeger._format_uber_trace_id( # pylint: disable=protected-access - cls.trace_id, cls.span_id, cls.parent_span_id, 11 + cls.serialized_uber_trace_id = ( + jaeger._format_uber_trace_id( # pylint: disable=protected-access + cls.trace_id, cls.span_id, cls.parent_span_id, 11 + ) ) def test_extract_valid_span(self): @@ -113,8 +115,10 @@ def test_debug_flag_set(self): self.assertEqual(FORMAT.DEBUG_FLAG, debug_flag_value) def test_sample_debug_flags_unset(self): - uber_trace_id = jaeger._format_uber_trace_id( # pylint: disable=protected-access - self.trace_id, self.span_id, self.parent_span_id, 0 + uber_trace_id = ( + jaeger._format_uber_trace_id( # pylint: disable=protected-access + self.trace_id, self.span_id, self.parent_span_id, 0 + ) ) old_carrier = {FORMAT.TRACE_ID_KEY: uber_trace_id} _, new_carrier = get_context_new_carrier(old_carrier) diff --git a/scripts/eachdist.py b/scripts/eachdist.py index 7a305a34e0f..3a9b2b3b9e6 100755 --- a/scripts/eachdist.py +++ b/scripts/eachdist.py @@ -229,7 +229,8 @@ def setup_instparser(instparser): ) releaseparser = subparsers.add_parser( - "release", help="Prepares release, used by maintainers and CI", + "release", + help="Prepares release, used by maintainers and CI", ) releaseparser.set_defaults(func=release_args) releaseparser.add_argument("--version", required=True) @@ -512,7 +513,11 @@ def lint_args(args): execute_args( parse_subargs( args, - ("exec", "python scripts/check_for_valid_readme.py {}", "--all",), + ( + "exec", + "python scripts/check_for_valid_readme.py {}", + "--all", + ), ) ) diff --git a/shim/opentelemetry-opentracing-shim/setup.py b/shim/opentelemetry-opentracing-shim/setup.py index b8a95207135..304a5e661e6 100644 --- a/shim/opentelemetry-opentracing-shim/setup.py +++ b/shim/opentelemetry-opentracing-shim/setup.py @@ -17,7 +17,12 @@ BASE_DIR = os.path.dirname(__file__) VERSION_FILENAME = os.path.join( - BASE_DIR, "src", "opentelemetry", "shim", "opentracing_shim", "version.py", + BASE_DIR, + "src", + "opentelemetry", + "shim", + "opentracing_shim", + "version.py", ) PACKAGE_INFO = {} with open(VERSION_FILENAME) as f: diff --git a/shim/opentelemetry-opentracing-shim/tests/test_shim.py b/shim/opentelemetry-opentracing-shim/tests/test_shim.py index a27d30de718..6feeedff061 100644 --- a/shim/opentelemetry-opentracing-shim/tests/test_shim.py +++ b/shim/opentelemetry-opentracing-shim/tests/test_shim.py @@ -623,7 +623,8 @@ def test_mixed_mode(self): ) as opentelemetry_span: self.assertIs( - span_shim.unwrap().context, opentelemetry_span.parent, + span_shim.unwrap().context, + opentelemetry_span.parent, ) with ( @@ -633,5 +634,6 @@ def test_mixed_mode(self): with self.shim.start_active_span("TestSpan17") as scope: self.assertIs( - scope.span.unwrap().parent, opentelemetry_span.context, + scope.span.unwrap().parent, + opentelemetry_span.context, ) diff --git a/shim/opentelemetry-opentracing-shim/tests/testbed/test_common_request_handler/test_asyncio.py b/shim/opentelemetry-opentracing-shim/tests/testbed/test_common_request_handler/test_asyncio.py index b0216dd7560..b4619b4ed80 100644 --- a/shim/opentelemetry-opentracing-shim/tests/testbed/test_common_request_handler/test_asyncio.py +++ b/shim/opentelemetry-opentracing-shim/tests/testbed/test_common_request_handler/test_asyncio.py @@ -111,7 +111,8 @@ async def do_task(): # Set ignore_active_span to False indicating that the # framework will do it for us. req_handler = RequestHandler( - self.tracer, ignore_active_span=False, + self.tracer, + ignore_active_span=False, ) client = Client(req_handler, self.loop) response = await client.send_task("correct_parent") From e183426165326d5d7cb751616546b07798e706a0 Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Fri, 16 Apr 2021 09:20:27 -0700 Subject: [PATCH 6/7] fix typo --- .../src/opentelemetry/exporter/otlp/proto/grpc/exporter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py index b76e41f9347..03b17cf2e42 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py @@ -201,7 +201,7 @@ def __init__( parsed_url = urlparse(endpoint) - if endpoint is None: + if insecure is None: if parsed_url.scheme == "https": insecure = False else: From 397a49971a86235182d6ff3b98351c21f4347b2b Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Fri, 16 Apr 2021 10:14:52 -0700 Subject: [PATCH 7/7] add test --- .../tests/test_otlp_trace_exporter.py | 47 +++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_trace_exporter.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_trace_exporter.py index cc6293f974d..5e0e9dd37b3 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_trace_exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_trace_exporter.py @@ -208,10 +208,8 @@ def test_env_variables(self, mock_exporter_mixin): def test_no_credentials_error( self, mock_ssl_channel, mock_secure, mock_stub ): - OTLPSpanExporter(endpoint="https://localhost:4317") + OTLPSpanExporter(insecure=False) self.assertTrue(mock_ssl_channel.called) - self.assertTrue(mock_secure.called) - self.assertTrue("localhost:4317" in mock_secure.call_args[0]) @patch.dict( "os.environ", @@ -236,6 +234,49 @@ def test_otlp_headers_from_env(self, mock_ssl_channel, mock_secure): exporter._headers, (("key3", "value3"), ("key4", "value4")) ) + # pylint: disable=no-self-use + @patch("opentelemetry.exporter.otlp.proto.grpc.exporter.insecure_channel") + @patch("opentelemetry.exporter.otlp.proto.grpc.exporter.secure_channel") + def test_otlp_exporter_endpoint(self, mock_secure, mock_insecure): + """Just OTEL_EXPORTER_OTLP_COMPRESSION should work""" + endpoints = [ + ( + "http://localhost:4317", + None, + mock_insecure, + ), + ( + "localhost:4317", + None, + mock_insecure, + ), + ( + "localhost:4317", + False, + mock_secure, + ), + ( + "https://localhost:4317", + None, + mock_secure, + ), + ( + "https://localhost:4317", + True, + mock_insecure, + ), + ] + for endpoint, insecure, mock_method in endpoints: + OTLPSpanExporter(endpoint=endpoint, insecure=insecure) + self.assertEqual( + 1, + mock_method.call_count, + "expected {} to be called for {} {}".format( + mock_method, endpoint, insecure + ), + ) + mock_method.reset_mock() + # pylint: disable=no-self-use @patch("opentelemetry.exporter.otlp.proto.grpc.exporter.insecure_channel") @patch.dict("os.environ", {OTEL_EXPORTER_OTLP_COMPRESSION: "gzip"})