-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
36 lines (31 loc) · 995 Bytes
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System.Diagnostics.Metrics;
using OpenTelemetry.Resources;
using OpenTelemetry.Metrics;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddOpenTelemetryMetrics(metricsProvider =>
{
metricsProvider
.AddConsoleExporter()
.AddOtlpExporter()
.AddMeter("otel.demo.metric")
.SetResourceBuilder(ResourceBuilder.CreateDefault()
.AddService(serviceName: "otel.demo", serviceVersion: "0.0.1")
);
});
var app = builder.Build();
var otel_metric = new Meter("otel.demo.metric", "0.0.1");
var randomNum = new Random();
// Create two metrics
var obs_gauge1 = otel_metric.CreateObservableGauge<int>("otel.demo.metric.gauge1", () =>
{
return randomNum.Next(10, 80);
});
var obs_gauge2 = otel_metric.CreateObservableGauge<double>("otel.demo.metric.gauge2", () =>
{
return randomNum.NextDouble();
});
app.MapGet("/otelmetric", () =>
{
return "Hello, Otel-Metric!";
});
app.Run();