mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-11-04 22:30:50 +08:00 
			
		
		
		
	wip
This commit is contained in:
		
							
								
								
									
										30
									
								
								samples/OcelotOpenTracing/OcelotOpenTracing.csproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								samples/OcelotOpenTracing/OcelotOpenTracing.csproj
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,30 @@
 | 
			
		||||
<Project Sdk="Microsoft.NET.Sdk.Worker">
 | 
			
		||||
 | 
			
		||||
  <PropertyGroup>
 | 
			
		||||
    <OutputType>Exe</OutputType>
 | 
			
		||||
    <TargetFramework>netcoreapp3.1</TargetFramework>
 | 
			
		||||
  </PropertyGroup>
 | 
			
		||||
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <PackageReference Include="Jaeger" Version="0.3.7" />
 | 
			
		||||
    <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.3" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <ProjectReference Include="..\..\src\Ocelot.Tracing.OpenTracing\Ocelot.Tracing.OpenTracing.csproj" />
 | 
			
		||||
    <ProjectReference Include="..\..\src\Ocelot\Ocelot.csproj" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <Content Update="appsettings.Development.json">
 | 
			
		||||
      <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
 | 
			
		||||
    </Content>
 | 
			
		||||
    <Content Update="appsettings.json">
 | 
			
		||||
      <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
 | 
			
		||||
    </Content>
 | 
			
		||||
    <Content Update="ocelot.json">
 | 
			
		||||
      <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
 | 
			
		||||
    </Content>
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
 | 
			
		||||
</Project>
 | 
			
		||||
							
								
								
									
										67
									
								
								samples/OcelotOpenTracing/Program.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										67
									
								
								samples/OcelotOpenTracing/Program.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,67 @@
 | 
			
		||||
using Microsoft.AspNetCore.Hosting;
 | 
			
		||||
using Microsoft.Extensions.Configuration;
 | 
			
		||||
using Microsoft.Extensions.Hosting;
 | 
			
		||||
using System.IO;
 | 
			
		||||
using Ocelot.DependencyInjection;
 | 
			
		||||
using Ocelot.Middleware;
 | 
			
		||||
using Microsoft.Extensions.Logging;
 | 
			
		||||
using Ocelot.Tracing.OpenTracing;
 | 
			
		||||
using Jaeger;
 | 
			
		||||
using Microsoft.Extensions.DependencyInjection;
 | 
			
		||||
using OpenTracing;
 | 
			
		||||
using OpenTracing.Util;
 | 
			
		||||
 | 
			
		||||
namespace OcelotOpenTracing
 | 
			
		||||
{
 | 
			
		||||
    internal static class Program
 | 
			
		||||
    {
 | 
			
		||||
        private static void Main(string[] args)
 | 
			
		||||
        {
 | 
			
		||||
 | 
			
		||||
            Host.CreateDefaultBuilder()
 | 
			
		||||
                .ConfigureWebHostDefaults(webBuilder =>
 | 
			
		||||
                {
 | 
			
		||||
                    webBuilder
 | 
			
		||||
                        .UseContentRoot(Directory.GetCurrentDirectory())
 | 
			
		||||
                        .UseKestrel()
 | 
			
		||||
                        .ConfigureAppConfiguration((hostingContext, config) =>
 | 
			
		||||
                        {
 | 
			
		||||
                            config
 | 
			
		||||
                                .SetBasePath(hostingContext.HostingEnvironment.ContentRootPath)
 | 
			
		||||
                                .AddJsonFile("appsettings.json", optional: false, reloadOnChange: false)
 | 
			
		||||
                                .AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json",
 | 
			
		||||
                                    optional: true, reloadOnChange: false)
 | 
			
		||||
                                .AddJsonFile("ocelot.json", optional: false, reloadOnChange: true)
 | 
			
		||||
                                .AddEnvironmentVariables();
 | 
			
		||||
                        })
 | 
			
		||||
                        .ConfigureServices((context, services) =>
 | 
			
		||||
                        {
 | 
			
		||||
                            services
 | 
			
		||||
                                .AddOcelot()
 | 
			
		||||
                                .AddOpenTracing();
 | 
			
		||||
 | 
			
		||||
                            services.AddSingleton<ITracer>(sp =>
 | 
			
		||||
                            {
 | 
			
		||||
                                var loggerFactory = sp.GetService<ILoggerFactory>();
 | 
			
		||||
                                Configuration config = new Configuration(context.HostingEnvironment.ApplicationName, loggerFactory);
 | 
			
		||||
 | 
			
		||||
                                var tracer = config.GetTracer();
 | 
			
		||||
                                GlobalTracer.Register(tracer);
 | 
			
		||||
                                return tracer;
 | 
			
		||||
                            });
 | 
			
		||||
 | 
			
		||||
                        })
 | 
			
		||||
                        .ConfigureLogging(logging =>
 | 
			
		||||
                        {
 | 
			
		||||
                            logging.AddConsole();
 | 
			
		||||
                        })
 | 
			
		||||
                        .Configure(app =>
 | 
			
		||||
                        {
 | 
			
		||||
                            app.UseOcelot().Wait();
 | 
			
		||||
                        });
 | 
			
		||||
                })
 | 
			
		||||
                .Build()
 | 
			
		||||
                .Run();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										9
									
								
								samples/OcelotOpenTracing/appsettings.Development.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								samples/OcelotOpenTracing/appsettings.Development.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,9 @@
 | 
			
		||||
{
 | 
			
		||||
  "Logging": {
 | 
			
		||||
    "LogLevel": {
 | 
			
		||||
      "Default": "Information",
 | 
			
		||||
      "Microsoft": "Warning",
 | 
			
		||||
      "Microsoft.Hosting.Lifetime": "Information"
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										10
									
								
								samples/OcelotOpenTracing/appsettings.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								samples/OcelotOpenTracing/appsettings.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,10 @@
 | 
			
		||||
{
 | 
			
		||||
  "Logging": {
 | 
			
		||||
    "LogLevel": {
 | 
			
		||||
      "Default": "Information",
 | 
			
		||||
      "Microsoft": "Warning",
 | 
			
		||||
      "Microsoft.Hosting.Lifetime": "Information"
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  "AllowedHosts": "*"
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										24
									
								
								samples/OcelotOpenTracing/ocelot.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								samples/OcelotOpenTracing/ocelot.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,24 @@
 | 
			
		||||
{
 | 
			
		||||
  "ReRoutes": [
 | 
			
		||||
    {
 | 
			
		||||
      "HttpHandlerOptions": {
 | 
			
		||||
        "UseTracing": true
 | 
			
		||||
      },
 | 
			
		||||
      "DownstreamPathTemplate": "/todos/{id}",
 | 
			
		||||
      "DownstreamScheme": "https",
 | 
			
		||||
      "DownstreamHostAndPorts": [
 | 
			
		||||
        {
 | 
			
		||||
          "Host": "jsonplaceholder.typicode.com",
 | 
			
		||||
          "Port": 443
 | 
			
		||||
        }
 | 
			
		||||
      ],
 | 
			
		||||
      "UpstreamPathTemplate": "/posts/{id}",
 | 
			
		||||
      "UpstreamHttpMethod": [
 | 
			
		||||
        "Get"
 | 
			
		||||
      ]
 | 
			
		||||
    }
 | 
			
		||||
  ],
 | 
			
		||||
  "GlobalConfiguration": {
 | 
			
		||||
    "BaseUrl": "https://localhost:5000"
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user