1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
6 #ifdef ENABLE_LOGS_PREVIEW
8 # include "opentelemetry/sdk/logs/processor.h"
9 # include "opentelemetry/sdk/resource/resource.h"
10 # include "opentelemetry/version.h"
12 OPENTELEMETRY_BEGIN_NAMESPACE
18 * A class which stores the LoggerContext context.
20 * This class meets the following design criteria:
21 * - A shared reference between LoggerProvider and Logger instantiated.
22 * - A thread-safe class that allows updating/altering processor/exporter pipelines
23 * and sampling config.
24 * - The owner/destroyer of Processors/Exporters. These will remain active until
25 * this class is destroyed. I.e. Sampling, Exporting, flushing, Custom Iterator etc. are all ok
26 * if this object is alive, and they will work together. If this object is destroyed, then no shared
27 * references to Processor, Exporter, Recordable, Custom Iterator etc. should exist, and all
28 * associated pipelines will have been flushed.
33 explicit LoggerContext(std::vector
<std::unique_ptr
<LogProcessor
>> &&processors
,
34 opentelemetry::sdk::resource::Resource resource
=
35 opentelemetry::sdk::resource::Resource::Create({})) noexcept
;
38 * Attaches a log processor to list of configured processors to this tracer context.
39 * Processor once attached can't be removed.
40 * @param processor The new log processor for this tracer. This must not be
41 * a nullptr. Ownership is given to the `TracerContext`.
43 * Note: This method is not thread safe.
45 void AddProcessor(std::unique_ptr
<LogProcessor
> processor
) noexcept
;
48 * Obtain the configured (composite) processor.
50 * Note: When more than one processor is active, this will
51 * return an "aggregate" processor
53 LogProcessor
&GetProcessor() const noexcept
;
56 * Obtain the resource associated with this tracer context.
57 * @return The resource for this tracer context.
59 const opentelemetry::sdk::resource::Resource
&GetResource() const noexcept
;
62 * Force all active LogProcessors to flush any buffered logs
63 * within the given timeout.
65 bool ForceFlush(std::chrono::microseconds timeout
= (std::chrono::microseconds::max
)()) noexcept
;
68 * Shutdown the log processor associated with this tracer provider.
70 bool Shutdown(std::chrono::microseconds timeout
= std::chrono::microseconds::max()) noexcept
;
73 // order of declaration is important here - resource object should be destroyed after processor.
74 opentelemetry::sdk::resource::Resource resource_
;
75 std::unique_ptr
<LogProcessor
> processor_
;
80 OPENTELEMETRY_END_NAMESPACE