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

How do I change the export frequency of the OTLPExporter? #4026

Closed
NetDevDewm opened this issue Dec 20, 2022 · 8 comments · Fixed by #4607
Closed

How do I change the export frequency of the OTLPExporter? #4026

NetDevDewm opened this issue Dec 20, 2022 · 8 comments · Fixed by #4607
Labels
question Further information is requested

Comments

@NetDevDewm
Copy link

Question

Currently I am attempting to set the OTLPExporterOptions for a MetricsProvider that relate to export frequency. Using the following I am able to successfully set up a provider and export metrics at the default time period of 10 secs (10000 ms):

MeterProvider metricsProvider = Sdk.CreateMeterProviderBuilder()
.AddMeter(serviceName)
.AddConsoleExporter()
.AddOtlpExporter(opt =>
{
opt.ExportProcessorType = ExportProcessorType.Simple;
opt.Endpoint = new Uri(metricsURI);
opt.Protocol = OtlpExportProtocol.Grpc;
})
.Build();

My question is, how is it possible to change the 10 second interval for this export to a collector?

I have tried several approaches:

  1. Setting the environment variables listed here https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md does not affect the export time.

  2. Setting the timeout in code via opt.TimeoutMilliseconds also does not affect the export time.

  3. Setting the timeout via opt.BatchExportProcessorOptions.ScheduledDelayMilliseconds. This appeared to be the wrong setting via this question Batch export vs periodic exporting with OLTP exporter #2767 and also does not affect the export time.

.NET version: net6.0
Packages:
OpenTelemetry Version=1.3.1
OpenTelemetry.Exporter.Console Version=1.3.1
OpenTelemetry.Exporter.OpenTelemetryProtocol Version=1.3.1

@NetDevDewm NetDevDewm added the question Further information is requested label Dec 20, 2022
@lechgu
Copy link

lechgu commented Dec 21, 2022

I had the same question. Ended up manually calling
provider.ForceFlush() when it is convenient for my application

@utpilla
Copy link
Contributor

utpilla commented Dec 22, 2022

The 10 seconds default value does not apply to Metrics. The default export interval for Metrics with OTLP Exporter is 60 seconds.

If you want to update the default export interval for Metrics you could either by setting the environment variable OTEL_METRIC_EXPORT_INTERVAL or by updating the ExportIntervalMilliseconds property in code. Here's an example that shows how to update the export interval for Metrics to 30 seconds.

.AddOtlpExporter((exporterOptions, metricReaderOptions) =>
{
    metricReaderOptions.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds = 30000;
})

@lechgu
Copy link

lechgu commented Dec 29, 2022

thanks, it was not obvious how to discover this.

@NetDevDewm
Copy link
Author

NetDevDewm commented Jan 4, 2023

I understand it was stated that the 10 secs default does not apply to metrics, but this is not the behavior I am seeing. I set up some Gauges and to count timeouts and such as shown below:

private Meter meter;
private ObservableGauge timeoutsGauge;

meter = new Meter("MyService", "1.0.0");
timeoutsGauge = meter.CreateObservableGauge("timeoutCount", () => OTLPManager.TimeoutCount);

MeterProvider metricsProvider = Sdk.CreateMeterProviderBuilder()
.AddMeter("MyService")
.AddConsoleExporter()
.AddOtlpExporter((opt, met) =>
{
opt.Endpoint = new Uri("http://metricsdb:8877");
opt.Protocol = OtlpExportProtocol.Grpc;
met.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds = 30000;
})
.Build();

When I use this code I get the following output:

Export timeoutsCount, Meter: MyService/1.0.0
(2023-01-04T15:57:52.1509322Z, 2023-01-04T15:58:01.9460954Z] LongGauge
Value: 0

Then, 10 seconds later:

Export timeoutsCount, Meter: MyService/1.0.0
(2023-01-04T15:57:52.1509322Z, 2023-01-04T15:58:11.9299727Z] LongGauge
Value: 0

If you check my original question, in approach 1 I tried setting the environment variables as well in my docker compose:

  • OTEL_METRIC_EXPORT_INTERVAL=30000

Neither the code above nor the environment variable affect the export time, I still see 10 seconds for each export and have been unable to change that frequency/interval.

@utpilla
Copy link
Contributor

utpilla commented Jan 10, 2023

@NetDevDewm Do you also have OTLP TraceExporter setup along with the OTLP MetricExporter? If yes, could you please try this again with the latest prerelease version 1.4.0-rc.2 version of OTLP Exporter. There was a fix made for this in #4058.

@MetalHexx
Copy link

The 10 seconds default value does not apply to Metrics. The default export interval for Metrics with OTLP Exporter is 60 seconds.

If you want to update the default export interval for Metrics you could either by setting the environment variable OTEL_METRIC_EXPORT_INTERVAL or by updating the ExportIntervalMilliseconds property in code. Here's an example that shows how to update the export interval for Metrics to 30 seconds.

.AddOtlpExporter((exporterOptions, metricReaderOptions) =>
{
    metricReaderOptions.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds = 30000;
})

Thank you! It took me a couple days to figure this out. I found it a little tough to find this for some reason. I gave you credit on this stackoverflow post:
https://stackoverflow.com/questions/75552005/opentelemetry-net-application-metrics-collected-slowly-by-collector/75563671#75563671

@utpilla
Copy link
Contributor

utpilla commented Feb 25, 2023

@MetalHexx Thanks for the feedback! We could definitely improve the documentation on how to configure OTLPExporter for Metrics and will work towards it.

@NetDevDewm
Copy link
Author

An update on this issue:
It appears that with the latest 1.4.0 release, this is now working with the environment variable OTEL_METRIC_EXPORT_INTERVAL

In my original question i linked to the github that showed these variables should be working - https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md

So, I had them in my docker compose, not working. Then, I updated recently to the 1.4.0 and noticed my exports were taking 30 seconds. I was confused and surprised to discover the env variable working now.

I know there were some options changes, which also cause me a problem with the new release that I have sorted out, so maybe it was related to that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants