Skip to content

Fix OTEL trace source broken by PR 5322#6494

Merged
kkondaka merged 3 commits intoopensearch-project:mainfrom
kkondaka:otel-trace-fix
Feb 8, 2026
Merged

Fix OTEL trace source broken by PR 5322#6494
kkondaka merged 3 commits intoopensearch-project:mainfrom
kkondaka:otel-trace-fix

Conversation

@kkondaka
Copy link
Copy Markdown
Collaborator

@kkondaka kkondaka commented Feb 6, 2026

Description

Fix OTEL trace source broken by PR #5322

The PR was started before OTEL standard support was added committed long after OTEL standard support was added. This resulted in regression of support for OTEL standard in otel-trace-source

Issues Resolved

Resolves #[Issue number to be closed when this PR is merged]

Check List

  • [ X] New functionality includes testing.
  • New functionality has a documentation issue. Please link to it in this PR.
    • New functionality has javadoc added
  • [ X] Commits are signed with a real name per the DCO

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>
Copy link
Copy Markdown
Collaborator

@KarstenSchnitter KarstenSchnitter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>
}

@Test
void testCreateWithAuthentication() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to assert internals instead of treating the service as black box and assert its behaviour?

This is a good example for it. The test could bootstrap the trace source and make sure that it doesn't accept requests that do not carry authentication information.

In this form, the test depends on the exact invocation of some internal component.

I'm addressing this here, because in #6250 I followed my line of reasoning getting rid of all the mocking, bootstrapping the service and testing with actual requests against it. Is that something to avoid?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think as a unit test, it is appropriate to have something like this. Though, we should also have tests that are more black box. Using a real server and web client provide much better tests for authentication.

Copy link
Copy Markdown
Member

@dlvenable dlvenable left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some comments. I also see a number of failing GitHub Actions.


ExportTraceServiceResponse response = armeriaHttpService.exportTrace(request);

assertNotNull(response);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move as much out of the try-with-resources block as possible. I'm fairly sure that the rest of this can go out of it.

verify(successRequestsCounter).increment();
assertThat(recordsReceived.size(), equalTo(1));
Span span = recordsReceived.get(0).getData();
if (outputFormat == OTelOutputFormat.OTEL) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's avoid conditions. Instead, make an ArgumentsProvider class which produces these as inputs.

Something like this:

    static class OTelOutputFormatToServiceNameKey implements ArgumentsProvider {
        @Override
        public Stream<? extends Arguments> provideArguments(final ExtensionContext extensionContext) {
            return Stream.of(
                    arguments(OTelOutputFormat.OPENSEARCH, "attributes/resource.attributes.service@name"),
                    arguments(OTelOutputFormat.OTEL, "resource/attributes/service.name")
            );
        }
    }

Then you just have:

assertThat(span.get(serviceNameKey, String.class), equalTo(TRACE_SERVICE_NAME));

}

@Test
void testCreateWithAuthentication() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think as a unit test, it is appropriate to have something like this. Though, we should also have tests that are more black box. Using a real server and web client provide much better tests for authentication.

public ArmeriaHttpService(Buffer<Record<Object>> buffer, final OTelOutputFormat otelOutputFormat, final PluginMetrics pluginMetrics, final int bufferWriteTimeoutInMillis) {
this.buffer = buffer;
this.oTelProtoDecoder = new OTelProtoOpensearchCodec.OTelProtoDecoder();
this.oTelProtoDecoder = (otelOutputFormat == OTelOutputFormat.OPENSEARCH) ? new OTelProtoOpensearchCodec.OTelProtoDecoder() : new OTelProtoStandardCodec.OTelProtoDecoder();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same as the change above. We'd be better off injecting the OTelProtoDecoder into these classes and making this decision in a single location.

@kkondaka
Copy link
Copy Markdown
Collaborator Author

kkondaka commented Feb 6, 2026

Actually I wanted @TomasLongo to write the unit tests separately because they were not there when the PR was merged. But I quickly generated few unit tests using AI :-)

Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>
Copy link
Copy Markdown
Member

@dlvenable dlvenable left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @kkondaka .

@KarstenSchnitter , Can you review again?

@kkondaka
Copy link
Copy Markdown
Collaborator Author

kkondaka commented Feb 7, 2026

@KarstenSchnitter please review this.

Copy link
Copy Markdown
Collaborator

@KarstenSchnitter KarstenSchnitter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for providing the fixe and adding the tests.

@kkondaka kkondaka merged commit 861369a into opensearch-project:main Feb 8, 2026
69 of 72 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.

4 participants