コード例 #1
0
        protected override async Task SendCustomLogFileMessagesAsync()
        {
            var stderrLogFile = string.Format("{0}.stderr.log", TracingConfiguration.GetLogFileNameWithoutExtension());

            await Client.SendAsync(new LogFileMessage {
                LogFile = stderrLogFile
            }).ConfigureAwait(continueOnCapturedContext: false);
        }
コード例 #2
0
        public WcfTraceLogger(ISpan span, TracingConfiguration configuration)
        {
            _span          = span;
            _configuration = configuration;

            if (_configuration.Verbose)
            {
                _span.Log("Started call");
            }
        }
コード例 #3
0
        public void GetAttachmentsStoragePath_NoException()
        {
            // arrange
            TracingConfiguration configuration = new TracingConfiguration();

            // act
            Action verify = () => configuration.GetAttachmentsStoragePath();

            // assert
            Assert.Null(Record.Exception(verify));
        }
コード例 #4
0
        public void GetAttachmentsStoragePath_ConfigurationNull()
        {
            // arrange
            TracingConfiguration configuration = null;

            // act
            Action verify = () => configuration.GetAttachmentsStoragePath();

            // assert
            Assert.Throws <ArgumentNullException>("configuration", verify);
        }
コード例 #5
0
        /// <summary>
        /// Adds <c>Azure BLOB Storage</c> telemetry attachment transmission services to the service collection.
        /// </summary>
        /// <param name="services">A <see cref="IServiceCollection"/> instance.</param>
        /// <param name="configuration">A <see cref="IConfiguration"/> instance.</param>
        /// <returns>The provided <see cref="IServiceCollection"/> instance.</returns>
        public static IServiceCollection AddBlobStorageTelemetryAttachmentTransmission(
            this IServiceCollection services,
            IConfiguration configuration)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            BlobStorageConfiguration blobStorageConfiguration = configuration
                                                                .GetSection("Tracing")
                                                                .GetSection("BlobStorage")
                                                                .Get <BlobStorageConfiguration>();

            AttachmentsOptions attachmentsOptions = configuration
                                                    .GetSection("Tracing")
                                                    .GetSection("Attachments")
                                                    .Get <AttachmentsOptions>() ?? new AttachmentsOptions();

            return(services
                   .AddTracingCore(configuration)
                   .AddSingleton(blobStorageConfiguration)
                   .AddSingleton(attachmentsOptions)
                   .AddSingleton(p =>
            {
                CloudStorageAccount account = CloudStorageAccount.Parse(blobStorageConfiguration.ConnectionString);
                CloudBlobClient client = account.CreateCloudBlobClient();
                CloudBlobContainer container = client.GetContainerReference(blobStorageConfiguration.AttachmentContainerName);

                container.CreateIfNotExistsAsync().GetAwaiter().GetResult();

                return container;
            })
                   .AddSingleton <IBlobContainer, BlobContainer>()
                   .AddSingleton <IMemoryBuffer <AttachmentDescriptor> >(sp => new MemoryBuffer <AttachmentDescriptor>(attachmentsOptions.Buffer))
                   .AddSingleton <ITransmissionSender <AttachmentDescriptor>, BlobStorageTransmissionSender>()
                   .AddSingleton <ITransmissionStorage <AttachmentDescriptor> >(p =>
            {
                TracingConfiguration tracingConfiguration = p.GetRequiredService <TracingConfiguration>();
                return new BlobStorageTransmissionStorage(tracingConfiguration.GetAttachmentsStoragePath());
            })
                   .AddSingleton <ITelemetryAttachmentTransmitter, BlobStorageTransmitter>()
                   .AddSingleton <IAttachmentTransmissionInitializer, AttachmentTransmissionInitializer>());
        }
コード例 #6
0
        /// <summary>
        /// 添加Jaeger链路追踪,实例对象ITracer
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="action"></param>
        /// <param name="openTracingBuilder"></param>
        /// <returns></returns>
        public static IFlashTractingBuilder AddJaeger(this IFlashTractingBuilder builder, Action <TracingConfiguration> action, Action <IOpenTracingBuilder> openTracingBuilder = null)
        {
            var config = new TracingConfiguration()
            {
                Open = false
            };

            action = action ?? throw new ArgumentNullException(nameof(action));
            action(config);

            builder.Services.AddTransient <TracingConfiguration>(sp =>
            {
                return(config);
            });
            AddJaeger(builder.Services, openTracingBuilder);
            return(builder);
        }
コード例 #7
0
 /// <summary>
 /// 添加Jaeger链路追踪,实例对象ITracer
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="configurationSection"></param>
 /// <param name="openTracingBuilder"></param>
 /// <returns></returns>
 public static IFlashTractingBuilder AddJaeger(this IFlashTractingBuilder builder, IConfigurationSection configurationSection, Action <IOpenTracingBuilder> openTracingBuilder = null)
 {
     builder.Services.AddTransient <TracingConfiguration>(sp =>
     {
         var config = configurationSection.Get <TracingConfiguration>();
         if (config == null)
         {
             config = new TracingConfiguration()
             {
                 Open = false
             };
         }
         return(config);
     });
     AddJaeger(builder.Services, openTracingBuilder);
     return(builder);
 }
コード例 #8
0
        public HostTelemetryInitializer(
            IHostApplicationLifetime applicationLifetime,
            ITelemetrySession session,
            IAttachmentTransmissionInitializer initializer,
            TracingConfiguration options)
        {
            _applicationLifetime = applicationLifetime ??
                                   throw new ArgumentNullException(nameof(applicationLifetime));
            _session = session ??
                       throw new ArgumentNullException(nameof(session));
            _initializer = initializer
                           ?? throw new ArgumentNullException(nameof(initializer));
            _options = options ??
                       throw new ArgumentNullException(nameof(options));

            RegisterForUnhandledExceptions();
        }
コード例 #9
0
        /// <summary>
        /// Adds <c>EventHub</c> telemetry event transmission services to the service collection.
        /// </summary>
        /// <param name="services">A <see cref="IServiceCollection"/> instance.</param>
        /// <param name="configuration">A <see cref="IConfiguration"/> instance.</param>
        /// <returns>The provided <see cref="IServiceCollection"/> instance.</returns>
        public static IServiceCollection AddEventHubTelemetryEventTransmission(
            this IServiceCollection services,
            IConfiguration configuration)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            EventHubConfiguration eventHubConfiguration = configuration
                                                          .GetSection("Tracing")
                                                          .GetSection("EventHub")
                                                          .Get <EventHubConfiguration>();

            EventsOptions eventsOptions = configuration
                                          .GetSection("Tracing")
                                          .GetSection("Events")
                                          .Get <EventsOptions>() ?? new EventsOptions();

            return(services
                   .AddTracingCore(configuration)
                   .AddSingleton(eventHubConfiguration)
                   .AddSingleton(eventsOptions)
                   .AddSingleton(eventsOptions.Buffer)
                   .AddSingleton(p =>
            {
                var connection = new EventHubConnection(eventHubConfiguration.ConnectionString);
                EventHubProducerClientOptions clientOptions = CreateEventHubClientOptions(eventHubConfiguration);
                return new EventHubProducerClient(connection, clientOptions);
            })
                   .AddSingleton <IMemoryBuffer <EventData> >(sp => new MemoryBuffer <EventData>(eventsOptions.Buffer))
                   .AddSingleton <ITransmissionBuffer <EventData, EventDataBatch>, EventHubTransmissionBuffer>()
                   .AddSingleton <ITransmissionSender <EventDataBatch>, EventHubTransmissionSender>()
                   .AddSingleton <ITransmissionStorage <EventData> >(p =>
            {
                TracingConfiguration tracingConfiguration = p.GetRequiredService <TracingConfiguration>();
                return new EventHubTransmissionStorage(tracingConfiguration.GetEventsStoragePath());
            })
                   .AddSingleton <ITelemetryEventTransmitter, EventHubTransmitter>());
        }
コード例 #10
0
        /// <summary>
        /// Adds <c>Thor Tracing</c> services to the service collection with EventHub and BLOB
        /// storage preconfigured for telemetry and attachment transmission.
        /// </summary>
        /// <param name="services">A <see cref="IServiceCollection"/> instance.</param>
        /// <param name="configuration">A <see cref="IConfiguration"/> instance.</param>
        /// <returns>The provided <see cref="IServiceCollection"/> instance.</returns>
        public static IServiceCollection AddTracing(
            this IServiceCollection services,
            IConfiguration configuration)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            TracingConfiguration tracingConfiguration = configuration
                                                        .GetSection("Tracing")
                                                        .Get <TracingConfiguration>();

            if (tracingConfiguration.Enabled)
            {
                // TODO: BlogStorage transmission should also not be active out-of-process
                services
                .AddTracingHttpMessageHandler(configuration)
                .AddBlobStorageTelemetryAttachmentTransmission(configuration)
                .AddTracingMinimum(configuration);

                if (tracingConfiguration.InProcess)
                {
                    services
                    .AddEventHubTelemetryEventTransmission(configuration)
                    .AddInProcessTelemetrySession(configuration);
                }
                else
                {
                    services
                    .AddEmptyTelemetrySession(configuration);
                }
            }

            return(services);
        }
コード例 #11
0
ファイル: Startup.cs プロジェクト: vazkarvishal/CarsUnlimited
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            TracingConfiguration tracingConfig = Configuration.GetSection("TracingConfiguration").Get <TracingConfiguration>();

            TraceExporterOptions exporter = (TraceExporterOptions)tracingConfig.Exporter;

            switch (exporter)
            {
            case TraceExporterOptions.JAEGER:
                services.AddOpenTelemetryTracing((builder) => builder
                                                 .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(_serviceName))
                                                 .AddAspNetCoreInstrumentation()
                                                 .AddHttpClientInstrumentation()
                                                 .AddJaegerExporter(jaegerOptions =>
                {
                    jaegerOptions.AgentHost = tracingConfig.JaegerEndpoint.Host;
                    jaegerOptions.AgentPort = tracingConfig.JaegerEndpoint.Port;
                }));
                break;

            case TraceExporterOptions.ZIPKIN:
                services.AddOpenTelemetryTracing((builder) => builder
                                                 .AddAspNetCoreInstrumentation()
                                                 .AddHttpClientInstrumentation()
                                                 .AddZipkinExporter(zipkinOptions =>
                {
                    zipkinOptions.Endpoint = new Uri(tracingConfig.ZipkinEndpoint);
                }));
                break;

            case TraceExporterOptions.OPENTELEMETRY_PROTOCOL:
                // Adding the OtlpExporter creates a GrpcChannel.
                // This switch must be set before creating a GrpcChannel/HttpClient when calling an insecure gRPC service.
                // See: https://docs.microsoft.com/aspnet/core/grpc/troubleshoot#call-insecure-grpc-services-with-net-core-client
                AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);

                services.AddOpenTelemetryTracing((builder) => builder
                                                 .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(_serviceName))
                                                 .AddAspNetCoreInstrumentation()
                                                 .AddHttpClientInstrumentation()
                                                 .AddOtlpExporter(otlpOptions =>
                {
                    otlpOptions.Endpoint = new Uri(tracingConfig.OltpEndpoint);
                }));
                break;

            default:
                services.AddOpenTelemetryTracing((builder) => builder
                                                 .AddAspNetCoreInstrumentation()
                                                 .AddHttpClientInstrumentation()
                                                 .AddConsoleExporter());
                break;
            }

            services.AddRazorPages();
            services.AddServerSideBlazor();
            services.AddSingleton <InventoryService>();
            services.AddSingleton <CartService>();
            services.AddSingleton <PurchaseService>();

            services.AddBlazoredToast();
        }
コード例 #12
0
 public void Deconstruct(
     out ConsoleConfiguration console,
     out FileConfiguration file,
     out ElasticSearchConfiguration elasticSearch,
     out TracingConfiguration tracing) => (console, file, elasticSearch, tracing) = (
     this.Console ?? new ConsoleConfiguration(),
コード例 #13
0
ファイル: Startup.cs プロジェクト: lgulliver/CarsUnlimited
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            TracingConfiguration tracingConfig = Configuration.GetSection("TracingConfiguration").Get <TracingConfiguration>();

            TraceExporterOptions exporter = (TraceExporterOptions)tracingConfig.Exporter;

            switch (exporter)
            {
            case TraceExporterOptions.JAEGER:
                services.AddOpenTelemetryTracing((builder) => builder
                                                 .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(_serviceName))
                                                 .AddAspNetCoreInstrumentation()
                                                 .AddHttpClientInstrumentation()
                                                 .AddJaegerExporter(jaegerOptions =>
                {
                    jaegerOptions.AgentHost = tracingConfig.JaegerEndpoint.Host;
                    jaegerOptions.AgentPort = tracingConfig.JaegerEndpoint.Port;
                })
                                                 .AddMongoDBInstrumentation());
                break;

            case TraceExporterOptions.ZIPKIN:
                services.AddOpenTelemetryTracing((builder) => builder
                                                 .AddAspNetCoreInstrumentation()
                                                 .AddHttpClientInstrumentation()
                                                 .AddZipkinExporter(zipkinOptions =>
                {
                    zipkinOptions.Endpoint = new Uri(tracingConfig.ZipkinEndpoint);
                })
                                                 .AddMongoDBInstrumentation());
                break;

            case TraceExporterOptions.OPENTELEMETRY_PROTOCOL:
                // Adding the OtlpExporter creates a GrpcChannel.
                // This switch must be set before creating a GrpcChannel/HttpClient when calling an insecure gRPC service.
                // See: https://docs.microsoft.com/aspnet/core/grpc/troubleshoot#call-insecure-grpc-services-with-net-core-client
                AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);

                services.AddOpenTelemetryTracing((builder) => builder
                                                 .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(_serviceName))
                                                 .AddAspNetCoreInstrumentation()
                                                 .AddHttpClientInstrumentation()
                                                 .AddOtlpExporter(otlpOptions =>
                {
                    otlpOptions.Endpoint = new Uri(tracingConfig.OltpEndpoint);
                })
                                                 .AddMongoDBInstrumentation());
                break;

            default:
                services.AddOpenTelemetryTracing((builder) => builder
                                                 .AddAspNetCoreInstrumentation()
                                                 .AddHttpClientInstrumentation()
                                                 .AddConsoleExporter()
                                                 .AddMongoDBInstrumentation());
                break;
            }

            services.Configure <InventoryDatabaseSettings>(
                Configuration.GetSection(nameof(InventoryDatabaseSettings)));

            services.AddSingleton <IInventoryDatabaseSettings>(sp =>
                                                               sp.GetRequiredService <IOptions <InventoryDatabaseSettings> >().Value);



            services.AddScoped(typeof(IMongoRepository <>), typeof(MongoRepository <>));

            services.AddScoped <IInventoryService, InventoryService>();

            services.AddControllers();
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "Cars Unlimited Inventory API", Version = "v1"
                });
            });

            services.AddHealthChecks();
        }
