From 96e99d50df0ca42a37e0db60ba16836cea024829 Mon Sep 17 00:00:00 2001 From: Zhonghao Zhao Date: Thu, 1 Feb 2024 12:14:05 -0800 Subject: [PATCH 1/7] Smal bug fix. --- aws-opentelemetry-distro/pyproject.toml | 1 + .../distro/aws_opentelemetry_configurator.py | 14 ++++++++++++-- .../distro/aws_span_metrics_processor_builder.py | 3 +++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/aws-opentelemetry-distro/pyproject.toml b/aws-opentelemetry-distro/pyproject.toml index eeb1d7423..dd78c192d 100644 --- a/aws-opentelemetry-distro/pyproject.toml +++ b/aws-opentelemetry-distro/pyproject.toml @@ -13,6 +13,7 @@ requires-python = ">=3.7" dependencies = [ "opentelemetry-api ~= 1.12", "opentelemetry-instrumentation == 0.43b0", + "opentelemetry-disto == 0.43b0", "opentelemetry-sdk ~= 1.13", "opentelemetry-sdk-extension-aws ~= 2.0.1", "opentelemetry-exporter-otlp-proto-grpc == 1.22.0" diff --git a/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_opentelemetry_configurator.py b/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_opentelemetry_configurator.py index fb2b77ea9..addf4b377 100644 --- a/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_opentelemetry_configurator.py +++ b/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_opentelemetry_configurator.py @@ -27,6 +27,9 @@ _OTelSDKConfigurator, ) from opentelemetry.sdk.environment_variables import _OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED +from opentelemetry.sdk.extension.aws.resource.ec2 import AwsEc2ResourceDetector +from opentelemetry.sdk.extension.aws.resource.ecs import AwsEcsResourceDetector +from opentelemetry.sdk.extension.aws.resource.eks import AwsEksResourceDetector from opentelemetry.sdk.metrics import MeterProvider from opentelemetry.sdk.metrics._internal.instrument import ( Counter, @@ -37,7 +40,7 @@ UpDownCounter, ) from opentelemetry.sdk.metrics.export import AggregationTemporality, PeriodicExportingMetricReader -from opentelemetry.sdk.resources import Resource +from opentelemetry.sdk.resources import Resource, get_aggregated_resources from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import BatchSpanProcessor, SpanExporter from opentelemetry.sdk.trace.id_generator import IdGenerator @@ -88,7 +91,14 @@ def _initialize_components(auto_instrumentation_version): # populate version if using auto-instrumentation if auto_instrumentation_version: auto_resource[ResourceAttributes.TELEMETRY_AUTO_VERSION] = auto_instrumentation_version - resource = Resource.create(auto_resource) + + resource = get_aggregated_resources( + [ + AwsEc2ResourceDetector(), + AwsEksResourceDetector(), + AwsEcsResourceDetector(), + ] + ).merge(Resource.create(auto_resource)) _init_tracing( exporters=trace_exporters, diff --git a/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_span_metrics_processor_builder.py b/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_span_metrics_processor_builder.py index 4f94af7b7..d2da41e54 100644 --- a/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_span_metrics_processor_builder.py +++ b/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_span_metrics_processor_builder.py @@ -57,6 +57,9 @@ def build(self) -> AwsSpanMetricsProcessor: error_histogram: Histogram = meter.create_histogram(_ERROR) fault_histogram: Histogram = meter.create_histogram(_FAULT) latency_histogram: Histogram = meter.create_histogram(_LATENCY, unit=_LATENCY_UNITS) + error_histogram.name = _ERROR + fault_histogram.name = _FAULT + latency_histogram.name = _LATENCY return AwsSpanMetricsProcessor( error_histogram, fault_histogram, latency_histogram, self._generator, self._resource From 2065a78375ec918413f7b5b3a2090ce021daf6c7 Mon Sep 17 00:00:00 2001 From: Zhonghao Zhao Date: Thu, 1 Feb 2024 12:20:16 -0800 Subject: [PATCH 2/7] Fix typo. --- aws-opentelemetry-distro/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws-opentelemetry-distro/pyproject.toml b/aws-opentelemetry-distro/pyproject.toml index dd78c192d..0dbec4b60 100644 --- a/aws-opentelemetry-distro/pyproject.toml +++ b/aws-opentelemetry-distro/pyproject.toml @@ -13,7 +13,7 @@ requires-python = ">=3.7" dependencies = [ "opentelemetry-api ~= 1.12", "opentelemetry-instrumentation == 0.43b0", - "opentelemetry-disto == 0.43b0", + "opentelemetry-distro == 0.43b0", "opentelemetry-sdk ~= 1.13", "opentelemetry-sdk-extension-aws ~= 2.0.1", "opentelemetry-exporter-otlp-proto-grpc == 1.22.0" From 52baef94722e29f8e57e76d74e81b1ff1a40778c Mon Sep 17 00:00:00 2001 From: Zhonghao Zhao Date: Tue, 6 Feb 2024 00:03:38 +0000 Subject: [PATCH 3/7] Add a TODO for Histrogram metric name override. --- .../opentelemetry/distro/aws_span_metrics_processor_builder.py | 1 + 1 file changed, 1 insertion(+) diff --git a/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_span_metrics_processor_builder.py b/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_span_metrics_processor_builder.py index d2da41e54..794fc0b84 100644 --- a/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_span_metrics_processor_builder.py +++ b/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_span_metrics_processor_builder.py @@ -57,6 +57,7 @@ def build(self) -> AwsSpanMetricsProcessor: error_histogram: Histogram = meter.create_histogram(_ERROR) fault_histogram: Histogram = meter.create_histogram(_FAULT) latency_histogram: Histogram = meter.create_histogram(_LATENCY, unit=_LATENCY_UNITS) + # TODO: Remove the Histogram name override after the CWAgent is fixed with metric name case-insensitive. error_histogram.name = _ERROR fault_histogram.name = _FAULT latency_histogram.name = _LATENCY From e407f8221d75a538f2ab28e0a23d586185ae31be Mon Sep 17 00:00:00 2001 From: Zhonghao Zhao Date: Tue, 6 Feb 2024 00:07:59 +0000 Subject: [PATCH 4/7] Remove python3.7 test because upstream opentelemetry-instrumentation requires >=3.8 --- .github/workflows/test.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e1eea45ce..251f3ad2d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,7 +9,6 @@ jobs: build: env: # We use these variables to convert between tox and GHA version literals - py37: 3.7 py38: 3.8 py39: 3.9 py310: "3.10" @@ -20,7 +19,7 @@ jobs: strategy: fail-fast: false # ensures the entire test matrix is run, even if one permutation fails matrix: - python-version: [ py37, py38, py39, py310, py311, pypy3 ] + python-version: [ py38, py39, py310, py311, pypy3 ] package: [ "aws-opentelemetry-distro" ] os: [ ubuntu-20.04 ] steps: From d9a487259727ebfea59b7602f9137de028314bac Mon Sep 17 00:00:00 2001 From: Zhonghao Zhao Date: Tue, 6 Feb 2024 18:32:38 +0000 Subject: [PATCH 5/7] Initial fix. --- .../opentelemetry/distro/_aws_metric_attribute_generator.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/_aws_metric_attribute_generator.py b/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/_aws_metric_attribute_generator.py index 55be7678f..a0f45e6d6 100644 --- a/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/_aws_metric_attribute_generator.py +++ b/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/_aws_metric_attribute_generator.py @@ -211,6 +211,10 @@ def _set_remote_service_and_operation(span: ReadableSpan, attributes: BoundedAtt elif is_key_present(span, _DB_SYSTEM) or is_key_present(span, _DB_OPERATION): remote_service = _get_remote_service(span, _DB_SYSTEM) remote_operation = _get_remote_operation(span, _DB_OPERATION) + elif is_key_present(span, _DB_SYSTEM) or (is_key_present(span, DB_STATEMENT("db.statement")) and key_not_present(span, _DB_OPERATION)) + remote_service = _get_remote_service(span, _DB_SYSTEM) + database_operation_key = DB_STATEMENT.split(" ")[0] + remote_operation = _get_remote_operation(span, database_operation_key) elif is_key_present(span, _FAAS_INVOKED_NAME) or is_key_present(span, _FAAS_TRIGGER): remote_service = _get_remote_service(span, _FAAS_INVOKED_NAME) remote_operation = _get_remote_operation(span, _FAAS_TRIGGER) From 061ec45716236efc7fe95ecd7e6ea40038a29af1 Mon Sep 17 00:00:00 2001 From: Zhonghao Zhao Date: Wed, 7 Feb 2024 05:08:12 +0000 Subject: [PATCH 6/7] Remove useless command in CONTRIBUTING.md. --- CONTRIBUTING.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 181f23806..0c88b42da 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -19,7 +19,6 @@ cd ./aws-opentelemetry-distro python3 -m build --outdir ../dist cd ../dist pkg_version=$(grep '__version__' ../aws-opentelemetry-distro/src/amazon/opentelemetry/distro/version.py | awk -F '"' '{print $2}') -pip wheel --no-deps aws_opentelemetry_distro-${pkg_version}.tar.gz pip install aws_opentelemetry_distro-${pkg_version}-py3-none-any.whl --force-reinstall cd .. ``` From 522c9363707b86d75d1155d19d2ddcc5d973b509 Mon Sep 17 00:00:00 2001 From: Zhonghao Zhao Date: Wed, 7 Feb 2024 05:11:23 +0000 Subject: [PATCH 7/7] Revert init fix. --- .../opentelemetry/distro/_aws_metric_attribute_generator.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/_aws_metric_attribute_generator.py b/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/_aws_metric_attribute_generator.py index a0f45e6d6..55be7678f 100644 --- a/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/_aws_metric_attribute_generator.py +++ b/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/_aws_metric_attribute_generator.py @@ -211,10 +211,6 @@ def _set_remote_service_and_operation(span: ReadableSpan, attributes: BoundedAtt elif is_key_present(span, _DB_SYSTEM) or is_key_present(span, _DB_OPERATION): remote_service = _get_remote_service(span, _DB_SYSTEM) remote_operation = _get_remote_operation(span, _DB_OPERATION) - elif is_key_present(span, _DB_SYSTEM) or (is_key_present(span, DB_STATEMENT("db.statement")) and key_not_present(span, _DB_OPERATION)) - remote_service = _get_remote_service(span, _DB_SYSTEM) - database_operation_key = DB_STATEMENT.split(" ")[0] - remote_operation = _get_remote_operation(span, database_operation_key) elif is_key_present(span, _FAAS_INVOKED_NAME) or is_key_present(span, _FAAS_TRIGGER): remote_service = _get_remote_service(span, _FAAS_INVOKED_NAME) remote_operation = _get_remote_operation(span, _FAAS_TRIGGER)