-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add opentelemetry #67
base: main
Are you sure you want to change the base?
Conversation
Use Jaeger for tracing
Add diagnostics for aspdotnet core, middleware, sqlserver, ef core, http clients, and action/result filters for controller actions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
11 file(s) reviewed, 14 comment(s)
Edit PR Review Bot Settings | Greptile
@@ -199,6 +199,7 @@ public void ConfigureServices(IServiceCollection services) | |||
{ | |||
config.Conventions.Add(new ApiExplorerGroupConvention()); | |||
config.Conventions.Add(new PublicApiControllersModelConvention()); | |||
config.Filters.Add(new TracingAttribute()); // Add tracing to controller actions and results |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Adding tracing to all controller actions may introduce performance overhead. Consider selective tracing for critical paths only.
{ | ||
IdentityModelEventSource.ShowPII = true; | ||
app.UseSerilog(env, appLifetime, globalSettings); | ||
|
||
// Middleware telemetry | ||
DiagnosticsHelpers.AddMiddlewareDiagnostics(serviceProvider); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Middleware diagnostics may miss some middleware. Ensure comprehensive coverage or implement fallback monitoring.
@@ -217,11 +218,15 @@ public void Configure( | |||
IWebHostEnvironment env, | |||
IHostApplicationLifetime appLifetime, | |||
GlobalSettings globalSettings, | |||
ILogger<Startup> logger) | |||
ILogger<Startup> logger, | |||
IServiceProvider serviceProvider) | |||
{ | |||
IdentityModelEventSource.ShowPII = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Showing PII in logs could lead to security vulnerabilities. Ensure this is disabled in production environments.
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.5.1-beta.1" /> | ||
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.5.1-beta.1" /> | ||
<PackageReference Include="OpenTelemetry.Instrumentation.SqlClient" Version="1.5.1-beta.1" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: These packages are in beta. Consider using stable versions for production, or document the use of beta packages.
_actionActivity.AddTag("exception", context.Exception.ToString()); | ||
_actionActivity.AddTag("exceptionStackTrace", context.Exception.StackTrace); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Be cautious about logging full exception details, as it may expose sensitive information. Consider logging only exception type and message
if (_activitySource.StartActivity(name, ActivityKind.Server) is Activity activity) | ||
{ | ||
_activities[name] = activity; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: This could potentially lead to a memory leak if activities are not properly removed. Consider implementing a cleanup mechanism
_activities[name].AddTag("exception", exception.ToString()); | ||
_activities[name].AddTag("exceptionStackTrace", exception.StackTrace); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Logging full exception details might expose sensitive information. Consider logging only necessary information
if (name == "Microsoft.AspNetCore.MiddlewareAnalysis.AnalysisMiddleware" || !_activities.ContainsKey(name)) | ||
{ | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: The activity might have already been stopped if an exception occurred. Add a check to ensure the activity is still running before stopping it
if (name == "Microsoft.AspNetCore.MiddlewareAnalysis.AnalysisMiddleware" || !_activities.ContainsKey(name)) | ||
{ | ||
return; | ||
} | ||
_activities[name].Stop(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider removing the activity from the dictionary after stopping it to prevent potential memory leaks
services.AddOpenTelemetry().WithTracing(tracerProviderBuilder => | ||
tracerProviderBuilder | ||
.AddSource(diagnosticsConfig.ActivitySource.Name) | ||
.ConfigureResource(resource => resource | ||
.AddService(diagnosticsConfig.ServiceName)) | ||
.AddAspNetCoreInstrumentation() | ||
.AddSqlClientInstrumentation() | ||
.AddEntityFrameworkCoreInstrumentation() | ||
.AddHttpClientInstrumentation() | ||
.AddOtlpExporter()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider adding sampling to reduce the volume of telemetry data in production
Type of change
Objective
Adds opentelemetry-based tracing to server projects. Note: tracing is used exclusively as a system profiler to aid in performance optimizations, not intended to trace usage at all. Please let me know if you find some leaked PII in here!
Code changes
TracingAttribute
. It works OK, but the library it relies on, Microsoft.Extensions.MiddlewareAnalysis, is poorly documented and seems to be long-forgotten. Sometimes it seems to randomly miss middlewares, but It certainly catches more than if we didn't have it...MiddlewareAnalysisDiagnosticsHelper
Before you submit
dotnet format --verify-no-changes
) (required)Greptile Summary
This pull request introduces OpenTelemetry-based tracing to the server projects, focusing on system profiling for performance optimization without tracking user-specific data.
docker-compose.yml
for distributed tracing analysisTracingAttribute
insrc/Core/Utilities/TracingAttribute.cs
to wrap controller actions and results with tracing activitiesDiagnosticsConfig
insrc/SharedWeb/Health/DiagnosticsConfig.cs
to configure ActivitySource based on project nameMiddlewareAnalysisDiagnosticAdapter
insrc/SharedWeb/Health/MiddlewareAnalysisDiagnosticAdapter.cs
for middleware execution tracingsrc/Api/Startup.cs
to integrate tracing and middleware telemetry in the application pipeline