Skip to content

Conversation

@majanjua-amzn
Copy link
Contributor

@majanjua-amzn majanjua-amzn commented Oct 24, 2025

Background

With the addition of onEnding as part of the ExtendedSpanProcessor in OTel core (open-telemetry/opentelemetry-java#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 majanjua-amzn self-assigned this Oct 24, 2025
@majanjua-amzn majanjua-amzn added the java Pull requests that update Java code label Oct 24, 2025
@majanjua-amzn majanjua-amzn force-pushed the refactor-exporter branch 3 times, most recently from 7167e8c to 0e1a512 Compare October 24, 2025 21:34
@majanjua-amzn majanjua-amzn marked this pull request as ready for review October 24, 2025 21:40
@majanjua-amzn majanjua-amzn requested a review from a team as a code owner October 24, 2025 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

java Pull requests that update Java code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant