Skip to content

Commit

Permalink
Add aws distro version to sdk.version resource attributes. (#69)
Browse files Browse the repository at this point in the history
*Issue #, if available:*

In Java,` telemetry.auto.version` resource attribute is being deprecated
([PR](open-telemetry/opentelemetry-java-instrumentation#9065)).
However, We don't find any related change in upstream. It is still
[being
used](https://github.com/open-telemetry/opentelemetry-python/blob/da48e0b131ff34ff382b7d1206f71b2e31929cab/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py#L364),
so we are not going to deprecate it in aws-opentelemetry-distro for now.
And we use `aws-opentlemetry-distro` version with "-aws" post-fix to be
the `telemetry.auto.version `, which match with the [Java
implementation](https://github.com/aws-observability/aws-otel-java-instrumentation/blob/294e957afbf48e766e3be9a11638050ef3736904/otelagent/build.gradle.kts#L101).

Testing:
Tested resource attributed are generated:
Before the change:
```
"resource": "BoundedAttributes({'telemetry.sdk.language': 'python', 'telemetry.sdk.name': 'opentelemetry', 'telemetry.sdk.version': '1.22.0', 'service.name': 'unknown_service', 'telemetry.auto.version': '0.43b0'}, maxlen=None)"
```
After the change:
```
"resource": "BoundedAttributes({'telemetry.sdk.language': 'python', 'telemetry.sdk.name': 'opentelemetry', 'telemetry.sdk.version': '1.22.0', 'service.name': 'unknown_service', 'telemetry.auto.version':'0.0.1-aws'}, maxlen=None)"
```


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.
  • Loading branch information
zzhlogin authored Feb 27, 2024
1 parent 232ca3e commit 71f4007
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from logging import Logger, getLogger
from typing import ClassVar, Dict, Type

from importlib_metadata import version
from typing_extensions import override

from amazon.opentelemetry.distro.always_record_sampler import AlwaysRecordSampler
Expand Down Expand Up @@ -80,10 +81,10 @@ class AwsOpenTelemetryConfigurator(_OTelSDKConfigurator):
# pylint: disable=no-self-use
@override
def _configure(self, **kwargs):
_initialize_components(kwargs.get("auto_instrumentation_version"))
_initialize_components()


def _initialize_components(auto_instrumentation_version):
def _initialize_components():
trace_exporters, metric_exporters, log_exporters = _import_exporters(
_get_exporter_names("traces"),
_get_exporter_names("metrics"),
Expand All @@ -94,11 +95,9 @@ def _initialize_components(auto_instrumentation_version):
id_generator = _import_id_generator(id_generator_name)
# if env var OTEL_RESOURCE_ATTRIBUTES is given, it will read the service_name
# from the env variable else defaults to "unknown_service"
auto_resource = {}
# populate version if using auto-instrumentation
if auto_instrumentation_version:
auto_resource[ResourceAttributes.TELEMETRY_AUTO_VERSION] = auto_instrumentation_version

auto_resource: Dict[str, any] = {}
auto_resource = _customize_versions(auto_resource)
resource = get_aggregated_resources(
[
AwsEc2ResourceDetector(),
Expand Down Expand Up @@ -213,6 +212,13 @@ def _customize_span_processors(provider: TracerProvider, resource: Resource) ->
return


def _customize_versions(auto_resource: Dict[str, any]) -> Dict[str, any]:
distro_version = version("aws-opentelemetry-distro")
auto_resource[ResourceAttributes.TELEMETRY_AUTO_VERSION] = distro_version + "-aws"
_logger.debug("aws-opentelementry-distro - version: %s", auto_resource[ResourceAttributes.TELEMETRY_AUTO_VERSION])
return auto_resource


def is_app_signals_enabled():
return os.environ.get(OTEL_AWS_APP_SIGNALS_ENABLED, False)

Expand Down

0 comments on commit 71f4007

Please sign in to comment.