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
Changes from 2 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
6 changes: 6 additions & 0 deletions src/OpenTelemetry/BaseExportProcessor.cs
Original file line number Diff line number Diff line change
@@ -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)
{
53 changes: 53 additions & 0 deletions src/OpenTelemetry/BaseExporter.cs
Original file line number Diff line number Diff line change
@@ -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)
{
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.
@@ -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)
{
return true;
}

/// <summary>
/// Called by <c>Shutdown</c>. This function should block the current
/// thread until shutdown completed or timed out.
3 changes: 3 additions & 0 deletions src/OpenTelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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