Skip to content

Commit 82b7a98

Browse files
committed
Merge branch 'add-copilot-review-instructions' into copilot-base
2 parents eaf81b1 + ee36ce4 commit 82b7a98

File tree

4 files changed

+240
-75
lines changed

4 files changed

+240
-75
lines changed

.github/copilot-instructions.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copilot Instructions for OpenTelemetry Java Contrib
2+
3+
This repository provides observability instrumentation for Java applications.
4+
5+
## Code Review Priorities
6+
7+
### Style Guide Compliance
8+
9+
**PRIORITY**: Verify that all code changes follow the [Style Guide](../docs/style-guide.md). Check:
10+
11+
- Code formatting (auto-formatting, static imports, class organization)
12+
- Java language conventions (`final` usage, `@Nullable` annotations, `Optional` usage)
13+
- Performance constraints (hot path allocations)
14+
- Implementation patterns (SPI registration, configuration conventions)
15+
- Gradle conventions (Kotlin DSL, plugin usage, module naming)
16+
- Documentation standards (README files, deprecation processes)
17+
18+
### Critical Areas
19+
20+
- **Public APIs**: Changes affect downstream users and require careful review
21+
- **Performance**: Instrumentation must have minimal overhead
22+
- **Thread Safety**: Ensure safe concurrent access patterns
23+
- **Memory Management**: Prevent leaks and excessive allocations
24+
25+
### Quality Standards
26+
27+
- Proper error handling with appropriate logging levels
28+
- OpenTelemetry specification and semantic convention compliance
29+
- Resource cleanup and lifecycle management
30+
- Comprehensive unit tests for new functionality

CONTRIBUTING.md

Lines changed: 36 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,65 @@
11
# Contributing
22

3-
Welcome to the OpenTelemetry Java Contrib Repository!
3+
Welcome to the OpenTelemetry Java Contrib repository!
44

55
## Introduction
66

