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

Sort instrumentations before adding them to ByteBuddy #1326

Merged
merged 2 commits into from
Oct 6, 2020

Conversation

pavolloffay
Copy link
Member

Signed-off-by: Pavol Loffay p.loffay@gmail.com

Use case: I am adding custom instrumenations that depend on the existing instrumentation from the core (for instance to get the current span). I want to make sure that the existing instrumentation is added to ByteBuddy before my custom instrumentation.

@iNikem
Copy link
Contributor

iNikem commented Oct 5, 2020

How exactly do you think achieving the desired order? Can you give an example?

@pavolloffay
Copy link
Member Author

How exactly do you think achieving the desired order? Can you give an example?

Let's say upstream instrumentation is named A.class the dependent custom instrumentation will have name AZ.class

BTW. I have noticed that the instrumentations are always loaded in alphanumeric order, however the java service loader does not document that it's guaranteed so I would like to sort them before adding to BB.

@iNikem
Copy link
Contributor

iNikem commented Oct 5, 2020

You mean, e.g. JMSMessageListenerInstrumentationZ.class ? Seems like very hacky :( Although I have to admit, I don't have a better option right away, I am not sure this is viable long term solution

@pavolloffay
Copy link
Member Author

Seems like very hacky :( Although I have to admit, I don't have a better option right away, I am not sure this is viable long term solution

At least it solves my problem :) It is clearly described that it's better to combine advice methods, however this is not always possible. The custom instrumentations are tested with the upstream version so the bugs should be easily detected.

An alternative approach could be to expose getPriority() in instrumentations and sort based on that. That said this is currently a blocker for me, could we move it forward?

@iNikem
Copy link
Contributor

iNikem commented Oct 5, 2020

@trask @tylerbenson WDYT?

@trask
Copy link
Member

trask commented Oct 5, 2020

An alternative approach could be to expose getPriority() in instrumentations and sort based on that

I like this, glowroot has similar:

https://github.com/glowroot/instrumentation/blob/0a70212737947f40b0cc90d90016a6b5db8f8b95/instrumentation-api/src/main/java/org/glowroot/instrumentation/api/weaving/Advice.java#L105-L120

I like the term "order" over "priority" because the term priority is always unclear to me whether low or high values have preference (thanks linux 😂). But I can live with priority if others prefer that.

@tylerbenson
Copy link
Member

I also don't like the "alphabetical sort" idea. I don't have strong feelings between order/priority.

@iNikem
Copy link
Contributor

iNikem commented Oct 5, 2020

+1 for Order

@pavolloffay
Copy link
Member Author

Alright let's go with the order

Signed-off-by: Pavol Loffay <p.loffay@gmail.com>
@pavolloffay
Copy link
Member Author

@iNikem @trask I have updated the PR and added getOrder to instrumenter interface.

Copy link
Contributor

@anuraaga anuraaga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool

@iNikem
Copy link
Contributor

iNikem commented Oct 6, 2020

So instrumentations with bigger order will override those with smaller order?

@pavolloffay
Copy link
Member Author

So instrumentations with bigger order will override those with smaller order?

Nothing is overridden. All advice methods will be applied. However the advice method that runs as second has access to the current span from the previous advice method.

@iNikem
Copy link
Contributor

iNikem commented Oct 6, 2020

Right, we are not talking about overriding here, we are talking about the order of application.

@mateuszrzeszutek
Copy link
Member

So instrumentation with order=1 runs after another one that has order=0, right? Could you include this in the JavaDoc?

Signed-off-by: Pavol Loffay <p.loffay@gmail.com>
@pavolloffay
Copy link
Member Author

@mateuszrzeszutek I have added to it to the Javadoc.

Copy link
Member

@trask trask left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@trask trask merged commit 3952290 into open-telemetry:master Oct 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants