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 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
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
11 changes: 7 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,12 @@
* `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))
* Changed BaseExportProcessor to have it override OnExport instead of OnEnd;
Added check for ActivityTraceFlags to BaseExportProcessor OnEnd
([#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
3 changes: 2 additions & 1 deletion test/OpenTelemetry.Tests/OpenTelemetry.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry\OpenTelemetry.csproj" />
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry\OpenTelemetry.csproj" />
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry.Exporter.InMemory\OpenTelemetry.Exporter.InMemory.csproj" />
<ProjectReference Include="..\..\src\OpenTelemetry.Exporter.Console\OpenTelemetry.Exporter.Console.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
28 changes: 28 additions & 0 deletions test/OpenTelemetry.Tests/Shared/RecordOnlySampler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// <copyright file="RecordOnlySampler.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 OpenTelemetry.Trace;

namespace OpenTelemetry.Tests
{
internal class RecordOnlySampler : TestSampler
{
public override SamplingResult ShouldSample(in SamplingParameters param)
{
return new SamplingResult(SamplingDecision.RecordOnly);
}
}
}
36 changes: 36 additions & 0 deletions test/OpenTelemetry.Tests/Shared/TestExportProcessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// <copyright file="TestExportProcessor.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.Collections.Generic;

namespace OpenTelemetry.Tests
{
internal class TestExportProcessor<T> : BaseExportProcessor<T>
where T : class
{
public List<T> ExportedItems = new List<T>();

public TestExportProcessor(BaseExporter<T> exporter)
: base(exporter)
{
}

public override void OnExport(T data)
{
this.ExportedItems.Add(data);
}
}
}
40 changes: 36 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,25 @@ public void CheckShutdownExport(int timeout)
Assert.Equal(1, processor.ReceivedCount);
Assert.Equal(0, processor.DroppedCount);
}

[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);
}
}
}
Loading