Skip to content

Commit

Permalink
Return AutoConfiguredOpenTelemetrySdkBuilder instead of the base type (
Browse files Browse the repository at this point in the history
  • Loading branch information
lmolkova authored Mar 6, 2024
1 parent 62a4810 commit 25afc3e
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ instead.

* Autoconfigure accepts encoded header values for OTLP exporters
([#6164](https://github.com/open-telemetry/opentelemetry-java/pull/6164))
* Return implementation type from `AutoConfiguredOpenTelemetrySdkBuilder.addLogRecordProcessorCustomizer`
([#6248](https://github.com/open-telemetry/opentelemetry-java/pull/6248))

#### Incubator

Expand Down
61 changes: 50 additions & 11 deletions buildSrc/src/main/kotlin/otel.japicmp-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
import com.google.auto.value.AutoValue
import japicmp.model.JApiChangeStatus
import japicmp.model.JApiClass
import japicmp.model.JApiCompatibility
import japicmp.model.JApiCompatibilityChange
import japicmp.model.JApiMethod
import japicmp.model.*
import me.champeau.gradle.japicmp.JapicmpTask
import me.champeau.gradle.japicmp.report.Violation
import me.champeau.gradle.japicmp.report.stdrules.AbstractRecordingSeenMembers
import me.champeau.gradle.japicmp.report.stdrules.BinaryIncompatibleRule
import me.champeau.gradle.japicmp.report.stdrules.RecordSeenMembersSetup
import me.champeau.gradle.japicmp.report.stdrules.SourceCompatibleRule
import me.champeau.gradle.japicmp.report.stdrules.UnchangedMemberRule
import me.champeau.gradle.japicmp.report.stdrules.*


plugins {
Expand Down Expand Up @@ -52,9 +44,56 @@ class AllowNewAbstractMethodOnAutovalueClasses : AbstractRecordingSeenMembers()
}

class SourceIncompatibleRule : AbstractRecordingSeenMembers() {

fun ignoreAddLogRecordProcessorCustomizerReturnTypeChange(member: JApiCompatibility): Violation? {
if (member is JApiClass &&
member.newClass.get().name.equals("io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder") &&
member.isChangeCausedByClassElement
) {
// member.isChangeCausedByClassElement check above
// limits source of changes to fields, methods and constructors

for (method in member.methods) {
if (!method.isSourceCompatible()) {
// addLogRecordProcessorCustomizer method had a return type change from base to impl class,
// japicmp (correctly) doesn't consider it as a METHOD_RETURN_TYPE_CHANGED
// compatibility issue. But still thinks that something wrong.
// Since it thinks that method did not change, it reports it as class-level violation,
// and we need to suppress it, but keep other checks on.
if (method.name.equals("addLogRecordProcessorCustomizer") &&
method.compatibilityChanges.isEmpty() &&
method.changeStatus == JApiChangeStatus.UNCHANGED) {
return null;
}
return Violation.error(method, "Method is not source compatible: $method")
}
}

for (field in member.fields) {
if (!field.isSourceCompatible()) {
return Violation.error(field, "Field is not source compatible: $field")
}
}

for (constructor in member.constructors) {
if (!constructor.isSourceCompatible()) {
return Violation.error(constructor, "Constructor is not source compatible: $constructor")
}
}
}

return Violation.error(member, "Not source compatible: $member")
}

override fun maybeAddViolation(member: JApiCompatibility): Violation? {
if (!member.isSourceCompatible()) {
return Violation.error(member, "Not source compatible")
// TODO: remove after 1.36.0 is released, see https://github.com/open-telemetry/opentelemetry-java/pull/6248
if (member.compatibilityChanges.isEmpty()) {
return ignoreAddLogRecordProcessorCustomizerReturnTypeChange(member)
}
// end of suppression

return Violation.error(member, "Not source compatible: $member")
}
return null
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Comparing source compatibility of against
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder (not serializable)
**** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder (not serializable)
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
===* UNCHANGED METHOD: PUBLIC SYNTHETIC (<- NON_SYNTHETIC) BRIDGE (<- NON_BRIDGE) io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizer addLogRecordProcessorCustomizer(java.util.function.BiFunction(<- <? super io.opentelemetry.sdk.logs.LogRecordProcessor,io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties,? extends io.opentelemetry.sdk.logs.LogRecordProcessor>))
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder addMetricReaderCustomizer(java.util.function.BiFunction<? super io.opentelemetry.sdk.metrics.export.MetricReader,io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties,? extends io.opentelemetry.sdk.metrics.export.MetricReader>)
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public AutoConfiguredOpenTelemetrySdkBuilder addLogRecordExporterCustomizer(
* <p>Multiple calls will execute the customizers in order.
*/
@Override
public AutoConfigurationCustomizer addLogRecordProcessorCustomizer(
public AutoConfiguredOpenTelemetrySdkBuilder addLogRecordProcessorCustomizer(
BiFunction<? super LogRecordProcessor, ConfigProperties, ? extends LogRecordProcessor>
logRecordProcessorCustomizer) {
requireNonNull(logRecordProcessorCustomizer, "logRecordProcessorCustomizer");
Expand Down

0 comments on commit 25afc3e

Please sign in to comment.