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 support for OTEL_BSP_EXPORT_* environmental variables #2219

Merged
merged 19 commits into from
Sep 3, 2021

Conversation

pellared
Copy link
Member

@pellared pellared commented Aug 2, 2021

Partially addresses #1453.

This feature is important so that we can reuse the SDK in https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation.

Changes

  • The BatchExportProcessorOptions defaults can be overridden using
    OTEL_BSP_SCHEDULE_DELAY, OTEL_BSP_EXPORT_TIMEOUT,
    OTEL_BSP_MAX_QUEUE_SIZE, OTEL_BSP_MAX_EXPORT_BATCH_SIZE
    envionmental variables as defined in the
    specification.

@pellared pellared changed the title Add support for OTEL_BSP_EXPORT_* environmental variables [WIP] Add support for OTEL_BSP_EXPORT_* environmental variables Aug 2, 2021
@codecov
Copy link

codecov bot commented Aug 2, 2021

Codecov Report

Merging #2219 (ceae91e) into main (232cc1d) will decrease coverage by 0.03%.
The diff coverage is 79.41%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2219      +/-   ##
==========================================
- Coverage   79.66%   79.63%   -0.04%     
==========================================
  Files         232      233       +1     
  Lines        7294     7325      +31     
==========================================
+ Hits         5811     5833      +22     
- Misses       1483     1492       +9     
Impacted Files Coverage Δ
...nTelemetry/Internal/OpenTelemetrySdkEventSource.cs 70.65% <57.14%> (-1.12%) ⬇️
...metry/Trace/BatchExportActivityProcessorOptions.cs 83.33% <83.33%> (ø)
...Telemetry.Exporter.Jaeger/JaegerExporterOptions.cs 84.21% <100.00%> (ø)
...orter.OpenTelemetryProtocol/OtlpExporterOptions.cs 84.61% <100.00%> (ø)
...Telemetry.Exporter.Zipkin/ZipkinExporterOptions.cs 100.00% <100.00%> (ø)
...ter.ZPages/Implementation/ZPagesActivityTracker.cs 97.14% <0.00%> (-2.86%) ⬇️
...Telemetry/Internal/SelfDiagnosticsEventListener.cs 96.85% <0.00%> (-0.79%) ⬇️

