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 Activity.IsRecorded check for Export #1574

Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 4 additions & 3 deletions src/OpenTelemetry/.publicApi/net452/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ abstract OpenTelemetry.Metrics.Export.MetricProcessor.Process(OpenTelemetry.Metr
abstract OpenTelemetry.Trace.Sampler.ShouldSample(in OpenTelemetry.Trace.SamplingParameters samplingParameters) -> OpenTelemetry.Trace.SamplingResult
override OpenTelemetry.BaseExportProcessor<T>.Dispose(bool disposing) -> void
override OpenTelemetry.BaseExportProcessor<T>.OnShutdown(int timeoutMilliseconds) -> bool
override OpenTelemetry.BatchExportProcessor<T>.OnEnd(T data) -> void
override OpenTelemetry.BatchExportProcessor<T>.OnExport(T data) -> void
override OpenTelemetry.BatchExportProcessor<T>.OnForceFlush(int timeoutMilliseconds) -> bool
override OpenTelemetry.BatchExportProcessor<T>.OnShutdown(int timeoutMilliseconds) -> bool
override OpenTelemetry.CompositeProcessor<T>.Dispose(bool disposing) -> void
Expand Down Expand Up @@ -214,14 +214,15 @@ override OpenTelemetry.Metrics.Aggregators.Int64MeasureMinMaxSumCountAggregator.
override OpenTelemetry.Metrics.Aggregators.Int64MeasureMinMaxSumCountAggregator.Update(long value) -> void
override OpenTelemetry.Metrics.Export.UngroupedBatcher.FinishCollectionCycle(out System.Collections.Generic.IEnumerable<OpenTelemetry.Metrics.Export.Metric> metrics) -> void
override OpenTelemetry.Metrics.Export.UngroupedBatcher.Process(OpenTelemetry.Metrics.Export.Metric metric) -> void
override OpenTelemetry.SimpleExportProcessor<T>.OnEnd(T data) -> void
override OpenTelemetry.SimpleExportProcessor<T>.OnExport(T data) -> void
override OpenTelemetry.Trace.AlwaysOffSampler.ShouldSample(in OpenTelemetry.Trace.SamplingParameters samplingParameters) -> OpenTelemetry.Trace.SamplingResult
override OpenTelemetry.Trace.AlwaysOnSampler.ShouldSample(in OpenTelemetry.Trace.SamplingParameters samplingParameters) -> OpenTelemetry.Trace.SamplingResult
override OpenTelemetry.Trace.ParentBasedSampler.ShouldSample(in OpenTelemetry.Trace.SamplingParameters samplingParameters) -> OpenTelemetry.Trace.SamplingResult
override OpenTelemetry.Trace.SamplingResult.Equals(object obj) -> bool
override OpenTelemetry.Trace.SamplingResult.GetHashCode() -> int
override OpenTelemetry.Trace.TraceIdRatioBasedSampler.ShouldSample(in OpenTelemetry.Trace.SamplingParameters samplingParameters) -> OpenTelemetry.Trace.SamplingResult
override abstract OpenTelemetry.BaseExportProcessor<T>.OnEnd(T data) -> void
abstract OpenTelemetry.BaseExportProcessor<T>.OnExport(T data) -> void
override sealed OpenTelemetry.BaseExportProcessor<T>.OnEnd(T data) -> void
override sealed OpenTelemetry.BaseExportProcessor<T>.OnStart(T data) -> void
readonly OpenTelemetry.BaseExportProcessor<T>.exporter -> OpenTelemetry.BaseExporter<T>
static OpenTelemetry.ProviderExtensions.GetResource(this OpenTelemetry.BaseProvider baseProvider) -> OpenTelemetry.Resources.Resource
Expand Down
7 changes: 4 additions & 3 deletions src/OpenTelemetry/.publicApi/net46/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ abstract OpenTelemetry.Metrics.Export.MetricProcessor.Process(OpenTelemetry.Metr
abstract OpenTelemetry.Trace.Sampler.ShouldSample(in OpenTelemetry.Trace.SamplingParameters samplingParameters) -> OpenTelemetry.Trace.SamplingResult
override OpenTelemetry.BaseExportProcessor<T>.Dispose(bool disposing) -> void
override OpenTelemetry.BaseExportProcessor<T>.OnShutdown(int timeoutMilliseconds) -> bool
override OpenTelemetry.BatchExportProcessor<T>.OnEnd(T data) -> void
override OpenTelemetry.BatchExportProcessor<T>.OnExport(T data) -> void
override OpenTelemetry.BatchExportProcessor<T>.OnForceFlush(int timeoutMilliseconds) -> bool
override OpenTelemetry.BatchExportProcessor<T>.OnShutdown(int timeoutMilliseconds) -> bool
override OpenTelemetry.CompositeProcessor<T>.Dispose(bool disposing) -> void
Expand Down Expand Up @@ -214,14 +214,15 @@ override OpenTelemetry.Metrics.Aggregators.Int64MeasureMinMaxSumCountAggregator.
override OpenTelemetry.Metrics.Aggregators.Int64MeasureMinMaxSumCountAggregator.Update(long value) -> void
override OpenTelemetry.Metrics.Export.UngroupedBatcher.FinishCollectionCycle(out System.Collections.Generic.IEnumerable<OpenTelemetry.Metrics.Export.Metric> metrics) -> void
override OpenTelemetry.Metrics.Export.UngroupedBatcher.Process(OpenTelemetry.Metrics.Export.Metric metric) -> void
override OpenTelemetry.SimpleExportProcessor<T>.OnEnd(T data) -> void
override OpenTelemetry.SimpleExportProcessor<T>.OnExport(T data) -> void
override OpenTelemetry.Trace.AlwaysOffSampler.ShouldSample(in OpenTelemetry.Trace.SamplingParameters samplingParameters) -> OpenTelemetry.Trace.SamplingResult
override OpenTelemetry.Trace.AlwaysOnSampler.ShouldSample(in OpenTelemetry.Trace.SamplingParameters samplingParameters) -> OpenTelemetry.Trace.SamplingResult
override OpenTelemetry.Trace.ParentBasedSampler.ShouldSample(in OpenTelemetry.Trace.SamplingParameters samplingParameters) -> OpenTelemetry.Trace.SamplingResult
override OpenTelemetry.Trace.SamplingResult.Equals(object obj) -> bool
override OpenTelemetry.Trace.SamplingResult.GetHashCode() -> int
override OpenTelemetry.Trace.TraceIdRatioBasedSampler.ShouldSample(in OpenTelemetry.Trace.SamplingParameters samplingParameters) -> OpenTelemetry.Trace.SamplingResult
override abstract OpenTelemetry.BaseExportProcessor<T>.OnEnd(T data) -> void
abstract OpenTelemetry.BaseExportProcessor<T>.OnExport(T data) -> void
override sealed OpenTelemetry.BaseExportProcessor<T>.OnEnd(T data) -> void
override sealed OpenTelemetry.BaseExportProcessor<T>.OnStart(T data) -> void
readonly OpenTelemetry.BaseExportProcessor<T>.exporter -> OpenTelemetry.BaseExporter<T>
static OpenTelemetry.ProviderExtensions.GetResource(this OpenTelemetry.BaseProvider baseProvider) -> OpenTelemetry.Resources.Resource
Expand Down
7 changes: 4 additions & 3 deletions src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ abstract OpenTelemetry.Metrics.Export.MetricProcessor.Process(OpenTelemetry.Metr
abstract OpenTelemetry.Trace.Sampler.ShouldSample(in OpenTelemetry.Trace.SamplingParameters samplingParameters) -> OpenTelemetry.Trace.SamplingResult
override OpenTelemetry.BaseExportProcessor<T>.Dispose(bool disposing) -> void
override OpenTelemetry.BaseExportProcessor<T>.OnShutdown(int timeoutMilliseconds) -> bool
override OpenTelemetry.BatchExportProcessor<T>.OnEnd(T data) -> void
override OpenTelemetry.BatchExportProcessor<T>.OnExport(T data) -> void
override OpenTelemetry.BatchExportProcessor<T>.OnForceFlush(int timeoutMilliseconds) -> bool
override OpenTelemetry.BatchExportProcessor<T>.OnShutdown(int timeoutMilliseconds) -> bool
override OpenTelemetry.CompositeProcessor<T>.Dispose(bool disposing) -> void
Expand Down Expand Up @@ -233,14 +233,15 @@ override OpenTelemetry.Metrics.Aggregators.Int64MeasureMinMaxSumCountAggregator.
override OpenTelemetry.Metrics.Aggregators.Int64MeasureMinMaxSumCountAggregator.Update(long value) -> void
override OpenTelemetry.Metrics.Export.UngroupedBatcher.FinishCollectionCycle(out System.Collections.Generic.IEnumerable<OpenTelemetry.Metrics.Export.Metric> metrics) -> void
override OpenTelemetry.Metrics.Export.UngroupedBatcher.Process(OpenTelemetry.Metrics.Export.Metric metric) -> void
override OpenTelemetry.SimpleExportProcessor<T>.OnEnd(T data) -> void
override OpenTelemetry.SimpleExportProcessor<T>.OnExport(T data) -> void
override OpenTelemetry.Trace.AlwaysOffSampler.ShouldSample(in OpenTelemetry.Trace.SamplingParameters samplingParameters) -> OpenTelemetry.Trace.SamplingResult
override OpenTelemetry.Trace.AlwaysOnSampler.ShouldSample(in OpenTelemetry.Trace.SamplingParameters samplingParameters) -> OpenTelemetry.Trace.SamplingResult
override OpenTelemetry.Trace.ParentBasedSampler.ShouldSample(in OpenTelemetry.Trace.SamplingParameters samplingParameters) -> OpenTelemetry.Trace.SamplingResult
override OpenTelemetry.Trace.SamplingResult.Equals(object obj) -> bool
override OpenTelemetry.Trace.SamplingResult.GetHashCode() -> int
override OpenTelemetry.Trace.TraceIdRatioBasedSampler.ShouldSample(in OpenTelemetry.Trace.SamplingParameters samplingParameters) -> OpenTelemetry.Trace.SamplingResult
override abstract OpenTelemetry.BaseExportProcessor<T>.OnEnd(T data) -> void
abstract OpenTelemetry.BaseExportProcessor<T>.OnExport(T data) -> void
override sealed OpenTelemetry.BaseExportProcessor<T>.OnEnd(T data) -> void
override sealed OpenTelemetry.BaseExportProcessor<T>.OnStart(T data) -> void
readonly OpenTelemetry.BaseExportProcessor<T>.exporter -> OpenTelemetry.BaseExporter<T>
static Microsoft.Extensions.Logging.OpenTelemetryLoggingExtensions.AddOpenTelemetry(this Microsoft.Extensions.Logging.ILoggingBuilder builder, System.Action<OpenTelemetry.Logs.OpenTelemetryLoggerOptions> configure = null) -> Microsoft.Extensions.Logging.ILoggingBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ abstract OpenTelemetry.Metrics.Export.MetricProcessor.Process(OpenTelemetry.Metr
abstract OpenTelemetry.Trace.Sampler.ShouldSample(in OpenTelemetry.Trace.SamplingParameters samplingParameters) -> OpenTelemetry.Trace.SamplingResult
override OpenTelemetry.BaseExportProcessor<T>.Dispose(bool disposing) -> void
override OpenTelemetry.BaseExportProcessor<T>.OnShutdown(int timeoutMilliseconds) -> bool
override OpenTelemetry.BatchExportProcessor<T>.OnEnd(T data) -> void
override OpenTelemetry.BatchExportProcessor<T>.OnExport(T data) -> void
override OpenTelemetry.BatchExportProcessor<T>.OnForceFlush(int timeoutMilliseconds) -> bool
override OpenTelemetry.BatchExportProcessor<T>.OnShutdown(int timeoutMilliseconds) -> bool
override OpenTelemetry.CompositeProcessor<T>.Dispose(bool disposing) -> void
Expand Down Expand Up @@ -233,14 +233,15 @@ override OpenTelemetry.Metrics.Aggregators.Int64MeasureMinMaxSumCountAggregator.
override OpenTelemetry.Metrics.Aggregators.Int64MeasureMinMaxSumCountAggregator.Update(long value) -> void
override OpenTelemetry.Metrics.Export.UngroupedBatcher.FinishCollectionCycle(out System.Collections.Generic.IEnumerable<OpenTelemetry.Metrics.Export.Metric> metrics) -> void
override OpenTelemetry.Metrics.Export.UngroupedBatcher.Process(OpenTelemetry.Metrics.Export.Metric metric) -> void
override OpenTelemetry.SimpleExportProcessor<T>.OnEnd(T data) -> void
override OpenTelemetry.SimpleExportProcessor<T>.OnExport(T data) -> void
override OpenTelemetry.Trace.AlwaysOffSampler.ShouldSample(in OpenTelemetry.Trace.SamplingParameters samplingParameters) -> OpenTelemetry.Trace.SamplingResult
override OpenTelemetry.Trace.AlwaysOnSampler.ShouldSample(in OpenTelemetry.Trace.SamplingParameters samplingParameters) -> OpenTelemetry.Trace.SamplingResult
override OpenTelemetry.Trace.ParentBasedSampler.ShouldSample(in OpenTelemetry.Trace.SamplingParameters samplingParameters) -> OpenTelemetry.Trace.SamplingResult
override OpenTelemetry.Trace.SamplingResult.Equals(object obj) -> bool
override OpenTelemetry.Trace.SamplingResult.GetHashCode() -> int
override OpenTelemetry.Trace.TraceIdRatioBasedSampler.ShouldSample(in OpenTelemetry.Trace.SamplingParameters samplingParameters) -> OpenTelemetry.Trace.SamplingResult
override abstract OpenTelemetry.BaseExportProcessor<T>.OnEnd(T data) -> void
abstract OpenTelemetry.BaseExportProcessor<T>.OnExport(T data) -> void
override sealed OpenTelemetry.BaseExportProcessor<T>.OnEnd(T data) -> void
override sealed OpenTelemetry.BaseExportProcessor<T>.OnStart(T data) -> void
readonly OpenTelemetry.BaseExportProcessor<T>.exporter -> OpenTelemetry.BaseExporter<T>
static Microsoft.Extensions.Logging.OpenTelemetryLoggingExtensions.AddOpenTelemetry(this Microsoft.Extensions.Logging.ILoggingBuilder builder, System.Action<OpenTelemetry.Logs.OpenTelemetryLoggerOptions> configure = null) -> Microsoft.Extensions.Logging.ILoggingBuilder
Expand Down
13 changes: 12 additions & 1 deletion src/OpenTelemetry/BaseExportProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// </copyright>

using System;
using System.Diagnostics;
using OpenTelemetry.Internal;

namespace OpenTelemetry
Expand Down Expand Up @@ -44,7 +45,17 @@ public sealed override void OnStart(T data)
}

/// <inheritdoc />
public abstract override void OnEnd(T data);
public sealed override void OnEnd(T data)
{
if (data is Activity activity && activity.ActivityTraceFlags == ActivityTraceFlags.None)
utpilla marked this conversation as resolved.
Show resolved Hide resolved
{
return;
}

this.OnExport(data);
}

public abstract void OnExport(T data);

internal override void SetParentProvider(BaseProvider parentProvider)
{
Expand Down
2 changes: 1 addition & 1 deletion src/OpenTelemetry/BatchExportProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public BatchExportProcessor(
internal long ProcessedCount => this.circularBuffer.RemovedCount;

/// <inheritdoc/>
public override void OnEnd(T data)
public override void OnExport(T data)
{
if (this.circularBuffer.TryAdd(data, maxSpinCount: 50000))
{
Expand Down
10 changes: 6 additions & 4 deletions src/OpenTelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
([#1515](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1515/))
* Implemented `Shutdown` for `TracerProvider`.
([#1489](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1489))
* `Resources.CreateServiceResource` has been removed in
favor of the `ResourceBuilder` API.
* `Resources.CreateServiceResource` has been removed in favor of the
`ResourceBuilder` API.
([#1533](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1533))
* `TracerProviderBuilder.SetResource` has been changed to
`TracerProviderBuilder.SetResourceBuilder`.
Expand All @@ -29,9 +29,11 @@
* `telemetry.sdk.name` = `opentelemetry`
* `telemetry.sdk.language` = `dotnet`
* `telemetry.sdk.version` = [SDK version]
* `Resource` constructor marked as internal, as `ResourceBuilder` is
the recommended API to build resources.
* `Resource` constructor marked as internal, as `ResourceBuilder` is the
recommended API to build resources.
([#1566](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1566))
* Added check for ActivityTraceFlags for export
utpilla marked this conversation as resolved.
Show resolved Hide resolved
([#1574](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1574))

## 0.8.0-beta.1

Expand Down
2 changes: 1 addition & 1 deletion src/OpenTelemetry/SimpleExportProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public SimpleExportProcessor(BaseExporter<T> exporter)
}

/// <inheritdoc />
public override void OnEnd(T data)
public override void OnExport(T data)
{
lock (this.syncObject)
{
Expand Down
60 changes: 56 additions & 4 deletions test/OpenTelemetry.Tests/Trace/BatchExportActivityProcessorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ public void CheckIfBatchIsExportingOnQueueLimit()
maxExportBatchSize: 1,
scheduledDelayMilliseconds: 100_000);

processor.OnEnd(new Activity("start"));
var activity = new Activity("start");
activity.ActivityTraceFlags = ActivityTraceFlags.Recorded;

processor.OnEnd(activity);

for (int i = 0; i < 10 && exportedItems.Count == 0; i++)
{
Expand Down Expand Up @@ -90,8 +93,14 @@ public void CheckForceFlushExport(int timeout)
maxExportBatchSize: 3,
exporterTimeoutMilliseconds: 30000);

processor.OnEnd(new Activity("start1"));
processor.OnEnd(new Activity("start2"));
var activity1 = new Activity("start1");
activity1.ActivityTraceFlags = ActivityTraceFlags.Recorded;

var activity2 = new Activity("start2");
activity2.ActivityTraceFlags = ActivityTraceFlags.Recorded;

processor.OnEnd(activity1);
processor.OnEnd(activity2);

Assert.Equal(0, processor.ProcessedCount);

Expand Down Expand Up @@ -129,7 +138,10 @@ public void CheckShutdownExport(int timeout)
maxExportBatchSize: 3,
exporterTimeoutMilliseconds: 30000);

processor.OnEnd(new Activity("start"));
var activity = new Activity("start");
activity.ActivityTraceFlags = ActivityTraceFlags.Recorded;

processor.OnEnd(activity);
processor.Shutdown(timeout);

if (timeout == 0)
Expand All @@ -144,5 +156,45 @@ public void CheckShutdownExport(int timeout)
Assert.Equal(1, processor.ReceivedCount);
Assert.Equal(0, processor.DroppedCount);
}

[Fact]
public void CheckExportForRecordingAndSampledActivity()
{
var exportedItems = new List<Activity>();
using var exporter = new InMemoryExporter<Activity>(exportedItems);
using var processor = new BatchExportProcessor<Activity>(
exporter,
maxQueueSize: 1,
maxExportBatchSize: 1);

var activity = new Activity("start");
activity.ActivityTraceFlags = ActivityTraceFlags.Recorded;

processor.OnEnd(activity);
processor.Shutdown();

Assert.Single(exportedItems);
Assert.Equal(1, processor.ProcessedCount);
}

[Fact]
public void CheckExportForRecordingButNotSampledActivity()
{
var exportedItems = new List<Activity>();
using var exporter = new InMemoryExporter<Activity>(exportedItems);
using var processor = new BatchExportProcessor<Activity>(
exporter,
maxQueueSize: 1,
maxExportBatchSize: 1);

var activity = new Activity("start");
activity.ActivityTraceFlags = ActivityTraceFlags.None;

processor.OnEnd(activity);
processor.Shutdown();

Assert.Empty(exportedItems);
Assert.Equal(0, processor.ProcessedCount);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,16 @@ public void CheckExportedOnEnd()
using var exporter = new InMemoryExporter<Activity>(exportedItems);
using var processor = new SimpleExportProcessor<Activity>(exporter);

processor.OnEnd(new Activity("start1"));
var activity1 = new Activity("start1");
activity1.ActivityTraceFlags = ActivityTraceFlags.Recorded;

processor.OnEnd(activity1);
Assert.Single(exportedItems);

processor.OnEnd(new Activity("start2"));
var activity2 = new Activity("start2");
activity2.ActivityTraceFlags = ActivityTraceFlags.Recorded;

processor.OnEnd(activity2);
Assert.Equal(2, exportedItems.Count);
}

Expand All @@ -55,8 +61,14 @@ public void CheckForceFlushExport(int timeout)
using var exporter = new InMemoryExporter<Activity>(exportedItems);
using var processor = new SimpleExportProcessor<Activity>(exporter);

processor.OnEnd(new Activity("start1"));
processor.OnEnd(new Activity("start2"));
var activity1 = new Activity("start1");
activity1.ActivityTraceFlags = ActivityTraceFlags.Recorded;

var activity2 = new Activity("start2");
activity2.ActivityTraceFlags = ActivityTraceFlags.Recorded;

processor.OnEnd(activity1);
processor.OnEnd(activity2);

// checking before force flush
Assert.Equal(2, exportedItems.Count);
Expand All @@ -76,13 +88,44 @@ public void CheckShutdownExport(int timeout)
using var exporter = new InMemoryExporter<Activity>(exportedItems);
using var processor = new SimpleExportProcessor<Activity>(exporter);

processor.OnEnd(new Activity("start"));
var activity = new Activity("start");
activity.ActivityTraceFlags = ActivityTraceFlags.Recorded;

processor.OnEnd(activity);

// checking before shutdown
Assert.Single(exportedItems);

processor.Shutdown(timeout);
Assert.Single(exportedItems);
}

[Fact]
public void CheckExportForRecordingAndSampledActivity()
{
var exportedItems = new List<Activity>();
using var exporter = new InMemoryExporter<Activity>(exportedItems);
using var processor = new SimpleExportProcessor<Activity>(exporter);

var activity = new Activity("start");
activity.ActivityTraceFlags = ActivityTraceFlags.Recorded;

processor.OnEnd(activity);
Assert.Single(exportedItems);
}

[Fact]
public void CheckExportForRecordingButNotSampledActivity()
{
var exportedItems = new List<Activity>();
using var exporter = new InMemoryExporter<Activity>(exportedItems);
using var processor = new SimpleExportProcessor<Activity>(exporter);

var activity = new Activity("start");
activity.ActivityTraceFlags = ActivityTraceFlags.None;

processor.OnEnd(activity);
Assert.Empty(exportedItems);
}
}
}