Skip to content

Commit

Permalink
Merge branch 'main' into broad-exception-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lzchen authored May 23, 2024
2 parents 75d2821 + 66a107f commit 1154652
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 14 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- `opentelemetry-instrumentation-dbapi` Fix compatibility with Psycopg3 to extract libpq build version (#2500)[https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2500]
- `opentelemetry-instrumentation-grpc` AioClientInterceptor should propagate with a Metadata object
([#2363](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2363))
- `opentelemetry-instrumentation-boto3sqs` Instrument Session and resource
Expand Down Expand Up @@ -126,7 +127,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#1959](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1959))
- `opentelemetry-resource-detector-azure` Added dependency for Cloud Resource ID attribute
([#2072](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2072))

## Version 1.21.0/0.42b0 (2023-11-01)

### Added
Expand Down Expand Up @@ -1540,4 +1541,3 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `opentelemetry-resource-detector-azure` Suppress instrumentation for `urllib` call
([#2178](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2178))
- AwsLambdaInstrumentor handles and re-raises function exception ([#2245](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2245))

Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def trace_item(self, coro_or_future):

async def trace_coroutine(self, coro):
if not hasattr(coro, "__name__"):
return
return coro
start = default_timer()
attr = {
"type": "coroutine",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,12 +427,19 @@ def traced_execution(
if args and self._commenter_enabled:
try:
args_list = list(args)
if hasattr(self._connect_module, "__libpq_version__"):
libpq_version = self._connect_module.__libpq_version__
else:
libpq_version = (
self._connect_module.pq.__build_version__
)

commenter_data = {
# Psycopg2/framework information
"db_driver": f"psycopg2:{self._connect_module.__version__.split(' ')[0]}",
"dbapi_threadsafety": self._connect_module.threadsafety,
"dbapi_level": self._connect_module.apilevel,
"libpq_version": self._connect_module.__libpq_version__,
"libpq_version": libpq_version,
"driver_paramstyle": self._connect_module.paramstyle,
}
if self._commenter_options.get(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,32 @@ def test_executemany_comment(self):
r"Select 1 /\*dbapi_threadsafety=123,driver_paramstyle='test',libpq_version=123,traceparent='\d{1,2}-[a-zA-Z0-9_]{32}-[a-zA-Z0-9_]{16}-\d{1,2}'\*/;",
)

def test_compatible_build_version_psycopg_psycopg2_libpq(self):
connect_module = mock.MagicMock()
connect_module.__version__ = mock.MagicMock()
connect_module.pq = mock.MagicMock()
connect_module.pq.__build_version__ = 123
connect_module.apilevel = 123
connect_module.threadsafety = 123
connect_module.paramstyle = "test"

db_integration = dbapi.DatabaseApiIntegration(
"testname",
"testcomponent",
enable_commenter=True,
commenter_options={"db_driver": False, "dbapi_level": False},
connect_module=connect_module,
)
mock_connection = db_integration.wrapped_connection(
mock_connect, {}, {}
)
cursor = mock_connection.cursor()
cursor.executemany("Select 1;")
self.assertRegex(
cursor.query,
r"Select 1 /\*dbapi_threadsafety=123,driver_paramstyle='test',libpq_version=123,traceparent='\d{1,2}-[a-zA-Z0-9_]{32}-[a-zA-Z0-9_]{16}-\d{1,2}'\*/;",
)

def test_executemany_flask_integration_comment(self):
connect_module = mock.MagicMock()
connect_module.__version__ = mock.MagicMock()
Expand Down
21 changes: 11 additions & 10 deletions resource/opentelemetry-resource-detector-azure/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ OpenTelemetry Resource detectors for Azure
This library contains OpenTelemetry `Resource Detectors <https://opentelemetry.io/docs/specs/otel/resource/sdk/#detecting-resource-information-from-the-environment>`_ for the following Azure resources:
* `Azure App Service <https://azure.microsoft.com/en-us/products/app-service>`_
* `Azure Virtual Machines <https://azure.microsoft.com/en-us/products/virtual-machines>`_
* `Azure Functions (Experimental) <https://azure.microsoft.com/en-us/products/functions>`_

Installation
------------
Expand Down Expand Up @@ -60,16 +61,6 @@ The Azure App Service Resource Detector sets the following Resource Attributes:
* ``service.instance.id`` set to the value of the ``WEBSITE_INSTANCE_ID`` environment variable.
* ``azure.app.service.stamp`` set to the value of the ``WEBSITE_HOME_STAMPNAME`` environment variable.

The Azure Functions Resource Detector sets the following Resource Attributes:
* ``service.name`` set to the value of the ``WEBSITE_SITE_NAME`` environment variable.
* ``process.id`` set to the process ID collected from the running process.
* ``cloud.platform`` set to ``azure_functions``.
* ``cloud.provider`` set to ``azure``.
* ``cloud.resource_id`` set using the ``WEBSITE_RESOURCE_GROUP``, ``WEBSITE_OWNER_NAME``, and ``WEBSITE_SITE_NAME`` environment variables.
* ``cloud.region`` set to the value of the ``REGION_NAME`` environment variable.
* ``faas.instance`` set to the value of the ``WEBSITE_INSTANCE_ID`` environment variable.
* ``faas.max_memory`` set to the value of the ``WEBSITE_MEMORY_LIMIT_MB`` environment variable.

The Azure VM Resource Detector sets the following Resource Attributes according to the response from the `Azure Metadata Service <https://learn.microsoft.com/azure/virtual-machines/instance-metadata-service?tabs=windows>`_:
* ``azure.vm.scaleset.name`` set to the value of the ``vmScaleSetName`` field.
* ``azure.vm.sku`` set to the value of the ``sku`` field.
Expand All @@ -84,6 +75,16 @@ The Azure VM Resource Detector sets the following Resource Attributes according
* ``os.version`` set to the value of the ``version`` field.
* ``service.instance.id`` set to the value of the ``vmId`` field.

The Azure Functions Resource Detector is currently experimental. It sets the following Resource Attributes:
* ``service.name`` set to the value of the ``WEBSITE_SITE_NAME`` environment variable.
* ``process.id`` set to the process ID collected from the running process.
* ``cloud.platform`` set to ``azure_functions``.
* ``cloud.provider`` set to ``azure``.
* ``cloud.resource_id`` set using the ``WEBSITE_RESOURCE_GROUP``, ``WEBSITE_OWNER_NAME``, and ``WEBSITE_SITE_NAME`` environment variables.
* ``cloud.region`` set to the value of the ``REGION_NAME`` environment variable.
* ``faas.instance`` set to the value of the ``WEBSITE_INSTANCE_ID`` environment variable.
* ``faas.max_memory`` set to the value of the ``WEBSITE_MEMORY_LIMIT_MB`` environment variable.

For more information, see the `Semantic Conventions for Cloud Resource Attributes <https://opentelemetry.io/docs/specs/otel/resource/semantic_conventions/cloud/>`_.

References
Expand Down

0 comments on commit 1154652

Please sign in to comment.