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

Review all exporters for unhandled exceptions #2872

Closed
4 tasks done
cijothomas opened this issue Feb 7, 2022 · 6 comments
Closed
4 tasks done

Review all exporters for unhandled exceptions #2872

cijothomas opened this issue Feb 7, 2022 · 6 comments
Labels
bug Something isn't working help wanted Good for taking. Extra help will be provided by maintainers

Comments

@cijothomas
Copy link
Member

cijothomas commented Feb 7, 2022

https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/error-handling.md#basic-error-handling-principles

"The SDK MUST NOT throw unhandled exceptions for errors in their own operations. For example, an exporter should not throw an exception when it cannot reach the endpoint to which it sends telemetry data."

This was exposed in #2870 where OTLP exporter crashed the whole process, but opening a dedicated issue to track fixing this. This is separate from the issue about when/how should SDK handle unhandled exceptions when user components behave bad.

This issue is only tracking the core components (as required by the spec) :

@cijothomas cijothomas added bug Something isn't working help wanted Good for taking. Extra help will be provided by maintainers labels Feb 7, 2022
@cijothomas
Copy link
Member Author

@Yun-Ting for OTLPExporter. @alanwest can guide here.

@TimothyMothra
Copy link
Contributor

TimothyMothra commented Feb 9, 2022

I can work on Prometheus

@TimothyMothra
Copy link
Contributor

I reviewed the Prometheus exporter.
TLDR; If this is used as designed, there should be no issues.
However, if the exporter is ever invoked while OnExport is set to null, this would throw an exception.

If we want to proceed with caution, we can add a try/catch to the Exporter or add a null check.
I'll follow up with @cijothomas offline to discuss.


  1. PrometheusExporter.Export will call PrometheusExporter.OnExport without a null check.

    public override ExportResult Export(in Batch<Metric> metrics)
    {
    return this.OnExport(metrics);
    }

  2. PrometheusExporter.OnExport should be set to PrometheusCollectionManager.OnCollect which DOES has a try/catch.
    This eventually calls BaseExportingMetricReader.ProcessMetrics which will call exporter.Export

    private ExportResult OnCollect(Batch<Metric> metrics)
    {
    int cursor = 0;
    try
    {

    internal override bool ProcessMetrics(in Batch<Metric> metrics, int timeoutMilliseconds)
    {
    // TODO: Do we need to consider timeout here?
    try
    {
    return this.exporter.Export(metrics) == ExportResult.Success;

  3. The PrometheusCollectionManager has a pattern I'm unfamiliar with.
    This sets PrometheusExporter.OnExport, then calls PrometheusExporter.Collect, and then sets PrometheusExporter.OnExport to null.

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    private bool ExecuteCollect()
    {
    this.exporter.OnExport = this.onCollectRef;
    bool result = this.exporter.Collect(Timeout.Infinite);
    this.exporter.OnExport = null;
    return result;
    }

@TimothyMothra

This comment was marked as resolved.

@cijothomas
Copy link
Member Author

https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/src/OpenTelemetry/Metrics/MetricReader.cs#L112-L124 MetricReader is catching all exceptions, so even if a MetricExporter throws, it wont crash. (This is different from Trace/Log as the BatchExporterProcessor doesn't catch exceptions from Exporter.)

@cijothomas
Copy link
Member Author

#2905 another crash from OTLP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Good for taking. Extra help will be provided by maintainers
Projects
None yet
Development

No branches or pull requests

2 participants