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();
|
||||
|
||||
|
||||
2
build.sh
2
build.sh
@@ -2,7 +2,7 @@
|
||||
|
||||
|
||||
MAJOR_VERSION="1"
|
||||
MINOR_VERSION="3"
|
||||
MINOR_VERSION="4"
|
||||
VERSION="$MAJOR_VERSION.$MINOR_VERSION"
|
||||
|
||||
dotnet publish Management.Web/ \
|
||||
|
||||
@@ -31,22 +31,12 @@ services:
|
||||
- 4318:4318 # OTLP http receiver
|
||||
- 55679:55679 # zpages extension
|
||||
|
||||
# The zipkin process services the UI, and also exposes a POST endpoint that
|
||||
# instrumentation can send trace data to.
|
||||
zipkin:
|
||||
image: ghcr.io/openzipkin/zipkin-slim
|
||||
container_name: zipkin
|
||||
# Environment settings are defined here https://github.com/openzipkin/zipkin/blob/master/zipkin-server/README.md#environment-variables
|
||||
environment:
|
||||
- STORAGE_TYPE=mem
|
||||
# Point the zipkin at the storage backend
|
||||
# - MYSQL_HOST=mysql
|
||||
# Uncomment to enable self-tracing
|
||||
# - SELF_TRACING_ENABLED=true
|
||||
# Uncomment to increase heap size
|
||||
# - JAVA_OPTS=-Xms128m -Xmx128m -XX:+ExitOnOutOfMemoryError
|
||||
ports:
|
||||
# Port used for the Zipkin UI and HTTP Api
|
||||
- 9411:9411
|
||||
# Uncomment to enable debug logging
|
||||
# command: --logging.level.zipkin2=DEBUG
|
||||
|
||||
23
ops/local-dev/docker-compose.yml
Normal file
23
ops/local-dev/docker-compose.yml
Normal file
@@ -0,0 +1,23 @@
|
||||
services:
|
||||
collector:
|
||||
image: otel/opentelemetry-collector-contrib
|
||||
volumes:
|
||||
- ../otel-collector-config.yml:/etc/otelcol-contrib/config.yaml
|
||||
ports:
|
||||
- 1888:1888 # pprof extension
|
||||
- 8888:8888 # Prometheus metrics exposed by the Collector
|
||||
- 8889:8889 # Prometheus exporter metrics
|
||||
- 13133:13133 # health_check extension
|
||||
- 4317:4317 # OTLP gRPC receiver
|
||||
- 4318:4318 # OTLP http receiver
|
||||
- 55679:55679 # zpages extension
|
||||
|
||||
zipkin:
|
||||
image: ghcr.io/openzipkin/zipkin-slim
|
||||
container_name: zipkin
|
||||
# Environment settings are defined here https://github.com/openzipkin/zipkin/blob/master/zipkin-server/README.md#environment-variables
|
||||
environment:
|
||||
- STORAGE_TYPE=mem
|
||||
ports:
|
||||
- 9411:9411
|
||||
# command: --logging.level.zipkin2=DEBUG
|
||||
Reference in New Issue
Block a user