Skip to content

Commit 36aa05a

Browse files
committed
chore: use IsThreadingDisabled instead of browser only
1 parent 276d81c commit 36aa05a

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/OpenTelemetry/BatchExportProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ private BatchExportWorker<T> CreateWorker()
167167
{
168168
#if NET
169169
// Use task-based worker for browser platform where threading may be limited
170-
if (OperatingSystem.IsBrowser() || !this.useThreads)
170+
if (ThreadingHelper.IsThreadingDisabled() || !this.useThreads)
171171
{
172172
return new BatchExportTaskWorker<T>(
173173
this.circularBuffer,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
namespace OpenTelemetry.Internal;
5+
6+
internal class ThreadingHelper
7+
{
8+
internal static bool IsThreadingDisabled()
9+
{
10+
// if the threadpool isn't using threads assume they aren't enabled
11+
ThreadPool.GetMaxThreads(out int workerThreads, out int completionPortThreads);
12+
13+
return workerThreads == 1 && completionPortThreads == 1;
14+
}
15+
}

src/OpenTelemetry/Metrics/Reader/PeriodicExportingMetricReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private PeriodicExportingMetricReaderWorker CreateWorker()
113113
{
114114
#if NET
115115
// Use task-based worker for browser platform where threading may be limited
116-
if (OperatingSystem.IsBrowser() || !this.useThreads)
116+
if (ThreadingHelper.IsThreadingDisabled() || !this.useThreads)
117117
{
118118
return new PeriodicExportingMetricReaderTaskWorker(
119119
this,

0 commit comments

Comments
 (0)