Skip to content

Commit e98d2b3

Browse files
authored
Merge branch 'main' into sqlalchemy-connect
2 parents d7b70f9 + 3770e57 commit e98d2b3

File tree

55 files changed

+74
-92
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+74
-92
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ jobs:
102102
steps:
103103
- name: Checkout Contrib Repo @ SHA - ${{ github.sha }}
104104
uses: actions/checkout@v2
105-
- name: Set up Python 3.9
105+
- name: Set up Python 3.10
106106
uses: actions/setup-python@v2
107107
with:
108-
python-version: 3.9
108+
python-version: "3.10"
109109
- name: Install tox
110110
run: pip install tox==3.27.1
111111
- name: Install libsnappy-dev

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
- `opentelemetry-instrumentation-celery` Record exceptions as events on the span.
13+
([#1573](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1573))
1214
- Add metric instrumentation for urllib
1315
([#1553](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1553))
1416
- `opentelemetry/sdk/extension/aws` Implement [`aws.ecs.*`](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/cloud_provider/aws/ecs.md) and [`aws.logs.*`](https://opentelemetry.io/docs/reference/specification/resource/semantic_conventions/cloud_provider/aws/logs/) resource attributes in the `AwsEcsResourceDetector` detector when the ECS Metadata v4 is available
@@ -19,6 +21,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1921
([#1613](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1613))
2022
- Fix aiohttp bug with unset `trace_configs`
2123
([#1592](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1592))
24+
- Fix aiohttp bug with unset `trace_configs`
25+
([#1592](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1592))
26+
- `opentelemetry-instrumentation-django` Allow explicit `excluded_urls` configuration through `instrument()`
27+
([#1618](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1618))
2228

2329
### Fixed
2430

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,15 @@ Meeting notes are available as a public [Google doc](https://docs.google.com/doc
9595
Approvers ([@open-telemetry/python-approvers](https://github.com/orgs/open-telemetry/teams/python-approvers)):
9696

9797
- [Aaron Abbott](https://github.com/aabmass), Google
98-
- [Nathaniel Ruiz Nowell](https://github.com/NathanielRN), AWS
99-
- [Owais Lone](https://github.com/owais), Splunk
10098
- [Sanket Mehta](https://github.com/sanketmehta28), Cisco
101-
- [Ashutosh Goel](https://github.com/ashu658), Cisco
99+
- [Shalev Roda](https://github.com/shalevr), Cisco
102100

103101
Emeritus Approvers:
104102

105103
- [Hector Hernandez](https://github.com/hectorhdzg), Microsoft
106104
- [Yusuke Tsutsumi](https://github.com/toumorokoshi), Google
105+
- [Nathaniel Ruiz Nowell](https://github.com/NathanielRN), AWS
106+
- [Ashutosh Goel](https://github.com/ashu658), Cisco
107107

108108
*Find more about the approver role in [community repository](https://github.com/open-telemetry/community/blob/main/community-membership.md#approver).*
109109

@@ -116,6 +116,7 @@ Maintainers ([@open-telemetry/python-maintainers](https://github.com/orgs/open-t
116116
Emeritus Maintainers:
117117

118118
- [Alex Boten](https://github.com/codeboten), Lightstep
119+
- [Owais Lone](https://github.com/owais), Splunk
119120

120121
*Find more about the maintainer role in [community repository](https://github.com/open-telemetry/community/blob/main/community-membership.md#maintainer).*
121122

exporter/opentelemetry-exporter-prometheus-remote-write/example/sampleapp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
# Callback to gather cpu usage
4848
def get_cpu_usage_callback(observer):
49-
for (number, percent) in enumerate(psutil.cpu_percent(percpu=True)):
49+
for number, percent in enumerate(psutil.cpu_percent(percpu=True)):
5050
labels = {"cpu_number": str(number)}
5151
yield Observation(percent, labels)
5252

exporter/opentelemetry-exporter-prometheus-remote-write/src/opentelemetry/exporter/prometheus_remote_write/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,6 @@ def _sanitize_string(string: str, type_: str) -> str:
300300
return sanitized
301301

302302
def _parse_histogram_data_point(self, data_point, name):
303-
304303
sample_attr_pairs = []
305304

306305
base_attrs = list(data_point.attributes.items())
@@ -341,7 +340,6 @@ def handle_bucket(value, bound=None, name_override=None):
341340
return sample_attr_pairs
342341

343342
def _parse_data_point(self, data_point, name=None):
344-
345343
attrs = tuple(data_point.attributes.items()) + (
346344
("__name__", self._sanitize_string(name, "name")),
347345
)

exporter/opentelemetry-exporter-prometheus-remote-write/src/opentelemetry/exporter/prometheus_remote_write/gen/remote_pb2.py

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exporter/opentelemetry-exporter-prometheus-remote-write/src/opentelemetry/exporter/prometheus_remote_write/gen/types_pb2.py

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exporter/opentelemetry-exporter-prometheus-remote-write/tests/test_prometheus_remote_write_exporter.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ def test_regex_invalid(prom_rw):
5656

5757

5858
def test_parse_data_point(prom_rw):
59-
6059
attrs = {"Foo": "Bar", "Baz": 42}
6160
timestamp = 1641946016139533244
6261
value = 242.42

instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/aiopg_integration.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ def get_traced_cursor_proxy(cursor, db_api_integration, *args, **kwargs):
127127

128128
# pylint: disable=abstract-method
129129
class AsyncCursorTracerProxy(AsyncProxyObject):
130-
131130
# pylint: disable=unused-argument
132131
def __init__(self, cursor, *args, **kwargs):
133132
super().__init__(cursor)

instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,8 @@ def collect_request_attributes(scope):
334334

335335
def collect_custom_request_headers_attributes(scope):
336336
"""returns custom HTTP request headers to be added into SERVER span as span attributes
337-
Refer specification https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#http-request-and-response-headers"""
337+
Refer specification https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#http-request-and-response-headers
338+
"""
338339

339340
sanitize = SanitizeValue(
340341
get_custom_headers(
@@ -359,7 +360,8 @@ def collect_custom_request_headers_attributes(scope):
359360

360361
def collect_custom_response_headers_attributes(message):
361362
"""returns custom HTTP response headers to be added into SERVER span as span attributes
362-
Refer specification https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#http-request-and-response-headers"""
363+
Refer specification https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#http-request-and-response-headers
364+
"""
363365

364366
sanitize = SanitizeValue(
365367
get_custom_headers(

instrumentation/opentelemetry-instrumentation-asyncpg/src/opentelemetry/instrumentation/asyncpg/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ def _uninstrument(self, **__):
131131
unwrap(asyncpg.Connection, method)
132132

133133
async def _do_execute(self, func, instance, args, kwargs):
134-
135134
exception = None
136135
params = getattr(instance, "_params", {})
137136
name = args[0] if args[0] else params.get("database", "postgresql")

instrumentation/opentelemetry-instrumentation-aws-lambda/src/opentelemetry/instrumentation/aws_lambda/__init__.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,7 @@ def custom_event_context_extractor(lambda_event):
8181
from opentelemetry.instrumentation.aws_lambda.version import __version__
8282
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
8383
from opentelemetry.instrumentation.utils import unwrap
84-
from opentelemetry.metrics import (
85-
MeterProvider,
86-
get_meter_provider,
87-
)
84+
from opentelemetry.metrics import MeterProvider, get_meter_provider
8885
from opentelemetry.propagate import get_global_textmap
8986
from opentelemetry.propagators.aws.aws_xray_propagator import (
9087
TRACE_HEADER_KEY,
@@ -282,7 +279,7 @@ def _instrument(
282279
disable_aws_context_propagation: bool = False,
283280
meter_provider: MeterProvider = None,
284281
):
285-
def _instrumented_lambda_handler_call(
282+
def _instrumented_lambda_handler_call( # noqa pylint: disable=too-many-branches
286283
call_wrapped, instance, args, kwargs
287284
):
288285
orig_handler_name = ".".join(
@@ -366,23 +363,21 @@ def _instrumented_lambda_handler_call(
366363
# NOTE: `force_flush` before function quit in case of Lambda freeze.
367364
_tracer_provider.force_flush(flush_timeout)
368365
except Exception: # pylint: disable=broad-except
369-
logger.exception(
370-
f"TracerProvider failed to flush traces"
371-
)
366+
logger.exception("TracerProvider failed to flush traces")
372367
else:
373-
logger.warning("TracerProvider was missing `force_flush` method. This is necessary in case of a Lambda freeze and would exist in the OTel SDK implementation.")
368+
logger.warning(
369+
"TracerProvider was missing `force_flush` method. This is necessary in case of a Lambda freeze and would exist in the OTel SDK implementation."
370+
)
374371

375372
_meter_provider = meter_provider or get_meter_provider()
376373
if hasattr(_meter_provider, "force_flush"):
377-
rem = flush_timeout - (time.time()-now)*1000
374+
rem = flush_timeout - (time.time() - now) * 1000
378375
if rem > 0:
379376
try:
380377
# NOTE: `force_flush` before function quit in case of Lambda freeze.
381378
_meter_provider.force_flush(rem)
382379
except Exception: # pylint: disable=broad-except
383-
logger.exception(
384-
f"MeterProvider failed to flush metrics"
385-
)
380+
logger.exception("MeterProvider failed to flush metrics")
386381
else:
387382
logger.warning(
388383
"MeterProvider was missing `force_flush` method. This is necessary in case of a Lambda freeze and would exist in the OTel SDK implementation."

instrumentation/opentelemetry-instrumentation-aws-lambda/tests/test_aws_lambda_instrumentation_manual.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,6 @@ def custom_event_context_extractor(lambda_event):
302302
test_env_patch.stop()
303303

304304
def test_lambda_no_error_with_invalid_flush_timeout(self):
305-
306305
test_env_patch = mock.patch.dict(
307306
"os.environ",
308307
{

instrumentation/opentelemetry-instrumentation-boto/src/opentelemetry/instrumentation/boto/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ def _common_request( # pylint: disable=too-many-locals
119119
args,
120120
kwargs,
121121
):
122-
123122
endpoint_name = getattr(instance, "host").split(".")[0]
124123

125124
with self._tracer.start_as_current_span(
@@ -166,7 +165,6 @@ def _common_request( # pylint: disable=too-many-locals
166165
return result
167166

168167
def _patched_query_request(self, original_func, instance, args, kwargs):
169-
170168
return self._common_request(
171169
("operation_name", "params", "path", "verb"),
172170
["operation_name", "params", "path"],

instrumentation/opentelemetry-instrumentation-boto/tests/test_boto_instrumentation.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ def test_s3_put(self):
187187

188188
@mock_lambda_deprecated
189189
def test_unpatch(self):
190-
191190
lamb = boto.awslambda.connect_to_region("us-east-2")
192191

193192
BotoInstrumentor().uninstrument()

instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ def _trace_failure(*args, **kwargs):
250250

251251
if ex is not None:
252252
status_kwargs["description"] = str(ex)
253+
span.record_exception(ex)
253254
span.set_status(Status(**status_kwargs))
254255

255256
@staticmethod

instrumentation/opentelemetry-instrumentation-confluent-kafka/src/opentelemetry/instrumentation/confluent_kafka/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ def instrument_consumer(consumer: Consumer, tracer_provider=None)
120120

121121

122122
class AutoInstrumentedProducer(Producer):
123-
124123
# This method is deliberately implemented in order to allow wrapt to wrap this function
125124
def produce(
126125
self, topic, value=None, *args, **kwargs

instrumentation/opentelemetry-instrumentation-confluent-kafka/src/opentelemetry/instrumentation/confluent_kafka/utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ def _enrich_span(
7373
offset: Optional[int] = None,
7474
operation: Optional[MessagingOperationValues] = None,
7575
):
76-
7776
if not span.is_recording():
7877
return
7978

instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,6 @@ def get_traced_cursor_proxy(cursor, db_api_integration, *args, **kwargs):
471471

472472
# pylint: disable=abstract-method
473473
class TracedCursorProxy(wrapt.ObjectProxy):
474-
475474
# pylint: disable=unused-argument
476475
def __init__(self, cursor, *args, **kwargs):
477476
wrapt.ObjectProxy.__init__(self, cursor)

instrumentation/opentelemetry-instrumentation-dbapi/tests/test_dbapi_integration.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ def test_executemany(self):
236236
)
237237

238238
def test_executemany_comment(self):
239-
240239
connect_module = mock.MagicMock()
241240
connect_module.__version__ = mock.MagicMock()
242241
connect_module.__libpq_version__ = 123
@@ -262,7 +261,6 @@ def test_executemany_comment(self):
262261
)
263262

264263
def test_executemany_flask_integration_comment(self):
265-
266264
connect_module = mock.MagicMock()
267265
connect_module.__version__ = mock.MagicMock()
268266
connect_module.__libpq_version__ = 123

instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,11 @@ def response_hook(span, request, response):
255255
from opentelemetry.metrics import get_meter
256256
from opentelemetry.semconv.metrics import MetricInstruments
257257
from opentelemetry.trace import get_tracer
258+
from opentelemetry.util.http import get_excluded_urls, parse_excluded_urls
258259

259260
DJANGO_2_0 = django_version >= (2, 0)
260261

262+
_excluded_urls_from_env = get_excluded_urls("DJANGO")
261263
_logger = getLogger(__name__)
262264

263265

@@ -286,14 +288,14 @@ def instrumentation_dependencies(self) -> Collection[str]:
286288
return _instruments
287289

288290
def _instrument(self, **kwargs):
289-
290291
# FIXME this is probably a pattern that will show up in the rest of the
291292
# ext. Find a better way of implementing this.
292293
if environ.get(OTEL_PYTHON_DJANGO_INSTRUMENT) == "False":
293294
return
294295

295296
tracer_provider = kwargs.get("tracer_provider")
296297
meter_provider = kwargs.get("meter_provider")
298+
_excluded_urls = kwargs.get("excluded_urls")
297299
tracer = get_tracer(
298300
__name__,
299301
__version__,
@@ -302,6 +304,11 @@ def _instrument(self, **kwargs):
302304
meter = get_meter(__name__, __version__, meter_provider=meter_provider)
303305
_DjangoMiddleware._tracer = tracer
304306
_DjangoMiddleware._meter = meter
307+
_DjangoMiddleware._excluded_urls = (
308+
_excluded_urls_from_env
309+
if _excluded_urls is None
310+
else parse_excluded_urls(_excluded_urls)
311+
)
305312
_DjangoMiddleware._otel_request_hook = kwargs.pop("request_hook", None)
306313
_DjangoMiddleware._otel_response_hook = kwargs.pop(
307314
"response_hook", None

instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
_django_instrumentor = DjangoInstrumentor()
9292

9393

94+
# pylint: disable=too-many-public-methods
9495
class TestMiddleware(WsgiTestBase):
9596
@classmethod
9697
def setUpClass(cls):
@@ -285,6 +286,18 @@ def test_exclude_lists(self):
285286
span_list = self.memory_exporter.get_finished_spans()
286287
self.assertEqual(len(span_list), 1)
287288

289+
def test_exclude_lists_through_instrument(self):
290+
_django_instrumentor.uninstrument()
291+
_django_instrumentor.instrument(excluded_urls="excluded_explicit")
292+
client = Client()
293+
client.get("/excluded_explicit")
294+
span_list = self.memory_exporter.get_finished_spans()
295+
self.assertEqual(len(span_list), 0)
296+
297+
client.get("/excluded_arg/123")
298+
span_list = self.memory_exporter.get_finished_spans()
299+
self.assertEqual(len(span_list), 1)
300+
288301
def test_span_name(self):
289302
# test no query_string
290303
Client().get("/span_name/1234/")

instrumentation/opentelemetry-instrumentation-elasticsearch/src/opentelemetry/instrumentation/elasticsearch/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ def wrapper(wrapped, _, args, kwargs):
201201
op_name,
202202
kind=SpanKind.CLIENT,
203203
) as span:
204-
205204
if callable(request_hook):
206205
request_hook(span, method, url, kwargs)
207206

instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,6 @@ def test_request_hook(self, request_mock):
323323
request_hook_kwargs_attribute = "request_hook.kwargs"
324324

325325
def request_hook(span, method, url, kwargs):
326-
327326
attributes = {
328327
request_hook_method_attribute: method,
329328
request_hook_url_attribute: url,

instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,6 @@ def _teardown_request(exc):
456456

457457

458458
class _InstrumentedFlask(flask.Flask):
459-
460459
_excluded_urls = None
461460
_tracer_provider = None
462461
_request_hook = None

instrumentation/opentelemetry-instrumentation-flask/tests/test_sqlcommenter.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ def tearDown(self):
3636
FlaskInstrumentor().uninstrument()
3737

3838
def test_sqlcommenter_enabled_default(self):
39-
4039
self.app = flask.Flask(__name__)
4140
self.app.route("/sqlcommenter")(self._sqlcommenter_endpoint)
4241
client = Client(self.app, Response)

instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/_server.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ def _set_remote_context(self, servicer_context):
221221
def _start_span(
222222
self, handler_call_details, context, set_status_on_exception=False
223223
):
224-
225224
# standard attributes
226225
attributes = {
227226
SpanAttributes.RPC_SYSTEM: "grpc",
@@ -283,7 +282,6 @@ def intercept_service(self, continuation, handler_call_details):
283282

284283
def telemetry_wrapper(behavior, request_streaming, response_streaming):
285284
def telemetry_interceptor(request_or_iterator, context):
286-
287285
# handle streaming responses specially
288286
if response_streaming:
289287
return self._intercept_server_stream(
@@ -327,7 +325,6 @@ def telemetry_interceptor(request_or_iterator, context):
327325
def _intercept_server_stream(
328326
self, behavior, handler_call_details, request_or_iterator, context
329327
):
330-
331328
with self._set_remote_context(context):
332329
with self._start_span(
333330
handler_call_details, context, set_status_on_exception=False

0 commit comments

Comments
 (0)