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

Figure out a way to trace through AsyncIterator #5607

Closed
xirzec opened this issue Oct 16, 2019 · 6 comments
Closed

Figure out a way to trace through AsyncIterator #5607

xirzec opened this issue Oct 16, 2019 · 6 comments
Assignees
Labels
Azure.Core Client This issue points to a problem in the data-plane of the library.
Milestone

Comments

@xirzec
Copy link
Member

xirzec commented Oct 16, 2019

Today methods that use the AsyncIterator pattern return a PagedAsyncIterableIterator. Under the covers, these methods call into a generator that returns the shape AsyncIterableIterator that eventually delegate to a method that makes a single request.

It's easy to create tracing Spans for the underlying method that performs a request, but it's less clear about what Spans should be created for the iterator itself. Since an iterator may never finish iterating its entire collection, starting a Span at the beginning of iteration might never finish.

@xirzec xirzec self-assigned this Oct 16, 2019
@xirzec xirzec added Azure.Core Client This issue points to a problem in the data-plane of the library. and removed triage labels Oct 16, 2019
@xirzec
Copy link
Member Author

xirzec commented Oct 31, 2019

keyvault-keys and keyvault-secrets currently instrument list* operations, but the parent span ends as soon as the iterator is created, which isn't great, since then child spans can be longer.

It looks like appconfiguration maybe does the same.

@xirzec
Copy link
Member Author

xirzec commented Oct 31, 2019

Same in keyvault libs

@maorleger
Copy link
Member

maorleger commented Dec 15, 2021

Lots has changed since this issue was made! Going to list my thoughts and revisit in the new year:

keyvault-keys and keyvault-secrets currently instrument list* operations, but the parent span ends as soon as the iterator is created, which isn't great, since then child spans can be longer.

It looks like appconfiguration maybe does the same.

I also noticed that we're just tracing the creation of the iterator which doesn't really trace anything interesting so at the time I just forged ahead with tracing the page fetching operation instead.

const currentSetResponse = await withTrace(
"listPropertiesOfKeyVersionsPage",
optionsComplete,
async (updatedOptions) => this.client.getKeyVersions(this.vaultUrl, name, updatedOptions)
);

const currentSetResponse = await withTrace(
"listPropertiesOfKeyVersionsPage",
options || {},
async (updatedOptions) =>
this.client.getKeyVersions(continuationState.continuationToken!, name, updatedOptions)
);

The downside of this approach is:

  1. that can be a little confusing if you do something like
for await (const thingy of client.listThings) { ... }

And then end up with N spans (depending on number of pages and how many you consume) at the convenience layer called listThingsPage

  1. It leaks the implementation detail that for await is an abstraction over byPage

But it is nice to trace over it, otherwise you'll just end up with some rogue http spans anyway when tracingPolicy runs. And as a consumer you can wrap the iteration in a logical parent span

Next step for me would be to see what this looks like in Jaeger when you have 100 secrets or something

Going to revisit this and see if this approach makes sense for general guidance...

@maorleger
Copy link
Member

By the way, I demo'd this to @lmolkova and she was happy with the direction here. She had a few additional improvements like adding the continuation token as a span attribute.

If we are happy with the approach I listed above - @xirzec do you like this approach or not really? Assuming you are good with this - what do we need to close out this issue? Just guidance? Issues open for all packages? Update code for all packages?

image

@xirzec
Copy link
Member Author

xirzec commented Feb 9, 2022

This seems like the most sensible thing we can do, even if the method itself isn't public it's pretty clear what is going on. We could establish a convention for how we name this thing to make it consistent (e.g. always take the list method name and suffix with Page)

maorleger added a commit that referenced this issue Feb 17, 2022
### Packages impacted by this PR
@azure/data-tables

### Issues associated with this PR
- #20213
- #5607 

### Describe the problem that is addressed by this PR
Now that @azure/[email protected] is out, and hopefully the last version
before GA, we need to upgrade a few packages in order to dogfood both the
upgrade experience and the usage of these packages with the new instrumentation package.

My goal was to upgrade one AMQP package and a few HTTP packages in addition to 
core-rest-pipeline to collect feedback.

Upgrading Data Tables now allows us to start using the new APIs in a client package.

### Provide a list of related PRs _(if any)_
- #20240
@maorleger
Copy link
Member

I have #20399 demonstrating this approach and #20411 tracking adding all this info to the guidelines in the next semester so I think it's safe to close this. Let me know if you disagree and we can reopen it.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Azure.Core Client This issue points to a problem in the data-plane of the library.
Projects
None yet
Development

No branches or pull requests

3 participants