-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #860 from iRevive/sdk-exporter/private-proto-models
sdk-exporter: generate proto models in the private package
- Loading branch information
Showing
10 changed files
with
138 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,43 @@ | ||
syntax = "proto3"; | ||
|
||
package opentelemetry.proto; | ||
|
||
import "scalapb/scalapb.proto"; | ||
|
||
// OpenTelemetry proto models are defined at https://github.com/open-telemetry/opentelemetry-proto. | ||
// By default, generated models are public, which makes them accessible on the classpath. | ||
// | ||
// This poses a significant problem because opentelemetry-proto may introduce binary-breaking changes. | ||
// As a result, any updates to the opentelemetry-proto can cause otel4s-sdk-exporter-proto to break binary compatibility. | ||
// | ||
// That's why we must generate them package-private. | ||
// | ||
// See: https://github.com/scalapb/ScalaPB/issues/1778, https://github.com/typelevel/otel4s/pull/860 | ||
// | ||
// Docs: | ||
// https://scalapb.github.io/docs/faq/#how-do-i-mark-a-generated-case-class-private | ||
// https://scalapb.github.io/docs/customizations/#auxiliary-options | ||
option (scalapb.options) = { | ||
scope: PACKAGE | ||
|
||
// override the package, so we can access the models | ||
package_name: "org.typelevel.otel4s.sdk.exporter.proto" | ||
|
||
aux_message_options: [ | ||
{ | ||
target: "*" | ||
options: { | ||
annotations: "private[exporter]" | ||
companion_annotations: "private[exporter]" | ||
} | ||
} | ||
] | ||
aux_enum_options: [ | ||
{ | ||
target: "*" | ||
options: { | ||
base_annotations: "private[exporter]" | ||
} | ||
} | ||
] | ||
}; |
1 change: 1 addition & 0 deletions
1
sdk-exporter/proto/src/scalafix/resources/META-INF/services/scalafix.v1.Rule
This file contains 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 @@ | ||
fix.NoPublicClasses |
30 changes: 30 additions & 0 deletions
30
sdk-exporter/proto/src/scalafix/scala/fix/NoPublicClasses.scala
This file contains 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,30 @@ | ||
package fix | ||
|
||
import scalafix.v1._ | ||
import scala.meta._ | ||
|
||
class NoPublicClasses extends SyntacticRule("NoPublicClasses") { | ||
override def description: String = "Disallows public classes and objects in the module" | ||
|
||
override def fix(implicit doc: SyntacticDocument): Patch = { | ||
doc.tree.collect { | ||
case defn: Defn.Class if !defn.mods.exists(_.is[Mod.Private]) && defn.parent.exists(_.is[Pkg.Body]) => | ||
Patch.lint( | ||
Diagnostic( | ||
id = "NoPublicClasses", | ||
message = "Public classes are not allowed in this module.", | ||
position = defn.pos | ||
) | ||
) | ||
|
||
case defn: Defn.Object if !defn.mods.exists(_.is[Mod.Private]) && defn.parent.exists(_.is[Pkg.Body]) => | ||
Patch.lint( | ||
Diagnostic( | ||
id = "NoPublicClasses", | ||
message = "Public objects are not allowed in this module.", | ||
position = defn.pos | ||
) | ||
) | ||
}.asPatch | ||
} | ||
} |
This file contains 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