public AzureMonitorTransmitter(AzureMonitorExporterOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            options.Retry.MaxRetries = 0;
            ConnectionString.ConnectionStringParser.GetValues(options.ConnectionString, out _instrumentationKey, out string ingestionEndpoint);
            _applicationInsightsRestClient = new ApplicationInsightsRestClient(new ClientDiagnostics(options), HttpPipelineBuilder.Build(options), host: ingestionEndpoint);

            if (!options.DisableOfflineStorage)
            {
                try
                {
                    _storage = new FileStorage(options.StorageDirectory);
                }
                catch (Exception)
                {
                    // TODO:
                    // log exception
                    // Remove this when we add an option to disable offline storage.
                    // So if someone opts in for storage and we cannot initialize, we can throw.
                    // Change needed on persistent storage side to throw if not able to create storage directory.
                }
            }
        }
 internal AzureMonitorLogExporter(AzureMonitorExporterOptions options, ITransmitter transmitter)
 {
     _options = options ?? throw new ArgumentNullException(nameof(options));
     ConnectionString.ConnectionStringParser.GetValues(_options.ConnectionString, out _instrumentationKey, out _);
     _transmitter    = transmitter;
     _resourceParser = new ResourceParser();
 }
示例#3
0
 internal AzureMonitorMetricExporter(AzureMonitorExporterOptions options, ITransmitter transmitter)
 {
     this.options = options ?? throw new ArgumentNullException(nameof(options));
     ConnectionString.ConnectionStringParser.GetValues(this.options.ConnectionString, out this.instrumentationKey, out _);
     this.Transmitter = transmitter;
     resourceParser   = new ResourceParser();
 }
示例#4
0
        public AzureMonitorTransmitter(AzureMonitorExporterOptions options)
        {
            ConnectionStringParser.GetValues(options.ConnectionString, out _, out string ingestionEndpoint);
            options.Retry.MaxRetries = 0;
            options.AddPolicy(new IngestionResponsePolicy(), HttpPipelinePosition.PerCall);

            applicationInsightsRestClient = new ApplicationInsightsRestClient(new ClientDiagnostics(options), HttpPipelineBuilder.Build(options), host: ingestionEndpoint);
        }
示例#5
0
        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))));
        }
        internal AzureMonitorTraceExporter(AzureMonitorExporterOptions options, ITransmitter transmitter)
        {
            _options = options ?? throw new ArgumentNullException(nameof(options));
            ConnectionString.ConnectionStringParser.GetValues(_options.ConnectionString, out _instrumentationKey, out _);
            _transmitter    = transmitter;
            _resourceParser = new ResourceParser();

            // Todo: Add check if offline storage is enabled by user via options
            _storageTransmissionEvaluator = new StorageTransmissionEvaluator(StorageTransmissionEvaluatorSampleSize);
        }
示例#7
0
        /// <summary>
        /// Adds Azure Monitor Log Exporter with OpenTelemetryLoggerOptions.
        /// </summary>
        /// <param name="loggerOptions"><see cref="OpenTelemetryLoggerOptions"/> options to use.</param>
        /// <param name="configure">Exporter configuration options.</param>
        /// <returns>The instance of <see cref="OpenTelemetryLoggerOptions"/> to chain the calls.</returns>
        public static OpenTelemetryLoggerOptions AddAzureMonitorLogExporter(this OpenTelemetryLoggerOptions loggerOptions, Action <AzureMonitorExporterOptions> configure = null)
        {
            if (loggerOptions == null)
            {
                throw new ArgumentNullException(nameof(loggerOptions));
            }

            var options = new AzureMonitorExporterOptions();

            configure?.Invoke(options);

            return(loggerOptions.AddProcessor(new BatchLogRecordExportProcessor(new AzureMonitorLogExporter(options))));
        }
        private static AzureMonitorTransmitter GetTransmitter()
        {
            AzureMonitorExporterOptions options = new AzureMonitorExporterOptions();

            options.ConnectionString = $"InstrumentationKey={testIkey};IngestionEndpoint={testEndpoint}";
            options.StorageDirectory = StorageHelper.GetDefaultStorageDirectory();
            AzureMonitorTransmitter transmitter = new AzureMonitorTransmitter(options);

            // Overwrite storage to reduce maintenance period
            transmitter._storage = new FileStorage(options.StorageDirectory, 5000, 5000);

            return(transmitter);
        }
示例#9
0
        /// <summary>
        /// Registers an Azure Monitor trace exporter that will receive <see cref="System.Diagnostics.Activity"/> instances.
        /// </summary>
        /// <param name="builder"><see cref="TracerProviderBuilder"/> builder to use.</param>
        /// <param name="configure">Exporter configuration options.</param>
        /// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
        public static TracerProviderBuilder AddAzureMonitorTraceExporter(this TracerProviderBuilder builder, Action <AzureMonitorExporterOptions> configure = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var options = new AzureMonitorExporterOptions();

            configure?.Invoke(options);

            // TODO: Pick Simple vs Batching based on AzureMonitorExporterOptions
            return(builder.AddProcessor(new BatchExportProcessor <Activity>(new AzureMonitorTraceExporter(options))));
        }
        /// <summary>
        /// Adds Azure Monitor Log Exporter with OpenTelemetryLoggerOptions.
        /// </summary>
        /// <param name="loggerOptions"><see cref="OpenTelemetryLoggerOptions"/> options to use.</param>
        /// <param name="configure">Exporter configuration options.</param>
        /// <returns>The instance of <see cref="OpenTelemetryLoggerOptions"/> to chain the calls.</returns>
        public static OpenTelemetryLoggerOptions AddAzureMonitorLogExporter(this OpenTelemetryLoggerOptions loggerOptions, Action <AzureMonitorExporterOptions> configure = null)
        {
            if (loggerOptions == null)
            {
                throw new ArgumentNullException(nameof(loggerOptions));
            }

            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();
            }

            return(loggerOptions.AddProcessor(new BatchLogRecordExportProcessor(new AzureMonitorLogExporter(options))));
        }
示例#11
0
        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
            }));
        }
        /// <summary>
        /// Registers an Azure Monitor trace exporter that will receive <see cref="System.Diagnostics.Activity"/> instances.
        /// </summary>
        /// <param name="builder"><see cref="TracerProviderBuilder"/> builder to use.</param>
        /// <param name="configure">Exporter configuration options.</param>
        /// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
        public static TracerProviderBuilder AddAzureMonitorTraceExporter(this TracerProviderBuilder builder, Action <AzureMonitorExporterOptions> configure = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            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();
            }

            // TODO: Pick Simple vs Batching based on AzureMonitorExporterOptions
            return(builder.AddProcessor(new BatchActivityExportProcessor(new AzureMonitorTraceExporter(options))));
        }
 public AzureMonitorTraceExporter(AzureMonitorExporterOptions options) : this(options, new AzureMonitorTransmitter(options))
 {
 }
示例#14
0
 public AzureMonitorMetricExporter(AzureMonitorExporterOptions options) : this(new AzureMonitorTransmitter(options))
 {
 }