add guage

This commit is contained in:
Simon Larsen
2023-10-24 13:35:26 +01:00
parent 67447c0bd7
commit ee54a324d7
23 changed files with 352 additions and 9 deletions

View File

@@ -56,12 +56,17 @@ builder.Services.AddOpenTelemetry()
System.Console.WriteLine($"OTLP Exporter is using {opt.Protocol} protocol and endpoint {opt.Endpoint}");
}));
// Custom metrics for the application
var greeterMeter = new Meter("OtPrGrYa.Example");
// Metrics.
builder.Services.AddOpenTelemetry()
.ConfigureResource(resource => resource
.AddService(serviceName: builder.Environment.ApplicationName))
.WithMetrics(metrics => metrics
.AddAspNetCoreInstrumentation()
.AddMeter("OtPrGrYa.Example")
.AddConsoleExporter((exporterOptions, metricReaderOptions) =>
{
metricReaderOptions.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds = 1000;
@@ -75,15 +80,29 @@ builder.Services.AddOpenTelemetry()
}
System.Console.WriteLine($"OTLP Exporter is using {opt.Protocol} protocol and endpoint {opt.Endpoint}");
}));
var app = builder.Build();
// Custom metrics for the application
var greeterMeter = new Meter("OtPrGrYa.Example", "1.0.0");
var value = 1;
int getGuage()
{
value++;
return value;
}
greeterMeter.CreateObservableGauge("ThreadCount", () => new[] { new Measurement<int>(ThreadPool.ThreadCount) });
var countGreetings = greeterMeter.CreateCounter<int>("greetings.count", description: "Counts the number of greetings");
// Custom ActivitySource for the application
var greeterActivitySource = new ActivitySource("OtPrGrJa.Example");

View File

