Add opentelemetry
Type of change
- [ ] Bug fix
- [x] New feature development
- [ ] Tech debt (refactoring, code cleanup, dependency upgrades, etc)
- [ ] Build/deploy pipeline (DevOps)
- [ ] Other
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
- launch.json/tasks.json/launchSettings.json Include Events project in builds, correct the port for events processor self host to be consistent with visual studio build settings and pattern for self-host version of other project (it was previously using the Events port by mistake).
- docker-compose: include jaeger as a tool to analyze tracing
- api/startup: Add tracing attribute to controller action execution. Turn on middleware telemetry to monitor execution of middlewares
- tracingAttribute: Logs tracing even at begin and end of action execution as well as wrapping result processing
- entityFramework.csproj: include EF-specific opentelemetry package
- DiagnosticsConfig: helper class to configure activity and service information in shared service configuration helpers.
- MiddlewareAnalysisDiagnosticsHelper: The idea behind this is to wrap all middleware with trace activities to track their execution time -- much like the controller action wrapping done by the
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... - diagnosticsHelpers: static class to add configuration helpers for diagnostics purposes
- serviceCollectionExtension: Add openetelemetry and diagnostic event emissions listened to by
MiddlewareAnalysisDiagnosticsHelper
Before you submit
- Please check for formatting errors (
dotnet format --verify-no-changes) (required) - If making database changes - make sure you also update Entity Framework queries and/or migrations
- Please add unit tests where it makes sense to do so (encouraged but not required)
- If this change requires a documentation update - notify the documentation team
- If this change has particular deployment requirements - notify the DevOps team
Checkmarx One – Scan Summary & Details – 15a9b098-9cbb-4edd-9a6f-f9367606e20c
No New Or Fixed Issues Found
Relates to https://github.com/bitwarden/server/pull/3224.
@justindbaur given your OTel usage I thought you might have some thoughts on this.
Codecov Report
Attention: Patch coverage is 73.19588% with 26 lines in your changes missing coverage. Please review.
Project coverage is 40.95%. Comparing base (
d9aa27d) to head (d1a83cf).
Additional details and impacted files
@@ Coverage Diff @@
## main #3316 +/- ##
==========================================
+ Coverage 40.90% 40.95% +0.05%
==========================================
Files 1260 1264 +4
Lines 60087 60184 +97
Branches 5486 5498 +12
==========================================
+ Hits 24580 24651 +71
- Misses 34373 34393 +20
- Partials 1134 1140 +6
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.