diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..cd967fc --- /dev/null +++ b/.dockerignore @@ -0,0 +1,25 @@ +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/.idea +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/azds.yaml +**/bin +**/charts +**/docker-compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md \ No newline at end of file diff --git a/Sample.MoneyTransfer.Api/RunWebApp.cs b/Sample.MoneyTransfer.Api/RunWebApp.cs index eedf39b..2937db0 100644 --- a/Sample.MoneyTransfer.Api/RunWebApp.cs +++ b/Sample.MoneyTransfer.Api/RunWebApp.cs @@ -1,5 +1,4 @@ -using Digma.MassTransit.Integration; -using MassTransit; +using MassTransit; using OpenTelemetry.Trace; using OpenTelemetry.Resources; using OpenTelemetry.Instrumentation.Digma; @@ -17,6 +16,38 @@ namespace Sample.MoneyTransfer.API; public class RunWebApp { + static void AddOpenTelemetry(IServiceCollection services, IConfiguration configuration, string otlpExporterUrl, string ? commitHash) + { + var otelBuilder = services.AddOpenTelemetry(); + var serviceName = typeof(RunWebApp).Assembly.GetName().Name!; + services.UseDigmaHttpDiagnosticObserver(); + var resourceBuilder = ResourceBuilder.CreateDefault() + .AddTelemetrySdk() + .AddService(serviceName) + .AddDigmaAttributes(configure => + { + if(commitHash is not null) configure.CommitId = commitHash; + configure.NamespaceRoot = "Sample"; + }) + .AddEnvironmentVariableDetector(); + + + otelBuilder + .WithTracing(builder => builder + .AddHttpClientInstrumentation() + .AddAspNetCoreInstrumentation(config => config.RecordException = true) + .SetResourceBuilder(resourceBuilder) + .AddOtlpExporter(c => + { + + c.Endpoint = new Uri(otlpExporterUrl); + c.Protocol = OtlpExportProtocol.Grpc; + }) + .SetErrorStatusOnException() + .AddSource("*") + ); + } + public static void Run(string[] args) { //Standard MVC boilerplate @@ -29,9 +60,10 @@ public static void Run(string[] args) builder.Services.AddSwaggerGen(); builder.Services.AddTransient(); builder.Services.AddTransient(); + - var digmaUrl = builder.Configuration.GetSection("Digma").GetValue("URL"); - Console.WriteLine($"Digma Url: {digmaUrl}"); + var otlpExporterUrl = builder.Configuration["OtlpExporterUrl"]; + Console.WriteLine($"OtlpExporterUrl: {otlpExporterUrl}"); var serviceName = typeof(RunWebApp).Assembly.GetName().Name; var serviceVersion = typeof(RunWebApp).Assembly.GetName().Version!.ToString(); @@ -89,36 +121,9 @@ public static void Run(string[] args) Console.WriteLine($"GetLocalCommitHash: {commitHash}"); builder.Services.UseDigmaHttpDiagnosticObserver(); - builder.Services.UseDigmaMassTransitConsumeObserver(o => - { - o.Observe(); - o.Observe(); - }); - - //Configure opentelemetry - builder.Services.AddOpenTelemetry().WithTracing(builder => builder - .AddAspNetCoreInstrumentation(options =>{options.RecordException = true;}) - .AddHttpClientInstrumentation() - .SetResourceBuilder( - ResourceBuilder.CreateDefault() - .AddTelemetrySdk() - .AddService(serviceName: serviceName, serviceVersion: serviceVersion ?? "0.0.0") - .AddDigmaAttributes(configure => - { - if(commitHash is not null) configure.CommitId = commitHash; - configure.SpanMappingPattern = @"(?[\S\.]+)\/(?\S+)\.(?\S+)"; - configure.SpanMappingReplacement = @"${ns}.Controllers.${class}.${method}"; - }) - ) - .AddOtlpExporter(c => - { - - c.Endpoint = new Uri(digmaUrl); - c.Protocol = OtlpExportProtocol.Grpc; - }) - .AddSource("*") - ); + AddOpenTelemetry(builder.Services, builder.Configuration, otlpExporterUrl, commitHash); + builder.Services .AddDbContext(options => options.UseInMemoryDatabase(databaseName: "Vault")); diff --git a/Sample.MoneyTransfer.Api/Sample.MoneyTransfer.API.csproj b/Sample.MoneyTransfer.Api/Sample.MoneyTransfer.API.csproj index e041984..8518fe9 100644 --- a/Sample.MoneyTransfer.Api/Sample.MoneyTransfer.API.csproj +++ b/Sample.MoneyTransfer.Api/Sample.MoneyTransfer.API.csproj @@ -14,8 +14,7 @@ - - + diff --git a/Sample.MoneyTransfer.Api/appsettings.json b/Sample.MoneyTransfer.Api/appsettings.json index e7ddae8..8872942 100644 --- a/Sample.MoneyTransfer.Api/appsettings.json +++ b/Sample.MoneyTransfer.Api/appsettings.json @@ -14,10 +14,7 @@ } } }, - "Digma": { - //Set URL to local Digma backend or cloud instance - "URL": "http://localhost:5050" - }, + "OtlpExporterUrl":"http://localhost:3050", // "RabbitMq": { // "Host": "localhost", // "Username": "admin", diff --git a/Sample.MoneyTransfer.Api/docker-compose.yml b/Sample.MoneyTransfer.Api/docker-compose.yml index 2b3f84f..5f472be 100644 --- a/Sample.MoneyTransfer.Api/docker-compose.yml +++ b/Sample.MoneyTransfer.Api/docker-compose.yml @@ -9,6 +9,7 @@ services: - Digma__URL=http://digma-collector-api:5050 - DEPLOYMENT_COMMIT_ID - DEPLOYMENT_ENV + - DIGMA_ENV_TYPE ports: - "7151:7151" networks: