-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added support for OTel-based distributed tracing (#20)
* feat: added support for distributed tracing * refactor: moved all .proto in the Protos root folder
- Loading branch information
Showing
20 changed files
with
208 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using System.Reflection; | ||
using OpenTelemetry.Trace; | ||
using OpenTelemetry.Exporter; | ||
using OpenTelemetry.Metrics; | ||
using OpenTelemetry.Resources; | ||
using Npgsql; | ||
|
||
namespace Vfps.Tracing | ||
{ | ||
public static class TracingConfigurationExtensions | ||
{ | ||
public static WebApplicationBuilder AddTracing(this WebApplicationBuilder builder) | ||
{ | ||
var assembly = Assembly.GetExecutingAssembly().GetName(); | ||
var assemblyVersion = assembly.Version?.ToString() ?? "unknown"; | ||
var tracingExporter = builder.Configuration.GetValue("Tracing:Exporter", "jaeger").ToLowerInvariant(); | ||
var serviceName = builder.Configuration.GetValue("Tracing:ServiceName", assembly.Name); | ||
|
||
var rootSamplerType = builder.Configuration.GetValue("Tracing:RootSampler", "AlwaysOnSampler"); | ||
var samplingRatio = builder.Configuration.GetValue("Tracing:SamplingProbability", 0.1d); | ||
|
||
Sampler rootSampler = rootSamplerType switch | ||
{ | ||
nameof(AlwaysOnSampler) => new AlwaysOnSampler(), | ||
nameof(AlwaysOffSampler) => new AlwaysOffSampler(), | ||
nameof(TraceIdRatioBasedSampler) => new TraceIdRatioBasedSampler(samplingRatio), | ||
_ => throw new ArgumentException($"Unsupported sampler type '{rootSamplerType}'"), | ||
}; | ||
|
||
builder.Services.AddOpenTelemetryTracing(options => | ||
{ | ||
options | ||
.ConfigureResource(r => r.AddService( | ||
serviceName: serviceName, | ||
serviceVersion: assemblyVersion, | ||
serviceInstanceId: Environment.MachineName)) | ||
.SetSampler(new ParentBasedSampler(rootSampler)) | ||
.AddNpgsql() | ||
.AddSource(Program.ActivitySource.Name) | ||
.AddAspNetCoreInstrumentation(o => | ||
{ | ||
o.Filter = (r) => | ||
{ | ||
var ignoredPaths = new[] | ||
{ | ||
"/healthz", | ||
"/readyz", | ||
"/livez" | ||
}; | ||
|
||
var path = r.Request.Path.Value!; | ||
return !ignoredPaths.Any(path.Contains); | ||
}; | ||
}); | ||
|
||
switch (tracingExporter) | ||
{ | ||
case "jaeger": | ||
options.AddJaegerExporter(); | ||
builder.Services.Configure<JaegerExporterOptions>(builder.Configuration.GetSection("Tracing:Jaeger")); | ||
break; | ||
|
||
case "otlp": | ||
var endpoint = builder.Configuration.GetValue("Tracing:Otlp:Endpoint", ""); | ||
options.AddOtlpExporter(otlpOptions => otlpOptions.Endpoint = new Uri(endpoint)); | ||
break; | ||
} | ||
}); | ||
|
||
return builder; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"Tracing": { | ||
"IsEnabled": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
version: v1 | ||
lint: | ||
ignore: | ||
- google/ | ||
- Protos/google/ | ||
use: | ||
- DEFAULT | ||
except: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.