Skip to content

Commit dd27b22

Browse files
authored
Merge branch 'main' into 3220-requests
2 parents ff8df88 + 2c0033f commit dd27b22

File tree

13 files changed

+804
-265
lines changed

13 files changed

+804
-265
lines changed

CHANGELOG.md

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

1616
- `opentelemetry-instrumentation-requests` Support explicit_bucket_boundaries_advisory in duration metrics
1717
([#3464](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3464))
18+
- `opentelemetry-instrumentation-redis` Add support for redis client-specific instrumentation.
19+
([#3143](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3143))
1820

1921
### Fixed
2022

@@ -34,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3436
- `opentelemetry-instrumentation-botocore` Capture server attributes for botocore API calls
3537
([#3448](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3448))
3638

39+
3740
## Version 1.32.0/0.53b0 (2025-04-10)
3841

3942
### Added

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
"https://opentelemetry-python.readthedocs.io/en/latest/",
123123
None,
124124
),
125+
"redis": ("https://redis-py.readthedocs.io/en/latest/", None),
125126
}
126127

127128
# http://www.sphinx-doc.org/en/master/config.html#confval-nitpicky
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
OpenTelemetry Redis Instrumentation
2-
===================================
1+
.. include:: ../../../instrumentation/opentelemetry-instrumentation-redis/README.rst
2+
:end-before: References
3+
4+
Usage
5+
-----
36

47
.. automodule:: opentelemetry.instrumentation.redis
58
:members:
69
:undoc-members:
7-
:show-inheritance:
10+
:show-inheritance:

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

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,35 @@
2020
2121
.. code:: python
2222
23+
import asyncio
2324
from opentelemetry.instrumentation.aiokafka import AIOKafkaInstrumentor
2425
from aiokafka import AIOKafkaProducer, AIOKafkaConsumer
2526
2627
# Instrument kafka
2728
AIOKafkaInstrumentor().instrument()
2829
2930
# report a span of type producer with the default settings
30-
producer = AIOKafkaProducer(bootstrap_servers=['localhost:9092'])
31-
await producer.send('my-topic', b'raw_bytes')
31+
async def produce():
32+
producer = AIOKafkaProducer(bootstrap_servers=['localhost:9092'])
33+
await producer.start()
34+
try:
35+
await producer.send_and_wait('my-topic', b'raw_bytes')
36+
finally:
37+
await producer.stop()
3238
3339
# report a span of type consumer with the default settings
34-
consumer = AIOKafkaConsumer('my-topic', group_id='my-group', bootstrap_servers=['localhost:9092'])
35-
async for message in consumer:
36-
# process message
40+
async def consume():
41+
consumer = AIOKafkaConsumer('my-topic', group_id='my-group', bootstrap_servers=['localhost:9092'])
42+
await consumer.start()
43+
try:
44+
async for message in consumer:
45+
# process message
46+
print(message)
47+
finally:
48+
await consumer.stop()
49+
50+
asyncio.run(produce())
51+
asyncio.run(consume())
3752
3853
The _instrument() method accepts the following keyword args:
3954
tracer_provider (TracerProvider) - an optional tracer provider
@@ -47,12 +62,14 @@ def async_consume_hook(span: Span, record: kafka.record.ABCRecord, args, kwargs)
4762
4863
.. code:: python
4964
50-
from opentelemetry.instrumentation.kafka import AIOKafkaInstrumentor
65+
import asyncio
66+
from opentelemetry.instrumentation.aiokafka import AIOKafkaInstrumentor
5167
from aiokafka import AIOKafkaProducer, AIOKafkaConsumer
5268
5369
async def async_produce_hook(span, args, kwargs):
5470
if span and span.is_recording():
5571
span.set_attribute("custom_user_attribute_from_async_response_hook", "some-value")
72+
5673
async def async_consume_hook(span, record, args, kwargs):
5774
if span and span.is_recording():
5875
span.set_attribute("custom_user_attribute_from_consume_hook", "some-value")
@@ -62,8 +79,15 @@ async def async_consume_hook(span, record, args, kwargs):
6279
6380
# Using kafka as normal now will automatically generate spans,
6481
# including user custom attributes added from the hooks
65-
producer = AIOKafkaProducer(bootstrap_servers=['localhost:9092'])
66-
await producer.send('my-topic', b'raw_bytes')
82+
async def produce():
83+
producer = AIOKafkaProducer(bootstrap_servers=['localhost:9092'])
84+
await producer.start()
85+
try:
86+
await producer.send_and_wait('my-topic', b'raw_bytes')
87+
finally:
88+
await producer.stop()
89+
90+
asyncio.run(produce())
6791
6892
API
6993
___

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

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,40 +23,53 @@
2323
2424
.. code-block:: python
2525
26+
import asyncio
2627
import aiopg
2728
from opentelemetry.instrumentation.aiopg import AiopgInstrumentor
2829
# Call instrument() to wrap all database connections
2930
AiopgInstrumentor().instrument()
3031
31-
cnx = await aiopg.connect(database='Database')
32-
cursor = await cnx.cursor()
33-
await cursor.execute("CREATE TABLE IF NOT EXISTS test (testField INTEGER)")
34-
await cursor.execute("INSERT INTO test (testField) VALUES (123)")
35-
cursor.close()
36-
cnx.close()
32+
dsn = 'user=user password=password host=127.0.0.1'
3733
38-
pool = await aiopg.create_pool(database='Database')
34+
async def connect():
35+
cnx = await aiopg.connect(dsn)
36+
cursor = await cnx.cursor()
37+
await cursor.execute("CREATE TABLE IF NOT EXISTS test (testField INTEGER)")
38+
await cursor.execute("INSERT INTO test (testField) VALUES (123)")
39+
cursor.close()
40+
cnx.close()
3941
40-
cnx = await pool.acquire()
41-
cursor = await cnx.cursor()
42-
await cursor.execute("CREATE TABLE IF NOT EXISTS test (testField INTEGER)")
43-
await cursor.execute("INSERT INTO test (testField) VALUES (123)")
44-
cursor.close()
45-
cnx.close()
42+
async def create_pool():
43+
pool = await aiopg.create_pool(dsn)
44+
cnx = await pool.acquire()
45+
cursor = await cnx.cursor()
46+
await cursor.execute("CREATE TABLE IF NOT EXISTS test (testField INTEGER)")
47+
await cursor.execute("INSERT INTO test (testField) VALUES (123)")
48+
cursor.close()
49+
cnx.close()
50+
51+
asyncio.run(connect())
52+
asyncio.run(create_pool())
4653
4754
.. code-block:: python
4855
56+
import asyncio
4957
import aiopg
5058
from opentelemetry.instrumentation.aiopg import AiopgInstrumentor
5159
60+
dsn = 'user=user password=password host=127.0.0.1'
61+
5262
# Alternatively, use instrument_connection for an individual connection
53-
cnx = await aiopg.connect(database='Database')
54-
instrumented_cnx = AiopgInstrumentor().instrument_connection(cnx)
55-
cursor = await instrumented_cnx.cursor()
56-
await cursor.execute("CREATE TABLE IF NOT EXISTS test (testField INTEGER)")
57-
await cursor.execute("INSERT INTO test (testField) VALUES (123)")
58-
cursor.close()
59-
instrumented_cnx.close()
63+
async def go():
64+
cnx = await aiopg.connect(dsn)
65+
instrumented_cnx = AiopgInstrumentor().instrument_connection(cnx)
66+
cursor = await instrumented_cnx.cursor()
67+
await cursor.execute("CREATE TABLE IF NOT EXISTS test (testField INTEGER)")
68+
await cursor.execute("INSERT INTO test (testField) VALUES (123)")
69+
cursor.close()
70+
instrumented_cnx.close()
71+
72+
asyncio.run(go())
6073
6174
API
6275
---

instrumentation/opentelemetry-instrumentation-httpx/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Instrumenting single clients
4848
****************************
4949

5050
If you only want to instrument requests for specific client instances, you can
51-
use the `instrument_client` method.
51+
use the `HTTPXClientInstrumentor.instrument_client` method.
5252

5353

5454
.. code-block:: python

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
import MySQLdb
2727
from opentelemetry.instrumentation.mysqlclient import MySQLClientInstrumentor
2828
29-
3029
MySQLClientInstrumentor().instrument()
3130
3231
cnx = MySQLdb.connect(database="MySQL_Database")
3332
cursor = cnx.cursor()
34-
cursor.execute("INSERT INTO test (testField) VALUES (123)"
33+
cursor.execute("CREATE TABLE IF NOT EXISTS test (testField INTEGER)")
34+
cursor.execute("INSERT INTO test (testField) VALUES (123)")
3535
cnx.commit()
3636
cursor.close()
3737
cnx.close()
@@ -52,7 +52,7 @@
5252
cnx = MySQLdb.connect(database="MySQL_Database")
5353
cursor = cnx.cursor()
5454
cursor.execute("CREATE TABLE IF NOT EXISTS test (testField INTEGER)")
55-
cursor.execute("INSERT INTO test (testField) VALUES (123)"
55+
cursor.execute("INSERT INTO test (testField) VALUES (123)")
5656
cnx.commit()
5757
cursor.close()
5858
cnx.close()
@@ -75,7 +75,7 @@
7575
)
7676
cursor = instrumented_cnx.cursor()
7777
cursor.execute("CREATE TABLE IF NOT EXISTS test (testField INTEGER)")
78-
cursor.execute("INSERT INTO test (testField) VALUES (123)"
78+
cursor.execute("INSERT INTO test (testField) VALUES (123)")
7979
instrumented_cnx.commit()
8080
cursor.close()
8181
instrumented_cnx.close()

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
3131
cnx = pymssql.connect(database="MSSQL_Database")
3232
cursor = cnx.cursor()
33-
cursor.execute("INSERT INTO test (testField) VALUES (123)"
33+
cursor.execute("CREATE TABLE IF NOT EXISTS test (testField INTEGER)")
34+
cursor.execute("INSERT INTO test (testField) VALUES (123)")
3435
cnx.commit()
3536
cursor.close()
3637
cnx.close()
@@ -44,7 +45,8 @@
4445
cnx = pymssql.connect(database="MSSQL_Database")
4546
instrumented_cnx = PyMSSQLInstrumentor().instrument_connection(cnx)
4647
cursor = instrumented_cnx.cursor()
47-
cursor.execute("INSERT INTO test (testField) VALUES (123)"
48+
cursor.execute("CREATE TABLE IF NOT EXISTS test (testField INTEGER)")
49+
cursor.execute("INSERT INTO test (testField) VALUES (123)")
4850
instrumented_cnx.commit()
4951
cursor.close()
5052
instrumented_cnx.close()

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@
3131
3232
cnx = pymysql.connect(database="MySQL_Database")
3333
cursor = cnx.cursor()
34-
cursor.execute("INSERT INTO test (testField) VALUES (123)"
34+
cursor.execute("CREATE TABLE IF NOT EXISTS test (testField INTEGER)")
35+
cursor.execute("INSERT INTO test (testField) VALUES (123)")
3536
cnx.commit()
3637
cursor.close()
3738
cnx.close()
3839
39-
4040
.. code:: python
4141
4242
import pymysql
@@ -53,7 +53,8 @@
5353
}
5454
)
5555
cursor = instrumented_cnx.cursor()
56-
cursor.execute("INSERT INTO test (testField) VALUES (123)"
56+
cursor.execute("CREATE TABLE IF NOT EXISTS test (testField INTEGER)")
57+
cursor.execute("INSERT INTO test (testField) VALUES (123)")
5758
instrumented_cnx.commit()
5859
cursor.close()
5960
instrumented_cnx.close()
@@ -75,12 +76,12 @@
7576
7677
cnx = pymysql.connect(database="MySQL_Database")
7778
cursor = cnx.cursor()
78-
cursor.execute("INSERT INTO test (testField) VALUES (123)"
79+
cursor.execute("CREATE TABLE IF NOT EXISTS test (testField INTEGER)")
80+
cursor.execute("INSERT INTO test (testField) VALUES (123)")
7981
cnx.commit()
8082
cursor.close()
8183
cnx.close()
8284
83-
8485
For example,
8586
::
8687

0 commit comments

Comments
 (0)