aws-otel-java-instrumentation icon indicating copy to clipboard operation
aws-otel-java-instrumentation copied to clipboard

Refactor AwsMetricAttributesSpanExporter to a processor

Open majanjua-amzn opened this issue 1 month ago • 0 comments

Background

With the addition of onEnding as part of the ExtendedSpanProcessor in OTel core (https://github.com/open-telemetry/opentelemetry-java/pull/6367), we are now able to modify spans before they are sent to an exporter. As such, we have the opportunity to refactor our AwsMetricAttributesSpanExporter which is responsible for adding service and dependency metric related attributes to spans as they are exported. This was done via some complicated span wrapping logic which is no longer necessary with onEnding.

Changes

  • Replaced all references to AwsMetricAttributesSpanExporter with AwsAttributeGeneratingSpanProcessor
  • Refactored AwsMetricAttributesSpanExporter to AwsAttributeGeneratingSpanProcessor, removing any exporter-related functionality and moving the span/attribute modification logic to processor.onEnding()
  • Replaced the AwsMetricAttributesSpanExporterBuilder with the AwsAttributeGeneratingSpanProcessorBuilder
  • Updated relevant tests expecting the exporter to expect the default exporters now that we don't set this extra exporter
  • Rewrote the relevant unit tests, see details in the testing section

Testing

Converted most of the exporter tests into equivalent tests for the new processor:

  • Removed:
    • Tests checking testing delegate classes, export, flush, and shutdown behaviour
      • testPassthroughDelegations
      • testExportDelegatingSpanDataBehaviour
    • Tests checking >1 span being exported at a time, as the processor handles one span at a time:
      • testExportDelegationWithMultipleSpans
    • Helper functions that are no longer needed
  • Added/renamed: (Notice some overlap, test cases before
    • testExportDelegationWithoutAttributeOrModificationtestOnEndingGeneratesBothWithoutOverride
    • testExportDelegationWithAttributeButWithoutModificationtestOnEndingGeneratesService
    • testExportDelegationWithoutAttributeButWithModificationtestOnEndingGeneratesBothWithoutOverride
    • testExportDelegationWithAttributeAndModificationtestOnEndingGeneratesBothWithOverride
    • testOverridenAttributestestOnEndingGeneratesBothWithOverride
    • testExportDelegationWithTwoMetricstestOnEndingGeneratesBothWithTwoMetrics
    • testConsumerProcessSpanHasEmptyAttributetestConsumerSpanHasEmptyAttributes
    • testExportDelegationWithDependencyMetricstestOnEndingGeneratesDependency

Also ran the entire main build workflow using this change successfully: https://github.com/aws-observability/aws-otel-java-instrumentation/actions/runs/18785649764

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

majanjua-amzn avatar Oct 24 '25 19:10 majanjua-amzn