Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion initializer/lib_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ def patch_otlp_span_flags() -> None:
def encode_span(sdk_span: ReadableSpan) -> PB2Span:
encoded_span = original_encode_span(sdk_span)
# THE FIX: fold the W3C trace flags into Span.flags (PR #4761).
encoded_span.flags |= int(sdk_span.get_span_context().trace_flags)
span_context = sdk_span.get_span_context()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you explain this please?

@natyharary natyharary Jul 5, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ty gave a warning on that: get_span_context() can return SpanContext or None.
if span_context is None then calling span_context.trace_flags will result in an exception and kill the entire process.

so we check for nullability, and if not null... we proceed

if span_context is not None:
encoded_span.flags |= int(span_context.trace_flags)
return encoded_span

def encode_links(links: Sequence[Link]) -> Optional[Sequence[PB2Span.Link]]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ classifiers = [
]
dependencies = [
"opentelemetry-api ~= 1.12",
"opentelemetry-instrumentation == 0.61b0",
"opentelemetry-semantic-conventions == 0.61b0",
"opentelemetry-util-http == 0.61b0",
"wrapt >= 1.0.0, < 2.0.0",
"opentelemetry-instrumentation == 0.62b1",
"opentelemetry-semantic-conventions == 0.62b1",
"opentelemetry-util-http == 0.62b1",
"wrapt >= 1.0.0, < 3.0.0",
]

[project.optional-dependencies]
Expand All @@ -55,4 +55,4 @@ include = [
]

[tool.hatch.build.targets.wheel]
packages = ["src/opentelemetry"]
packages = ["src/opentelemetry"]
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "0.61b0"
__version__ = "0.62b1"
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ classifiers = [
"Programming Language :: Python :: 3.14",
]
dependencies = [
"opentelemetry-instrumentation == 0.61b0",
"opentelemetry-instrumentation == 0.62b1",
"opentelemetry-api ~= 1.12",
"wrapt >= 1.0.0, < 2.0.0",
"wrapt >= 1.0.0, < 3.0.0",
]

[project.optional-dependencies]
instruments = [
"confluent-kafka >= 1.8.2, <= 2.13.0",
"confluent-kafka >= 1.8.2, < 3.0.0",
]

[project.entry-points.opentelemetry_instrumentor]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,11 +384,11 @@ def wrap_poll(func, instance, tracer, args, kwargs):
if instance._current_consume_span:
_end_current_consume_span(instance)

with tracer.start_as_current_span(
"recv", end_on_exit=True, kind=trace.SpanKind.CONSUMER
):
record = func(*args, **kwargs)
if record:
record = func(*args, **kwargs)
if record:
with tracer.start_as_current_span(
"recv", end_on_exit=True, kind=trace.SpanKind.CONSUMER
):
_create_new_consume_span(instance, tracer, [record])
_enrich_span(
instance._current_consume_span,
Expand All @@ -406,11 +406,11 @@ def wrap_consume(func, instance, tracer, args, kwargs):
if instance._current_consume_span:
_end_current_consume_span(instance)

with tracer.start_as_current_span(
"recv", end_on_exit=True, kind=trace.SpanKind.CONSUMER
):
records = func(*args, **kwargs)
if len(records) > 0:
records = func(*args, **kwargs)
if len(records) > 0:
with tracer.start_as_current_span(
"recv", end_on_exit=True, kind=trace.SpanKind.CONSUMER
):
_create_new_consume_span(instance, tracer, records)
_enrich_span(
instance._current_consume_span,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# limitations under the License.


_instruments = ("confluent-kafka >= 1.8.2, <= 2.13.0",)
_instruments = ("confluent-kafka >= 1.8.2, < 3.0.0",)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

__version__ = "0.61b0"
__version__ = "0.62b1"
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ classifiers = [
]
dependencies = [
"opentelemetry-api ~= 1.12",
"opentelemetry-instrumentation == 0.61b0",
"opentelemetry-semantic-conventions == 0.61b0",
"wrapt >= 1.0.0, < 2.0.0",
"opentelemetry-instrumentation == 0.62b1",
"opentelemetry-semantic-conventions == 0.62b1",
"wrapt >= 1.0.0, < 3.0.0",
]

[project.optional-dependencies]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "0.61b0"
__version__ = "0.62b1"
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ classifiers = [
]
dependencies = [
"opentelemetry-api ~= 1.12",
"opentelemetry-instrumentation == 0.61b0",
"opentelemetry-semantic-conventions == 0.61b0",
"opentelemetry-instrumentation == 0.62b1",
"opentelemetry-semantic-conventions == 0.62b1",
"packaging >= 21.0",
"wrapt >= 1.11.2",
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,24 +110,24 @@
SQLComment in span attribute
****************************
If sqlcommenter is enabled, you can opt into the inclusion of sqlcomment in
the query span ``db.statement`` attribute for your needs. If ``commenter_options``
have been set, the span attribute comment will also be configured by this
setting.
the query span ``db.statement`` and/or ``db.query.text`` attribute for your
needs. If ``commenter_options`` have been set, the span attribute comment
will also be configured by this setting.

.. code:: python

from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor

# Opts into sqlcomment for SQLAlchemy trace integration.
# Opts into sqlcomment for `db.statement` span attribute.
# Opts into sqlcomment for `db.statement` and/or `db.query.text` span attribute.
SQLAlchemyInstrumentor().instrument(
enable_commenter=True,
commenter_options={},
enable_attribute_commenter=True,
)

Warning:
Capture of sqlcomment in ``db.statement`` may have high cardinality without platform normalization. See `Semantic Conventions for database spans <https://opentelemetry.io/docs/specs/semconv/database/database-spans/#generating-a-summary-of-the-query-text>`_ for more information.
Capture of sqlcomment in ``db.statement``/``db.query.text`` may have high cardinality without platform normalization. See `Semantic Conventions for database spans <https://opentelemetry.io/docs/specs/semconv/database/database-spans/#generating-a-summary-of-the-query-text>`_ for more information.

API
---
Expand All @@ -141,6 +141,11 @@
from sqlalchemy.engine.base import Engine
from wrapt import wrap_function_wrapper as _w

from opentelemetry.instrumentation._semconv import (
_get_schema_url_for_signal_types,
_OpenTelemetrySemanticConventionStability,
_OpenTelemetryStabilitySignalType,
)
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
from opentelemetry.instrumentation.sqlalchemy.engine import (
EngineTracer,
Expand Down Expand Up @@ -181,20 +186,32 @@ def _instrument(self, **kwargs):
Returns:
An instrumented engine if passed in as an argument or list of instrumented engines, None otherwise.
"""
# Initialize semantic conventions opt-in if needed
_OpenTelemetrySemanticConventionStability._initialize()

# Determine schema URL based on both DATABASE and HTTP signal types
# and semconv opt-in mode
schema_url = _get_schema_url_for_signal_types(
[
_OpenTelemetryStabilitySignalType.DATABASE,
_OpenTelemetryStabilitySignalType.HTTP,
]
)

tracer_provider = kwargs.get("tracer_provider")
tracer = get_tracer(
__name__,
__version__,
tracer_provider,
schema_url="https://opentelemetry.io/schemas/1.11.0",
schema_url=schema_url,
)

meter_provider = kwargs.get("meter_provider")
meter = get_meter(
__name__,
__version__,
meter_provider,
schema_url="https://opentelemetry.io/schemas/1.11.0",
schema_url=schema_url,
)

connections_usage = meter.create_up_down_counter(
Expand Down
Loading
Loading