Adds .NET distributed tracing instrumentation & metrics.#1200
Adds .NET distributed tracing instrumentation & metrics.#1200fdcastel wants to merge 21 commits intoFirebirdSQL:masterfrom
Conversation
|
Included the final portion of #1196 (metrics) here, as it requires the same infrastructure as traces. |
|
Here is before and after comparison of Perf benchmark results on my machine. BenchmarkDotNet=v0.13.2, OS=Windows 11 (10.0.26120.2130)
AMD Ryzen 9 5950X, 1 CPU, 32 logical and 16 physical cores
.NET SDK=9.0.100-rc.2.24474.11
[Host] : .NET 8.0.10 (8.0.1024.46610), X64 RyuJIT AVX2
NuGet : .NET 6.0.35 (6.0.3524.45918), X64 RyuJIT AVX2
Project : .NET 6.0.35 (6.0.3524.45918), X64 RyuJIT AVX2
Jit=RyuJit Platform=X64 Toolchain=.NET 6.0
WarmupCount=3 Perf.CommandBenchmarkFirebirdSQL:master (Old) <-> fdcastel:add-telemetry-trace (New)
|
|
Thanks @willibrandon. This surely can be improved. Could you kindly share the steps/configuration you used for the above benchmark results? Mine here produces a comparison between |
|
@willibrandon I pushed a new PR in #1203 (it is based on this PR). Could you please clone it and run The script will compare the current project (built from sources with .NET8) with the latest NuGet release ( |
|
@fdcastel - Interesting, and thanks! Taking a look now. |
|
Okay, I see how the performance project works now with the conditional project/package reference, and with the latest Nuget release being the baseline. That is way better approach than the way I was attempting to compare the the results historically. @fdcastel - Thank you very much for showing me how the performance project works. I just want try and confirm we haven't regressed in someway with this change. |
47a5b9b to
fe2b942
Compare
|
Rebased with latest |
|
@cincuranet Do you wish to move this work forward? If yes, I could rebase it with the latest |
|
@fdcastel Yes. |
fe2b942 to
7fe1327
Compare
|
Rebased onto latest |
StartActivity() returns null when no listeners are interested in the
activity. The code accessed activity.IsAllDataRequested without a null
check, causing a NullReferenceException. Use the Npgsql-style pattern
'activity is not { IsAllDataRequested: true }' for early return.
Stopwatch ticks are not TimeSpan ticks when Stopwatch.IsHighResolution is true (most systems). TimeSpan.FromTicks(stopwatchTicks) produces incorrect durations. Use Stopwatch.GetElapsedTime() which correctly handles the frequency conversion.
The semantic conventions renamed db.system to db.system.name. The well-known value for Firebird is 'firebirdsql', not 'firebird'. Updated in both FbActivitySource (spans) and FbConnection (metrics).
The semantic conventions mark db.namespace as Conditionally Required when available. The connection's Database property is used as the value.
The semantic conventions mark error.type as Conditionally Required on failure. For FbException, use the SQLSTATE code; for other exceptions, use the full exception type name.
Per OTel semantic conventions, db.query.text and db.query.parameter.* are Opt-In level attributes that may expose sensitive data. They should not be collected by default. Added IsQueryTextTracingEnabled flag and reuse IsParameterLoggingEnabled for parameter tracing.
Replace hardcoded '1.0.0' version with the assembly's informational version, keeping the telemetry version in sync with the NuGet package.
…ecording TraceCommandException now records metrics immediately and resets _startedAtTicks so the later TraceCommandStop (called during Release) does not record a second, inflated duration that includes cleanup time.
- Remove db.transaction_id custom tag (not in OTel spec, causes server round-trip per traced command) - Remove commented-out db.snapshot_id code - Remove deprecated exception.escaped attribute - Remove NormalizeDbNull helper, inline DBNull check
- Set server.port on spans when using a non-default port - Set db.stored_procedure.name for StoredProcedure command types - Fix server.address in MetricsConnectionAttributes to not concatenate the port (server.port is now a separate attribute) - Clean up leftover placeholder comments
Set db.query.summary as the low-cardinality activity name on all spans. For Text commands, extract the first SQL verb (SELECT, INSERT, etc.) and use it as db.operation.name and in the activity name.
Debug.Assert checks that TraceCommandStart was called before the stop or exception path, helping catch lifecycle bugs during development.
Prevents potential NullReferenceException if metrics are recorded before the connection string is set.
Change GetMetrics() to return IEnumerable of tuples via Select instead of allocating a Dictionary via ToDictionary on every collection cycle. Also simplify GetConnectionMax to use Select instead of SelectMany.
Suggest default histogram bucket boundaries for operation duration and connection create time histograms, improving out-of-the-box resolution. Guarded by NET9_0_OR_GREATER since InstrumentAdvice is a .NET 9 API.
Expose the telemetry source names as public constants so consumers can easily subscribe: builder.AddSource(FbTelemetry.ActivitySourceName) and builder.AddMeter(FbTelemetry.MeterName). Internal code updated to use the constants.
Document the ActivitySource and Meter names, available span attributes, opt-in sensitive attributes, and available metrics with their types and semantic convention references.
|
New fixes / improvements: Critical fixes:
Semantic convention compliance:
Architecture improvements:
New features:
Documentation:
|
Initial work for #1196.