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

[feature request] Make Kafka instrumentation more amenable to unit testing #2356

Open
IGx89 opened this issue Dec 3, 2024 · 2 comments
Open
Labels
comp:instrumentation.confluentkafka Things related to OpenTelemetry.Instrumentation.ConfluentKafka enhancement New feature or request

Comments

@IGx89
Copy link

IGx89 commented Dec 3, 2024

Component

OpenTelemetry.Instrumentation.ConfluentKafka

Is your feature request related to a problem?

I want to be able to unit test my application logic using mock IConsumer's instead of only being able to do E2E testing against a live Kafka instance.

I have code using the IConsumer.ConsumeAndProcessMessageAsync extension method and want to unit test it. I'm injecting an IConsumer mock into the DI container to facilitate that. That extension method throws an exception if consumer is not InstrumentedConsumer<TKey, TValue>, an internal class, preventing me from unit testing that code.

What is the expected behavior?

There are multiple possible solutions, including making InstrumentedConsumer public or removing the unnecessary consumer is not InstrumentedConsumer<TKey, TValue> check from the extension method.

Which alternative solutions or features have you considered?

Writing E2E tests (much slower and more complicated) or not testing my app logic, neither of which is appealing.

Additional context

No response

@IGx89 IGx89 added the enhancement New feature or request label Dec 3, 2024
@github-actions github-actions bot added the comp:instrumentation.confluentkafka Things related to OpenTelemetry.Instrumentation.ConfluentKafka label Dec 3, 2024
Copy link
Contributor

github-actions bot commented Dec 3, 2024

Tagging component owner(s).

@g7ed6e

@IGx89
Copy link
Author

IGx89 commented Dec 3, 2024

I found another workaround that involves using reflection to set the "consumer" field on InstrumentedConsumer to my mock consumer. That unblocks me for now, but still would be nice to have a non-hacky solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:instrumentation.confluentkafka Things related to OpenTelemetry.Instrumentation.ConfluentKafka enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant