Skip to content

Commit 6079f22

Browse files
authored
Merge branch 'main' into deprecate_events
2 parents 1c7c8a4 + 62da90e commit 6079f22

File tree

114 files changed

+4211
-1137
lines changed

Some content is hidden

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

114 files changed

+4211
-1137
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
repos:
22
- repo: https://github.com/astral-sh/ruff-pre-commit
33
# Ruff version.
4-
rev: v0.6.9
4+
rev: v0.14.1
55
hooks:
66
# Run the linter.
77
- id: ruff

CHANGELOG.md

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,72 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212

1313
## Unreleased
1414

15+
- docs: Added sqlcommenter example
16+
([#4734](https://github.com/open-telemetry/opentelemetry-python/pull/4734))
17+
- build: bump ruff to 0.14.1
18+
([#4782](https://github.com/open-telemetry/opentelemetry-python/pull/4782))
19+
- Add `opentelemetry-exporter-credential-provider-gcp` as an optional dependency to `opentelemetry-exporter-otlp-proto-grpc`
20+
and `opentelemetry-exporter-otlp-proto-http`
21+
([#4760](https://github.com/open-telemetry/opentelemetry-python/pull/4760))
22+
- semantic-conventions: Bump to 1.38.0
23+
([#4791](https://github.com/open-telemetry/opentelemetry-python/pull/4791))
24+
- [BREAKING] Remove LogData and extend SDK LogRecord to have instrumentation scope
25+
([#4676](https://github.com/open-telemetry/opentelemetry-python/pull/4676))
26+
- [BREAKING] Rename several classes from Log to LogRecord
27+
([#4647](https://github.com/open-telemetry/opentelemetry-python/pull/4647))
28+
29+
**Migration Guide:**
30+
31+
`LogData` has been removed. Users should update their code as follows:
32+
33+
- **For Log Exporters:** Change from `Sequence[LogData]` to `Sequence[ReadableLogRecord]`
34+
```python
35+
# Before
36+
from opentelemetry.sdk._logs import LogData
37+
def export(self, batch: Sequence[LogData]) -> LogRecordExportResult:
38+
...
39+
40+
# After
41+
from opentelemetry.sdk._logs import ReadableLogRecord
42+
def export(self, batch: Sequence[ReadableLogRecord]) -> LogRecordExportResult:
43+
...
44+
```
45+
46+
- **For Log Processors:** Use `ReadWriteLogRecord` for processing, `ReadableLogRecord` for exporting
47+
```python
48+
# Before
49+
from opentelemetry.sdk._logs import LogData
50+
def on_emit(self, log_data: LogData):
51+
...
52+
53+
# After
54+
from opentelemetry.sdk._logs import ReadWriteLogRecord, ReadableLogRecord
55+
def on_emit(self, log_record: ReadWriteLogRecord):
56+
# Convert to ReadableLogRecord before exporting
57+
readable = ReadableLogRecord(
58+
log_record=log_record.log_record,
59+
resource=log_record.resource or Resource.create({}),
60+
instrumentation_scope=log_record.instrumentation_scope,
61+
limits=log_record.limits,
62+
)
63+
...
64+
```
65+
66+
- **Accessing log data:** Use the same attributes on `ReadableLogRecord`/`ReadWriteLogRecord`
67+
- `log_record.log_record` - The API LogRecord (contains body, severity, attributes, etc.)
68+
- `log_record.resource` - The Resource
69+
- `log_record.instrumentation_scope` - The InstrumentationScope (now included, was in LogData before)
70+
- `log_record.limits` - The LogRecordLimits
71+
- Mark the Events API/SDK as deprecated. The Logs API/SDK should be used instead, an event is now a `LogRecord` with the `event_name` field set
72+
([#4654](https://github.com/open-telemetry/opentelemetry-python/pull/4654)).
73+
74+
## Version 1.38.0/0.59b0 (2025-10-16)
75+
1576
- Add `rstcheck` to pre-commit to stop introducing invalid RST
1677
([#4755](https://github.com/open-telemetry/opentelemetry-python/pull/4755))
1778
- logs: extend Logger.emit to accept separated keyword arguments
1879
([#4737](https://github.com/open-telemetry/opentelemetry-python/pull/4737))
19-
- Mark the Events API/SDK as deprecated. The Logs API/SDK should be used instead. An event is now a `LogRecord` with the `event_name` field set
20-
([#4654](https://github.com/open-telemetry/opentelemetry-python/pull/4654)).
80+
2181

2282
## Version 1.37.0/0.58b0 (2025-09-11)
2383

CONTRIBUTING.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# Contributing to opentelemetry-python
2-
3-
The Python special interest group (SIG) meets weekly on Thursdays at 9AM PST. Check the [OpenTelemetry community calendar](https://calendar.google.com/calendar/embed?src=google.com_b79e3e90j7bbsa2n2p5an5lf60%40group.calendar.google.com) for specific dates and Zoom meeting links.
2+
The Python special interest group (SIG) meets weekly on Thursdays at 9AM PST. Check the [OpenTelemetry community calendar](https://groups.google.com/a/opentelemetry.io/g/calendar-python) for specific dates and Zoom meeting links.
43

54
See the [public meeting notes](https://docs.google.com/document/d/1CIMGoIOZ-c3-igzbd6_Pnxx1SjAkjwqoYSUWxPY8XIs/edit)
65
for a summary description of past meetings.
76

8-
See to the [community membership document](https://github.com/open-telemetry/community/blob/main/community-membership.md)
7+
See the [community membership document](https://github.com/open-telemetry/community/blob/main/community-membership.md)
98
on how to become a [**Member**](https://github.com/open-telemetry/community/blob/main/community-membership.md#member),
109
[**Approver**](https://github.com/open-telemetry/community/blob/main/community-membership.md#approver)
1110
and [**Maintainer**](https://github.com/open-telemetry/community/blob/main/community-membership.md#maintainer).
@@ -276,7 +275,7 @@ to your PR, can still happen.
276275

277276
Right now Github [does not allow](https://github.com/orgs/community/discussions/5634) PRs
278277
to be edited by maintainers if the corresponding repo fork exists in a Github organization.
279-
Please for this repo in a personal Github account instead.
278+
Please fork this repo in a personal Github account instead.
280279

281280
One of the maintainers will merge the PR once it is **ready to merge**.
282281

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ For more information about the maintainer role, see the [community repository](h
113113
- [Dylan Russell](https://github.com/dylanrussell), Google
114114
- [Emídio Neto](https://github.com/emdneto), PicPay
115115
- [Jeremy Voss](https://github.com/jeremydvoss), Microsoft
116+
- [Liudmila Molkova](https://github.com/lmolkova), Grafana Labs
116117
- [Owais Lone](https://github.com/owais), Splunk
117118
- [Pablo Collins](https://github.com/pmcollins), Splunk
118119
- [Shalev Roda](https://github.com/shalevr), Cisco
@@ -125,7 +126,7 @@ For more information about the approver role, see the [community repository](htt
125126

126127
- [Alex Boten](https://github.com/codeboten)
127128
- [Chris Kleinknecht](https://github.com/c24t)
128-
- [Diego Hurtado](https://github.com/ocelotl), Lightstep
129+
- [Diego Hurtado](https://github.com/ocelotl)
129130
- [Owais Lone](https://github.com/owais)
130131
- [Reiley Yang](https://github.com/reyang)
131132
- [Srikanth Chekuri](https://github.com/srikanthccv)

dev-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ psutil==5.9.6
1717
GitPython==3.1.41
1818
pre-commit==3.7.0; python_version >= '3.9'
1919
pre-commit==3.5.0; python_version < '3.9'
20-
ruff==0.6.9
20+
ruff==0.14.1

docs/conf.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
("py:class", "CarrierT"),
101101
("py:obj", "opentelemetry.propagators.textmap.CarrierT"),
102102
("py:obj", "Union"),
103+
("py:data", "typing.Union"),
103104
(
104105
"py:class",
105106
"opentelemetry.sdk.metrics._internal.instrument._Synchronous",
@@ -144,8 +145,11 @@
144145
"py:class",
145146
"opentelemetry.proto.collector.metrics.v1.metrics_service_pb2.ExportMetricsServiceRequest",
146147
),
147-
("py:class", "opentelemetry.sdk._logs._internal.export.LogExporter"),
148-
("py:class", "opentelemetry.sdk._logs._internal.export.LogExportResult"),
148+
("py:class", "opentelemetry.sdk._logs._internal.export.LogRecordExporter"),
149+
(
150+
"py:class",
151+
"opentelemetry.sdk._logs._internal.export.LogRecordExportResult",
152+
),
149153
(
150154
"py:class",
151155
"opentelemetry.proto.collector.logs.v1.logs_service_pb2.ExportLogsServiceRequest",

docs/examples/django/manage.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ def main():
3030
DjangoInstrumentor().instrument()
3131

3232
try:
33-
from django.core.management import execute_from_command_line
33+
from django.core.management import ( # noqa: PLC0415
34+
execute_from_command_line,
35+
)
3436
except ImportError as exc:
3537
raise ImportError(
3638
"Couldn't import Django. Are you sure it's installed and "

docs/examples/metrics/prometheus-grafana/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Prometheus Instrumentation
33

44
This shows how to use ``opentelemetry-exporter-prometheus`` to automatically generate Prometheus metrics.
55

6-
The source files of these examples are available :scm_web:`here <docs/examples/prometheus-grafana/>`.
6+
The source files of these examples are available :scm_web:`here <docs/examples/metrics/prometheus-grafana/>`.
77

88
Preparation
99
-----------
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
sqlcommenter
2+
============
3+
4+
This is an example of how to use OpenTelemetry Python instrumention with
5+
sqlcommenter to enrich database query statements with contextual information.
6+
For more information on sqlcommenter concepts, see:
7+
8+
* `Semantic Conventions - Database Spans <https://github.com/open-telemetry/semantic-conventions/blob/main/docs/database/database-spans.md#sql-commenter>`_
9+
* `sqlcommenter <https://google.github.io/sqlcommenter/>`_
10+
11+
The source files of this example are available `here <https://github.com/open-telemetry/opentelemetry-python/tree/main/docs/examples/sqlcommenter/>`_.
12+
This example uses Docker to manage a database server and OpenTelemetry collector.
13+
14+
Run MySQL server
15+
----------------
16+
17+
A running MySQL server with general logs enabled will store query statements with context resulting from the sqlcommenter feature enabled in this example.
18+
19+
.. code-block:: sh
20+
21+
cd books_database
22+
docker build -t books-db .
23+
docker run -d --name books-db -p 3366:3306 books-db
24+
cd ..
25+
26+
Check that the run is working and the general log is available:
27+
28+
.. code-block:: sh
29+
30+
docker exec -it books-db tail -f /var/log/general.log
31+
32+
Run OpenTelemetry Collector
33+
---------------------------
34+
35+
Running the OpenTelemetry collector will show the MySQL instrumentor's
36+
comment-in-span-attribute feature, which this example has also enabled.
37+
38+
.. code-block:: sh
39+
40+
docker run \
41+
-p 4317:4317 \
42+
-v $(pwd)/collector-config.yaml:/etc/otel/config.yaml \
43+
otel/opentelemetry-collector-contrib:latest
44+
45+
Run the sqlcommenter example
46+
----------------------------
47+
48+
Set up and activate a Python virtual environment. Install these
49+
dependencies of the sqlcommenter example:
50+
51+
.. code-block:: sh
52+
53+
pip install opentelemetry-sdk \
54+
opentelemetry-exporter-otlp-proto-grpc \
55+
opentelemetry-instrumentation-mysql \
56+
mysql-connector-python
57+
58+
Then, run this script, which instruments all mysql-connector calls with
59+
two sqlcommenter features opted in.
60+
61+
.. code-block:: sh
62+
63+
python instrumented_query.py
64+
65+
Note that OpenTelemetry instrumentation with sqlcommenter is also
66+
available for other Python database client drivers/object relation
67+
mappers (ORMs). See full list at `instrumentation`_.
68+
69+
.. _instrumentation: https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation
70+
71+
Check MySQL server general log and spans for sqlcomment
72+
-------------------------------------------------------
73+
74+
After running the query script, check the MySQL general log contents:
75+
76+
.. code-block:: sh
77+
78+
docker exec -it books-db tail -f /var/log/general.log
79+
80+
For each instrumented ``SELECT`` call, a query was made and logged with
81+
a sqlcomment appended. For example:
82+
83+
.. code::
84+
85+
2025-09-02T18:49:06.981980Z 186 Query SELECT * FROM authors WHERE id = 1 /*db_driver='mysql.connector%%3A9.4.0',dbapi_level='2.0',dbapi_threadsafety=1,driver_paramstyle='pyformat',mysql_client_version='9.4.0',traceparent='00-2c45248f2beefdd9688b0a94eb4ac9ee-4f3af9a825aae9b1-01'*/
86+
87+
In the running OpenTelemetry collector, you'll also see one span per
88+
``SELECT`` call. Each of those span's trace ID and span ID will
89+
correspond to a query log sqlcomment. With the comment-in-attribute
90+
feature enabled, the span's ``db.statement`` attribute will also contain
91+
the sqlcomment. For example:
92+
93+
.. code::
94+
95+
ScopeSpans #0
96+
ScopeSpans SchemaURL: https://opentelemetry.io/schemas/1.11.0
97+
InstrumentationScope opentelemetry.instrumentation.mysql 0.57b0
98+
Span #0
99+
Trace ID : 2c45248f2beefdd9688b0a94eb4ac9ee
100+
Parent ID :
101+
ID : 4f3af9a825aae9b1
102+
Name : SELECT
103+
Kind : Client
104+
Start time : 2025-09-02 18:49:06.982341 +0000 UTC
105+
End time : 2025-09-02 18:49:06.98463 +0000 UTC
106+
Status code : Unset
107+
Status message :
108+
Attributes:
109+
-> db.system: Str(mysql)
110+
-> db.name: Str(books)
111+
-> db.statement: Str(SELECT * FROM authors WHERE id = %s /*db_driver='mysql.connector%%3A9.4.0',dbapi_level='2.0',dbapi_threadsafety=1,driver_paramstyle='pyformat',mysql_client_version='9.4.0',traceparent='00-2c45248f2beefdd9688b0a94eb4ac9ee-4f3af9a825aae9b1-01'*/)
112+
-> db.user: Str(books)
113+
-> net.peer.name: Str(localhost)
114+
-> net.peer.port: Int(3366)
115+
116+
117+
References
118+
----------
119+
120+
* `OpenTelemetry Project <https://opentelemetry.io/>`_
121+
* `OpenTelemetry Collector <https://github.com/open-telemetry/opentelemetry-collector>`_
122+
* `OpenTelemetry MySQL instrumentation <https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-mysql>`_
123+
* `Semantic Conventions - Database Spans <https://github.com/open-telemetry/semantic-conventions/blob/main/docs/database/database-spans.md#sql-commenter>`_
124+
* `sqlcommenter <https://google.github.io/sqlcommenter/>`_
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM mysql:8.0
2+
3+
ENV MYSQL_ROOT_PASSWORD=root
4+
ENV MYSQL_DATABASE=books
5+
6+
ADD books.sql /docker-entrypoint-initdb.d/
7+
8+
RUN echo "CREATE USER IF NOT EXISTS 'books'@'%' IDENTIFIED WITH mysql_native_password BY 'books123';" > /docker-entrypoint-initdb.d/01-create-user.sql && \
9+
echo "GRANT ALL PRIVILEGES ON books.* TO 'books'@'%';" >> /docker-entrypoint-initdb.d/01-create-user.sql && \
10+
echo "FLUSH PRIVILEGES;" >> /docker-entrypoint-initdb.d/01-create-user.sql
11+
12+
# Prepare general logs
13+
RUN mkdir -p /var/log && \
14+
touch /var/log/general.log && \
15+
chown mysql:mysql /var/log/general.log
16+
17+
EXPOSE 3306
18+
19+
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
20+
CMD mysqladmin ping -p${MYSQL_ROOT_PASSWORD} || exit 1
21+
22+
# Start MySQL with general logging enabled and compatible authentication
23+
CMD ["mysqld", "--general-log=1", "--general-log-file=/var/log/general.log"]

0 commit comments

Comments
 (0)