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

Integrate Testcontainers into OpenTelemetry .NET tests #4193

Closed
HofmeisterAn opened this issue Feb 15, 2023 · 4 comments
Closed

Integrate Testcontainers into OpenTelemetry .NET tests #4193

HofmeisterAn opened this issue Feb 15, 2023 · 4 comments
Labels
enhancement New feature or request infra Infra work - CI/CD, code coverage, linters

Comments

@HofmeisterAn
Copy link
Contributor

HofmeisterAn commented Feb 15, 2023

Feature Request

👋 OpenTelemetry maintainers and community! I wanted to introduce myself as one of the Testcontainers maintainers, working primarily on the .NET implementation. I know that Testcontainers has been adopted in some of the other OpenTelemetry implementations, such as Go and Java, and I believe that the .NET version could benefit from it as well.

For those who may not be familiar, Testcontainers is an open-source library that makes it easy to spin up and manage disposable Docker containers for testing. By using Testcontainers, you can run your tests in an environment that closely mimics production, without having to manually manage infrastructure or worry about the dependencies of your application. This can lead to more reliable and reproducible test results.

An example configuration for a PostgreSQL or Redis container look like:

_postgreSqlContainer = new ContainerBuilder()
    .WithImage("postgres:15.1")
    .WithPortBinding(5432, true)
    .WithEnvironment("POSTGRES_DB", "postgres")
    .WithEnvironment("POSTGRES_USER", "postgres")
    .WithEnvironment("POSTGRES_PASSWORD", Guid.NewGuid().ToString())
    .WithWaitStrategy(Wait.ForUnixContainer().UntilCommandIsCompleted("pg_isready"))
    .Build();

_redisContainer = new ContainerBuilder()
    .WithImage("redis:7.0")
    .WithPortBinding(6379, true)
    .WithWaitStrategy(Wait.ForUnixContainer().UntilCommandIsCompleted("redis-cli", "ping"))
    .Build();

Please note that we will be supporting pre-configured modules (e.g. PostgreSQL), including best practices in the future. This will reduce the configuration to a bare minimum, typically requiring only a single line:

_redisContainer = new RedisBuilder().Build();
_postgreSqlContainer = new PostgreSqlBuilder().Build();

I believe that integrating Testcontainers into the OpenTelemetry .NET implementation could be a great way to improve the testing experience. I am happy to help integrate Testcontainers into OpenTelemetry .NET, and I look forward to potentially collaborating with all of you.

Thanks for all the hard work you do to maintain and improve OpenTelemetry!

Is your feature request related to a problem?

-

Describe the solution you'd like:

-

Describe alternatives you've considered.

-

Additional Context

-

@HofmeisterAn HofmeisterAn added the enhancement New feature or request label Feb 15, 2023
@cijothomas cijothomas added the infra Infra work - CI/CD, code coverage, linters label Feb 15, 2023
@cijothomas
Copy link
Member

Thanks @HofmeisterAn ! Happy to incorporate this to replace our manual spinning up of docker for some of the tests.
Would you be willing to offer a PR to replace one test (check the link below to see one sql test which require sql server spun up in a container) to use this approach so we can quickly see the benefits?

https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/test/OpenTelemetry.Instrumentation.SqlClient.Tests/SqlClientTests.cs#L85

@Kielek
Copy link
Contributor

Kielek commented Feb 15, 2023

@HofmeisterAn, if you have some time, please review also auto instrumentation repository.
It heavily depends on Testcontainers, but any advices to improve the code are welcomed.

Ref: https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/d9eb0250d2f1527b7b950247e2f88017929b371b/test/IntegrationTests/MySqlDataTests.cs

@HofmeisterAn
Copy link
Contributor Author

HofmeisterAn commented Feb 15, 2023

Would you be willing to offer a PR to replace one test (check the link below to see one sql test which require sql server spun up in a container) to use this approach so we can quickly see the benefits?

OC, I will take a look at it. In case I have questions, I will reply here.

It heavily depends on Testcontainers, but any advices to improve the code are welcomed.

Sure, I can take a look at it afterwards.

@HofmeisterAn
Copy link
Contributor Author

Since we were able to enable the MSSQL integration tests as mentioned by @cijothomas, I think we can close the issue.

if you have some time, please review also auto instrumentation repository.
It heavily depends on Testcontainers, but any advices to improve the code are welcomed.

@Kielek, I will take a look at the opentelemetry-dotnet-instrumentation repository in the next few days and create a follow-up issue there.

Thanks everyone, great collaboration 🙌.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request infra Infra work - CI/CD, code coverage, linters
Projects
None yet
Development

No branches or pull requests

3 participants