Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 37 additions & 38 deletions src/OpenTelemetry/Logs/BatchLogRecordExportProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,52 +19,51 @@
using System.Diagnostics;
using OpenTelemetry.Logs;

namespace OpenTelemetry
namespace OpenTelemetry;

/// <summary>
/// Implements a batch log record export processor.
/// </summary>
public class BatchLogRecordExportProcessor : BatchExportProcessor<LogRecord>
{
/// <summary>
/// Implements a batch log record export processor.
/// Initializes a new instance of the <see cref="BatchLogRecordExportProcessor"/> class.
/// </summary>
public class BatchLogRecordExportProcessor : BatchExportProcessor<LogRecord>
/// <param name="exporter">Log record exporter.</param>
/// <param name="maxQueueSize">The maximum queue size. After the size is reached data are dropped. The default value is 2048.</param>
/// <param name="scheduledDelayMilliseconds">The delay interval in milliseconds between two consecutive exports. The default value is 5000.</param>
/// <param name="exporterTimeoutMilliseconds">How long the export can run before it is cancelled. The default value is 30000.</param>
/// <param name="maxExportBatchSize">The maximum batch size of every export. It must be smaller or equal to maxQueueSize. The default value is 512.</param>
public BatchLogRecordExportProcessor(
BaseExporter<LogRecord> exporter,
int maxQueueSize = DefaultMaxQueueSize,
int scheduledDelayMilliseconds = DefaultScheduledDelayMilliseconds,
int exporterTimeoutMilliseconds = DefaultExporterTimeoutMilliseconds,
int maxExportBatchSize = DefaultMaxExportBatchSize)
: base(
exporter,
maxQueueSize,
scheduledDelayMilliseconds,
exporterTimeoutMilliseconds,
maxExportBatchSize)
{
/// <summary>
/// Initializes a new instance of the <see cref="BatchLogRecordExportProcessor"/> class.
/// </summary>
/// <param name="exporter">Log record exporter.</param>
/// <param name="maxQueueSize">The maximum queue size. After the size is reached data are dropped. The default value is 2048.</param>
/// <param name="scheduledDelayMilliseconds">The delay interval in milliseconds between two consecutive exports. The default value is 5000.</param>
/// <param name="exporterTimeoutMilliseconds">How long the export can run before it is cancelled. The default value is 30000.</param>
/// <param name="maxExportBatchSize">The maximum batch size of every export. It must be smaller or equal to maxQueueSize. The default value is 512.</param>
public BatchLogRecordExportProcessor(
BaseExporter<LogRecord> exporter,
int maxQueueSize = DefaultMaxQueueSize,
int scheduledDelayMilliseconds = DefaultScheduledDelayMilliseconds,
int exporterTimeoutMilliseconds = DefaultExporterTimeoutMilliseconds,
int maxExportBatchSize = DefaultMaxExportBatchSize)
: base(
exporter,
maxQueueSize,
scheduledDelayMilliseconds,
exporterTimeoutMilliseconds,
maxExportBatchSize)
{
}
}

/// <inheritdoc/>
public override void OnEnd(LogRecord data)
{
// Note: Intentionally doing a Debug.Assert here and not a
// Guard.ThrowIfNull to save prod cycles. Null should really never
// happen here.
Debug.Assert(data != null, "LogRecord was null.");
/// <inheritdoc/>
public override void OnEnd(LogRecord data)
{
// Note: Intentionally doing a Debug.Assert here and not a
// Guard.ThrowIfNull to save prod cycles. Null should really never
// happen here.
Debug.Assert(data != null, "LogRecord was null.");

data!.Buffer();
data!.Buffer();

data.AddReference();
data.AddReference();

if (!this.TryExport(data))
{
LogRecordSharedPool.Current.Return(data);
}
if (!this.TryExport(data))
{
LogRecordSharedPool.Current.Return(data);
}
}
}
177 changes: 88 additions & 89 deletions src/OpenTelemetry/Logs/ILogger/OpenTelemetryLoggerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,108 +20,107 @@
using OpenTelemetry.Internal;
using OpenTelemetry.Resources;

namespace OpenTelemetry.Logs
namespace OpenTelemetry.Logs;

/// <summary>
/// Contains OpenTelemetry logging options.
/// </summary>
public class OpenTelemetryLoggerOptions
{
internal readonly List<BaseProcessor<LogRecord>> Processors = new();
internal ResourceBuilder? ResourceBuilder;

/// <summary>
/// Contains OpenTelemetry logging options.
/// Gets or sets a value indicating whether or not formatted log message
/// should be included on generated <see cref="LogRecord"/>s. Default
/// value: <see langword="false"/>.
/// </summary>
public class OpenTelemetryLoggerOptions
{
internal readonly List<BaseProcessor<LogRecord>> Processors = new();
internal ResourceBuilder? ResourceBuilder;
/// <remarks>
/// Note: When set to <see langword="false"/> a formatted log message
/// will not be included if a message template can be found. If a
/// message template is not found, a formatted log message is always
/// included.
/// </remarks>
public bool IncludeFormattedMessage { get; set; }

/// <summary>
/// Gets or sets a value indicating whether or not formatted log message
/// should be included on generated <see cref="LogRecord"/>s. Default
/// value: <see langword="false"/>.
/// </summary>
/// <remarks>
/// Note: When set to <see langword="false"/> a formatted log message
/// will not be included if a message template can be found. If a
/// message template is not found, a formatted log message is always
/// included.
/// </remarks>
public bool IncludeFormattedMessage { get; set; }

/// <summary>
/// Gets or sets a value indicating whether or not log scopes should be
/// included on generated <see cref="LogRecord"/>s. Default value:
/// <see langword="false"/>.
/// </summary>
public bool IncludeScopes { get; set; }
/// <summary>
/// Gets or sets a value indicating whether or not log scopes should be
/// included on generated <see cref="LogRecord"/>s. Default value:
/// <see langword="false"/>.
/// </summary>
public bool IncludeScopes { get; set; }

/// <summary>
/// Gets or sets a value indicating whether or not log state should be
/// parsed into <see cref="LogRecord.Attributes"/> on generated <see
/// cref="LogRecord"/>s. Default value: <see langword="false"/>.
/// </summary>
/// <remarks>
/// Notes:
/// <list type="bullet">
/// <item>Parsing is only executed when the state logged does NOT
/// implement <see cref="IReadOnlyList{T}"/> or <see
/// cref="IEnumerable{T}"/> where <c>T</c> is <c>KeyValuePair&lt;string,
/// object&gt;</c>.</item>
/// <item>When <see cref="ParseStateValues"/> is set to <see
/// langword="true"/> <see cref="LogRecord.State"/> will always be <see
/// langword="null"/>.</item>
/// </list>
/// </remarks>
public bool ParseStateValues { get; set; }
/// <summary>
/// Gets or sets a value indicating whether or not log state should be
/// parsed into <see cref="LogRecord.Attributes"/> on generated <see
/// cref="LogRecord"/>s. Default value: <see langword="false"/>.
/// </summary>
/// <remarks>
/// Notes:
/// <list type="bullet">
/// <item>Parsing is only executed when the state logged does NOT
/// implement <see cref="IReadOnlyList{T}"/> or <see
/// cref="IEnumerable{T}"/> where <c>T</c> is <c>KeyValuePair&lt;string,
/// object&gt;</c>.</item>
/// <item>When <see cref="ParseStateValues"/> is set to <see
/// langword="true"/> <see cref="LogRecord.State"/> will always be <see
/// langword="null"/>.</item>
/// </list>
/// </remarks>
public bool ParseStateValues { get; set; }

/// <summary>
/// Gets or sets a value indicating whether or not attributes specified
/// via log state should be included on generated <see
/// cref="LogRecord"/>s. Default value: <see langword="true"/>.
/// </summary>
internal bool IncludeAttributes { get; set; } = true;
/// <summary>
/// Gets or sets a value indicating whether or not attributes specified
/// via log state should be included on generated <see
/// cref="LogRecord"/>s. Default value: <see langword="true"/>.
/// </summary>
internal bool IncludeAttributes { get; set; } = true;

/// <summary>
/// Gets or sets a value indicating whether or not the <see
/// cref="Activity.TraceStateString"/> for the current <see
/// cref="Activity"/> should be included on generated <see
/// cref="LogRecord"/>s. Default value: <see langword="false"/>.
/// </summary>
internal bool IncludeTraceState { get; set; }
/// <summary>
/// Gets or sets a value indicating whether or not the <see
/// cref="Activity.TraceStateString"/> for the current <see
/// cref="Activity"/> should be included on generated <see
/// cref="LogRecord"/>s. Default value: <see langword="false"/>.
/// </summary>
internal bool IncludeTraceState { get; set; }

/// <summary>
/// Adds processor to the options.
/// </summary>
/// <param name="processor">Log processor to add.</param>
/// <returns>Returns <see cref="OpenTelemetryLoggerOptions"/> for chaining.</returns>
public OpenTelemetryLoggerOptions AddProcessor(BaseProcessor<LogRecord> processor)
{
Guard.ThrowIfNull(processor);
/// <summary>
/// Adds processor to the options.
/// </summary>
/// <param name="processor">Log processor to add.</param>
/// <returns>Returns <see cref="OpenTelemetryLoggerOptions"/> for chaining.</returns>
public OpenTelemetryLoggerOptions AddProcessor(BaseProcessor<LogRecord> processor)
{
Guard.ThrowIfNull(processor);

this.Processors.Add(processor);
this.Processors.Add(processor);

return this;
}
return this;
}

/// <summary>
/// Sets the <see cref="ResourceBuilder"/> from which the Resource associated with
/// this provider is built from. Overwrites currently set ResourceBuilder.
/// </summary>
/// <param name="resourceBuilder"><see cref="ResourceBuilder"/> from which Resource will be built.</param>
/// <returns>Returns <see cref="OpenTelemetryLoggerOptions"/> for chaining.</returns>
public OpenTelemetryLoggerOptions SetResourceBuilder(ResourceBuilder resourceBuilder)
{
Guard.ThrowIfNull(resourceBuilder);
/// <summary>
/// Sets the <see cref="ResourceBuilder"/> from which the Resource associated with
/// this provider is built from. Overwrites currently set ResourceBuilder.
/// </summary>
/// <param name="resourceBuilder"><see cref="ResourceBuilder"/> from which Resource will be built.</param>
/// <returns>Returns <see cref="OpenTelemetryLoggerOptions"/> for chaining.</returns>
public OpenTelemetryLoggerOptions SetResourceBuilder(ResourceBuilder resourceBuilder)
{
Guard.ThrowIfNull(resourceBuilder);

this.ResourceBuilder = resourceBuilder;
return this;
}
this.ResourceBuilder = resourceBuilder;
return this;
}

internal OpenTelemetryLoggerOptions Copy()
internal OpenTelemetryLoggerOptions Copy()
{
return new()
{
return new()
{
IncludeFormattedMessage = this.IncludeFormattedMessage,
IncludeScopes = this.IncludeScopes,
ParseStateValues = this.ParseStateValues,
IncludeAttributes = this.IncludeAttributes,
IncludeTraceState = this.IncludeTraceState,
};
}
IncludeFormattedMessage = this.IncludeFormattedMessage,
IncludeScopes = this.IncludeScopes,
ParseStateValues = this.ParseStateValues,
IncludeAttributes = this.IncludeAttributes,
IncludeTraceState = this.IncludeTraceState,
};
}
}
Loading