From 17de331195ed3d954097011bc434495642dbc1da Mon Sep 17 00:00:00 2001 From: Paulo Janotti Date: Tue, 28 Jun 2022 18:00:59 -0700 Subject: [PATCH] Correct the case for MongoDB (#899) --- docs/config.md | 2 +- ...goDbController.cs => MongoDBController.cs} | 4 ++-- integrations.json | 4 ++-- run-example.sh | 2 +- .../EnvironmentConfigurationTracerHelper.cs | 2 +- .../Configuration/TracerInstrumentation.cs | 4 ++-- .../MongoDb/MongoClientIntegration.cs | 4 ++-- ...goDbCollection.cs => MongoDBCollection.cs} | 20 +++++++++---------- .../{MongoDbTests.cs => MongoDBTests.cs} | 16 +++++++-------- .../Configuration/SettingsTests.cs | 2 +- .../Properties/launchSettings.json | 2 +- 11 files changed, 31 insertions(+), 31 deletions(-) rename examples/AspNetCoreMvc/Controllers/{MongoDbController.cs => MongoDBController.cs} (94%) rename test/IntegrationTests/{MongoDbCollection.cs => MongoDBCollection.cs} (80%) rename test/IntegrationTests/{MongoDbTests.cs => MongoDBTests.cs} (88%) diff --git a/docs/config.md b/docs/config.md index 29647d30b1..9f3f47e4af 100644 --- a/docs/config.md +++ b/docs/config.md @@ -41,7 +41,7 @@ for more details. | `AspNet` | ASP.NET Core | * | source | | `GraphQL` | [GraphQL](https://www.nuget.org/packages/GraphQL/) | ≥2.3.0 & < 3.0.0 | bytecode | | `HttpClient` | [System.Net.Http.HttpClient](https://docs.microsoft.com/dotnet/api/system.net.http.httpclient) and [System.Net.HttpWebRequest](https://docs.microsoft.com/dotnet/api/system.net.httpwebrequest) | * | source | -| `MongoDb` | [MongoDB.Driver.Core](https://www.nuget.org/packages/MongoDB.Driver.Core) **Not supported on .NET Framework** | ≥2.3.0 & < 3.0.0 | source & bytecode | +| `MongoDB` | [MongoDB.Driver.Core](https://www.nuget.org/packages/MongoDB.Driver.Core) **Not supported on .NET Framework** | ≥2.3.0 & < 3.0.0 | source & bytecode | | `SqlClient` | [Microsoft.Data.SqlClient](https://www.nuget.org/packages/Microsoft.Data.SqlClient) and [System.Data.SqlClient](https://www.nuget.org/packages/System.Data.SqlClient) | * | source | ### Instrumented metrics libraries and frameworks diff --git a/examples/AspNetCoreMvc/Controllers/MongoDbController.cs b/examples/AspNetCoreMvc/Controllers/MongoDBController.cs similarity index 94% rename from examples/AspNetCoreMvc/Controllers/MongoDbController.cs rename to examples/AspNetCoreMvc/Controllers/MongoDBController.cs index 7f8f65f724..e4982b9a55 100644 --- a/examples/AspNetCoreMvc/Controllers/MongoDbController.cs +++ b/examples/AspNetCoreMvc/Controllers/MongoDBController.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,7 +23,7 @@ namespace Examples.AspNetCoreMvc.Controllers; [Route("api/mongo")] -public class MongoDbController : ControllerBase +public class MongoDBController : ControllerBase { private const string ConnectionString = "mongodb://localhost:27017"; diff --git a/integrations.json b/integrations.json index 4afda7f834..f72da818d9 100644 --- a/integrations.json +++ b/integrations.json @@ -1,6 +1,6 @@ [ { - "name": "MongoDb", + "name": "MongoDB", "method_replacements": [ { "caller": {}, @@ -21,7 +21,7 @@ }, "wrapper": { "assembly": "OpenTelemetry.AutoInstrumentation", - "type": "OpenTelemetry.AutoInstrumentation.Instrumentations.MongoDb.MongoClientIntegration", + "type": "OpenTelemetry.AutoInstrumentation.Instrumentations.MongoDB.MongoClientIntegration", "action": "CallTargetModification" } } diff --git a/run-example.sh b/run-example.sh index d672f2359b..138884cf07 100644 --- a/run-example.sh +++ b/run-example.sh @@ -60,7 +60,7 @@ docker-compose -f ./dev/docker-compose.yaml -f ./examples/docker-compose.yaml up # instrument and run HTTP server app in background export {OTEL_DOTNET_AUTO_TRACES_PLUGINS,OTEL_DOTNET_AUTO_METRICS_PLUGINS}="Examples.AspNetCoreMvc.OtelSdkPlugin, Examples.AspNetCoreMvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null:Examples.Vendor.Distro.Plugin, Examples.Vendor.Distro, Version=0.0.1.0, Culture=neutral, PublicKeyToken=null" -ENABLE_PROFILING=${enableProfiling} OTEL_DOTNET_AUTO_TRACES_ENABLED_INSTRUMENTATIONS="AspNet,MongoDb,SqlClient" OTEL_DOTNET_AUTO_METRICS_ADDITIONAL_SOURCES="MyCompany.MyProduct.MyLibrary" OTEL_DOTNET_AUTO_METRICS_ENABLED_INSTRUMENTATIONS="AspNet,NetRuntime,HttpClient" OTEL_SERVICE_NAME="aspnet-server" OTEL_TRACES_EXPORTER=${tracesExporter} OTEL_METRICS_EXPORTER=${metricsExporter} ./dev/instrument.sh ASPNETCORE_URLS="http://127.0.0.1:8080/" dotnet ./examples/AspNetCoreMvc/bin/${configuration}/${aspNetAppTargetFramework}/Examples.AspNetCoreMvc.dll & +ENABLE_PROFILING=${enableProfiling} OTEL_DOTNET_AUTO_TRACES_ENABLED_INSTRUMENTATIONS="AspNet,MongoDB,SqlClient" OTEL_DOTNET_AUTO_METRICS_ADDITIONAL_SOURCES="MyCompany.MyProduct.MyLibrary" OTEL_DOTNET_AUTO_METRICS_ENABLED_INSTRUMENTATIONS="AspNet,NetRuntime,HttpClient" OTEL_SERVICE_NAME="aspnet-server" OTEL_TRACES_EXPORTER=${tracesExporter} OTEL_METRICS_EXPORTER=${metricsExporter} ./dev/instrument.sh ASPNETCORE_URLS="http://127.0.0.1:8080/" dotnet ./examples/AspNetCoreMvc/bin/${configuration}/${aspNetAppTargetFramework}/Examples.AspNetCoreMvc.dll & unset OTEL_DOTNET_AUTO_TRACES_PLUGINS OTEL_DOTNET_AUTO_METRICS_PLUGINS ./dev/wait-local-port.sh 8080 diff --git a/src/OpenTelemetry.AutoInstrumentation/Configuration/EnvironmentConfigurationTracerHelper.cs b/src/OpenTelemetry.AutoInstrumentation/Configuration/EnvironmentConfigurationTracerHelper.cs index f1c7295381..e82dfa85f3 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configuration/EnvironmentConfigurationTracerHelper.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configuration/EnvironmentConfigurationTracerHelper.cs @@ -29,7 +29,7 @@ internal static class EnvironmentConfigurationTracerHelper [TracerInstrumentation.HttpClient] = builder => builder.AddHttpClientInstrumentation(), [TracerInstrumentation.AspNet] = builder => builder.AddSdkAspNetInstrumentation(), [TracerInstrumentation.SqlClient] = builder => builder.AddSqlClientInstrumentation(), - [TracerInstrumentation.MongoDb] = builder => builder.AddSource("MongoDB.Driver.Core.Extensions.DiagnosticSources") + [TracerInstrumentation.MongoDB] = builder => builder.AddSource("MongoDB.Driver.Core.Extensions.DiagnosticSources") }; public static TracerProviderBuilder UseEnvironmentVariables(this TracerProviderBuilder builder, TracerSettings settings) diff --git a/src/OpenTelemetry.AutoInstrumentation/Configuration/TracerInstrumentation.cs b/src/OpenTelemetry.AutoInstrumentation/Configuration/TracerInstrumentation.cs index 51b76d4bcf..6f12ca7c00 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configuration/TracerInstrumentation.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configuration/TracerInstrumentation.cs @@ -42,7 +42,7 @@ public enum TracerInstrumentation GraphQL, /// - /// MongoDb instrumentation. + /// MongoDB instrumentation. /// - MongoDb + MongoDB } diff --git a/src/OpenTelemetry.AutoInstrumentation/Instrumentations/MongoDb/MongoClientIntegration.cs b/src/OpenTelemetry.AutoInstrumentation/Instrumentations/MongoDb/MongoClientIntegration.cs index 57f227e591..bace102ea0 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Instrumentations/MongoDb/MongoClientIntegration.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Instrumentations/MongoDb/MongoClientIntegration.cs @@ -21,7 +21,7 @@ using System.Text.RegularExpressions; using OpenTelemetry.AutoInstrumentation.CallTarget; -namespace OpenTelemetry.AutoInstrumentation.Instrumentations.MongoDb +namespace OpenTelemetry.AutoInstrumentation.Instrumentations.MongoDB { /// /// MongoDB.Driver.MongoClient calltarget instrumentation @@ -34,7 +34,7 @@ namespace OpenTelemetry.AutoInstrumentation.Instrumentations.MongoDb ParameterTypeNames = new[] { "MongoDB.Driver.MongoClientSettings" }, MinimumVersion = "2.3.0", MaximumVersion = "2.65535.65535", - IntegrationName = "MongoDb")] + IntegrationName = "MongoDB")] public class MongoClientIntegration { #if NETCOREAPP3_1_OR_GREATER diff --git a/test/IntegrationTests/MongoDbCollection.cs b/test/IntegrationTests/MongoDBCollection.cs similarity index 80% rename from test/IntegrationTests/MongoDbCollection.cs rename to test/IntegrationTests/MongoDBCollection.cs index daec89dc01..912d5b2a9b 100644 --- a/test/IntegrationTests/MongoDbCollection.cs +++ b/test/IntegrationTests/MongoDBCollection.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,19 +24,19 @@ namespace IntegrationTests.MongoDB; [CollectionDefinition(Name)] -public class MongoDbCollection : ICollectionFixture +public class MongoDBCollection : ICollectionFixture { - public const string Name = nameof(MongoDbCollection); + public const string Name = nameof(MongoDBCollection); } -public class MongoDbFixture : IAsyncLifetime +public class MongoDBFixture : IAsyncLifetime { - private const int MongoDbPort = 27017; - private const string MongoDbImage = "mongo:5.0.6"; + private const int MongoDBPort = 27017; + private const string MongoDBImage = "mongo:5.0.6"; private TestcontainersContainer _container; - public MongoDbFixture() + public MongoDBFixture() { Port = TcpPortProvider.GetOpenPort(); } @@ -59,10 +59,10 @@ public async Task DisposeAsync() private async Task LaunchMongoContainerAsync(int port) { var mongoContainersBuilder = new TestcontainersBuilder() - .WithImage(MongoDbImage) + .WithImage(MongoDBImage) .WithName($"mongo-db-{port}") - .WithPortBinding(port, MongoDbPort) - .WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(MongoDbPort)); + .WithPortBinding(port, MongoDBPort) + .WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(MongoDBPort)); var container = mongoContainersBuilder.Build(); await container.StartAsync(); diff --git a/test/IntegrationTests/MongoDbTests.cs b/test/IntegrationTests/MongoDBTests.cs similarity index 88% rename from test/IntegrationTests/MongoDbTests.cs rename to test/IntegrationTests/MongoDBTests.cs index bc4b9dcf28..7a0d3817cf 100644 --- a/test/IntegrationTests/MongoDbTests.cs +++ b/test/IntegrationTests/MongoDBTests.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,17 +24,17 @@ namespace IntegrationTests.MongoDB { - [Collection(MongoDbCollection.Name)] - public class MongoDbTests : TestHelper + [Collection(MongoDBCollection.Name)] + public class MongoDBTests : TestHelper { - private readonly MongoDbFixture _mongoDb; + private readonly MongoDBFixture _mongoDB; - public MongoDbTests(ITestOutputHelper output, MongoDbFixture mongoDb) + public MongoDBTests(ITestOutputHelper output, MongoDBFixture mongoDB) : base("MongoDB", output) { - _mongoDb = mongoDb; + _mongoDB = mongoDB; - SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_ENABLED_INSTRUMENTATIONS", "MongoDb"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_ENABLED_INSTRUMENTATIONS", "MongoDB"); SetEnvironmentVariable("OTEL_SERVICE_NAME", "TestApplication.MongoDB"); } @@ -46,7 +46,7 @@ public void SubmitsTraces() int agentPort = TcpPortProvider.GetOpenPort(); using (var agent = new MockZipkinCollector(Output, agentPort)) - using (var processResult = RunTestApplicationAndWaitForExit(agent.Port, arguments: $"--mongo-db {_mongoDb.Port}", enableStartupHook: true)) + using (var processResult = RunTestApplicationAndWaitForExit(agent.Port, arguments: $"--mongo-db {_mongoDB.Port}", enableStartupHook: true)) { Assert.True(processResult.ExitCode >= 0, $"Process exited with code {processResult.ExitCode} and exception: {processResult.StandardError}"); diff --git a/test/OpenTelemetry.AutoInstrumentation.Tests/Configuration/SettingsTests.cs b/test/OpenTelemetry.AutoInstrumentation.Tests/Configuration/SettingsTests.cs index f51b339030..62f72a7fcb 100644 --- a/test/OpenTelemetry.AutoInstrumentation.Tests/Configuration/SettingsTests.cs +++ b/test/OpenTelemetry.AutoInstrumentation.Tests/Configuration/SettingsTests.cs @@ -117,7 +117,7 @@ public void MetricExporter_SupportedValues(string metricExporter, MetricsExporte [InlineData(nameof(TracerInstrumentation.AspNet), TracerInstrumentation.AspNet)] [InlineData(nameof(TracerInstrumentation.GraphQL), TracerInstrumentation.GraphQL)] [InlineData(nameof(TracerInstrumentation.HttpClient), TracerInstrumentation.HttpClient)] - [InlineData(nameof(TracerInstrumentation.MongoDb), TracerInstrumentation.MongoDb)] + [InlineData(nameof(TracerInstrumentation.MongoDB), TracerInstrumentation.MongoDB)] [InlineData(nameof(TracerInstrumentation.SqlClient), TracerInstrumentation.SqlClient)] public void TracerSettings_Instrumentations_SupportedValues(string tracerInstrumentation, TracerInstrumentation expectedTracerInstrumentation) { diff --git a/test/test-applications/integrations/TestApplication.MongoDB/Properties/launchSettings.json b/test/test-applications/integrations/TestApplication.MongoDB/Properties/launchSettings.json index 3757301741..7c04535a8b 100644 --- a/test/test-applications/integrations/TestApplication.MongoDB/Properties/launchSettings.json +++ b/test/test-applications/integrations/TestApplication.MongoDB/Properties/launchSettings.json @@ -12,7 +12,7 @@ "DOTNET_ADDITIONAL_DEPS": "$(SolutionDir)bin\\tracer-home\\AdditionalDeps", "OTEL_TRACES_EXPORTER": "zipkin", "OTEL_EXPORTER_ZIPKIN_ENDPOINT": "http://127.0.0.1:9411/api/v2/spans", - "OTEL_DOTNET_AUTO_TRACES_ENABLED_INSTRUMENTATIONS": "MongoDb", + "OTEL_DOTNET_AUTO_TRACES_ENABLED_INSTRUMENTATIONS": "MongoDB", "OTEL_DOTNET_AUTO_DEBUG": "1", "OTEL_DOTNET_AUTO_TRACES_CONSOLE_EXPORTER_ENABLED": "true", "OTEL_DOTNET_AUTO_INTEGRATIONS_FILE": "$(SolutionDir)bin\\tracer-home\\integrations.json",