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

Add exporter ForceFlush #2525

Merged
merged 4 commits into from
Oct 27, 2021
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
11 changes: 5 additions & 6 deletions build/Common.prod.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<!-- Temporarily disable public API check till metrics get close to Release
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="$(MicrosoftCodeAnalysisAnalyzersPkgVer)" Condition=" $(OS) == 'Windows_NT'">
<!-- Temporarily disable public API check till metrics get close to Release
cijothomas marked this conversation as resolved.
Show resolved Hide resolved
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="$(MicrosoftCodeAnalysisAnalyzersPkgVer)" Condition=" $(OS) == 'Windows_NT'">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
-->
</PackageReference>
-->
</ItemGroup>

<ItemGroup Condition="'$(MinVerTagPrefix)' == 'core-' AND '$(CheckAPICompatibility)' == 'true'">
<PackageReference Include="Microsoft.DotNet.ApiCompat" Version="6.0.0-beta.21308.1" PrivateAssets="All" />
Expand Down
5 changes: 3 additions & 2 deletions docs/logs/extending-the-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ not covered by the built-in exporters:
* Exporters should derive from `OpenTelemetry.BaseExporter<LogRecord>` (which
belongs to the [OpenTelemetry](../../../src/OpenTelemetry/README.md) package)
and implement the `Export` method.
* Exporters can optionally implement the `OnShutdown` method.
* Exporters can optionally implement the `OnForceFlush` and `OnShutdown` method.
* Depending on user's choice and load on the application, `Export` may get
called with one or more log records.
* Exporters will only receive sampled-in log records.
* Exporters should not throw exceptions from `Export` and `OnShutdown`.
* Exporters should not throw exceptions from `Export`, `OnForceFlush` and
`OnShutdown`.
* Exporters should not modify log records they receive (the same log records may
be exported again by different exporter).
* Exporters are responsible for any retry logic needed by the scenario. The SDK
Expand Down
5 changes: 3 additions & 2 deletions docs/trace/extending-the-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ not covered by the built-in exporters:
* Exporters should derive from `OpenTelemetry.BaseExporter<Activity>` (which
belongs to the [OpenTelemetry](../../../src/OpenTelemetry/README.md) package)
and implement the `Export` method.
* Exporters can optionally implement the `OnShutdown` method.
* Exporters can optionally implement the `OnForceFlush` and `OnShutdown` method.
* Depending on user's choice and load on the application, `Export` may get
called with one or more activities.
* Exporters will only receive sampled-in and ended activities.
* Exporters should not throw exceptions from `Export` and `OnShutdown`.
* Exporters should not throw exceptions from `Export`, `OnForceFlush` and
`OnShutdown`.
* Exporters should not modify activities they receive (the same activity may be
exported again by different exporter).
* Exporters are responsible for any retry logic needed by the scenario. The SDK
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
OpenTelemetry.BaseExporter<T>.ForceFlush(int timeoutMilliseconds = -1) -> bool
OpenTelemetry.Trace.BatchExportActivityProcessorOptions
OpenTelemetry.Trace.BatchExportActivityProcessorOptions.BatchExportActivityProcessorOptions() -> void
OpenTelemetry.Trace.BatchExportActivityProcessorOptions.BatchExportActivityProcessorOptions() -> void
override OpenTelemetry.BaseExportProcessor<T>.OnForceFlush(int timeoutMilliseconds) -> bool
override OpenTelemetry.BatchExportProcessor<T>.Dispose(bool disposing) -> void
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the Dispose was added by some previous PR(s).

virtual OpenTelemetry.BaseExporter<T>.OnForceFlush(int timeoutMilliseconds) -> bool
6 changes: 6 additions & 0 deletions src/OpenTelemetry/BaseExportProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ internal override void SetParentProvider(BaseProvider parentProvider)

protected abstract void OnExport(T data);

/// <inheritdoc />
protected override bool OnForceFlush(int timeoutMilliseconds)
{
return this.exporter.ForceFlush(timeoutMilliseconds);
}

/// <inheritdoc />
protected override bool OnShutdown(int timeoutMilliseconds)
{
Expand Down
53 changes: 53 additions & 0 deletions src/OpenTelemetry/BaseExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,38 @@ public abstract class BaseExporter<T> : IDisposable
/// <returns>Result of the export operation.</returns>
public abstract ExportResult Export(in Batch<T> batch);

/// <summary>
/// Flushes the exporter, blocks the current thread until flush
/// completed, shutdown signaled or timed out.
/// </summary>
/// <param name="timeoutMilliseconds">
/// The number (non-negative) of milliseconds to wait, or
/// <c>Timeout.Infinite</c> to wait indefinitely.
/// </param>
/// <returns>
/// Returns <c>true</c> when flush succeeded; otherwise, <c>false</c>.
/// </returns>
/// <exception cref="ArgumentOutOfRangeException">
/// Thrown when the <c>timeoutMilliseconds</c> is smaller than -1.
/// </exception>
/// <remarks>
/// This function guarantees thread-safety.
/// </remarks>
public bool ForceFlush(int timeoutMilliseconds = Timeout.Infinite)
reyang marked this conversation as resolved.
Show resolved Hide resolved
{
Guard.InvalidTimeout(timeoutMilliseconds, nameof(timeoutMilliseconds));

try
{
return this.OnForceFlush(timeoutMilliseconds);
}
catch (Exception ex)
{
OpenTelemetrySdkEventSource.Log.SpanProcessorException(nameof(this.ForceFlush), ex);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be something generic rather than about spans - also this is an exporter not a processor. A lot of the events in OpenTelemetrySdkEventSource are span-centric right now... a holistic review of the usage of OpenTelemetrySdkEventSource could be useful - I can create an issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. this is something we need to tackle surely.
Related to this: #1529 as well

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be something generic rather than about spans - also this is an exporter not a processor. A lot of the events in OpenTelemetrySdkEventSource are span-centric right now... a holistic review of the usage of OpenTelemetrySdkEventSource could be useful - I can create an issue.

+1, I also want to solve this problem. The current internal diagnostic logs are misleading and most of them are not actionable.

return false;
}
}

/// <summary>
/// Attempts to shutdown the exporter, blocks the current thread until
/// shutdown completed or timed out.
Expand Down Expand Up @@ -102,6 +134,27 @@ public void Dispose()
GC.SuppressFinalize(this);
}

/// <summary>
/// Called by <c>ForceFlush</c>. This function should block the current
/// thread until flush completed, shutdown signaled or timed out.
/// </summary>
/// <param name="timeoutMilliseconds">
/// The number (non-negative) of milliseconds to wait, or
/// <c>Timeout.Infinite</c> to wait indefinitely.
/// </param>
/// <returns>
/// Returns <c>true</c> when flush succeeded; otherwise, <c>false</c>.
/// </returns>
/// <remarks>
/// This function is called synchronously on the thread which called
/// <c>ForceFlush</c>. This function should be thread-safe, and should
/// not throw exceptions.
/// </remarks>
protected virtual bool OnForceFlush(int timeoutMilliseconds)
reyang marked this conversation as resolved.
Show resolved Hide resolved
{
return true;
}

/// <summary>
/// Called by <c>Shutdown</c>. This function should block the current
/// thread until shutdown completed or timed out.
Expand Down
3 changes: 3 additions & 0 deletions src/OpenTelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
`FormatException` if it fails to parse any of the supported environment
variables.

* Added `BaseExporter.ForceFlush`.
([#2525](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2525))

## 1.2.0-beta1

Released 2021-Oct-08
Expand Down