getsentry / sentry-dotnet

Sentry SDK for .NET
https://docs.sentry.io/platforms/dotnet
MIT License
579 stars 206 forks source link

Ability to overwrite start/end times for transactions and spans #2683

Open vhn opened 11 months ago

vhn commented 11 months ago

Problem Statement

We have some systems that are not able to run a sentry SDK directly due to limitations on 3rd party binaries. For these we are planning to manually log a simple span tree and forward the data to a proxy. The proxy would then use a Sentry SDK to upload it all to Sentry.

In order for this to work we'd need to be able to manually set start/end times via the Sentry SDK as they won't be matching the times on the proxy, but rather those manually recorded on the instrumented servers.

Solution Brainstorm

We've noticed that the Javascript SDK has the ability to change these fields, see here: https://github.com/getsentry/sentry-javascript/blob/5c2546f6ee2b56321614ba6f78811163fe783db4/packages/core/src/tracing/span.ts https://github.com/getsentry/sentry-javascript/blob/5c2546f6ee2b56321614ba6f78811163fe783db4/packages/core/src/tracing/transaction.ts

whereas those same members are private in the .NET equivalent: https://github.com/getsentry/sentry-dotnet/blob/d59d08cbc54669a0e98684516d2ce54839b6b55a/src/Sentry/Transaction.cs

Is this something you would be open to adding so our proxy does not have to use javascript? Or, if the use case is better handled some other way that we've missed, please let us know.

jamescrosswell commented 11 months ago

Hey @vhn, interesting problem. I'm wondering, are you planning to send the events through to Sentry asynchronously and would there likely be a consequential delay between when the event gets raised and when it gets created on your proxy agent?

In any event, one possible solution I can think of with the existing code base is that Transaction does have a public constructor that takes an ITransaction parameter. Typically what it's receiving there is an instance of TransactionTracer... the idea is that TransactionTracer is the ITransaction implementation that gets used for most of the instrumentation and Transaction is basically immutable - it's really just there to send things across the wire to Sentry.io.

Unfortunately the setter methods on TransactionTracer.StartTimeStamp and TransactionTracer.EndTimeStamp are also internal, but it would be possible to create your own tracer (a custom implementation of ITransaction... maybe a ForwardingTransaction: ITransaction class or something and you could pass that into the Transaction constructor.