-
Notifications
You must be signed in to change notification settings - Fork 1k
Copilot instructions #15393
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
Merged
Merged
Copilot instructions #15393
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| # OpenTelemetry Java Instrumentation | ||
|
|
||
| ## Testing | ||
|
|
||
| Tests use AssertJ for assertions and JUnit 5 as the testing framework | ||
|
|
||
| Test classes and methods should not be public | ||
|
|
||
| When registering tests in gradle configurations, if using `val testName by registering(Test::class) {`... | ||
| then you need to include `testClassesDirs` and `classpath` like so: | ||
|
|
||
| ``` | ||
| val testExperimental by registering(Test::class) { | ||
| testClassesDirs = sourceSets.test.get().output.classesDirs | ||
| classpath = sourceSets.test.get().runtimeClasspath | ||
| ... | ||
| } | ||
| ``` | ||
|
|
||
| ## General Java guidelines | ||
|
|
||
| * Always import classes when possible (i.e. don't use fully qualified class names in code). | ||
|
|
||
| ## Gradle CLI | ||
|
|
||
| Never use the `--rerun-tasks` flag unless explicitly asked to use this option. | ||
|
|
||
| Gradle automatically detects changes and re-runs tasks automatically when needed. Using `--rerun-tasks` | ||
| is wasteful and slows down builds unnecessarily. | ||
|
|
||
| ## Throwing exceptions | ||
|
|
||
| When writing instrumentation, you have to be really careful about throwing exceptions. For library | ||
| instrumentations it might be acceptable, but in javaagent code you shouldn't throw exceptions | ||
| (keep in mind that javaagent instrumentations sometimes use library instrumentations). | ||
|
|
||
| In javaagent instrumentations we try not to break applications. If there are changes in the instrumented | ||
| library that are not compatible with the instrumentation we disable the instrumentation instead of letting | ||
| it fail. This is handled by muzzle. In javaagent instrumentations you should not fail if the methods | ||
| that you need don't exist. | ||
|
|
||
| ## Javaagent Instrumentation | ||
|
|
||
| ### Java8BytecodeBridge | ||
|
|
||
| When to use `Java8BytecodeBridge.currentContext()` vs `Context.current()` ? | ||
|
|
||
| Using `Context.current()` is preferred. `Java8BytecodeBridge.currentContext()` is for using inside | ||
| advice. We need this method because advice code is inlined in the instrumented method as it is. | ||
| Since `Context.current()` is a static interface method it will cause a bytecode verification error | ||
| when it is inserted into a pre 8 class. `Java8BytecodeBridge.currentContext()` is a regular class | ||
| static method and can be used in any class version. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use claude locally instead of copilot, and I create specialized context collections for different tasks, which is pretty large and I haven't had any issues, but point taken.
I just slimmed it down a lot more. I was thinking of using this to collect various tips and things that come up in code reviews, as opposed to specifically including things I had issues with copilot with, but maybe thats the wrong approach and this should be updated as we encounter copilot specific issues? In which case I can cut this down even more for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense to me. I think we can split instructions now to apply only to reviews vs coding agent if needed. I do hope to use (and improve) the copilot code reviews more.