7-
This repository focuses on providing tools and utilities for Java-based observability, such as remote JMX metric gathering and reporting. We’re excited to have you here! Whether you’re fixing a bug, adding a feature, or suggesting an idea, your contributions are invaluable.
7+
This repository provides observability libraries and utilities for Java applications that complement
8+
the [OpenTelemetry Java SDK](https://github.com/open-telemetry/opentelemetry-java) and
9+
[OpenTelemetry Java Instrumentation](https://github.com/open-telemetry/opentelemetry-java-instrumentation)
10+
projects.
811

9-
Before submitting new features or changes to current functionality, it is recommended to first
10-
[open an issue](https://github.com/open-telemetry/opentelemetry-java-contrib/issues/new)
11-
and discuss your ideas or propose the changes you wish to make.
12-
13-
Questions? Ask in the OpenTelemetry [java channel](https://cloud-native.slack.com/archives/C014L2KCTE3)
12+
Before submitting new features or changes, please consider
13+
[opening an issue](https://github.com/open-telemetry/opentelemetry-java-contrib/issues/new) first to
14+
discuss your ideas.
1415

1516
Pull requests for bug fixes are always welcome!
1617

17-
## Pre-requisites
18-
19-
To work with this repository, ensure you have:
20-
21-
### Tools:
22-
23-
Java 17 or higher
24-
25-
### Platform Notes:
18+
## Building and Testing
2619

27-
macOS/Linux: Ensure JAVA_HOME is set correctly.
20+
While most modules target Java 8, building this project requires Java 17 or higher.
2821

29-
## Workflow
30-
31-
1. Fork the repository
32-
2. Clone locally
33-
3. Create a branch before working on an issue
34-
35-
## Local Run/Build
36-
37-
In order to build and test this whole repository you need JDK 11+.
38-
39-
#### Snapshot builds
40-
41-
For developers testing code changes before a release is complete, there are
42-
snapshot builds of the `main` branch. They are available from
43-
the Sonatype snapshot repository at `https://central.sonatype.com/repository/maven-snapshots/`
44-
([browse](https://central.sonatype.com/service/rest/repository/browse/maven-snapshots/io/opentelemetry/contrib/)).
45-
46-
#### Building from source
47-
48-
Building using Java 11+:
22+
To build the project:
4923

5024
```bash
51-
$ java -version
25+
./gradlew assemble
5226
```
5327

28+
To run the tests:
29+
5430
```bash
55-
$ ./gradlew assemble
31+
./gradlew test
5632
```
5733

58-
## Testing
34+
Some modules include integration tests that can be run with:
5935

6036
```bash
61-
$ ./gradlew test
37+
./gradlew integrationTest
6238
```
6339

64-
### Some modules have integration tests
40+
## Snapshot Builds
6541

66-
```
67-
$ ./gradlew integrationTest
68-
```
42+
Snapshot builds of the `main` branch are available from the Sonatype snapshot repository at:
43+
`https://central.sonatype.com/repository/maven-snapshots/`
44+
([browse](https://central.sonatype.com/service/rest/repository/browse/maven-snapshots/io/opentelemetry/contrib/)).
45+
46+
## Style Guide
47+
48+
See [Style Guide](docs/style-guide.md).
6949

70-
Follow the Java Instrumentation [Style Guide](https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/docs/contributing/style-guideline.md) from the opentelemetry-java-instrumentation repository.
50+
## Pull Request Guidelines
7151

72-
Failure? Check logs for errors or mismatched dependencies.
52+
When submitting a pull request, please ensure that you:
7353

74-
## Gradle conventions
54+
- Clearly describe the change and its motivation
55+
- Mention any breaking changes
56+
- Include tests for new functionality
57+
- Follow the [Style Guide](docs/style-guide.md)
7558

76-
- Use kotlin instead of groovy
77-
- Plugin versions should be specified in `settings.gradle.kts`, not in individual modules
78-
- All modules use `plugins { id("otel.java-conventions") }`
59+
## Getting Help
7960

80-
## Further Help
61+
If you need assistance or have questions:
8162

82-
Join [#otel-java](https://cloud-native.slack.com/archives/C014L2KCTE3) on OpenTelemetry Slack
63+
- Post on the [#otel-java](https://cloud-native.slack.com/archives/C014L2KCTE3) Slack channel
64+
- [Open an issue](https://github.com/open-telemetry/opentelemetry-java-contrib/issues/new/choose) in
65+
this repository

README.md

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,30 +48,9 @@ On reaching stable status, the `otel.stable` value in `gradle.properties` should
4848
Note that currently all the libraries are released together with the version of this repo, so breaking changes (after stable
4949
status is reached) would bump the major version of all libraries together. This could get complicated so `stable` has a high bar.
5050

51-
## Getting Started
52-
53-
```bash
54-
# Apply formatting
55-
$ ./gradlew spotlessApply
56-
57-
# Build the complete project
58-
$ ./gradlew build
59-
60-
# Run integration tests
61-
$ ./gradlew integrationTest
62-
63-
# Clean artifacts
64-
$ ./gradlew clean
65-
```
66-
6751
## Contributing
6852

69-
The Java Contrib project was initially formed to provide methods of easy remote JMX metric gathering and reporting,
70-
which is actively in development. If you have an idea for a similar use case in the metrics, traces, or logging
71-
domain we would be very interested in supporting it. Please
72-
[open an issue](https://github.com/open-telemetry/opentelemetry-java-contrib/issues/new/choose) to share your idea or
73-
suggestion. PRs are always welcome and greatly appreciated, but for larger functional changes a pre-coding introduction
74-
can be helpful to ensure this is the correct place and that active or conflicting efforts don't exist.
53+
See [CONTRIBUTING.md](CONTRIBUTING.md).
7554

7655
### Maintainers
7756

docs/style-guide.md

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
# Style Guide
2+
3+
This project follows the
4+
[Google Java Style Guide](https://google.github.io/styleguide/javaguide.html).
5+
6+
## Code Formatting
7+
8+
### Auto-formatting
9+
10+
The build will fail if source code is not formatted according to Google Java Style.
11+
12+
Run the following command to reformat all files:
13+
14+
```bash
15+
./gradlew spotlessApply
16+
```
17+
18+
For IntelliJ users, an `.editorconfig` file is provided that IntelliJ will automatically use to
19+
adjust code formatting settings. However, it does not support all required rules, so you may still
20+
need to run `./gradlew spotlessApply` periodically.
21+
22+
### Static imports
23+
24+
Consider statically importing the following commonly used methods and constants:
25+
26+
- **Test methods**
27+
- `io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions` (assertThat, satisfies, etc.)
28+
- `org.assertj.core.api.Assertions.*` (assertThat, assertThatThrownBy, entry, etc.)
29+
- `org.mockito.Mockito.*` (when, mock, verify, times, etc.)
30+
- `org.mockito.ArgumentMatchers.*` (any, eq, anyLong, etc.)
31+
- **Utility methods**
32+
- `io.opentelemetry.api.common.AttributeKey.*` (stringKey, longKey, etc.)
33+
- `java.util.Arrays.*` (asList, etc.)
34+
- `java.util.Collections.*` (singletonList, emptyList, emptyMap, emptySet, etc.)
35+
- `java.util.stream.Collectors.*` (toList, toMap, toSet, etc.)
36+
- `java.util.Objects` (requireNonNull, etc.)
37+
- `java.util.logging.Level.*` (FINE, INFO, WARNING, etc.)
38+
- `java.nio.charset.StandardCharsets.*` (UTF_8, etc.)
39+
- **Time unit constants**
40+
- `java.util.concurrent.TimeUnit.*` (SECONDS, etc.)
41+
- **OpenTelemetry semantic convention constants**
42+
- All constants under `io.opentelemetry.semconv.**`
43+
44+
### Class organization
45+
46+
Prefer this order:
47+
48+
- Static fields (final before non-final)
49+
- Instance fields (final before non-final)
50+
- Constructors
51+
- Methods
52+
- Nested classes
53+
54+
**Method ordering**: Place calling methods above the methods they call. For example, place private
55+
methods below the non-private methods that use them.
56+
57+
**Static utility classes**: Place the private constructor (used to prevent instantiation) after all
58+
methods.
59+
60+
## Java Language Conventions
61+
62+
### Package conventions
63+
64+
Classes in `.internal` packages are not considered public API and may change without notice. These
65+
packages contain implementation details that should not be used by external consumers.
66+
67+
- Use `.internal` packages for implementation classes that need to be public within the module but
68+
should not be used externally
69+
- Try to avoid referencing `.internal` classes from other modules
70+
71+
### `final` keyword usage
72+
73+
Public API classes should be declared `final` where possible.
74+
75+
Methods should only be declared `final` if they are in non-final public API classes.
76+
77+
Fields should be declared `final` where possible.
78+
79+
Method parameters and local variables should never be declared `final`.
80+
81+
### `@Nullable` annotation usage
82+
83+
**Note: This section is aspirational and may not reflect the current codebase.**
84+
85+
Annotate all parameters and fields that can be `null` with `@Nullable` (specifically
86+
`javax.annotation.Nullable`, which is included by the `otel.java-conventions` Gradle plugin as a
87+
`compileOnly` dependency).
88+
89+
`@NonNull` is unnecessary as it is the default.
90+
91+
**Defensive programming**: Public APIs should still check for `null` parameters even if not
92+
annotated with `@Nullable`. Internal APIs do not need these checks.
93+
94+
**Enforcement**: Use the `otel.errorprone-conventions` Gradle plugin in all modules:
95+
96+
```kotlin
97+
plugins {
98+
id("otel.errorprone-conventions")
99+
}
100+
```
101+
102+
### `Optional` usage
103+
104+
Following the reasoning from
105+
[Writing a Java library with better experience (slide 12)](https://speakerdeck.com/trustin/writing-a-java-library-with-better-experience?slide=12),
106+
`java.util.Optional` usage is kept to a minimum.
107+
108+
**Guidelines**:
109+
110+
- `Optional` shouldn't appear in public API signatures
111+
- Avoid `Optional` on the hot path (instrumentation code), unless the instrumented library uses it
112+
113+
## Tooling conventions
114+
115+
### AssertJ
116+
117+
Prefer AssertJ assertions over JUnit assertions (assertEquals, assertTrue, etc.) for better error
118+
messages.
119+
120+
### AutoService
121+
122+
Use the `@AutoService` annotation when implementing SPI interfaces. This automatically generates the
123+
necessary `META-INF/services/` files at compile time, eliminating the need to manually create and
124+
maintain service registration files.
125+
126+
```java
127+
@AutoService(AutoConfigurationCustomizerProvider.class)
128+
public class MyCustomizerProvider implements AutoConfigurationCustomizerProvider {
129+
// implementation
130+
}
131+
```
132+
133+
### Gradle
134+
135+
- Use Kotlin instead of Groovy for build scripts
136+
- Plugin versions should be specified in `settings.gradle.kts`, not in individual modules
137+
- All modules should use `plugins { id("otel.java-conventions") }`
138+
- Set module names with `otelJava.moduleName.set("io.opentelemetry.contrib.mymodule")`
139+
140+
## Configuration
141+
142+
- Use `otel.` prefix for all configuration property keys
143+
- Read config via the `ConfigProperties` interface
144+
- Provide sensible defaults and document all options
145+
- Validate configuration early with clear error messages
146+
147+
## Performance
148+
149+
Avoid allocations on the hot path (instrumentation code) whenever possible. This includes `Iterator`
150+
allocations from collections; note that `for (SomeType t : plainJavaArray)` does not allocate an
151+
iterator object.
152+
153+
Non-allocating Stream API usage on the hot path is acceptable but may not fit the surrounding code
154+
style; this is a judgment call. Some Stream APIs make efficient allocation difficult (e.g.,
155+
`collect` with pre-sized sink data structures involves convoluted `Supplier` code, or lambdas passed
156+
to `forEach` may be capturing/allocating lambdas).
157+
158+
## Documentation
159+
160+
### Component README files
161+
162+
- Include a component owners section in each module's README
163+
- Document configuration options with examples
164+
165+
### Deprecation and breaking changes
166+
167+
Breaking changes are allowed in unstable modules (published with `-alpha` version suffix).
168+
169+
1. Mark APIs with `@Deprecated` and a removal timeline (there must be at least one release with the
170+
API marked as deprecated before removing it)
171+
2. Document the replacement in Javadoc with `@deprecated` tag
172+
3. Note the migration path for breaking changes under a "Migration notes" section of CHANGELOG.md
173+
(create this section at the top of the Unreleased section if not already present)

0 commit comments

Comments
 (0)