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

Added SimpleExporter and BatchExporter for Activity and LogRecord #1622

Merged
2 changes: 1 addition & 1 deletion docs/logs/extending-the-sdk/LoggerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ public static OpenTelemetryLoggerOptions AddMyExporter(this OpenTelemetryLoggerO
throw new ArgumentNullException(nameof(options));
}

return options.AddProcessor(new BatchExportProcessor<LogRecord>(new MyExporter()));
return options.AddProcessor(new BatchLogRecordExportProcessor(new MyExporter()));
}
}
2 changes: 1 addition & 1 deletion docs/logs/extending-the-sdk/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static void Main()
builder.AddOpenTelemetry(options => options
.AddProcessor(new MyProcessor("ProcessorA"))
.AddProcessor(new MyProcessor("ProcessorB"))
.AddProcessor(new SimpleExportProcessor<LogRecord>(new MyExporter("ExporterX")))
.AddProcessor(new SimpleLogRecordExportProcessor(new MyExporter("ExporterX")))
.AddMyExporter());
});

Expand Down
2 changes: 1 addition & 1 deletion docs/trace/extending-the-sdk/MyExporterHelperExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ public static TracerProviderBuilder AddMyExporter(this TracerProviderBuilder bui
throw new ArgumentNullException(nameof(builder));
}

