Skip to content
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

implement events v1.32 #1291

Merged
merged 15 commits into from May 5, 2024
Merged

Conversation

brettmc
Copy link
Collaborator

@brettmc brettmc commented Apr 26, 2024

implement the events api + sdk per spec v1.32:

  • event logger is now only retrievable via an event logger provider
  • domain attribute for events is removed
  • events accept a subset of LogRecord fields, rather than an entire LogRecord

todo: the spec is a little unclear on exactly how an EventLoggerProvider should access the Logger that it uses. Since the only way a Logger should be obtained is through a LoggerProvider (at least, that's true for other signals, but not expressly forbidden by the logs bridge API), I've gone with an EventLoggerProvider containing a LoggerProvider, from which it gets its logger.

The event logger API suggests that the above is correct ("EventLoggers can be accessed with a EventLoggerProvider"), however the event logger SDK says that "The SDK MAY be implemented on top of the Logs Bridge API".

implement the events api + sdk per spec v1.32:
- event logger is now only retrievable via an event logger provider
- domain attribute for events is removed
- events accept a subset of logrecord params, rather than an entire logrecord
src/API/Logs/EventLoggerProviderInterface.php Outdated Show resolved Hide resolved
src/API/Logs/EventLoggerInterface.php Outdated Show resolved Hide resolved
$context && $logRecord->setContext($context);
$logRecord->setSeverityNumber($severityNumber ?? Severity::INFO);

$this->logger->emit($logRecord);

This comment was marked as outdated.

Copy link

codecov bot commented Apr 27, 2024

Codecov Report

Attention: Patch coverage is 84.61538% with 12 lines in your changes are missing coverage. Please review.

Project coverage is 74.02%. Comparing base (100e593) to head (c04ce0b).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #1291      +/-   ##
============================================
+ Coverage     74.00%   74.02%   +0.02%     
- Complexity     2367     2384      +17     
============================================
  Files           347      352       +5     
  Lines          7077     7131      +54     
============================================
+ Hits           5237     5279      +42     
- Misses         1840     1852      +12     
Flag Coverage Δ
8.1 74.02% <84.61%> (+0.02%) ⬆️
8.2 74.02% <84.61%> (+0.02%) ⬆️
8.3 74.02% <84.61%> (+0.02%) ⬆️
8.4 72.90% <84.61%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
src/API/Globals.php 94.11% <100.00%> (+0.56%) ⬆️
src/API/Instrumentation/CachedInstrumentation.php 100.00% <100.00%> (ø)
src/API/Instrumentation/Configurator.php 100.00% <100.00%> (ø)
src/API/Instrumentation/ContextKeys.php 100.00% <100.00%> (ø)
src/API/Logs/LogRecord.php 100.00% <100.00%> (ø)
src/API/Logs/Map/Psr3.php 100.00% <100.00%> (ø)
src/API/Logs/Severity.php 100.00% <100.00%> (ø)
src/SDK/Logs/EventLogger.php 100.00% <100.00%> (ø)
src/SDK/Logs/EventLoggerProvider.php 100.00% <100.00%> (ø)
src/SDK/Logs/EventLoggerProviderFactory.php 100.00% <100.00%> (ø)
... and 7 more

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 100e593...c04ce0b. Read the comment docs.

@brettmc brettmc marked this pull request as ready for review April 27, 2024 23:27
@brettmc brettmc requested a review from a team as a code owner April 27, 2024 23:27
src/API/Logs/EventLoggerInterface.php Outdated Show resolved Hide resolved
@@ -42,9 +42,9 @@ public function setContext(?ContextInterface $context = null): self
/**
* @see https://opentelemetry.io/docs/reference/specification/logs/data-model/#field-severitynumber
*/
public function setSeverityNumber(int $severityNumber): self
public function setSeverityNumber(Severity $severityNumber): self
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to keep Severity|int here to preserve BC.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we've removed emitEvent(LogRecord), there shouldn't be any direct usage of this class outside of log appenders (the monolog one in contrib is the only one I'm aware of). So, I don't think this is a critical BC to maintain...?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has very likely low/no impact (as LogRecord::setSeverityNumber(Psr::serverityNumber($...)) stays compatible); but it is also quite trivial to keep BC. IMO we should preserve BC for the low chance that someone is using the logs API w/ a non-PSR-3 logger.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, reverted to maintain BC. I also deprecated Psr::severityNumber in favour of moving that logic into the enum itself.

src/API/Logs/NoopEventLoggerProvider.php Outdated Show resolved Hide resolved
src/SDK/Logs/EventLogger.php Outdated Show resolved Hide resolved
src/SDK/Logs/EventLogger.php Outdated Show resolved Hide resolved
src/SDK/Logs/EventLogger.php Outdated Show resolved Hide resolved
src/SDK/Logs/EventLogger.php Outdated Show resolved Hide resolved
src/API/Logs/EventLoggerInterface.php Outdated Show resolved Hide resolved
examples/logs/exporters/otlp_grpc.php Outdated Show resolved Hide resolved
@bobstrecansky bobstrecansky merged commit 500f6ee into open-telemetry:main May 5, 2024
10 checks passed
brettmc added a commit to brettmc/opentelemetry-php that referenced this pull request May 14, 2024
* implement events v1.32
implement the events api + sdk per spec v1.32:
- event logger is now only retrievable via an event logger provider
- domain attribute for events is removed
- events accept a subset of logrecord params, rather than an entire logrecord

* convert severity to a backed enum

* lint

* remove instead of deprecating logEvent, mark Logger constructor as internal

* make severity an enum only

* event attributes to iterable

* inject ClockInterface, add CachedInstrumentation, update examples

* set correct defaults for events

* test coverage

* Revert "make severity an enum only"

This reverts commit 7108229.
Also, move PSR-3 mapping into the Severity enum.

* event attributes to iterable

* apply review feedback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants