Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# OpenTelemetry Java Instrumentation
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm interested in keeping this as lean as possible, because I keep running into context confusion (or ignoring context) when I pass in too much.
Which of these have been helpful for you in real world usage?

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

Copy link
Member

Choose a reason for hiding this comment

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

I was thinking of using this to collect various tips and things that come up in code reviews

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.


## 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.
Loading