-
-
Notifications
You must be signed in to change notification settings - Fork 37
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
Added LogProcessors and implemented shutdown and forceFlush for LoggerProviders #132
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5b3de96
Renamed LogProcessor to LogRecordProcessor
evanlauer1 476aa2f
Added `noOpLoggerProvider` and removed `MonadIO` constraint from `cre…
evanlauer1 38f79c9
Renamed `LogProcessor` to `LogRecordProcessor`
evanlauer1 bc48af2
Call processors' onEmit when a log is emitted
evanlauer1 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 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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
{-# LANGUAGE NamedFieldPuns #-} | ||
|
||
module OpenTelemetry.Internal.Logging.Types ( | ||
LogRecordProcessor (..), | ||
LoggerProvider (..), | ||
Logger (..), | ||
ReadWriteLogRecord, | ||
|
@@ -18,28 +19,63 @@ module OpenTelemetry.Internal.Logging.Types ( | |
toShortName, | ||
) where | ||
|
||
import Control.Concurrent.Async | ||
import Data.Function (on) | ||
import qualified Data.HashMap.Strict as H | ||
import Data.IORef (IORef, atomicModifyIORef, modifyIORef, newIORef, readIORef) | ||
import Data.Text (Text) | ||
import Data.Vector (Vector) | ||
import OpenTelemetry.Common (Timestamp, TraceFlags) | ||
import OpenTelemetry.Context.Types (Context) | ||
import OpenTelemetry.Internal.Common.Types (InstrumentationLibrary) | ||
import OpenTelemetry.Internal.Common.Types (InstrumentationLibrary, ShutdownResult) | ||
import OpenTelemetry.Internal.Trace.Id (SpanId, TraceId) | ||
import OpenTelemetry.LogAttributes | ||
import OpenTelemetry.Resource (MaterializedResources) | ||
|
||
|
||
data LogRecordProcessor = LogRecordProcessor | ||
{ logRecordProcessorOnEmit :: ReadWriteLogRecord -> Context -> IO () | ||
-- ^ Called when a LogRecord is emitted. This method is called synchronously on the thread that emitted the LogRecord, therefore it SHOULD NOT block or throw exceptions. | ||
-- | ||
-- A LogRecordProcessor may freely modify logRecord for the duration of the OnEmit call. If logRecord is needed after OnEmit returns (i.e. for asynchronous processing) only reads are permitted. | ||
, logRecordProcessorShutdown :: IO (Async ShutdownResult) | ||
-- ^ Shuts down the processor. Called when SDK is shut down. This is an opportunity for processor to do any cleanup required. | ||
-- | ||
-- Shutdown SHOULD be called only once for each LogRecordProcessor instance. After the call to Shutdown, subsequent calls to OnEmit are not allowed. SDKs SHOULD ignore these calls gracefully, if possible. | ||
-- | ||
-- Shutdown SHOULD provide a way to let the caller know whether it succeeded, failed or timed out. | ||
-- | ||
-- Shutdown MUST include the effects of ForceFlush. | ||
-- | ||
-- Shutdown SHOULD complete or abort within some timeout. Shutdown can be implemented as a blocking API or an asynchronous API which notifies the caller via a callback or an event. | ||
-- OpenTelemetry SDK authors can decide if they want to make the shutdown timeout configurable. | ||
, logRecordProcessorForceFlush :: IO () | ||
-- ^ This is a hint to ensure that any tasks associated with LogRecords for which the LogRecordProcessor had already received events prior to the call to ForceFlush SHOULD be completed | ||
-- as soon as possible, preferably before returning from this method. | ||
-- | ||
-- In particular, if any LogRecordProcessor has any associated exporter, it SHOULD try to call the exporter’s Export with all LogRecords for which this was not already done and then invoke ForceFlush on it. | ||
-- The built-in LogRecordProcessors MUST do so. If a timeout is specified (see below), the LogRecordProcessor MUST prioritize honoring the timeout over finishing all calls. It MAY skip or abort some or all | ||
-- Export or ForceFlush calls it has made to achieve this goal. | ||
-- | ||
-- ForceFlush SHOULD provide a way to let the caller know whether it succeeded, failed or timed out. | ||
-- | ||
-- ForceFlush SHOULD only be called in cases where it is absolutely necessary, such as when using some FaaS providers that may suspend the process after an invocation, but before the LogRecordProcessor exports the emitted LogRecords. | ||
-- | ||
-- ForceFlush SHOULD complete or abort within some timeout. ForceFlush can be implemented as a blocking API or an asynchronous API which notifies the caller via a callback or an event. OpenTelemetry SDK authors | ||
-- can decide if they want to make the flush timeout configurable. | ||
} | ||
|
||
|
||
-- | @Logger@s can be created from @LoggerProvider@s | ||
data LoggerProvider = LoggerProvider | ||
{ loggerProviderResource :: MaterializedResources | ||
{ loggerProviderProcessors :: Vector LogRecordProcessor | ||
, loggerProviderResource :: MaterializedResources | ||
-- ^ Describes the source of the log, aka resource. Multiple occurrences of events coming from the same event source can happen across time and they all have the same value of Resource. | ||
-- Can contain for example information about the application that emits the record or about the infrastructure where the application runs. Data formats that represent this data model | ||
-- may be designed in a manner that allows the Resource field to be recorded only once per batch of log records that come from the same source. SHOULD follow OpenTelemetry semantic conventions for Resources. | ||
-- This field is optional. | ||
, loggerProviderAttributeLimits :: AttributeLimits | ||
} | ||
deriving (Show, Eq) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cannot derive |
||
|
||
|
||
{- | @LogRecords@ can be created from @Loggers@. @Logger@s are uniquely identified by the @libraryName@, @libraryVersion@, @schemaUrl@ fields of @InstrumentationLibrary@. | ||
|
@@ -48,7 +84,7 @@ Creating two @Logger@s with the same identity but different @libraryAttributes@ | |
data Logger = Logger | ||
{ loggerInstrumentationScope :: InstrumentationLibrary | ||
-- ^ Details about the library that the @Logger@ instruments. | ||
, loggerProvider :: LoggerProvider | ||
, loggerLoggerProvider :: LoggerProvider | ||
-- ^ The @LoggerProvider@ that created this @Logger@. All configuration for the @Logger@ is contained in the @LoggerProvider@. | ||
} | ||
|
||
|
@@ -128,11 +164,11 @@ instance IsReadableLogRecord ReadableLogRecord where | |
instance IsReadableLogRecord ReadWriteLogRecord where | ||
readLogRecord (ReadWriteLogRecord _ ref) = readIORef ref | ||
readLogRecordInstrumentationScope (ReadWriteLogRecord (Logger {loggerInstrumentationScope}) _) = loggerInstrumentationScope | ||
readLogRecordResource (ReadWriteLogRecord Logger {loggerProvider = LoggerProvider {loggerProviderResource}} _) = loggerProviderResource | ||
readLogRecordResource (ReadWriteLogRecord Logger {loggerLoggerProvider = LoggerProvider {loggerProviderResource}} _) = loggerProviderResource | ||
|
||
|
||
instance IsReadWriteLogRecord ReadWriteLogRecord where | ||
readLogRecordAttributeLimits (ReadWriteLogRecord Logger {loggerProvider = LoggerProvider {loggerProviderAttributeLimits}} _) = loggerProviderAttributeLimits | ||
readLogRecordAttributeLimits (ReadWriteLogRecord Logger {loggerLoggerProvider = LoggerProvider {loggerProviderAttributeLimits}} _) = loggerProviderAttributeLimits | ||
modifyLogRecord (ReadWriteLogRecord _ ref) = modifyIORef ref | ||
atomicModifyLogRecord (ReadWriteLogRecord _ ref) = atomicModifyIORef ref | ||
|
||
|
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 |
---|---|---|
|
@@ -44,9 +44,6 @@ data Exporter a = Exporter | |
} | ||
|
||
|
||
data ShutdownResult = ShutdownSuccess | ShutdownFailure | ShutdownTimeout | ||
|
||
|
||
data Processor = Processor | ||
{ processorOnStart :: IORef ImmutableSpan -> Context -> IO () | ||
-- ^ Called when a span is started. This method is called synchronously on the thread that started the span, therefore it should not block or throw exceptions. | ||
|
@@ -186,19 +183,6 @@ data SpanArguments = SpanArguments | |
} | ||
|
||
|
||
-- | The outcome of a call to 'OpenTelemetry.Trace.forceFlush' | ||
data FlushResult | ||
= -- | One or more spans did not export from all associated exporters | ||
-- within the alotted timeframe. | ||
FlushTimeout | ||
| -- | Flushing spans to all associated exporters succeeded. | ||
FlushSuccess | ||
| -- | One or more exporters failed to successfully export one or more | ||
-- unexported spans. | ||
FlushError | ||
deriving (Show) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved to |
||
|
||
|
||
{- | | ||
@SpanKind@ describes the relationship between the @Span@, its parents, and its children in a Trace. @SpanKind@ describes two independent properties that benefit tracing systems during analysis. | ||
|
||
|
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,19 @@ | ||
{- | | ||
@LogRecordProcessor@ is an interface which allows hooks for @LogRecord@ emit method invocations. | ||
|
||
Built-in log processors are responsible for batching and conversion of spans to exportable representation and passing batches to exporters. | ||
|
||
Log processors can be registered directly on SDK LoggerProvider and they are invoked in the same order as they were registered. | ||
|
||
Each processor registered on LoggerProvider is a start of pipeline that consist of log processor and optional exporter. SDK MUST allow to end each pipeline with individual exporter. | ||
|
||
SDK MUST allow users to implement and configure custom processors and decorate built-in processors for advanced scenarios such as tagging or filtering. | ||
-} | ||
module OpenTelemetry.LogRecordProcessor ( | ||
LogRecordProcessor (..), | ||
ShutdownResult (..), | ||
) where | ||
|
||
import OpenTelemetry.Internal.Common.Types | ||
import OpenTelemetry.Internal.Logging.Types | ||
|
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type is similar to
Processor
defined inOpenTelemetry.Internal.Trace.Types
. Notable differences are the type variablebody
becauseLogRecord
needs it, and changingonStart
andonEnd
toonEmit
in accordance with the spec. MaybeProcessor
should be renamed toSpanProcessor
because there is more than one type of Processor now?