コード例 #14
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            TracingConfiguration tracingConfig = Configuration.GetSection("TracingConfiguration").Get <TracingConfiguration>();
            RedisSettings        redisSettings = Configuration.GetSection("RedisSettings").Get <RedisSettings>();

            var redisConfiguration = new RedisConfiguration()
            {
                AbortOnConnectFail = true,
                Hosts = new RedisHost[]
                {
                    new RedisHost()
                    {
                        Host = redisSettings.Host, Port = redisSettings.Port
                    },
                },
                AllowAdmin                = false,
                Database                  = 0,
                ConnectTimeout            = 10000,
                Ssl                       = redisSettings.Ssl,
                Password                  = redisSettings.Password,
                ServerEnumerationStrategy = new ServerEnumerationStrategy()
                {
                    Mode       = ServerEnumerationStrategy.ModeOptions.All,
                    TargetRole = ServerEnumerationStrategy.TargetRoleOptions.Any,
                    UnreachableServerAction = ServerEnumerationStrategy.UnreachableServerActionOptions.Throw
                },
                MaxValueLength = 1024,
                PoolSize       = 5
            };

            TraceExporterOptions exporter = (TraceExporterOptions)tracingConfig.Exporter;

            switch (exporter)
            {
            case TraceExporterOptions.JAEGER:
                services.AddOpenTelemetryTracing((builder) => builder
                                                 .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(_serviceName))
                                                 .AddAspNetCoreInstrumentation()
                                                 .AddHttpClientInstrumentation()
                                                 .AddJaegerExporter(jaegerOptions =>
                {
                    jaegerOptions.AgentHost = tracingConfig.JaegerEndpoint.Host;
                    jaegerOptions.AgentPort = tracingConfig.JaegerEndpoint.Port;
                }));
                break;

            case TraceExporterOptions.ZIPKIN:
                services.AddOpenTelemetryTracing((builder) => builder
                                                 .AddAspNetCoreInstrumentation()
                                                 .AddHttpClientInstrumentation()
                                                 .AddZipkinExporter(zipkinOptions =>
                {
                    zipkinOptions.Endpoint = new Uri(tracingConfig.ZipkinEndpoint);
                }));
                break;

            case TraceExporterOptions.OPENTELEMETRY_PROTOCOL:
                // Adding the OtlpExporter creates a GrpcChannel.
                // This switch must be set before creating a GrpcChannel/HttpClient when calling an insecure gRPC service.
                // See: https://docs.microsoft.com/aspnet/core/grpc/troubleshoot#call-insecure-grpc-services-with-net-core-client
                AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);

                services.AddOpenTelemetryTracing((builder) => builder
                                                 .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(_serviceName))
                                                 .AddAspNetCoreInstrumentation()
                                                 .AddHttpClientInstrumentation()
                                                 .AddOtlpExporter(otlpOptions =>
                {
                    otlpOptions.Endpoint = new Uri(tracingConfig.OltpEndpoint);
                }));
                break;

            default:
                services.AddOpenTelemetryTracing((builder) => builder
                                                 .AddAspNetCoreInstrumentation()
                                                 .AddHttpClientInstrumentation()
                                                 .AddConsoleExporter());
                break;
            }

            services.AddStackExchangeRedisExtensions <SystemTextJsonSerializer>(redisConfiguration);

            services.AddScoped <IUpdateCartService, UpdateCartService>();
            services.AddScoped <IGetCartItems, GetCartItems>();

            services.AddControllers();
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "Cars Unlimited Cart API", Version = "v1"
                });
            });

            services.AddHealthChecks();
        }