-
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
Open
jaydeluca
wants to merge
3
commits into
open-telemetry:main
Choose a base branch
from
jaydeluca:copilot-instructions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Copilot instructions #15393
Changes from 2 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,130 @@ | ||
| # OpenTelemetry Java Instrumentation | ||
|
|
||
| OpenTelemetry Java Instrumentation is a Java agent that provides automatic instrumentation for a wide variety of libraries and frameworks. It dynamically injects bytecode to capture telemetry data without requiring code changes. | ||
|
|
||
| Always reference these instructions first and fallback to search or bash commands only when you encounter unexpected information that does not match the info here. | ||
|
|
||
| ## General notes | ||
|
|
||
| - Use Java 21 for building (required, see `.java-version`) | ||
| - `./gradlew assemble` -- builds the complete Java agent. NEVER CANCEL. Set timeout to 60+ minutes. | ||
| - The Java agent artifact will be at: `javaagent/build/libs/opentelemetry-javaagent-<version>.jar` | ||
| - Code quality: | ||
| - `./gradlew spotlessCheck` -- NEVER CANCEL. ~500 modules. Set timeout to 30+ minutes. | ||
| - `./gradlew spotlessApply` -- auto-fix formatting issues | ||
| - `./gradlew generateLicenseReport --no-build-cache` -- update license information | ||
| - Docker is required for some tests (smoke tests, instrumentation tests using testcontainers) | ||
| - Node 16 for Vaadin tests (if working on Vaadin instrumentation) | ||
|
|
||
|
|
||
| ## Internal docs | ||
|
|
||
| The following documentation should be referenced: | ||
|
|
||
| ### Core Development Guides | ||
|
|
||
| - `docs/contributing/writing-instrumentation.md` - Complete guide for writing new instrumentation (library and javaagent) | ||
| - `docs/contributing/using-instrumenter-api.md` - Detailed documentation on the Instrumenter API (core to all instrumentation) | ||
| - `docs/contributing/writing-instrumentation-module.md` - How to implement InstrumentationModule classes | ||
| - `docs/contributing/style-guideline.md` - Code style, formatting rules, and conventions (Google Java Style Guide) | ||
|
|
||
| ### Architecture & Structure | ||
|
|
||
| - `docs/contributing/javaagent-structure.md` - Class loader architecture and javaagent internal structure | ||
| - `docs/contributing/muzzle.md` - Safety mechanism that prevents instrumentation mismatches | ||
| - `docs/contributing/javaagent-test-infra.md` - Testing infrastructure and patterns | ||
|
|
||
| ### Testing & Debugging | ||
|
|
||
| - `docs/contributing/running-tests.md` - How to run tests across different Java versions and configurations | ||
| - `docs/contributing/debugging.md` - Debugging instrumentation and tests | ||
|
|
||
| ### Documentation & Project Scope | ||
|
|
||
| - `docs/contributing/documenting-instrumentation.md` - How to document instrumentation (metadata.yaml, telemetry collection) | ||
| - `docs/supported-libraries.md` - List of supported libraries and frameworks | ||
| - `docs/instrumentation-list.yaml` - Generated comprehensive instrumentation reference (DO NOT edit manually) | ||
|
|
||
| ### Configuration & Features | ||
|
|
||
| - `docs/logger-mdc-instrumentation.md` - MDC (Mapped Diagnostic Context) instrumentation details | ||
|
|
||
| ## Key Files to Check After Changes | ||
|
|
||
| - Always run `./gradlew spotlessCheck` before committing or the CI will fail | ||
| - Update supported libraries docs: `docs/supported-libraries.md` | ||
| - Update metadata.yaml file if applicable (see `docs/contributing/documenting-instrumentation.md`) | ||
|
|
||
| ## Repository Structure | ||
|
|
||
| Key directories: | ||
|
|
||
| - `instrumentation/` - Contains all instrumentation modules (modules for different libraries) | ||
| - `javaagent/` - Core Java agent implementation | ||
| - `docs/` - Documentation including supported libraries list | ||
| - `smoke-tests/` - End-to-end integration tests | ||
| - `examples/` - Example extensions and distributions | ||
| - `gradle-plugins/` - Custom Gradle plugins used by the build | ||
| - `.github/workflows/` - CI/CD pipeline definitions | ||
| - `settings.gradle.kts` - Contains all module definitions | ||
|
|
||
| ## Testing | ||
|
|
||
| ### Commands | ||
|
|
||
| - `./gradlew test` -- runs tests. NEVER CANCEL. Set timeout to 180+ minutes. | ||
| - `./gradlew check` -- runs all tests and checks. NEVER CANCEL. Set timeout to 180+ minutes. | ||
| - `./gradlew :smoke-tests:test` -- runs smoke tests (separate from main test suite) | ||
| - `./gradlew test -PtestJavaVersion=<version>` -- test on specific Java version (8, 11, 17, 21, 23, 24, 25-ea) | ||
| - `./gradlew test -PtestLatestDeps=true` -- test against latest dependency versions | ||
|
|
||
| ### Guidelines | ||
|
|
||
| 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