Skip to content

Commit

Permalink
Merge pull request #19 from digma-ai/upgrade-dependencies
Browse files Browse the repository at this point in the history
Upgrade dependencies
  • Loading branch information
shaykeren authored Sep 9, 2024
2 parents 2ce5371 + f58903c commit bc437d9
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 39 deletions.
25 changes: 25 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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
71 changes: 38 additions & 33 deletions Sample.MoneyTransfer.Api/RunWebApp.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Digma.MassTransit.Integration;
using MassTransit;
using MassTransit;
using OpenTelemetry.Trace;
using OpenTelemetry.Resources;
using OpenTelemetry.Instrumentation.Digma;
Expand All @@ -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
Expand All @@ -29,9 +60,10 @@ public static void Run(string[] args)
builder.Services.AddSwaggerGen();
builder.Services.AddTransient<TransferFundsEventConsumer>();
builder.Services.AddTransient<QueryOptimizationEventConsumer>();


var digmaUrl = builder.Configuration.GetSection("Digma").GetValue<string>("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();

Expand Down Expand Up @@ -89,36 +121,9 @@ public static void Run(string[] args)

Console.WriteLine($"GetLocalCommitHash: {commitHash}");
builder.Services.UseDigmaHttpDiagnosticObserver();
builder.Services.UseDigmaMassTransitConsumeObserver(o =>
{
o.Observe<TransferFundsEventConsumer>();
o.Observe<QueryOptimizationEventConsumer>();
});

//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 = @"(?<ns>[\S\.]+)\/(?<class>\S+)\.(?<method>\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<Gringotts >(options =>
options.UseInMemoryDatabase(databaseName: "Vault"));
Expand Down
3 changes: 1 addition & 2 deletions Sample.MoneyTransfer.Api/Sample.MoneyTransfer.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
<PackageReference Include="MathNet.Numerics" Version="5.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.4" />
<PackageReference Include="OpenTel.Digma.MassTransit.Integration" Version="0.6.14" />
<PackageReference Include="OpenTel.Instrumentation.Digma" Version="0.6.14" />
<PackageReference Include="OpenTel.Instrumentation.Digma" Version="0.6.16" />
<PackageReference Include="OpenTelemetry" Version="1.6.0" />
<PackageReference Include="OpenTelemetry.Contrib.Instrumentation.EntityFrameworkCore" Version="1.0.0-beta2" />
<PackageReference Include="OpenTelemetry.Exporter.Jaeger" Version="1.6.0-rc.1" />
Expand Down
5 changes: 1 addition & 4 deletions Sample.MoneyTransfer.Api/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions Sample.MoneyTransfer.Api/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ services:
- Digma__URL=http://digma-collector-api:5050
- DEPLOYMENT_COMMIT_ID
- DEPLOYMENT_ENV
- DIGMA_ENV_TYPE
ports:
- "7151:7151"
networks:
Expand Down

0 comments on commit bc437d9

Please sign in to comment.