Skip to content
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

Adding AwsUnsampledOnlySpanProcessor to export batches of unsampled spans #948

Merged
merged 8 commits into from
Nov 12, 2024

Conversation

srprash
Copy link
Contributor

@srprash srprash commented Nov 7, 2024

Description of changes

Following the approach as ADOT Python: aws-observability/aws-otel-python-instrumentation#247. Note that the span attribute key was later changed to aws.trace.flag.sampled.

Introducing AwsUnsampledOnlySpanProcessor that can be appended to a TracerProvider. This span processor wraps a BatchSpanProcessor for delegating all the operations after processing. The AwsUnsampledOnlySpanProcessor does 2 things:

  • onStart - Sets the aws.trace.flag.sampled span attribute on each span.
  • onEnd - If the span is unsampled, only then it is delegated to the BSP, otherwise it is dropped.

Testing

Setup
@Test
  public void testExportingUnsampledSpan() {
    SpanProcessor unsampledSpanProcessor = AwsUnsampledOnlySpanProcessor.builder().build();

    SdkTracerProvider tp =
        SdkTracerProvider.builder()
            .addSpanProcessor(unsampledSpanProcessor)
            .setSampler(AlwaysRecordSampler.create(Sampler.alwaysOff())) // change to alwaysOn to sample
            .build();

    Tracer tracer = OpenTelemetrySdk.builder().setTracerProvider(tp).build().getTracer("hello");

    Span span = tracer.spanBuilder("MySpan_unsampled_006").startSpan();
    span.setAttribute("foo", "bar");
    span.end();

    unsampledSpanProcessor.forceFlush();

    // add 5 seconds delay
    try {
      Thread.sleep(5000);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }
Observations:
  • Unsampled span is exported in a batch.
  • Switching to alwaysOn sampler, the sampled span is not exported at all.

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

@srprash srprash marked this pull request as ready for review November 8, 2024 00:21
@srprash srprash requested a review from a team as a code owner November 8, 2024 00:21
@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 81.25000% with 6 lines in your changes missing coverage. Please review.

Project coverage is 71.38%. Comparing base (09e6487) to head (d236e90).
Report is 368 commits behind head on main.

Files with missing lines Patch % Lines
...agent/providers/AwsUnsampledOnlySpanProcessor.java 68.42% 6 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@              Coverage Diff              @@
##               main     #948       +/-   ##
=============================================
- Coverage     85.71%   71.38%   -14.33%     
- Complexity       19      303      +284     
=============================================
  Files             3       26       +23     
  Lines            49     1094     +1045     
  Branches          5      145      +140     
=============================================
+ Hits             42      781      +739     
- Misses            3      267      +264     
- Partials          4       46       +42     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@srprash srprash merged commit 2f6490b into aws-observability:main Nov 12, 2024
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants