-
Notifications
You must be signed in to change notification settings - Fork 763
/
BatchLogRecordExportProcessor.cs
70 lines (63 loc) · 2.85 KB
/
BatchLogRecordExportProcessor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// <copyright file="BatchLogRecordExportProcessor.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
#nullable enable
using System.Diagnostics;
using OpenTelemetry.Logs;
namespace OpenTelemetry
{
/// <summary>
/// Implements a batch log record export processor.
/// </summary>
public class BatchLogRecordExportProcessor : BatchExportProcessor<LogRecord>
{
/// <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.");
data!.Buffer();
data.AddReference();
if (!this.TryExport(data))
{
LogRecordSharedPool.Current.Return(data);
}
}
}
}