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

Add thrift javaagent instrumentation #8370

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

tkyun123
Copy link

Fix: #1573

For personal needs, I'm trying to trace my thrift application, and I finally Implemented a general thrift javaagent instrumentation , I'd like to share with those who hava same need.

I hava completed javaagent part, and I will complete tests within the next few weeks

@tkyun123 tkyun123 requested a review from a team April 26, 2023 17:14
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Apr 26, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

Copy link
Member

@mateuszrzeszutek mateuszrzeszutek left a comment

Choose a reason for hiding this comment

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

Hey @tkyun123,
Is this PR ready for review? Or perhaps did you want to open a draft PR?

@@ -71,7 +71,7 @@ tasks.withType<JavaCompile>().configureEach {
"-Xlint:-options",

// Fail build on any warning
"-Werror"
// "-Werror"
Copy link
Member

Choose a reason for hiding this comment

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

There's several "debug" changed in this PR you'll need to revert before it actually can receive approval; this is one of them.

@@ -509,7 +509,7 @@ hideFromDependabot(":instrumentation:vibur-dbcp-11.0:javaagent")
hideFromDependabot(":instrumentation:vibur-dbcp-11.0:library")
hideFromDependabot(":instrumentation:vibur-dbcp-11.0:testing")
hideFromDependabot(":instrumentation:wicket-8.0:javaagent")

hideFromDependabot(":instrumentation:thrift:javaagent")
Copy link
Member

Choose a reason for hiding this comment

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

By convention, we put the minimum supported library version in the module name; in case of thrift it should be :instrumentation:thrift-0.14:javaagent

}

dependencies {
implementation("org.apache.thrift:libthrift:0.14.1")
Copy link
Member

Choose a reason for hiding this comment

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

implementation will result in the library being included inside the javaagent, which probably is not what you're aiming for. You can use library instead (our own "syntactic sugar" configuration that's equivalent to compileOnly):

Suggested change
implementation("org.apache.thrift:libthrift:0.14.1")
library("org.apache.thrift:libthrift:0.14.1")

@tkyun123
Copy link
Author

thank for your advice,I will check and revert my debug changes,now this PR is not ready yet,I still need some time to finish all the test cases

@trask trask marked this pull request as draft April 28, 2023 19:02
@tkyun123
Copy link
Author

tests completed,please review

@tkyun123 tkyun123 marked this pull request as ready for review May 10, 2023 13:32
@laurit
Copy link
Contributor

laurit commented May 10, 2023

closing and reopening to trigger checks

@laurit laurit closed this May 10, 2023
@laurit laurit reopened this May 10, 2023
@laurit laurit closed this May 11, 2023
@laurit laurit reopened this May 11, 2023
@laurit
Copy link
Contributor

laurit commented May 11, 2023

@tkyun123 the first thing you should work on is to get the build passing

build.gradle.kts Outdated
@@ -98,3 +98,17 @@ if (gradle.startParameter.taskNames.any { it.equals("listTestsInPartition") }) {
}
}
}

allprojects {
Copy link
Contributor

Choose a reason for hiding this comment

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

You should remove this

import org.apache.thrift.protocol.TProtocolDecorator;

public abstract class AbstractProtocolWrapper extends TProtocolDecorator {
public static final String OIJ_THRIFT_FIELD_NAME = "OIJ_FIELD_NAME";
Copy link
Contributor

Choose a reason for hiding this comment

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

this doesn't seem to be used anywhere


public abstract class AbstractProtocolWrapper extends TProtocolDecorator {
public static final String OIJ_THRIFT_FIELD_NAME = "OIJ_FIELD_NAME";
public static final short OIJ_THRIFT_FIELD_ID = 3333;
Copy link
Contributor

Choose a reason for hiding this comment

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

OIJ_THRIFT_FIELD_ID is a weird name , what does OIJ stand for? I assume that this is the id for the field that you use for context propagation? If so it would be nice to have a comment. Also would it make sense to use a larger number than 3333? Would that reduce the risk of colliding with an existing field? Would it make sense to make this configurable?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

Yes. Make it configurable with a default value
May make sense

Copy link
Author

Choose a reason for hiding this comment

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

Yes. Make it configurable with a default value
May make sense

public static final String OIJ_THRIFT_FIELD_NAME = "OIJ_FIELD_NAME";
public static final short OIJ_THRIFT_FIELD_ID = 3333;

public AbstractProtocolWrapper(TProtocol protocol) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this class have any other purpose besides containing OIJ_THRIFT_FIELD_ID field?

Copy link
Author

Choose a reason for hiding this comment

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

No,just for containing this field

import org.apache.thrift.protocol.TMessage;
import org.apache.thrift.protocol.TProtocol;

@SuppressWarnings({"serial"})
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this @SuppressWarnings needed, this class does not seem to be serializable?

@tkyun123
Copy link
Author

65d2ed75aecf43a376a4fa674830d9d
I‘m confused about this muzzle check result,I‘m sure I do nothing to this instrumentation, How could I fix this

@laurit
Copy link
Contributor

laurit commented May 12, 2023

65d2ed75aecf43a376a4fa674830d9d I‘m confused about this muzzle check result,I‘m sure I do nothing to this instrumentation, How could I fix this

delete https://github.com/tkyun123/opentelemetry-java-instrumentation/blob/085e840266fc3b6c5a0140f75874bbcea476ccac/build.gradle.kts#L102-L114

@laurit
Copy link
Contributor

laurit commented May 19, 2023

@opentelemetrybot update

@trask
Copy link
Member

trask commented May 19, 2023

@opentelemetrybot help

@opentelemetrybot
Copy link
Collaborator

Available commands:

  • @opentelemetrybot spotless - runs ./gradlew spotlessApply
  • @opentelemetrybot license - runs ./gradlew generateLicenseReport
  • @opentelemetrybot apidiff - runs ./gradlew jApiCmp
  • @opentelemetrybot update - updates branch with merge commit
  • @opentelemetrybot rerun - re-runs failed checks (NOT IMPLEMENTED YET)
  • @opentelemetrybot help - displays available commands

@trask
Copy link
Member

trask commented May 19, 2023

@opentelemetrybot update

@trask
Copy link
Member

trask commented May 19, 2023

ah, it looks like our automation doesn't work when the PR is from a branch named main

@tkyun123 can you merge upstream/main into your PR, that will likely resolve the test failures

@breedx-splk
Copy link
Contributor

@tkyun123 did you see @trask's comment about merging main into your fork?

@tkyun123
Copy link
Author

tkyun123 commented Jun 7, 2023

I am sorry for the late reply. Now I have mergd main into my PR

@Override
public void transform(TypeTransformer transformer) {
transformer.applyAdviceToMethod(
isMethod().and(named("sendBase")).and(isProtected()),

Choose a reason for hiding this comment

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

It is possible that the sendbase method is public, should we remove this rule?

transformer.applyAdviceToMethod(
isMethod().and(named("receiveBase")),
ThriftClientInstrumentation.class.getName() + "$ClientReceiveAdvice");
transformer.applyAdviceToMethod(

Choose a reason for hiding this comment

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

There are two constructors for TServiceClient. One of them takes two arguments

return readFieldBegin();
}
context = serverInstrumenter().start(clientContext, request);
serverInstrumenter().end(context, request, 0, null);

Choose a reason for hiding this comment

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

This line is redundant

@andrew-lozoya
Copy link

Where is this PR at?

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.

Add support for thrift
8 participants