How do I set UserID in AWS XRay sdk traces within dotnet core web api using httpcontext

342 views Asked by At

I'm interested in setting an xray "trace" UserID within an asp.net core web api (based on authenticated user claims contained within HttpContext User.Claims) To me, it makes sense that if OAuth token has for example some claims containing identity information regarding the client of an api, that the xray trace have some attribute which is also contained within the claims (user email, or even custom claim)

What method do I need to call on the AWS XRay SDK in order to manually set this value?

Is there a method on an instance of AWSXRayRecorder?

Ive tried the below but this does not appear to be the solution, rather just a weak attempt or educated guess.

            AWSXRayRecorder recorder = AWSXRayRecorder.Instance;
            recorder.AddAnnotation("UserID", "123");
            recorder.AddAnnotation("User", "456");

How does the sdk allow this type of control? Does it allow this type of control such that we can set the value of UserID?

Here you can see within the analytics tab, User is not set (showing "-") enter image description here

I understand I can use annotations in a similar way, but here what I am specifically asking about is what shows on the UI above, the "User"

Ive also tried the below, however, this does not appear to have any effect on what I see on the analytics

    var segment1 = (Segment)AWSXRayRecorder.Instance.GetEntity();
    var segment2 = (Segment)AWSXRayRecorder.Instance.TraceContext.GetEntity();
    segment1.SetUser("User1");
    segment2.SetUser("User2");
1

There are 1 answers

2
Bhautik Pipaliya On

I think currently you can set values like userID or user in the trace data using AddAnnotation or AddMetadata method. Would you be able to explain why AddAnnotation method is not the right usage for your use case? I don't think X-Ray SDK supports any other APIs to set such values other than AddAnnotation and AddMetadata methods.