mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
added quieter opentelemetry tracer
This commit is contained in:
14
Management.Web/ConfigurationSetup.cs
Normal file
14
Management.Web/ConfigurationSetup.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
public static class ConfigurationSetup
|
||||
{
|
||||
public static void Canvas(WebApplicationBuilder builder)
|
||||
{
|
||||
var canvas_token = builder.Configuration["CANVAS_TOKEN"] ?? throw new Exception("CANVAS_TOKEN is null");
|
||||
|
||||
var canvas_url = builder.Configuration["CANVAS_URL"];
|
||||
if (canvas_url == null)
|
||||
{
|
||||
Console.WriteLine("CANVAS_URL is null, defaulting to https://snow.instructure.com");
|
||||
builder.Configuration["CANVAS_URL"] = "https://snow.instructure.com";
|
||||
}
|
||||
}
|
||||
}
|
||||
20
Management.Web/CustomConsoleExporter.cs
Normal file
20
Management.Web/CustomConsoleExporter.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System.Diagnostics;
|
||||
using OpenTelemetry;
|
||||
|
||||
public class CustomConsoleExporter : BaseExporter<Activity>
|
||||
{
|
||||
public override ExportResult Export(in Batch<Activity> batch)
|
||||
{
|
||||
using var scope = SuppressInstrumentationScope.Begin();
|
||||
|
||||
foreach (var activity in batch)
|
||||
{
|
||||
string[] ignoreOperations = [
|
||||
"Microsoft.AspNetCore.Hosting.HttpRequestIn",
|
||||
];
|
||||
if (!ignoreOperations.Contains(activity.OperationName))
|
||||
Console.WriteLine($"{activity.OperationName}: {activity.DisplayName}");
|
||||
}
|
||||
return ExportResult.Success;
|
||||
}
|
||||
}
|
||||
@@ -18,37 +18,30 @@ using OpenTelemetry.Logs;
|
||||
using OpenTelemetry.Metrics;
|
||||
using OpenTelemetry.Resources;
|
||||
using OpenTelemetry.Trace;
|
||||
using OpenTelemetry;
|
||||
|
||||
DotEnv.Load();
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
var canvas_token = builder.Configuration["CANVAS_TOKEN"];
|
||||
if (canvas_token == null)
|
||||
throw new Exception("CANVAS_TOKEN is null");
|
||||
var canvas_url = builder.Configuration["CANVAS_URL"];
|
||||
if (canvas_url == null)
|
||||
{
|
||||
Console.WriteLine("CANVAS_URL is null, defaulting to https://snow.instructure.com");
|
||||
builder.Configuration["CANVAS_URL"] = "https://snow.instructure.com";
|
||||
}
|
||||
ConfigurationSetup.Canvas(builder);
|
||||
|
||||
const string serviceName = "canvas-management";
|
||||
|
||||
// builder.Logging.AddOpenTelemetry(options =>
|
||||
// {
|
||||
// options
|
||||
// .SetResourceBuilder(
|
||||
// ResourceBuilder
|
||||
// .CreateDefault()
|
||||
// .AddService(serviceName)
|
||||
// )
|
||||
// .AddOtlpExporter(o =>
|
||||
// {
|
||||
// o.Endpoint = new Uri("http://localhost:4317/");
|
||||
// })
|
||||
// .AddConsoleExporter();
|
||||
// });
|
||||
builder.Logging.AddOpenTelemetry(options =>
|
||||
{
|
||||
options
|
||||
.SetResourceBuilder(
|
||||
ResourceBuilder
|
||||
.CreateDefault()
|
||||
.AddService(serviceName)
|
||||
)
|
||||
.AddOtlpExporter(o =>
|
||||
{
|
||||
o.Endpoint = new Uri("http://localhost:4317/");
|
||||
});
|
||||
// .AddConsoleExporter();
|
||||
});
|
||||
|
||||
builder.Services.AddOpenTelemetry()
|
||||
.ConfigureResource(resource => resource.AddService(serviceName))
|
||||
@@ -59,15 +52,16 @@ builder.Services.AddOpenTelemetry()
|
||||
o.Endpoint = new Uri("http://localhost:4317/");
|
||||
})
|
||||
.AddAspNetCoreInstrumentation()
|
||||
.AddConsoleExporter()
|
||||
);
|
||||
// .WithMetrics(metrics => metrics
|
||||
// .AddOtlpExporter(o => {
|
||||
// o.Endpoint = new Uri("http://localhost:4317/");
|
||||
// })
|
||||
// .AddAspNetCoreInstrumentation()
|
||||
// .AddConsoleExporter()
|
||||
// );
|
||||
.AddProcessor(new BatchActivityExportProcessor(new CustomConsoleExporter()))
|
||||
)
|
||||
.WithMetrics(metrics => metrics
|
||||
.AddOtlpExporter(o =>
|
||||
{
|
||||
o.Endpoint = new Uri("http://localhost:4317/");
|
||||
}
|
||||
)
|
||||
.AddAspNetCoreInstrumentation()
|
||||
);
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddRazorPages();
|
||||
@@ -133,3 +127,4 @@ foreach (var address in addresses)
|
||||
}
|
||||
|
||||
app.WaitForShutdown();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user