#How do I get the current TraceId?

67 messages · Page 1 of 1 (latest)

fervent valley
#

hi,
I am working on an Azure Functions app using Sentry and I want to send the Sentry TraceId to the response so that the end user (the client using my API) can see the TraceId and use it for support. How can I get TraceID? I only see the EventId in the SentrySdk.LastEventId. Thanks!

sacred flax
#

What SDK are you using?

hardy pendant
#

I think something like

var traceHeader = SentrySdk.GetTraceHeader();
var traceId = traceHeader?.TraceId;

should work.

#

But that's on the .NET Azure Functions app. There you get the extracted ID from the incoming request's headers. And then you want to send it back to the frontend?
Ideally, it'd originate from the frontend anyway. So.. fair What SDK are you using? there?

fervent valley
#

hi @sacred flax and @hardy pendant , thanks for the reply. I am working on a Unity game using Unity SDK with a Azure Functions Isolated Worker backend. I am using 2 different DSNs, which is what was suggeste to me in the chat here when I first set it up, one for the mobile game and one for the backend. When the backend has an error, it generates a traceId which right now is a guid I create, and returns this to the client so the client can do something with it (like report to support for example) right now we are in development so we use it to search the logs to identify root cause of the issue. I would like to avoid having multiple TraceIds, the Sentry one and the application one, and just send the client the TraceId from Sentry and use that in my log searches

#

Or, if there's a way for my to override sentries TraceId, that would work too, and I could tell Sentry to use my Guid for its traceId

#

it doesn't seem like GetTraceHeader() is what I need. I need the TraceId that when I search, it pulls up the issue like this:

#

when I tried using Trace Header, it was a different value

#

if I use EventId returned from LogException, it will come up in the search based on EventID, but I really don't want to do that, because I want to be able to search for non-failure scenarios this way as well sometimes

hardy pendant
#

Oh I see. Lemme think for a second.

fervent valley
#

hey @hardy pendant , any idea how to get that TraceId I need?

hardy pendant
#

Ah snap! Sorry about that!

#

So in your system, the Unity game is the origin of those requests, right? So the game does something, it causes an error on your Azure Functions App and you want to connect that request with the error.

fervent valley
#

yeah, basically. So I return a TraceId back to the game client from the server which is a GUID I generate. Actually, I'm using the AzureFunctions_InvocationId which Sentry seems to automatically Tag for me

#

this way, the user can give me a log or screenshot which contains TraceId for troubleshooting later

hardy pendant
#

Are you using unity web reqests for that?

fervent valley
#

yes

hardy pendant
#

Unfortunately, we don't have proper wrappers setup for that just yet. But you could grab and set the traceID on the Unity side of things and add those to the request.

#

Sentry then is able to connect those and you can keep using the ID

#

I've got a sample of pretty much exactly that here

fervent valley
#

awesome thanks, what is the contents of the Baggage thing?

#

do I need to do something special with these values, or will the Azure Fucntions Sentry middelware autoamtically handle these headers for me?

hardy pendant
#

The baggage contains the sampling decision from the upstream SDK and some dynamic sampling contexts

hardy pendant
fervent valley
#

nice, I'll playh with these and see what I get

#

is there any examples of how to best setup Sentry for Unity when you instantiate it and set the config values?

hardy pendant
#

Other than letting it self-initialize? If you need to do any programmatic configuration you can set those build-/runtime configs. Those are scriptable objects that have their config method invoked right before the SDK initializes.
We're splitting it in two (unfortunately) because of mobile, where the native SDKs for Android and iOS do their own thing before the engine even kicks in.

#

We've got a sample here

hardy pendant
#

Let me know if you run into any problems. More than happy to iterate on the SDK

fervent valley
#

thanks, does the trace header and baggage change on each request?

#

my game client and game backend should use 2 different DSNs, right?

fervent valley
#

I just tried making 30 API calls in a row in a test, and it seems like it did not generate 30 unique Sentry sentryTraceHeader guid values. It looks like it re-used the values sort of randomly? sometimes 2 consecutive calls used the same one, sometimes it was 4 consecutive calls, sometimes just one call and it changed

#

Is this what you expected? this seems odd to me, I thought this was for tracing an individual request, so each request would have a unique ID?

fervent valley
#

hey, I think I resolved the issue. I added a transaction at the start and end of each request, and now the SentrySDk.GetTraceHeader() stuff is unique on each request

#

it's pretty cool! now I can see both backend and game client working together in traces. But what is the gap in between, do you know?

hardy pendant
#

Hmm.. odd, that does not look right. The function is auto-instrumented by the SDK? Or are you creating a transaction yourself?

fervent valley
#

hey @hardy pendant , I'm doing a custom transaction, its because like I said previously, without doing this, Sentry was re-using the trace headers for multiple requests, so I have to manually create a transaction on each request. I got this idea from the sample you showed so I'm guessing thats "by design"

#

I moved around some tracing code, does this look right now?

hardy pendant
# fervent valley

It does. I'm just curious to know what's up with those huge delays before and after the function does its thing.

fervent valley
#

the stuff before and after that I assume is the game client code doing things like making the network call, parsing, etc

hardy pendant
#

Fair enough, actually

#

But the relationship now looks like it's supposed to

fervent valley
#

awesome, thank you for confirming

#

one thing I noticed is the UserId is some random guid on the client. I am not setting it explicitly

#

on the server, its working as expected as I am setting it explicitly

#

do you know where that random UserId comes from on the client?

hardy pendant
fervent valley
#

wow, the hierarchy and screenshot feature of Sentry is freaking incredible

#

the one thing I'm not seeing though is the server side of failures. For example, client sends a web request to server, includes the baggage/traceID, and server logs an error, client receives the error and it also logs an error. I am now looking at the clients error, and do not see any links to the server

#

of course, since I actually print a traceId to the message (I have my server send my own custom TraceID to client which I log on both sides), I can find it by searching the server logs with that TraceId, but I'm surprised that I dont just see the automatic connection in the error log for the client

hardy pendant
#

There should be a "View Full Trace" at the top left of the issue

fervent valley
#

thanks @hardy pendant , I didn't see the server side in the full trace. I'll try to send an example

#

I am also getting some warnings, so maybe I am doing something wrong

#

for example, I get this : "Sentry: (Warning) Push scope called in global mode, returning. "

fervent valley
#

I also get this warning, I posted in a different thread:

#
UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
Sentry.Unity.Integrations.UnityLogHandlerIntegration:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[]) (at /sentry-unity/src/Sentry.Unity/Integrations/UnityLogHandlerIntegration.cs:99)
UnityEngine.Logger:Log (UnityEngine.LogType,string,object)
Sentry.Unity.UnityLogger:Log (Sentry.SentryLevel,string,System.Exception,object[]) (at /sentry-unity/src/Sentry.Unity/UnityLogger.cs:33)
Sentry.Extensibility.DiagnosticLoggerExtensions:LogIfEnabled (Sentry.Extensibility.IDiagnosticLogger,Sentry.SentryLevel,System.Exception,string) (at /sentry-unity/src/sentry-dotnet/src/Sentry/Extensibility/DiagnosticLoggerExtensions.cs:428)
Sentry.Extensibility.DiagnosticLoggerExtensions:LogWarning (Sentry.SentryOptions,string) (at /sentry-unity/src/sentry-dotnet/src/Sentry/Extensibility/DiagnosticLoggerExtensions.cs:178)
Sentry.GlobalSessionManager:ResumeSession () (at /sentry-unity/src/sentry-dotnet/src/Sentry/GlobalSessionManager.cs:384)
Sentry.Internal.Hub:ResumeSession () (at /sentry-unity/src/sentry-dotnet/src/Sentry/Internal/Hub.cs:320)
Sentry.Unity.Integrations.SessionIntegration/<>c__DisplayClass2_0:<Register>b__0 () (at /sentry-unity/src/Sentry.Unity/Integrations/SessionIntegration.cs:27)
Sentry.Unity.SentryMonoBehaviour:UpdatePauseStatus (bool) (at /sentry-unity/src/Sentry.Unity/SentryMonoBehaviour.cs:86)
Sentry.Unity.SentryMonoBehaviour:OnApplicationFocus (bool) (at /sentry-unity/src/Sentry.Unity/SentryMonoBehaviour.cs:99)
UnityEditor.HostView:OnFocus ()```
fervent valley
#

@hardy pendant it seems like I had to register things twice to get everything working in my azure functions startup

#

no idea why, but now profiling and ful trace is working

#

here's what my program.cs looks like now. I had to add the builder.UseSentry() with all the options, and then the plumbing seems to work now fully. PReviously I was using logging.AddSentry only. I am doing the logging.AddSentry since I am using the MS ILogging integration which I thought made that part required

hardy pendant
#

Hey @fervent valley, sorry, I just got back, let me catch up here

hardy pendant