return builder.AddProcessor(new BatchExportProcessor<Activity>(new MyExporter()));
return builder.AddProcessor(new BatchActivityExportProcessor(new MyExporter()));
}
}
2 changes: 1 addition & 1 deletion docs/trace/extending-the-sdk/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static void Main()
.AddSource("OTel.Demo")
.AddProcessor(new MyProcessor("ProcessorA"))
.AddProcessor(new MyProcessor("ProcessorB"))
.AddProcessor(new SimpleExportProcessor<Activity>(new MyExporter("ExporterX")))
.AddProcessor(new SimpleActivityExportProcessor(new MyExporter("ExporterX")))
.AddMyExporter()
.Build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static TracerProviderBuilder AddConsoleExporter(this TracerProviderBuilde

var options = new ConsoleExporterOptions();
configure?.Invoke(options);
return builder.AddProcessor(new SimpleExportProcessor<Activity>(new ConsoleExporter<Activity>(options)));
return builder.AddProcessor(new SimpleActivityExportProcessor(new ConsoleExporter<Activity>(options)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static OpenTelemetryLoggerOptions AddConsoleExporter(this OpenTelemetryLo

var options = new ConsoleExporterOptions();
configure?.Invoke(options);
return loggerOptions.AddProcessor(new SimpleExportProcessor<LogRecord>(new ConsoleExporter<LogRecord>(options)));
return loggerOptions.AddProcessor(new SimpleLogRecordExportProcessor(new ConsoleExporter<LogRecord>(options)));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static TracerProviderBuilder AddInMemoryExporter(this TracerProviderBuild
throw new ArgumentNullException(nameof(exportedItems));
}

return builder.AddProcessor(new SimpleExportProcessor<Activity>(new InMemoryExporter<Activity>(exportedItems)));
return builder.AddProcessor(new SimpleActivityExportProcessor(new InMemoryExporter<Activity>(exportedItems)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static OpenTelemetryLoggerOptions AddInMemoryExporter(this OpenTelemetryL
throw new ArgumentNullException(nameof(exportedItems));
}

return loggerOptions.AddProcessor(new SimpleExportProcessor<LogRecord>(new InMemoryExporter<LogRecord>(exportedItems)));
return loggerOptions.AddProcessor(new SimpleLogRecordExportProcessor(new InMemoryExporter<LogRecord>(exportedItems)));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ public static TracerProviderBuilder AddJaegerExporter(this TracerProviderBuilder

if (exporterOptions.ExportProcessorType == ExportProcessorType.Simple)
{
return builder.AddProcessor(new SimpleExportProcessor<Activity>(jaegerExporter));
return builder.AddProcessor(new SimpleActivityExportProcessor(jaegerExporter));
}
else
{
return builder.AddProcessor(new BatchExportProcessor<Activity>(
return builder.AddProcessor(new BatchActivityExportProcessor(
jaegerExporter,
exporterOptions.BatchExportProcessorOptions.MaxQueueSize,
exporterOptions.BatchExportProcessorOptions.ScheduledDelayMilliseconds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ public static TracerProviderBuilder AddOtlpExporter(this TracerProviderBuilder b

if (exporterOptions.ExportProcessorType == ExportProcessorType.Simple)
{
return builder.AddProcessor(new SimpleExportProcessor<Activity>(otlpExporter));
return builder.AddProcessor(new SimpleActivityExportProcessor(otlpExporter));
}
else
{
return builder.AddProcessor(new BatchExportProcessor<Activity>(
return builder.AddProcessor(new BatchActivityExportProcessor(
otlpExporter,
exporterOptions.BatchExportProcessorOptions.MaxQueueSize,
exporterOptions.BatchExportProcessorOptions.ScheduledDelayMilliseconds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ public static TracerProviderBuilder AddZipkinExporter(this TracerProviderBuilder

if (exporterOptions.ExportProcessorType == ExportProcessorType.Simple)
{
return builder.AddProcessor(new SimpleExportProcessor<Activity>(zipkinExporter));
return builder.AddProcessor(new SimpleActivityExportProcessor(zipkinExporter));
}
else
{
return builder.AddProcessor(new BatchExportProcessor<Activity>(
return builder.AddProcessor(new BatchActivityExportProcessor(
zipkinExporter,
exporterOptions.BatchExportProcessorOptions.MaxQueueSize,
exporterOptions.BatchExportProcessorOptions.ScheduledDelayMilliseconds,
Expand Down
12 changes: 3 additions & 9 deletions src/OpenTelemetry/BaseExportProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public abstract class BaseExportProcessor<T> : BaseProcessor<T>
/// Initializes a new instance of the <see cref="BaseExportProcessor{T}"/> class.
/// </summary>
/// <param name="exporter">Exporter instance.</param>
public BaseExportProcessor(BaseExporter<T> exporter)
protected BaseExportProcessor(BaseExporter<T> exporter)
{
this.exporter = exporter ?? throw new ArgumentNullException(nameof(exporter));
}
Expand All @@ -44,18 +44,12 @@ public sealed override void OnStart(T data)
{
}

/// <inheritdoc />
public sealed override void OnEnd(T data)
public override void OnEnd(T data)
{
if (data is Activity activity && activity.ActivityTraceFlags == ActivityTraceFlags.None)
{
return;
}

this.OnExport(data);
}

public abstract void OnExport(T data);
protected abstract void OnExport(T data);

internal override void SetParentProvider(BaseProvider parentProvider)
{
Expand Down
49 changes: 49 additions & 0 deletions src/OpenTelemetry/BatchActivityExportProcessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// <copyright file="BatchActivityExportProcessor.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>

using System.Diagnostics;

namespace OpenTelemetry
{
public class BatchActivityExportProcessor : BatchExportProcessor<Activity>
{
public BatchActivityExportProcessor(
BaseExporter<Activity> exporter,
int maxQueueSize = DefaultMaxQueueSize,
int scheduledDelayMilliseconds = DefaultScheduledDelayMilliseconds,
int exporterTimeoutMilliseconds = DefaultExporterTimeoutMilliseconds,
int maxExportBatchSize = DefaultMaxExportBatchSize)
: base(
exporter,
maxQueueSize,
scheduledDelayMilliseconds,
exporterTimeoutMilliseconds,
maxExportBatchSize)
{
}

/// <inheritdoc />
public override void OnEnd(Activity data)
{
if (!data.Recorded)
{
return;
}

this.OnExport(data);
}
}
}
6 changes: 3 additions & 3 deletions src/OpenTelemetry/BatchExportProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace OpenTelemetry
/// Implements processor that batches telemetry objects before calling exporter.
/// </summary>
/// <typeparam name="T">The type of telemetry object to be exported.</typeparam>
public class BatchExportProcessor<T> : BaseExportProcessor<T>
public abstract class BatchExportProcessor<T> : BaseExportProcessor<T>
where T : class
{
internal const int DefaultMaxQueueSize = 2048;
Expand All @@ -52,7 +52,7 @@ public class BatchExportProcessor<T> : BaseExportProcessor<T>
/// <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 BatchExportProcessor(
protected BatchExportProcessor(
BaseExporter<T> exporter,
int maxQueueSize = DefaultMaxQueueSize,
int scheduledDelayMilliseconds = DefaultScheduledDelayMilliseconds,
Expand Down Expand Up @@ -108,7 +108,7 @@ public BatchExportProcessor(
internal long ProcessedCount => this.circularBuffer.RemovedCount;

/// <inheritdoc/>
public override void OnExport(T data)
protected override void OnExport(T data)
{
if (this.circularBuffer.TryAdd(data, maxSpinCount: 50000))
{
Expand Down
41 changes: 41 additions & 0 deletions src/OpenTelemetry/BatchLogRecordExportProcessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// <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>

#if NET461 || NETSTANDARD2_0
using OpenTelemetry.Logs;

namespace OpenTelemetry
{
public class BatchLogRecordExportProcessor : BatchExportProcessor<LogRecord>
{
public BatchLogRecordExportProcessor(
BaseExporter<LogRecord> exporter,
int maxQueueSize = DefaultMaxQueueSize,
int scheduledDelayMilliseconds = DefaultScheduledDelayMilliseconds,
int exporterTimeoutMilliseconds = DefaultExporterTimeoutMilliseconds,
int maxExportBatchSize = DefaultMaxExportBatchSize)
: base(
exporter,
maxQueueSize,
scheduledDelayMilliseconds,
exporterTimeoutMilliseconds,
maxExportBatchSize)
{

}
}
}
#endif
39 changes: 39 additions & 0 deletions src/OpenTelemetry/SimpleActivityExportProcessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// <copyright file="SimpleActivityExportProcessor.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>

using System.Diagnostics;

namespace OpenTelemetry
{
public class SimpleActivityExportProcessor : SimpleExportProcessor<Activity>
{
public SimpleActivityExportProcessor(BaseExporter<Activity> exporter)
: base(exporter)
{
}

/// <inheritdoc />
public override void OnEnd(Activity data)
{
if (!data.Recorded)
{
return;
}

this.OnExport(data);
}
}
}
6 changes: 3 additions & 3 deletions src/OpenTelemetry/SimpleExportProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace OpenTelemetry
/// Implements processor that exports telemetry data at each OnEnd call.
/// </summary>
/// <typeparam name="T">The type of telemetry object to be exported.</typeparam>
public class SimpleExportProcessor<T> : BaseExportProcessor<T>
public abstract class SimpleExportProcessor<T> : BaseExportProcessor<T>
where T : class
{
private readonly object syncObject = new object();
Expand All @@ -32,13 +32,13 @@ public class SimpleExportProcessor<T> : BaseExportProcessor<T>
/// Initializes a new instance of the <see cref="SimpleExportProcessor{T}"/> class.
/// </summary>
/// <param name="exporter">Exporter instance.</param>
public SimpleExportProcessor(BaseExporter<T> exporter)
protected SimpleExportProcessor(BaseExporter<T> exporter)
: base(exporter)
{
}

/// <inheritdoc />
public override void OnExport(T data)
protected override void OnExport(T data)
{
lock (this.syncObject)
{
Expand Down
30 changes: 30 additions & 0 deletions src/OpenTelemetry/SimpleLogRecordExportProcessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// <copyright file="SimpleLogRecordExportProcessor.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>

#if NET461 || NETSTANDARD2_0
using OpenTelemetry.Logs;

namespace OpenTelemetry
{
public class SimpleLogRecordExportProcessor : SimpleExportProcessor<LogRecord>
{
public SimpleLogRecordExportProcessor(BaseExporter<LogRecord> exporter)
: base(exporter)
{
}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void ToOtlpResourceSpansTest(bool addResource)

using var openTelemetrySdk = builder.Build();

var processor = new BatchExportProcessor<Activity>(new TestExporter<Activity>(RunTest));
var processor = new BatchActivityExportProcessor(new TestExporter<Activity>(RunTest));
const int numOfSpans = 10;
bool isEven;
for (var i = 0; i < numOfSpans; i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void SuppresssesInstrumentation()
Endpoint = new Uri($"http://{this.testServerHost}:{this.testServerPort}/api/v2/spans?requestId={requestId}"),
};
var zipkinExporter = new ZipkinExporter(exporterOptions);
var exportActivityProcessor = new BatchExportProcessor<Activity>(zipkinExporter);
var exportActivityProcessor = new BatchActivityExportProcessor(zipkinExporter);

var openTelemetrySdk = Sdk.CreateTracerProviderBuilder()
.AddSource(ActivitySourceName)
Expand Down Expand Up @@ -168,7 +168,7 @@ public void IntegrationTest(bool useShortTraceIds, bool useTestResource, bool is
exporter.SetLocalEndpointFromResource(Resource.Empty);
}

var processor = new SimpleExportProcessor<Activity>(exporter);
var processor = new SimpleActivityExportProcessor(exporter);

processor.OnEnd(activity);

Expand Down
Loading