@pellared pellared changed the title [WIP] Add support for OTEL_BSP_EXPORT_* environmental variables Add support for OTEL_BSP_EXPORT_* environmental variables Aug 2, 2021
@pellared pellared marked this pull request as ready for review August 2, 2021 12:13
@pellared pellared requested a review from a team August 2, 2021 12:13
namespace OpenTelemetry
{
public class BatchExportProcessorOptions<T>
where T : class
{
internal const string MaxQueueSizeEnvVarKey = "OTEL_BSP_MAX_QUEUE_SIZE";
Copy link
Member

Choose a reason for hiding this comment

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

These are specific to batch span processors, we need some logic to make sure it is not affecting other scenario (e.g. metrics).

Copy link
Member Author

@pellared pellared Aug 6, 2021

Choose a reason for hiding this comment

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

Do you have any proposal on how to approach this?

I think that the root problem is that the .NET SDK tries to use common (premature?) abstractions to implement multiple OTel specification components. E.g. we have a common exporter base class for both metrics and traces exporter. I am aware it reduces some code duplication but it tightly couples the API and it may be hard to maintain backward compatibility going this way.

Can we use BatchExportProcessorOptions for tracing (to not break SemVer) and create a BatchMetricsExportProcessorOptions for metrics SDK?

Moreover, I think we should consider separating the metrics and traces SDKs.

Copy link
Member

Choose a reason for hiding this comment

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

What if we did something like...

        internal const string SpanMaxQueueSizeEnvVarKey = "OTEL_BSP_MAX_QUEUE_SIZE";

        internal const string SpanMaxExportBatchSizeEnvVarKey = "OTEL_BSP_MAX_EXPORT_BATCH_SIZE";

        internal const string SpanExporterTimeoutEnvVarKey = "OTEL_BSP_EXPORT_TIMEOUT";

        internal const string SpanScheduledDelayEnvVarKey = "OTEL_BSP_SCHEDULE_DELAY";

        public BatchExportProcessorOptions()
        {
            if (typeof(T) == typeof(Activity))
            {
               LoadSpanEnvVars();
            }
        }

        private void LoadSpanEnvVars()
        {
            int value;

            if (TryLoadEnvVarInt(SpanExporterTimeoutEnvVarKey, out value))
            {
                this.ExporterTimeoutMilliseconds = value;
            }

            if (TryLoadEnvVarInt(SpanMaxExportBatchSizeEnvVarKey, out value))
            {
                this.MaxExportBatchSize = value;
            }

            if (TryLoadEnvVarInt(SpanMaxQueueSizeEnvVarKey, out value))
            {
                this.MaxQueueSize = value;
            }

            if (TryLoadEnvVarInt(SpanScheduledDelayEnvVarKey, out value))
            {
                this.ScheduledDelayMilliseconds = value;
            }
        }

I'm not really a fan of duck typing in generics like this but trying to introduce classes into the hierarchy now will probably be a breaking change.

Copy link
Member Author

@pellared pellared Aug 6, 2021

Choose a reason for hiding this comment

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

@CodeBlanch thanks 👍

but trying to introduce classes into the hierarchy now will probably be a breaking change

That is why I suggest changing the metrics SDK as AFAIK it od not stable yet. And leave the tracing SDK as it is.

Your proposal would work and probably it is the most pragmatic idea for this PR. But maybe it is worth taking a step back and make more refactoring in separate PR(s).

Copy link
Member Author

@pellared pellared Aug 9, 2021

Choose a reason for hiding this comment

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

@CodeBlanch
I noticed that OtlpMetricsExporter uses OtlpExporterOptions which has a BatchExportProcessorOptions<Activity>.

Personally, I would prefer to redesign the OtlpMetricsExporter. The main repository's readme says that metrics are experimental so probably it is acceptable. Then we could redesign OtlpMetricsExporter to not have BatchExportProcessorOptions as it is not used anyway. I think we could refactor OtlpMetricsExporter as a separate issue+PR.

Regarding this PR I see the following options:

  1. We could just improve the BatchExportProcessorOptions docs and say that this option is designed for the tracing SDK.

  2. Instead of "duck typing in generics" we could also possibly create a subclass BatchSpanExportProcessorOptions and use it like this:

    public BatchExportProcessorOptions<Activity> BatchExportProcessorOptions { get; set; } = new BatchSpanExportProcessorOptions();

    not sure how much of a breaking change - I guess 99% of the existing code should simply work. Personally, I find such "common property grouping" as a code smell and possible premature abstraction. Will the exporters handle all of the possible options?

  3. Use the "duck typing in generics" proposed here

Shouldn't the tracing and metrics packages be distributed separately to avoid confusion? How the user would distinguish between stable and unstable API?

@reyang PTAL as well

Copy link
Member Author

@pellared pellared Aug 11, 2021

Choose a reason for hiding this comment

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

After the SIG meeting, I have an impression that this would be the preferred way forward:

  1. Create an issue that OtlpMetricsExporter should not reference BatchExportProcessorOptions<Activity>. Done here: OtlpMetricsExporter should not reference BatchExportProcessorOptions<Activity> #2246
  2. Create a BatchSpanExportProcessorOptions as a subclass of BatchExportProcessorOptions<Activity>. Addressed here: 092ddea

@pellared pellared requested a review from reyang August 6, 2021 10:11
@pellared pellared requested a review from CodeBlanch August 9, 2021 11:01
@pellared
Copy link
Member Author

@open-telemetry/dotnet-approvers PTAL

@pellared pellared force-pushed the support-OTEL_BSP-env-vars branch from f078cd0 to 917fd8d Compare August 12, 2021 06:36
@pellared pellared requested a review from cijothomas August 12, 2021 06:53
@dszmigielski
Copy link
Contributor

@open-telemetry/dotnet-approvers could you PTAL, so we can close this one? It's been hanging here for quite a long time now.

Copy link
Member

@reyang reyang left a comment

Choose a reason for hiding this comment

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

LGTM. Sorry for my delayed response, I was focusing on the metrics part recently.

@@ -202,10 +202,24 @@ purposes, the SDK provides the following built-in processors:
* [BatchExportProcessor&lt;T&gt;](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk.md#batching-processor)
: This is an exporting processor which batches the telemetry before sending to
the configured exporter.

The following environment variables can be used to override the default
values of the `BatchExportActivityProcessorOptions`.
Copy link
Member

Choose a reason for hiding this comment

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

might be a good idea to call out that this env variables affect all exporters unless individually overridden in code.

@cijothomas cijothomas merged commit 79d4c49 into open-telemetry:main Sep 3, 2021
@cijothomas
Copy link
Member

@pellared Merging this. Please take a note of couple of suggestion, and consider follow ups to address them.

@pellared
Copy link
Member Author

pellared commented Sep 8, 2021

@cijothomas @CodeBlanch I have the follow-ups very high on my TODO list. I am just overwhelmed with other stuff ATM.

@pellared pellared deleted the support-OTEL_BSP-env-vars branch September 8, 2021 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants