aws-otel-java-instrumentation
aws-otel-java-instrumentation copied to clipboard
Refactor AwsMetricAttributesSpanExporter to a processor
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
AwsMetricAttributesSpanExporterwithAwsAttributeGeneratingSpanProcessor - Refactored
AwsMetricAttributesSpanExportertoAwsAttributeGeneratingSpanProcessor, removing any exporter-related functionality and moving the span/attribute modification logic toprocessor.onEnding() - Replaced the
AwsMetricAttributesSpanExporterBuilderwith theAwsAttributeGeneratingSpanProcessorBuilder - 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
testPassthroughDelegationstestExportDelegatingSpanDataBehaviour
- 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
- Tests checking testing delegate classes, export, flush, and shutdown behaviour
- Added/renamed: (Notice some overlap, test cases before
testExportDelegationWithoutAttributeOrModification→testOnEndingGeneratesBothWithoutOverridetestExportDelegationWithAttributeButWithoutModification→testOnEndingGeneratesServicetestExportDelegationWithoutAttributeButWithModification→testOnEndingGeneratesBothWithoutOverridetestExportDelegationWithAttributeAndModification→testOnEndingGeneratesBothWithOverridetestOverridenAttributes→testOnEndingGeneratesBothWithOverridetestExportDelegationWithTwoMetrics→testOnEndingGeneratesBothWithTwoMetricstestConsumerProcessSpanHasEmptyAttribute→testConsumerSpanHasEmptyAttributestestExportDelegationWithDependencyMetrics→testOnEndingGeneratesDependency
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.