@@ -84,10 +84,7 @@ public static IHostBuilder AddApm(this IHostBuilder builder, ApmConfig config)
84
84
b . AddConsoleExporter ( ) ;
85
85
86
86
if ( config . EnableExporter )
87
- b . AddFilteredOtlpExporter ( c =>
88
- {
89
- c . Filter = a => a . Duration > TimeSpan . FromMilliseconds ( config . MinDurationMs ) || a . GetTagItem ( "db.system" ) is not null ;
90
- } ) ;
87
+ b . AddOtlpExporter ( ) ;
91
88
} ) ;
92
89
93
90
services . AddOpenTelemetry ( ) . WithMetrics ( b =>
@@ -177,84 +174,3 @@ public ApmConfig(IConfigurationRoot config, string processName, string? serviceV
177
174
public bool Debug => _apmConfig . GetValue ( "Debug" , false ) ;
178
175
public bool Console => _apmConfig . GetValue ( "Console" , false ) ;
179
176
}
180
-
181
- public sealed class CustomFilterProcessor : CompositeProcessor < Activity >
182
- {
183
- private readonly Func < Activity , bool > ? _filter ;
184
-
185
- public CustomFilterProcessor ( BaseProcessor < Activity > processor , Func < Activity , bool > ? filter ) : base ( new [ ] { processor } )
186
- {
187
- _filter = filter ;
188
- }
189
-
190
- public override void OnEnd ( Activity activity )
191
- {
192
- if ( _filter is null || _filter ( activity ) )
193
- base . OnEnd ( activity ) ;
194
- }
195
- }
196
-
197
- public static class CustomFilterProcessorExtensions
198
- {
199
- public static TracerProviderBuilder AddFilteredOtlpExporter ( this TracerProviderBuilder builder , Action < FilteredOtlpExporterOptions > ? configure = null )
200
- {
201
- ArgumentNullException . ThrowIfNull ( builder ) ;
202
-
203
- if ( builder is IDeferredTracerProviderBuilder deferredTracerProviderBuilder )
204
- {
205
- return deferredTracerProviderBuilder . Configure ( ( sp , providerBuilder ) =>
206
- {
207
- var oltpOptions = sp . GetService < IOptions < FilteredOtlpExporterOptions > > ( ) ? . Value ?? new FilteredOtlpExporterOptions ( ) ;
208
- AddFilteredOtlpExporter ( providerBuilder , oltpOptions , configure , sp ) ;
209
- } ) ;
210
- }
211
-
212
- return AddFilteredOtlpExporter ( builder , new FilteredOtlpExporterOptions ( ) , configure , serviceProvider : null ) ;
213
- }
214
-
215
- internal static TracerProviderBuilder AddFilteredOtlpExporter (
216
- TracerProviderBuilder builder ,
217
- FilteredOtlpExporterOptions exporterOptions ,
218
- Action < FilteredOtlpExporterOptions > ? configure ,
219
- IServiceProvider ? serviceProvider ,
220
- Func < BaseExporter < Activity > , BaseExporter < Activity > > ? configureExporterInstance = null )
221
- {
222
-
223
- configure ? . Invoke ( exporterOptions ) ;
224
-
225
- exporterOptions . TryEnableIHttpClientFactoryIntegration ( serviceProvider , "OtlpTraceExporter" ) ;
226
-
227
- BaseExporter < Activity > otlpExporter = new OtlpTraceExporter ( exporterOptions ) ;
228
-
229
- if ( configureExporterInstance is not null )
230
- otlpExporter = configureExporterInstance ( otlpExporter ) ;
231
-
232
- if ( exporterOptions . ExportProcessorType == ExportProcessorType . Simple )
233
- {
234
- return builder . AddProcessor ( new CustomFilterProcessor ( new SimpleActivityExportProcessor ( otlpExporter ) , exporterOptions . Filter ) ) ;
235
- }
236
-
237
- var batchOptions = exporterOptions . BatchExportProcessorOptions ?? new ( ) ;
238
- return builder . AddProcessor ( new CustomFilterProcessor ( new BatchActivityExportProcessor (
239
- otlpExporter ,
240
- batchOptions . MaxQueueSize ,
241
- batchOptions . ScheduledDelayMilliseconds ,
242
- batchOptions . ExporterTimeoutMilliseconds ,
243
- batchOptions . MaxExportBatchSize ) , exporterOptions . Filter ) ) ;
244
- }
245
-
246
- public static void TryEnableIHttpClientFactoryIntegration ( this OtlpExporterOptions options , IServiceProvider ? serviceProvider , string httpClientName )
247
- {
248
- // use reflection to call the method
249
- var exporterExtensionsType = typeof ( OtlpExporterOptions ) . Assembly . GetType ( "OpenTelemetry.Exporter.OtlpExporterOptionsExtensions" ) ;
250
- exporterExtensionsType ? . GetMethod ( "TryEnableIHttpClientFactoryIntegration" ) ? . Invoke ( null , [ options ,
251
- serviceProvider ! ,
252
- httpClientName
253
- ] ) ;
254
- }
255
- }
256
-
257
- public class FilteredOtlpExporterOptions : OtlpExporterOptions
258
- {
259
- public Func < Activity , bool > ? Filter { get ; set ; }
260
- }
0 commit comments