@@ -11,7 +11,8 @@
"OpenTelemetry.Exporter.Console": "1.6.0",
"OpenTelemetry.Exporter.OpenTelemetryProtocol": "1.6.0",
"OpenTelemetry.Extensions.Hosting": "1.6.0",
"OpenTelemetry.Instrumentation.AspNetCore": "1.5.1-beta.1"
"OpenTelemetry.Instrumentation.AspNetCore": "1.5.1-beta.1",
"OpenTelemetry.Instrumentation.Runtime": "1.5.1"
},
"runtime": {
"otel-dotnet.dll": {}
@@ -207,6 +208,17 @@
}
}
},
"OpenTelemetry.Instrumentation.Runtime/1.5.1": {
"dependencies": {
"OpenTelemetry.Api": "1.6.0"
},
"runtime": {
"lib/net6.0/OpenTelemetry.Instrumentation.Runtime.dll": {
"assemblyVersion": "1.5.1.0",
"fileVersion": "1.5.1.0"
}
}
},
"System.Diagnostics.DiagnosticSource/7.0.2": {
"dependencies": {
"System.Runtime.CompilerServices.Unsafe": "6.0.0"
@@ -398,6 +410,13 @@
"path": "opentelemetry.instrumentation.aspnetcore/1.5.1-beta.1",
"hashPath": "opentelemetry.instrumentation.aspnetcore.1.5.1-beta.1.nupkg.sha512"
},
"OpenTelemetry.Instrumentation.Runtime/1.5.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-F3uYt/T5+2YZCxZmAdoK7u5AZxqDLYaTj5ddZ//Cnn9x+Lys9D9wRzqizQgKpAQJJ6prVh0TcBEbCCpEKKDZvw==",
"path": "opentelemetry.instrumentation.runtime/1.5.1",
"hashPath": "opentelemetry.instrumentation.runtime.1.5.1.nupkg.sha512"
},
"System.Diagnostics.DiagnosticSource/7.0.2": {
"type": "package",
"serviceable": true,

View File

@@ -1 +1 @@
02d49b3f532cf4a85b56dd95b3e5d85b0107dabb
dd731758440b2020b7f6d3116dc659916e251de0

View File

@@ -33,3 +33,4 @@
/Users/nawazdhandala/Projects/OneUptime/oneuptime/Examples/otel-dotnet/bin/Debug/net6.0/Grpc.Net.Client.dll
/Users/nawazdhandala/Projects/OneUptime/oneuptime/Examples/otel-dotnet/bin/Debug/net6.0/Grpc.Net.Common.dll
/Users/nawazdhandala/Projects/OneUptime/oneuptime/Examples/otel-dotnet/bin/Debug/net6.0/OpenTelemetry.Exporter.OpenTelemetryProtocol.dll
/Users/nawazdhandala/Projects/OneUptime/oneuptime/Examples/otel-dotnet/bin/Debug/net6.0/OpenTelemetry.Instrumentation.Runtime.dll

View File

@@ -53,6 +53,10 @@
"OpenTelemetry.Instrumentation.AspNetCore": {
"target": "Package",
"version": "[1.5.1-beta.1, )"
},
"OpenTelemetry.Instrumentation.Runtime": {
"target": "Package",
"version": "[1.5.1, )"
}
},
"imports": [

View File

@@ -300,6 +300,18 @@
"Microsoft.AspNetCore.App"
]
},
"OpenTelemetry.Instrumentation.Runtime/1.5.1": {
"type": "package",
"dependencies": {
"OpenTelemetry.Api": "[1.5.1, 2.0.0)"
},
"compile": {
"lib/net6.0/OpenTelemetry.Instrumentation.Runtime.dll": {}
},
"runtime": {
"lib/net6.0/OpenTelemetry.Instrumentation.Runtime.dll": {}
}
},
"System.Diagnostics.DiagnosticSource/7.0.2": {
"type": "package",
"dependencies": {
@@ -794,6 +806,24 @@
"opentelemetry.instrumentation.aspnetcore.nuspec"
]
},
"OpenTelemetry.Instrumentation.Runtime/1.5.1": {
"sha512": "F3uYt/T5+2YZCxZmAdoK7u5AZxqDLYaTj5ddZ//Cnn9x+Lys9D9wRzqizQgKpAQJJ6prVh0TcBEbCCpEKKDZvw==",
"type": "package",
"path": "opentelemetry.instrumentation.runtime/1.5.1",
"files": [
".nupkg.metadata",
".signature.p7s",
"lib/net462/OpenTelemetry.Instrumentation.Runtime.dll",
"lib/net462/OpenTelemetry.Instrumentation.Runtime.xml",
"lib/net6.0/OpenTelemetry.Instrumentation.Runtime.dll",
"lib/net6.0/OpenTelemetry.Instrumentation.Runtime.xml",
"lib/netstandard2.0/OpenTelemetry.Instrumentation.Runtime.dll",
"lib/netstandard2.0/OpenTelemetry.Instrumentation.Runtime.xml",
"opentelemetry-icon-color.png",
"opentelemetry.instrumentation.runtime.1.5.1.nupkg.sha512",
"opentelemetry.instrumentation.runtime.nuspec"
]
},
"System.Diagnostics.DiagnosticSource/7.0.2": {
"sha512": "hYr3I9N9811e0Bjf2WNwAGGyTuAFbbTgX1RPLt/3Wbm68x3IGcX5Cl75CMmgT6WlNwLQ2tCCWfqYPpypjaf2xA==",
"type": "package",
@@ -919,7 +949,8 @@
"OpenTelemetry.Exporter.Console >= 1.6.0",
"OpenTelemetry.Exporter.OpenTelemetryProtocol >= 1.6.0",
"OpenTelemetry.Extensions.Hosting >= 1.6.0",
"OpenTelemetry.Instrumentation.AspNetCore >= 1.5.1-beta.1"
"OpenTelemetry.Instrumentation.AspNetCore >= 1.5.1-beta.1",
"OpenTelemetry.Instrumentation.Runtime >= 1.5.1"
]
},
"packageFolders": {
@@ -974,6 +1005,10 @@
"OpenTelemetry.Instrumentation.AspNetCore": {
"target": "Package",
"version": "[1.5.1-beta.1, )"
},
"OpenTelemetry.Instrumentation.Runtime": {
"target": "Package",
"version": "[1.5.1, )"
}
},
"imports": [

View File

@@ -1,6 +1,6 @@
{
"version": 2,
"dgSpecHash": "q904JtYq1lLAiuvP7YZAtmR3LAs+M1o5PfyM0Qj3+rz7xX6AiTGIp6qCcuj7Ew3h5sJxnepofHEAg0S9PbQ4GA==",
"dgSpecHash": "kBspCkYM82GK1DjcaFAxuFSJ5yyZDweAwZpDY3NzeL+b5AIdlzzBhqF0w41aQvigzdX60YHSP8Nwd+epadb4vQ==",
"success": true,
"projectFilePath": "/Users/nawazdhandala/Projects/OneUptime/oneuptime/Examples/otel-dotnet/otel-dotnet.csproj",
"expectedPackageFiles": [
@@ -28,6 +28,7 @@
"/Users/nawazdhandala/.nuget/packages/opentelemetry.exporter.opentelemetryprotocol/1.6.0/opentelemetry.exporter.opentelemetryprotocol.1.6.0.nupkg.sha512",
"/Users/nawazdhandala/.nuget/packages/opentelemetry.extensions.hosting/1.6.0/opentelemetry.extensions.hosting.1.6.0.nupkg.sha512",
"/Users/nawazdhandala/.nuget/packages/opentelemetry.instrumentation.aspnetcore/1.5.1-beta.1/opentelemetry.instrumentation.aspnetcore.1.5.1-beta.1.nupkg.sha512",
"/Users/nawazdhandala/.nuget/packages/opentelemetry.instrumentation.runtime/1.5.1/opentelemetry.instrumentation.runtime.1.5.1.nupkg.sha512",
"/Users/nawazdhandala/.nuget/packages/system.diagnostics.diagnosticsource/7.0.2/system.diagnostics.diagnosticsource.7.0.2.nupkg.sha512",
"/Users/nawazdhandala/.nuget/packages/system.memory/4.5.3/system.memory.4.5.3.nupkg.sha512",
"/Users/nawazdhandala/.nuget/packages/system.runtime.compilerservices.unsafe/6.0.0/system.runtime.compilerservices.unsafe.6.0.0.nupkg.sha512",

View File

@@ -8,3 +8,10 @@
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0

View File

@@ -12,6 +12,7 @@
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.6.0" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.6.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.5.1-beta.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.5.1" />
</ItemGroup>
</Project>