Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a way to enrich dependencies logs with context at the beginning of api call #1624

Merged
merged 11 commits into from
Aug 6, 2021

Conversation

xiao-lix
Copy link
Contributor

@xiao-lix xiao-lix commented Aug 3, 2021

  • Add a new configuration to allow users to enrich custom properties on requests.
  • The configuration is a call back function that add extra properties to the dependency data, and it works on both xhr and fetch requests.

Related Issue: How to enrich dependencies logs with context at the beginning of api call? #1561

Update:
The basic usage would be adding configurations when AI gets initialized:

addRequestContext: (requestContext) => {
    if (requestContext.xhr) {
        return {
            test: "ajax context",
            xhrStatus: requestContext.status,
            xhrTimeout: requestContext.xhr.timeout,
            xhrResonseURL: requestContext.xhr.responseURL
        }
    }
    if (requestContext.request && requestContext.response) {
        return {
            test: "fetch context",
            fetchStatus: requestContext.status,
            fetchRequestURL: requestContext.request,
            fetchReponseType: requestContext.response.type,
            fetchResponseStatusText: requestContext.response.statusText 
        }
    }
}

And in the payload, you'll find the specified dimensions are captured in properties field:
eg. Fetch
image

eg. Ajax
image

@xiao-lix xiao-lix requested a review from MSNev August 3, 2021 21:33
@MSNev MSNev added this to the 2.x.x (Next Release) milestone Aug 4, 2021
@xiao-lix xiao-lix merged commit 2c27497 into master Aug 6, 2021
@streamingpro
Copy link

Thanks for these changes. Is there a way to access request body as part of xhr? We have single endpoint for all the dependency calls (API), but the request body has the specific method name. Currently, AI log shows single operation name and we are not able to figure out the actual method until we look at end-to-end transaction. If there is a way, we want to get the method name from request body and append it to the operation name before sending the telemetry. Thank you

@MSNev
Copy link
Collaborator

MSNev commented Sep 28, 2021

Sorry for the delay as I've been away.

I just went through the code and I can't see a current way to directly access the send body of the request.
We could probably keep a reference of the request around so that once we get the response it could be passed onto the addRequestContext function... But that will have memory impacts as the formatted body (JSON) will hang around longer.

Another possible way (as you own the backend) would be to return a response header with the extra information that you want to include and then in the addRequestContext() you should then be able to access the response headers and figure out what you want to log??

@streamingpro
Copy link

Thank you for the suggestions. I am sorry for the delay in updating here. I went with second option as I just needed a operation name and I have full control on back-end. Thank you once again for your time and looking into my request/question.

@MSNev MSNev deleted the lxiao/request-callback branch March 1, 2022 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants