-
Couldn't load subscription status.
- Fork 66
Refactor AwsMetricAttributesSpanExporter to a processor #1250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,95 @@ | ||||||||||||||||||||
| /* | ||||||||||||||||||||
| * Copyright Amazon.com, Inc. or its affiliates. | ||||||||||||||||||||
| * | ||||||||||||||||||||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||||||||||||||||||||
| * You may not use this file except in compliance with the License. | ||||||||||||||||||||
| * A copy of the License is located at | ||||||||||||||||||||
| * | ||||||||||||||||||||
| * http://aws.amazon.com/apache2.0 | ||||||||||||||||||||
| * | ||||||||||||||||||||
| * or in the "license" file accompanying this file. This file is distributed | ||||||||||||||||||||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||||||||||||||||||||
| * express or implied. See the License for the specific language governing | ||||||||||||||||||||
| * permissions and limitations under the License. | ||||||||||||||||||||
| */ | ||||||||||||||||||||
|
|
||||||||||||||||||||
| package software.amazon.opentelemetry.javaagent.providers; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_SPAN_KIND; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| import io.opentelemetry.api.common.Attributes; | ||||||||||||||||||||
| import io.opentelemetry.context.Context; | ||||||||||||||||||||
| import io.opentelemetry.sdk.resources.Resource; | ||||||||||||||||||||
| import io.opentelemetry.sdk.trace.ReadWriteSpan; | ||||||||||||||||||||
| import io.opentelemetry.sdk.trace.ReadableSpan; | ||||||||||||||||||||
| import io.opentelemetry.sdk.trace.data.SpanData; | ||||||||||||||||||||
| import io.opentelemetry.sdk.trace.internal.ExtendedSpanProcessor; | ||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I forgot that |
||||||||||||||||||||
| import java.util.Map; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| public class AwsAttributeGeneratingSpanProcessor implements ExtendedSpanProcessor { | ||||||||||||||||||||
|
|
||||||||||||||||||||
| private final MetricAttributeGenerator generator; | ||||||||||||||||||||
| private final Resource resource; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| public static AwsAttributeGeneratingSpanProcessor create( | ||||||||||||||||||||
| MetricAttributeGenerator generator, Resource resource) { | ||||||||||||||||||||
| return new AwsAttributeGeneratingSpanProcessor(generator, resource); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| private AwsAttributeGeneratingSpanProcessor( | ||||||||||||||||||||
| MetricAttributeGenerator generator, Resource resource) { | ||||||||||||||||||||
| this.generator = generator; | ||||||||||||||||||||
| this.resource = resource; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| @Override | ||||||||||||||||||||
| public void onStart(Context parentContext, ReadWriteSpan span) {} | ||||||||||||||||||||
|
|
||||||||||||||||||||
| @Override | ||||||||||||||||||||
| public boolean isStartRequired() { | ||||||||||||||||||||
| return false; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| @Override | ||||||||||||||||||||
| public void onEnding(ReadWriteSpan span) { | ||||||||||||||||||||
| // If the map has no items, no modifications are required. If there is one item, it means the | ||||||||||||||||||||
| // span either produces Service or Dependency metric attributes, and in either case we want to | ||||||||||||||||||||
| // modify the span with them. If there are two items, the span produces both Service and | ||||||||||||||||||||
| // Dependency metric attributes indicating the span is a local dependency root. The Service | ||||||||||||||||||||
| // Attributes must be a subset of the Dependency, with the exception of AWS_SPAN_KIND. The | ||||||||||||||||||||
| // knowledge that the span is a local root is more important than knowing that it is a | ||||||||||||||||||||
| // Dependency metric, so we take all the Dependency metrics but replace AWS_SPAN_KIND with | ||||||||||||||||||||
| // LOCAL_ROOT. | ||||||||||||||||||||
| SpanData spanData = span.toSpanData(); | ||||||||||||||||||||
| Map<String, Attributes> attributeMap = | ||||||||||||||||||||
| generator.generateMetricAttributeMapFromSpan(span.toSpanData(), resource); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| boolean generatesServiceMetrics = | ||||||||||||||||||||
|
Comment on lines
+63
to
+67
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
| AwsSpanProcessingUtil.shouldGenerateServiceMetricAttributes(spanData); | ||||||||||||||||||||
| boolean generatesDependencyMetrics = | ||||||||||||||||||||
| AwsSpanProcessingUtil.shouldGenerateDependencyMetricAttributes(spanData); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if (generatesServiceMetrics && generatesDependencyMetrics) { | ||||||||||||||||||||
| // Order matters: dependency metric attributes include AWS_SPAN_KIND key | ||||||||||||||||||||
| span.setAllAttributes(attributeMap.get(MetricAttributeGenerator.DEPENDENCY_METRIC)); | ||||||||||||||||||||
| span.setAttribute(AWS_SPAN_KIND, AwsSpanProcessingUtil.LOCAL_ROOT); | ||||||||||||||||||||
| } else if (generatesServiceMetrics) { | ||||||||||||||||||||
| span.setAllAttributes(attributeMap.get(MetricAttributeGenerator.SERVICE_METRIC)); | ||||||||||||||||||||
| } else if (generatesDependencyMetrics) { | ||||||||||||||||||||
| span.setAllAttributes(attributeMap.get(MetricAttributeGenerator.DEPENDENCY_METRIC)); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
Comment on lines
+72
to
+80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consideration: If (for example) |
||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| @Override | ||||||||||||||||||||
| public boolean isOnEndingRequired() { | ||||||||||||||||||||
| return true; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| @Override | ||||||||||||||||||||
| public void onEnd(ReadableSpan span) {} | ||||||||||||||||||||
|
|
||||||||||||||||||||
| @Override | ||||||||||||||||||||
| public boolean isEndRequired() { | ||||||||||||||||||||
| return false; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe comment that the order of span processors matters. I actually wonder if it would be better to have some kind of explicit enforcement of this.