-
Notifications
You must be signed in to change notification settings - Fork 971
Add guidance for null checking, promote ApiUsageLogger to opentelemetry-common public API #8318
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
687d67e
Add guidance for null checking, promote ApiUsageLogger to opentelemet…
jack-berg 922d71e
add logNullParam
jack-berg eef3bf3
Add logNullParam helper method
jack-berg 807b0b1
guidance for sdk extension interfaces
jack-berg c8bf1cc
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
jack-berg a89f825
japicmp
jack-berg 63d2f64
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
jack-berg a90a682
Move to *.impl.* package, add warning first time usage issue occurs
jack-berg ae7548a
update japicmp
jack-berg 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
42 changes: 0 additions & 42 deletions
42
api/all/src/main/java/io/opentelemetry/api/internal/ApiUsageLogger.java
This file was deleted.
Oops, something went wrong.
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
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
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
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
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
52 changes: 52 additions & 0 deletions
52
common/src/main/java/io/opentelemetry/common/ApiUsageLogger.java
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,52 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.common; | ||
|
|
||
| import java.util.logging.Level; | ||
| import java.util.logging.Logger; | ||
|
|
||
| /** | ||
| * A utility for logging API misuse, allowing operators to diagnose invalid usage with a single | ||
| * logging configuration entry. | ||
| * | ||
| * <p>Logs at {@link Level#FINEST} by default, so messages are silent in production unless | ||
| * explicitly enabled. Each log record includes a {@link Throwable} to make the offending call site | ||
| * visible in the stack trace without requiring the exception to be thrown. | ||
| * | ||
| * <p>To investigate API misuse, configure the logger named {@code io.opentelemetry.usage} at {@link | ||
| * Level#FINEST} in development, or periodically in staging/production. | ||
| * | ||
| * <p>This class is public for use by OpenTelemetry component authors. It is not intended for use by | ||
| * application developers. | ||
| */ | ||
| public final class ApiUsageLogger { | ||
|
|
||
| /** The logger name used for all API-misuse diagnostics. */ | ||
| private static final Logger LOGGER = Logger.getLogger("io.opentelemetry.usage"); | ||
|
|
||
| /** | ||
| * Log a misuse of {@code apiClass#methodName} with the given {@code message}. | ||
| * | ||
| * <p>Logs at {@link Level#FINEST} and includes a stack trace. | ||
| * | ||
| * @param apiClass the public API class where the misuse occurred | ||
| * @param methodName the name of the method where the misuse occurred | ||
| * @param message a brief description of the problem | ||
| */ | ||
| public static void log(Class<?> apiClass, String methodName, String message) { | ||
| log(apiClass, methodName, message, Level.FINEST); | ||
| } | ||
|
|
||
| // Visible for testing | ||
| static void log(Class<?> apiClass, String methodName, String message, Level level) { | ||
| if (LOGGER.isLoggable(level)) { | ||
| LOGGER.log( | ||
| level, apiClass.getSimpleName() + "." + methodName + "(): " + message, new Throwable()); | ||
| } | ||
| } | ||
|
|
||
| private ApiUsageLogger() {} | ||
| } | ||
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
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 |
|---|---|---|
| @@ -1,2 +1,5 @@ | ||
| Comparing source compatibility of opentelemetry-common-1.62.0-SNAPSHOT.jar against opentelemetry-common-1.61.0.jar | ||
| No changes. | ||
| +++ NEW CLASS: PUBLIC(+) FINAL(+) io.opentelemetry.common.ApiUsageLogger (not serializable) | ||
| +++ CLASS FILE FORMAT VERSION: 52.0 <- n.a. | ||
| +++ NEW SUPERCLASS: java.lang.Object | ||
| +++ NEW METHOD: PUBLIC(+) STATIC(+) void log(java.lang.Class<?>, java.lang.String, java.lang.String) |
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.