private static MeterProviderBuilder AddMyFeature(MeterProviderBuilder meterProviderBuilder) { (meterProviderBuilder.GetServices() ?? throw new NotSupportedException("MyFeature requires a hosting MeterProviderBuilder instance.")) .AddSingleton <TestReader>(); return(meterProviderBuilder.AddReader <TestReader>()); }
public MeterProviderBuilder ConfigureMeterProvider(MeterProviderBuilder builder) { var typeName = this.ToString(); Console.WriteLine($"Hello from Meter Plugin - {typeName}"); return(builder); }
public static MeterProviderBuilder AddMyExporter(this MeterProviderBuilder builder) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } return(builder.AddReader(new BaseExportingMetricReader(new MyExporter()))); }
public static MeterProviderBuilder InvokePlugins(this MeterProviderBuilder builder, IEnumerable <string> pluginsAssemblyQualifiedNames) { foreach (var assemblyQualifiedName in pluginsAssemblyQualifiedNames) { builder = builder.InvokePlugin(assemblyQualifiedName); } return(builder); }
public static MeterProviderBuilder AddAzureMonitorMetricExporter(this MeterProviderBuilder builder, Action <AzureMonitorExporterOptions> configure = null) { var options = new AzureMonitorExporterOptions(); configure?.Invoke(options); var exporter = new AzureMonitorMetricExporter(options); return(builder.AddReader(new PeriodicExportingMetricReader(new AzureMonitorMetricExporter(options)))); }
public static MeterProviderBuilder AddMyExporter(this MeterProviderBuilder builder, int exportIntervalMilliSeconds = Timeout.Infinite) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (exportIntervalMilliSeconds == Timeout.Infinite) { // Export triggered manually only. return(builder.AddReader(new BaseExportingMetricReader(new MyExporter()))); } else { // Export is triggered periodically. return(builder.AddReader(new PeriodicExportingMetricReader(new MyExporter(), exportIntervalMilliSeconds))); } }
private static MeterProviderBuilder InvokePlugin(this MeterProviderBuilder builder, string pluginAssemblyQualifiedName) { const string configureMeterProviderMethodName = "ConfigureMeterProvider"; // get the type and method var t = Type.GetType(pluginAssemblyQualifiedName, throwOnError: true); var mi = t.GetMethod(configureMeterProviderMethodName, new Type[] { typeof(MeterProviderBuilder) }); if (mi is null) { throw new MissingMethodException(t.Name, configureMeterProviderMethodName); } // execute var obj = Activator.CreateInstance(t); var result = mi.Invoke(obj, new object[] { builder }); return((MeterProviderBuilder)result); }
/// <summary> /// Apply configuration conventions /// </summary> /// <param name="builder"></param> /// <param name="conventionContext"></param> /// <returns></returns> public static MeterProviderBuilder ApplyConventions(this MeterProviderBuilder builder, IConventionContext conventionContext) { var configuration = conventionContext.Get <IConfiguration>() ?? throw new ArgumentException("Configuration was not found in context", nameof(conventionContext)); foreach (var item in conventionContext.Conventions.Get <IOpenTelemetryMetricsConvention, OpenTelemetryMetricsConvention>()) { if (item is IOpenTelemetryMetricsConvention convention) { convention.Register(conventionContext, configuration, builder); } else if (item is OpenTelemetryMetricsConvention @delegate) { @delegate(conventionContext, configuration, builder); } } return(builder); }
public static MeterProviderBuilder AddAzureMonitorMetricExporter(this MeterProviderBuilder builder, Action <AzureMonitorExporterOptions> configure = null) { var options = new AzureMonitorExporterOptions(); configure?.Invoke(options); // TODO: Fallback to default location if location provided via options does not work. if (!options.DisableOfflineStorage && options.StorageDirectory == null) { options.StorageDirectory = StorageHelper.GetDefaultStorageDirectory(); } var exporter = new AzureMonitorMetricExporter(options); return(builder.AddReader(new PeriodicExportingMetricReader(new AzureMonitorMetricExporter(options)) { TemporalityPreference = MetricReaderTemporalityPreference.Delta })); }
static MeterProviderBuilder AddMetrics <T>(this MeterProviderBuilder builder, TagList?customTags = null) where T : class, IWithCustomTags { builder.GetServices().AddSingleton <T>(); return(builder is IDeferredMeterProviderBuilder deferredMeterProviderBuilder ? deferredMeterProviderBuilder.Configure( (sp, b) => { b.AddInstrumentation( () => { var instrument = sp.GetRequiredService <T>(); if (customTags != null) { instrument.SetCustomTags(customTags.Value); } return instrument; } ); } ) : builder); }
public void AddAspNetCoreInstrumentation_BadArgs() { MeterProviderBuilder builder = null; Assert.Throws <ArgumentNullException>(() => builder.AddAspNetCoreInstrumentation()); }
/// <summary> /// Adds metrics instrumentation for core components such as application service and event store /// </summary> /// <param name="builder"></param> /// <param name="customTags"></param> /// <returns></returns> public static MeterProviderBuilder AddEventuous(this MeterProviderBuilder builder, TagList?customTags = null) => Ensure.NotNull(builder) .AddMeter(EventuousMetrics.MeterName) .AddMetrics <EventuousMetrics>(customTags);
public MeterProviderBuilder ConfigureMeterProvider(MeterProviderBuilder builder) { return(builder); }
/// <inheritdoc /> public void Register(IConventionContext conventionContext, IConfiguration configuration, MeterProviderBuilder builder) { builder.AddAspNetCoreInstrumentation(); }
/// <summary> /// Add instrumentation for Couchbase to the metric builder. /// </summary> /// <param name="builder">The <see cref="MeterProviderBuilder" />.</param> /// <returns>The <see cref="MeterProviderBuilder" />.</returns> public static MeterProviderBuilder AddCouchbaseInstrumentation(this MeterProviderBuilder builder) { // ReSharper disable once SuspiciousTypeConversion.Global if (builder is IDeferredMeterProviderBuilder deferredMeterProviderBuilder) { return(deferredMeterProviderBuilder.Configure(static (_, deferredBuilder) =>