Skip to content

Commit 708d137

Browse files
Merge branch 'main' into sqlcommenter-readthedocs
2 parents 6733bc1 + 5a15f57 commit 708d137

File tree

9 files changed

+84
-58
lines changed

9 files changed

+84
-58
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2323
([#3886](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3886))
2424
- `opentelemetry-instrumentation-mysql`, `opentelemetry-instrumentation-mysqlclient`, `opentelemetry-instrumentation-pymysql`: improve readthedocs for sqlcommenter configuration.
2525
([#3885](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3885))
26+
- `opentelemetry-instrumentation-django`: improve readthedocs for sqlcommenter configuration.
27+
([#3884](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3884))
2628

2729
### Fixed
2830

2931
- `opentelemetry-instrumentation-botocore`: Handle dict input in _decode_tool_use for Bedrock streaming
3032
([#3875](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3875))
33+
- `opentelemetry-instrumentation-aiohttp-client`, `opentelemetry-instrumentation-aiohttp-server`: Fix readme links and text
34+
([#3902](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3902))
3135
- `opentelemetry-instrumentation-aws-lambda`: Fix ImportError with slash-delimited handler paths
3236
([#3894](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3894))
37+
- `opentelemetry-exporter-richconsole`: Prevent deadlock when parent span is not part of the batch
38+
([#3900](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3900))
3339
- `opentelemetry-instrumentation-psycopg2`, `opentelemetry-instrumentation-psycopg`: improve readthedocs for sqlcommenter configuration.
3440
([#3882](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3882))
3541

exporter/opentelemetry-exporter-richconsole/src/opentelemetry/exporter/richconsole/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,17 @@ def spans_to_tree(spans: typing.Sequence[ReadableSpan]) -> Dict[str, Tree]:
173173
trees = {}
174174
parents = {}
175175
spans = list(spans)
176+
span_ids = {s.context.span_id for s in spans}
176177
while spans:
177178
for span in spans:
178-
if not span.parent:
179+
if not span.parent or span.parent.span_id not in span_ids:
179180
trace_id = opentelemetry.trace.format_trace_id(
180181
span.context.trace_id
181182
)
182-
trees[trace_id] = Tree(label=f"Trace {trace_id}")
183-
child = trees[trace_id].add(
183+
tree = trees.setdefault(
184+
trace_id, Tree(label=f"Trace {trace_id}")
185+
)
186+
child = tree.add(
184187
label=Text.from_markup(
185188
f"[blue][{_ns_to_time(span.start_time)}][/blue] [bold]{span.name}[/bold], span {opentelemetry.trace.format_span_id(span.context.span_id)}"
186189
)

exporter/opentelemetry-exporter-richconsole/test-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pluggy==1.5.0
99
py-cpuinfo==9.0.0
1010
Pygments==2.17.2
1111
pytest==7.4.4
12+
pytest-timeout==2.3.1
1213
rich==13.7.1
1314
tomli==2.0.1
1415
typing_extensions==4.12.2

exporter/opentelemetry-exporter-richconsole/tests/test_rich_exporter.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,15 @@ def test_multiple_traces(tracer_provider):
9696
parent_2.name in child.label
9797
for child in trees[traceid_1].children[0].children
9898
)
99+
100+
101+
@pytest.mark.timeout(30)
102+
def test_no_deadlock(tracer_provider):
103+
# non-regression test for https://github.com/open-telemetry/opentelemetry-python-contrib/issues/3254
104+
105+
tracer = tracer_provider.get_tracer(__name__)
106+
with tracer.start_as_current_span("parent"):
107+
with tracer.start_as_current_span("child") as child:
108+
pass
109+
110+
RichConsoleSpanExporter.spans_to_tree((child,))

instrumentation-genai/opentelemetry-instrumentation-google-genai/CHANGELOG.md

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

88
## Unreleased
99

10+
- Minor change to check LRU cache in Completion Hook before acquiring semaphore/thread ([#3907](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3907)).
11+
1012
## Version 0.4b0 (2025-10-16)
1113

1214
- Implement the new semantic convention changes made in https://github.com/open-telemetry/semantic-conventions/pull/2179.

instrumentation/opentelemetry-instrumentation-aiohttp-client/README.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Installation
1919
References
2020
----------
2121

22+
* `OpenTelemetry aiohttp client Instrumentation <https://opentelemetry-python-contrib.readthedocs.io/en/latest/instrumentation/aiohttp_client/aiohttp_client.html>`_
23+
* `aiohttp Tracing Reference <https://docs.aiohttp.org/en/stable/tracing_reference.html>`_
2224
* `OpenTelemetry Project <https://opentelemetry.io/>`_
23-
* `aiohttp client Tracing <https://docs.aiohttp.org/en/stable/tracing_reference.html>`_
2425
* `OpenTelemetry Python Examples <https://github.com/open-telemetry/opentelemetry-python/tree/main/docs/examples>`_

instrumentation/opentelemetry-instrumentation-aiohttp-server/README.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ OpenTelemetry aiohttp server Integration
33

44
|pypi|
55

6-
.. |pypi| image:: https://badge.fury.io/py/opentelemetry-instrumentation-aiohttp-client.svg
7-
:target: https://pypi.org/project/opentelemetry-instrumentation-aiohttp-client/
6+
.. |pypi| image:: https://badge.fury.io/py/opentelemetry-instrumentation-aiohttp-server.svg
7+
:target: https://pypi.org/project/opentelemetry-instrumentation-aiohttp-server/
88

99
This library allows tracing HTTP requests made by the
1010
`aiohttp server <https://docs.aiohttp.org/en/stable/server.html>`_ library.
@@ -19,6 +19,7 @@ Installation
1919
References
2020
----------
2121

22+
* `OpenTelemetry aiohttp server Instrumentation <https://opentelemetry-python-contrib.readthedocs.io/en/latest/instrumentation/aiohttp_server/aiohttp_server.html>`_
23+
* `aiohttp Tracing Reference <https://docs.aiohttp.org/en/stable/tracing_reference.html>`_
2224
* `OpenTelemetry Project <https://opentelemetry.io/>`_
23-
* `aiohttp client Tracing <https://docs.aiohttp.org/en/stable/tracing_reference.html>`_
2425
* `OpenTelemetry Python Examples <https://github.com/open-telemetry/opentelemetry-python/tree/main/docs/examples>`_

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

Lines changed: 48 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -170,64 +170,61 @@ def response_hook(span, request, response):
170170
Note:
171171
The environment variable names used to capture HTTP headers are still experimental, and thus are subject to change.
172172
173-
SQLCOMMENTER
174-
*****************************************
175-
You can optionally configure Django instrumentation to enable sqlcommenter which enriches
176-
the query with contextual information.
173+
SQLCommenter
174+
************
175+
You can optionally enable sqlcommenter which enriches the query with contextual
176+
information. Queries made after setting up trace integration with sqlcommenter
177+
enabled will have configurable key-value pairs appended to them, e.g.
178+
``Users().objects.all()`` will result in
179+
``"select * from auth_users; /*traceparent=00-01234567-abcd-01*/"``. This
180+
supports context propagation between database client and server when database log
181+
records are enabled. For more information, see:
182+
183+
* `Semantic Conventions - Database Spans <https://github.com/open-telemetry/semantic-conventions/blob/main/docs/database/database-spans.md#sql-commenter>`_
184+
* `sqlcommenter <https://google.github.io/sqlcommenter/>`_
177185
178186
.. code:: python
179187
180188
from opentelemetry.instrumentation.django import DjangoInstrumentor
181189
182190
DjangoInstrumentor().instrument(is_sql_commentor_enabled=True)
183191
184-
185-
For example,
186-
::
187-
188-
Invoking Users().objects.all() will lead to sql query "select * from auth_users" but when SQLCommenter is enabled
189-
the query will get appended with some configurable tags like "select * from auth_users /*metrics=value*/;"
190-
191-
192-
SQLCommenter Configurations
193-
***************************
194-
We can configure the tags to be appended to the sqlquery log by adding below variables to the settings.py
195-
196-
SQLCOMMENTER_WITH_FRAMEWORK = True(Default) or False
197-
198-
For example,
199-
::
200-
Enabling this flag will add django framework and it's version which is /*framework='django%3A2.2.3*/
201-
202-
SQLCOMMENTER_WITH_CONTROLLER = True(Default) or False
203-
204-
For example,
205-
::
206-
Enabling this flag will add controller name that handles the request /*controller='index'*/
207-
208-
SQLCOMMENTER_WITH_ROUTE = True(Default) or False
209-
210-
For example,
211-
::
212-
Enabling this flag will add url path that handles the request /*route='polls/'*/
213-
214-
SQLCOMMENTER_WITH_APP_NAME = True(Default) or False
215-
216-
For example,
217-
::
218-
Enabling this flag will add app name that handles the request /*app_name='polls'*/
219-
220-
SQLCOMMENTER_WITH_OPENTELEMETRY = True(Default) or False
221-
222-
For example,
223-
::
224-
Enabling this flag will add opentelemetry traceparent /*traceparent='00-fd720cffceba94bbf75940ff3caaf3cc-4fd1a2bdacf56388-01'*/
225-
226-
SQLCOMMENTER_WITH_DB_DRIVER = True(Default) or False
227-
228-
For example,
229-
::
230-
Enabling this flag will add name of the db driver /*db_driver='django.db.backends.postgresql'*/
192+
Warning:
193+
Duplicate sqlcomments may be appended to the sqlquery log if DjangoInstrumentor
194+
sqlcommenter is enabled in addition to sqlcommenter for an active instrumentation
195+
of a database driver or object-relational mapper (ORM) in the same database client
196+
stack. For example, if psycopg2 driver is used and Psycopg2Instrumentor has
197+
sqlcommenter enabled, then both DjangoInstrumentor and Psycopg2Instrumentor will
198+
append comments to the query statement.
199+
200+
SQLCommenter with commenter_options
201+
***********************************
202+
The key-value pairs appended to the query can be configured using
203+
variables in Django ``settings.py``. When sqlcommenter is enabled, all
204+
available KVs/tags are calculated by default, i.e. ``True`` for each. The
205+
``settings.py`` values support *opting out* of specific KVs.
206+
207+
Available settings.py commenter options
208+
#######################################
209+
210+
We can configure the tags to be appended to the sqlquery log by adding below variables to
211+
``settings.py``, e.g. ``SQLCOMMENTER_WITH_FRAMEWORK = False``
212+
213+
+-------------------------------------+-----------------------------------------------------------+---------------------------------------------------------------------------+
214+
| ``settings.py`` variable | Description | Example |
215+
+=====================================+===========================================================+===========================================================================+
216+
| ``SQLCOMMENTER_WITH_FRAMEWORK`` | Django framework name with version (URL encoded). | ``framework='django%%%%3A4.2.0'`` |
217+
+-------------------------------------+-----------------------------------------------------------+---------------------------------------------------------------------------+
218+
| ``SQLCOMMENTER_WITH_CONTROLLER`` | Django controller/view name that handles the request. | ``controller='index'`` |
219+
+-------------------------------------+-----------------------------------------------------------+---------------------------------------------------------------------------+
220+
| ``SQLCOMMENTER_WITH_ROUTE`` | URL path pattern that handles the request. | ``route='polls/'`` |
221+
+-------------------------------------+-----------------------------------------------------------+---------------------------------------------------------------------------+
222+
| ``SQLCOMMENTER_WITH_APP_NAME`` | Django app name that handles the request. | ``app_name='polls'`` |
223+
+-------------------------------------+-----------------------------------------------------------+---------------------------------------------------------------------------+
224+
| ``SQLCOMMENTER_WITH_OPENTELEMETRY`` | OpenTelemetry context as traceparent at time of query. | ``traceparent='00-fd720cffceba94bbf75940ff3caaf3cc-4fd1a2bdacf56388-01'`` |
225+
+-------------------------------------+-----------------------------------------------------------+---------------------------------------------------------------------------+
226+
| ``SQLCOMMENTER_WITH_DB_DRIVER`` | Database driver name used by Django. | ``db_driver='django.db.backends.postgresql'`` |
227+
+-------------------------------------+-----------------------------------------------------------+---------------------------------------------------------------------------+
231228
232229
API
233230
---

util/opentelemetry-util-genai/src/opentelemetry/util/genai/_upload/completion_hook.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ def done(future: Future[None]) -> None:
149149
path,
150150
contents_hashed_to_filename,
151151
), json_encodeable in upload_data.items():
152+
if contents_hashed_to_filename and path in self.lru_dict:
153+
self.lru_dict.move_to_end(path)
154+
continue
152155
# could not acquire, drop data
153156
if not self._semaphore.acquire(blocking=False): # pylint: disable=consider-using-with
154157
_logger.warning(

0 commit comments

Comments
 (0)