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 UdpExporter for Otlp spans #944

Merged
merged 6 commits into from
Nov 7, 2024
Merged

Conversation

srprash
Copy link
Contributor

@srprash srprash commented Nov 4, 2024

Description of changes:

Adding a new SpanExporter that can export spans to a configurable endpoint over UDP.

  • The spans are first protobuf encoded, then base64 encoded, then prefixed with T1S or T1U (depending on sampled), and finally appended to the {"format":"json","version":1}\n string before being exported to the endpoint, default is 127.0.0.1:2000.
  • Related: Add OTLP UDP exporter aws-otel-python-instrumentation#232

Testing:

Wrote a test to create and export a real span via X-Ray Daemon running locally.

  • Unit test

    @Test
    public void testExporter() { // TODO: only for testing. remove.
    Tracer tracer = OpenTelemetrySdk.builder().build().getTracer("hello");
    
    Span mySpan = tracer.spanBuilder("DoTheLoop_5").startSpan();
    int numIterations = 5;
    mySpan.setAttribute("NumIterations", numIterations);
    mySpan.setAttribute(AttributeKey.stringArrayKey("foo"), Arrays.asList("bar1", "bar2"));
    try (var scope = mySpan.makeCurrent()) {
      for (int i = 1; i <= numIterations; i++) {
        System.out.println("i = " + i);
      }
    } finally {
      mySpan.end();
    }
    
    OtlpUdpSpanExporter exporter = new OtlpUdpSpanExporterBuilder().build();
    
    ReadableSpan readableSpan = (ReadableSpan) mySpan;
    SpanData spanData = readableSpan.toSpanData();
    
    exporter.export(Collections.singletonList(spanData));
    }
  • Observed trace data in X-Ray service

    {
    "Id": "1-246f2975-8c1d813535803fea548be818",
    "Duration": 0.003,
    "LimitExceeded": false,
    "Segments": [
       {
           "Id": "455654be8f47d669",
           "Document": {
               "id": "455654be8f47d669",
               "name": "DoTheLoop_5",
               "start_time": 1730828092.934588,
               "trace_id": "1-246f2975-8c1d813535803fea548be818",
               "end_time": 1730828092.9371202,
               "annotations": {
                   "span.name": "DoTheLoop_5",
                   "span.kind": "INTERNAL"
               },
               "metadata": {
                   "telemetry.sdk.language": "java",
                   "service.name": "unknown_service:java",
                   "foo": [
                       "bar1",
                       "bar2"
                   ],
                   "NumIterations": 5,
                   "telemetry.sdk.version": "1.34.1",
                   "telemetry.sdk.name": "opentelemetry"
               }
           }
       }
    ]
    }

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 5, 2024 18:12
@srprash srprash requested a review from a team as a code owner November 5, 2024 18:12
@srprash srprash requested a review from bjrara November 5, 2024 21:40
wangzlei
wangzlei previously approved these changes Nov 6, 2024
@srprash
Copy link
Contributor Author

srprash commented Nov 6, 2024

The trivy image scan failure causing CI to fail is due to this issue: aquasecurity/trivy-action#389
No fix from trivy yet. A suggested workaround is to pull the db image from AWS ECR but I haven't tried it.

@srprash srprash merged commit ffc6afe into aws-observability:main Nov 7, 2024
2 of 4 checks passed
@srprash
Copy link
Contributor Author

srprash commented Nov 7, 2024

Had to override the checks and merge due to trivy scan issue mentioned above.

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