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

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

Closed
thoo1 opened this issue May 5, 2021 · 3 comments
Closed

Comments

@thoo1
Copy link

thoo1 commented May 5, 2021

Is your feature request related to a problem? Please describe.
API calls take some time. We have a use case where we'd like to capture some context at the beginning of the api call, and enrich the dependencies log with this context. We're finding that our current implementation is not using the public interface of app insights sdk and is pretty fragile.

Describe the solution you'd like
A way to hook into the start of the API call which app insights SDK has patch over the fetch and xhr functions. Then add some metadata to the telemetryItem object which would log as part of the "customDimensions"

Describe alternatives you've considered
Currently we do this by

  • patching over fetch and xhr functions in a similar way as the app insights sdk
  • in these patched functions we get the added "Request-Id" header that app insights adds, and use that as a key to add the context we want to enrich the log with, into a map.
  • so the map looks like {string: Context} where the string is the "Request-Id"
  • then in the telemetry initializer, we do a lookup in the map using telemetryItem.baseData.id to find the context and enrich the log

This is pretty fragile and isn't part of the interface of application insights sdk.

Additional context
Please feel free to contact me on teams (my alias is thoo) for more info

@MSNev
Copy link
Collaborator

MSNev commented May 26, 2021

Agree, I just went digging into the code to see if there would be an easier way than what you have already done and I can't find any other safer way that wouldn't get broken.

So yes, adding a callback to the config would probably be the easiest way to do this, and there are a couple of places in the code (_openHandler() and _createFetchRecord()) where it would make sense to have the callback called so the returned map could be added to the internal ajaxRecord, and them populated into the event -- which would still facilitate using a telemetryInitializer() to munge the data if required.

@MSNev
Copy link
Collaborator

MSNev commented Sep 13, 2021

v2.7.0 is not fully deployed to NPM and all CDN endpoints

@MSNev MSNev closed this as completed Sep 13, 2021
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants