19 | Swapping to the Development environment displays detailed information about the error that occurred.
20 |
21 |
22 | The Development environment shouldn't be enabled for deployed applications.
23 | It can result in displaying sensitive information from exceptions to end users.
24 | For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development
25 | and restarting the app.
26 |
27 |
--------------------------------------------------------------------------------
/src/GrpcService/GrpcService.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0
5 | enable
6 | enable
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/src/Worker/Worker.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0
5 | enable
6 | enable
7 | dotnet-Worker-544E6C2E-D3B8-4198-B323-3D1D47E687C0
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/WebClient/WebClient.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0
5 | enable
6 | enable
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/src/WebClient/Pages/Hello.cshtml.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json;
2 | using System.Web;
3 | using Microsoft.AspNetCore.Mvc;
4 | using Microsoft.AspNetCore.Mvc.RazorPages;
5 |
6 | namespace WebClient.Pages;
7 |
8 | public class HelloModel : PageModel
9 | {
10 | private readonly IHttpClientFactory _httpClientFactory;
11 |
12 | public HelloModel(IHttpClientFactory httpClientFactory) => _httpClientFactory = httpClientFactory;
13 |
14 | [BindProperty]
15 | public OutputModel Output { get; set; }
16 |
17 | public async Task OnGetAsync(string username)
18 | {
19 | using var client = _httpClientFactory.CreateClient();
20 |
21 | var greetingResponse = await client.GetAsync($"https://localhost:5003/hello?username={HttpUtility.UrlEncode(username)}");
22 |
23 | Output = await JsonSerializer.DeserializeAsync(
24 | await greetingResponse.Content.ReadAsStreamAsync(),
25 | new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
26 |
27 | return Page();
28 | }
29 |
30 | public record OutputModel(string Greeting);
31 | }
32 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 João Antunes
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/docker-compose.dependencies.yml:
--------------------------------------------------------------------------------
1 | version: "3"
2 |
3 | services:
4 | zipkin:
5 | image: openzipkin/zipkin
6 | hostname: zipkin
7 | container_name: zipkin
8 | ports:
9 | - "9411:9411"
10 | jaeger:
11 | image: jaegertracing/all-in-one:1
12 | hostname: jaeger
13 | container_name: jaeger
14 | ports:
15 | - "6831:6831/udp" # accepts jaeger.thrift over compact thrift protocol
16 | - "16686:16686" # ui
17 | # for more ports and information, check https://www.jaegertracing.io/docs/1.26/getting-started/
18 | rabbitmq:
19 | image: rabbitmq:3-management-alpine
20 | hostname: rabbitmq
21 | container_name: rabbitmq
22 | ports:
23 | - "5672:5672" # rabbit itself
24 | - "15672:15672" # management ui
25 | postgres:
26 | image: "postgres:13-alpine"
27 | hostname: "postgres"
28 | container_name: postgres
29 | ports:
30 | - "5432:5432"
31 | environment:
32 | POSTGRES_USER: "user"
33 | POSTGRES_PASSWORD: "pass"
34 | seq:
35 | image: "datalust/seq:2021"
36 | hostname: seq
37 | container_name: seq
38 | ports:
39 | - "5341:5341" # ingestion API
40 | - "5555:80" # ui
41 | environment:
42 | ACCEPT_EULA: "Y"
--------------------------------------------------------------------------------
/src/GrpcService/Program.cs:
--------------------------------------------------------------------------------
1 | using GrpcService;
2 | using OpenTelemetry.Resources;
3 | using OpenTelemetry.Trace;
4 |
5 | // not needed, W3C is now default
6 | // System.Diagnostics.Activity.DefaultIdFormat = System.Diagnostics.ActivityIdFormat.W3C;
7 |
8 | var builder = WebApplication.CreateBuilder(args);
9 |
10 | builder.Services.AddLogging(builder => builder.AddSeq());
11 | builder.Services.AddGrpc();
12 |
13 | builder.Services.AddOpenTelemetryTracing(builder =>
14 | {
15 | builder
16 | .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("GrpcService"))
17 | .AddAspNetCoreInstrumentation()
18 | .AddHttpClientInstrumentation()
19 | .AddSource(nameof(GreeterService)) // when we manually create activities, we need to setup the sources here
20 | .AddZipkinExporter(options =>
21 | {
22 | // not needed, it's the default
23 | //options.Endpoint = new Uri("http://localhost:9411/api/v2/spans");
24 | })
25 | .AddJaegerExporter(options =>
26 | {
27 | // not needed, it's the default
28 | //options.AgentHost = "localhost";
29 | //options.AgentPort = 6831;
30 | });
31 | });
32 |
33 |
34 | var app = builder.Build();
35 |
36 | app.UseHttpsRedirection();
37 | app.UseRouting();
38 |
39 | app.UseEndpoints(endpoints =>
40 | {
41 | endpoints.MapGrpcService();
42 |
43 | endpoints.MapGet("/", async context =>
44 | {
45 | await context.Response.WriteAsync("Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909");
46 | });
47 | });
48 |
49 | app.Run();
--------------------------------------------------------------------------------
/src/Worker/Program.cs:
--------------------------------------------------------------------------------
1 | using EasyNetQ;
2 | using OpenTelemetry.Resources;
3 | using OpenTelemetry.Trace;
4 | using Worker;
5 |
6 | IHost host = Host.CreateDefaultBuilder(args)
7 | .ConfigureServices(services =>
8 | {
9 | services.AddSingleton(_ => RabbitHutch.CreateBus("host=localhost"));
10 | services.AddLogging(builder => builder.AddSeq());
11 | services.AddOpenTelemetryTracing(builder =>
12 | {
13 | builder
14 | .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("Worker"))
15 | .AddSource(nameof(MessageHandler)) // when we manually create activities, we need to setup the sources here
16 | .AddZipkinExporter(options =>
17 | {
18 | // not needed, it's the default
19 | //options.Endpoint = new Uri("http://localhost:9411/api/v2/spans");
20 | })
21 | .AddJaegerExporter(options =>
22 | {
23 | // not needed, it's the default
24 | //options.AgentHost = "localhost";
25 | //options.AgentPort = 6831;
26 | });
27 | });
28 | // OpenTelemetry adds an hosted service of its own, so we should register it before our hosted services,
29 | // or we might start handing messages (or whatever our background service does) before tracing is up and running
30 | // (noticed this as when I stopped this service and sent messages to the queue, the first message handled
31 | // wouldn't show up in the traces)
32 | services.AddHostedService();
33 | })
34 | .Build();
35 |
36 | await host.RunAsync();
37 |
38 | public record HelloMessage(string Greeting);
--------------------------------------------------------------------------------
/src/WebApi/MessagePublisher.cs:
--------------------------------------------------------------------------------
1 | using EasyNetQ;
2 | using EasyNetQ.Topology;
3 | using OpenTelemetry;
4 | using OpenTelemetry.Context.Propagation;
5 | using System.Diagnostics;
6 |
7 | namespace WebApi;
8 |
9 | public class MessagePublisher : IDisposable
10 | {
11 | private static readonly ActivitySource ActivitySource = new ActivitySource(nameof(MessagePublisher));
12 | private static readonly TextMapPropagator Propagator = Propagators.DefaultTextMapPropagator;
13 |
14 | private readonly IBus _bus;
15 | private readonly Lazy _exchange;
16 |
17 | public MessagePublisher()
18 | {
19 | _bus = RabbitHutch.CreateBus("host=localhost");
20 | _exchange = new Lazy(() => _bus.Advanced.ExchangeDeclare("hello.exchange", ExchangeType.Topic));
21 | }
22 |
23 | public void Dispose() => _bus.Dispose();
24 |
25 | public async Task PublishAsync(T message)
26 | {
27 | using var activity = ActivitySource.StartActivity("message send", ActivityKind.Producer);
28 | var messageProperties = new MessageProperties();
29 |
30 | ActivityContext contextToInject = activity?.Context ?? Activity.Current?.Context ?? default;
31 |
32 | // Inject the ActivityContext into the message headers to propagate trace context to the receiving service.
33 | Propagator.Inject(new PropagationContext(contextToInject, Baggage.Current), messageProperties, InjectTraceContext);
34 |
35 | await _bus.Advanced.PublishAsync(_exchange.Value, "hello.message", false, new Message(message, messageProperties));
36 |
37 | void InjectTraceContext(MessageProperties messageProperties, string key, string value)
38 | {
39 | if (messageProperties.Headers is null)
40 | {
41 | messageProperties.Headers = new Dictionary();
42 | }
43 |
44 | messageProperties.Headers[key] = value;
45 | }
46 | }
47 | }
--------------------------------------------------------------------------------
/src/WebApi/WebApi.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0
5 | enable
6 | enable
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | all
16 | runtime; build; native; contentfiles; analyzers; buildtransitive
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/src/WebClient/Program.cs:
--------------------------------------------------------------------------------
1 | using OpenTelemetry.Resources;
2 | using OpenTelemetry.Trace;
3 |
4 | // not needed, W3C is now default
5 | // System.Diagnostics.Activity.DefaultIdFormat = System.Diagnostics.ActivityIdFormat.W3C;
6 |
7 | var builder = WebApplication.CreateBuilder(args);
8 |
9 | builder.Services.AddLogging(builder => builder.AddSeq());
10 |
11 | builder.Services.AddRazorPages();
12 |
13 | builder.Services.AddHttpClient();
14 |
15 | builder.Services.AddOpenTelemetryTracing(builder =>
16 | {
17 | builder
18 | .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("WebClient"))
19 | .AddAspNetCoreInstrumentation(
20 | // if we wanted to ignore some specific requests, we could use the filter
21 | options => options.Filter = httpContext => !httpContext.Request.Path.Value?.Contains("/_framework/aspnetcore-browser-refresh.js") ?? true)
22 | .AddHttpClientInstrumentation(
23 | // we can hook into existing activities and customize them
24 | options => options.Enrich = (activity, eventName, rawObject) =>
25 | {
26 | if(eventName == "OnStartActivity" && rawObject is System.Net.Http.HttpRequestMessage request && request.Method == HttpMethod.Get)
27 | {
28 | activity.SetTag("RandomDemoTag", "Adding some random demo tag, just to see things working");
29 | }
30 | }
31 | )
32 | .AddZipkinExporter(options =>
33 | {
34 | // not needed, it's the default
35 | //options.Endpoint = new Uri("http://localhost:9411/api/v2/spans");
36 | })
37 | .AddJaegerExporter(options =>
38 | {
39 | // not needed, it's the default
40 | //options.AgentHost = "localhost";
41 | //options.AgentPort = 6831;
42 | });
43 | });
44 |
45 | var app = builder.Build();
46 |
47 | app.UseHttpsRedirection();
48 | app.UseStaticFiles();
49 |
50 | app.UseRouting();
51 |
52 | app.UseEndpoints(endpoints =>
53 | {
54 | endpoints.MapRazorPages();
55 | });
56 |
57 | app.Run();
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # Exploring distributed tracing with ASP.NET Core
2 | ## Intro
3 | Simple set of ASP.NET Core applications to explore distributed tracing support, as well as the standard [W3C Trace Context](https://www.w3.org/TR/trace-context/) usage.
4 |
5 | 1. `WebClient` - basic Razor Pages web application with a single feature - provide a name to be greeted.
6 | 2. `WebApi` - basic web API exposing a single endpoint, receiving the user name and responding with a greeting.
7 | 3. `GrpcService` - template provided gRPC service with a single operation, the user name and responding with a greeting.
8 | 4. `Worker` - background worker application, handling RabbitMQ messages.
9 |
10 | The goal of having these 4 applications is to see the context flowing along with the requests/messages.
11 |
12 | ASP.NET Core flows this trace context automatically, for example, including the information in `HttpClient` requests.
13 |
14 | ~~The default format is not the W3C recommendation, but it's a line of code of configuration to get it.~~ (wasn't when I first did this with ASP.NET Core 3.1, as I'm updating to 6.0, it's now default)
15 |
16 | ## Viewing the trace context
17 |
18 | ### Logs
19 |
20 | The simplest way to see this in action is looking at the logs, as we can then see this information printed out.
21 |
22 | Even better than seeing things printed in the console, is to centralize the logs, then use the filters to find the logs we want. To see it in action, we're using [Seq](https://datalust.co/seq).
23 |
24 | ### OpenTelemetry, Zipkin and Jaeger
25 |
26 | Another interesting way to view this in action is to use other telemetry tools.
27 |
28 | For this sample, we'll use [OpenTelemetry](https://opentelemetry.io/), [Zipkin](https://zipkin.io/) and [Jaeger](https://www.jaegertracing.io/).
29 |
30 | OpenTelemetry provides a set of tools to capture the trace information and then make available to observability tools (like Zipkin and Jaeger). OpenTelemetry provides a set of [NuGet packages](https://github.com/open-telemetry/opentelemetry-dotnet) we can use to easily integration with .NET.
31 |
32 | Zipkin and Jaeger, as mentioned before, are observability tools, where we can analyze the behavior of our applications through the collected traces. They are equivalent (though surely there might exist pros and cons to them), so normally we'd use only one, but I wanted to take the opportunity to see both in action.
33 |
34 | ### Getting things running
35 |
36 | Before running the .NET applications, we need to have our dependencies up, which in this case are RabbitMQ, PostgreSQL, Seq, Zipkin and Jaeger. To get them all running, there's a Docker Compose file in the repository root, so we just need to execute:
37 |
38 | ```
39 | docker compose -f docker-compose.dependencies.yml up
40 | ```
41 |
42 | ## Other resources
43 |
44 | To do this exploration in general, but particularly the RabbitMQ bits, relied heavily on the docs and examples provided in the [OpenTelemetry .NET repository](https://github.com/open-telemetry/opentelemetry-dotnet), like the [OpenTelemetry Example Application](https://github.com/open-telemetry/opentelemetry-dotnet/tree/core-1.1.0/examples/MicroserviceExample).
--------------------------------------------------------------------------------
/src/Worker/MessageHandler.cs:
--------------------------------------------------------------------------------
1 | using EasyNetQ;
2 | using EasyNetQ.Topology;
3 | using OpenTelemetry;
4 | using OpenTelemetry.Context.Propagation;
5 | using System.Diagnostics;
6 | using System.Text;
7 |
8 | namespace Worker;
9 |
10 | public class MessageHandler : BackgroundService
11 | {
12 | private static readonly ActivitySource ActivitySource = new ActivitySource(nameof(MessageHandler));
13 | private static readonly TextMapPropagator Propagator = new TraceContextPropagator();
14 |
15 | private readonly IBus _bus;
16 | private readonly ILogger _logger;
17 |
18 | public MessageHandler(IBus bus, ILogger logger) => (_bus, _logger) = (bus, logger);
19 |
20 | protected override async Task ExecuteAsync(CancellationToken stoppingToken)
21 | {
22 | var queue = GetQueue();
23 |
24 | using var subscription = _bus.Advanced.Consume(
25 | queue,
26 | async (messageBytes, properties, receivedInfo) =>
27 | {
28 | // Extract the PropagationContext of the upstream parent from the message headers
29 | var parentContext = Propagator.Extract(default, properties, ExtractTraceContext);
30 |
31 | // Inject extracted info into current context
32 | Baggage.Current = parentContext.Baggage;
33 |
34 | // start an activity
35 | using var activity = ActivitySource.StartActivity("message receive", ActivityKind.Consumer, parentContext.ActivityContext, tags: new[] { new KeyValuePair("server", Environment.MachineName) });
36 |
37 | AddMessagingTags(activity, receivedInfo);
38 |
39 | _logger.LogInformation("Handling message: {message}", System.Text.Json.JsonSerializer.Deserialize(messageBytes.Span));
40 |
41 | await Task.Delay(TimeSpan.FromSeconds(5));
42 | });
43 |
44 | await UntilCancelled(stoppingToken);
45 |
46 | Queue GetQueue()
47 | {
48 | var queue = _bus.Advanced.QueueDeclare("hello.worker");
49 | var exchange = _bus.Advanced.ExchangeDeclare("hello.exchange", ExchangeType.Topic);
50 | var binding = _bus.Advanced.Bind(exchange, queue, "hello.*");
51 | return queue;
52 | }
53 |
54 | IEnumerable ExtractTraceContext(MessageProperties properties, string key)
55 | {
56 | try
57 | {
58 | if (properties.Headers.TryGetValue(key, out var value) && value is byte[] bytes)
59 | {
60 | return new[] { Encoding.UTF8.GetString(bytes) };
61 | }
62 | }
63 | catch (Exception ex)
64 | {
65 | _logger.LogError(ex, "Failed to extract trace context");
66 | }
67 |
68 | return Enumerable.Empty();
69 | }
70 |
71 | static void AddMessagingTags(Activity? activity, MessageReceivedInfo receivedInfo)
72 | {
73 | // https://github.com/open-telemetry/opentelemetry-dotnet/tree/core-1.1.0/examples/MicroserviceExample/Utils/Messaging
74 | // Following OpenTelemetry messaging specification conventions
75 | // See:
76 | // * https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/messaging.md#messaging-attributes
77 | // * https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/messaging.md#rabbitmq
78 |
79 | activity?.SetTag("messaging.system", "rabbitmq");
80 | activity?.SetTag("messaging.destination_kind", "queue");
81 | activity?.SetTag("messaging.destination", receivedInfo.Exchange);
82 | activity?.SetTag("messaging.rabbitmq.routing_key", receivedInfo.RoutingKey);
83 | }
84 |
85 | static async Task UntilCancelled(CancellationToken ct)
86 | {
87 | var tcs = new TaskCompletionSource();
88 | using var ctRegistration = ct.Register(() => tcs.SetResult(true));
89 | await tcs.Task;
90 | }
91 | }
92 |
93 | }
94 |
--------------------------------------------------------------------------------
/src/WebApi/Program.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.EntityFrameworkCore;
2 | using Microsoft.EntityFrameworkCore.Metadata.Builders;
3 | using OpenTelemetry.Resources;
4 | using OpenTelemetry.Trace;
5 | using WebApi;
6 | using static GrpcService.Greeter;
7 |
8 | // not needed, W3C is now default
9 | // System.Diagnostics.Activity.DefaultIdFormat = System.Diagnostics.ActivityIdFormat.W3C;
10 |
11 | var builder = WebApplication.CreateBuilder(args);
12 |
13 | builder.Services.AddLogging(builder => builder.AddSeq());
14 | builder.Services.AddControllers();
15 | builder.Services.AddGrpcClient(options =>
16 | {
17 | options.Address = new Uri("https://localhost:5004");
18 | });
19 |
20 | builder.Services.AddDbContext(options => options.UseNpgsql("server=localhost;port=5432;user id=user;password=pass;database=Hello"));
21 |
22 | builder.Services.AddOpenTelemetryTracing(builder =>
23 | {
24 | builder
25 | .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("WebApi"))
26 | .AddAspNetCoreInstrumentation()
27 | .AddHttpClientInstrumentation()
28 | // to avoid double activity, one for HttpClient, another for the gRPC client
29 | // -> https://github.com/open-telemetry/opentelemetry-dotnet/blob/core-1.1.0/src/OpenTelemetry.Instrumentation.GrpcNetClient/README.md#suppressdownstreaminstrumentation
30 | .AddGrpcClientInstrumentation(options => options.SuppressDownstreamInstrumentation = true)
31 | // besides instrumenting EF, we also want the queries to be part of the telemetry (hence SetDbStatementForText = true)
32 | .AddEntityFrameworkCoreInstrumentation(options => options.SetDbStatementForText = true)
33 | .AddSource(nameof(MessagePublisher)) // when we manually create activities, we need to setup the sources here
34 | .AddZipkinExporter(options =>
35 | {
36 | // not needed, it's the default
37 | //options.Endpoint = new Uri("http://localhost:9411/api/v2/spans");
38 | })
39 | .AddJaegerExporter(options =>
40 | {
41 | // not needed, it's the default
42 | //options.AgentHost = "localhost";
43 | //options.AgentPort = 6831;
44 | });
45 | });
46 |
47 | builder.Services.AddSingleton();
48 |
49 | var app = builder.Build();
50 |
51 | app.UseHttpsRedirection();
52 | app.UseRouting();
53 |
54 | app.UseAuthorization();
55 |
56 | app.MapGet("/hello", async (string username, GreeterClient greeterClient, MessagePublisher messagePublisher, HelloDbContext db) =>
57 | {
58 | var response = await greeterClient.SayHelloAsync(new GrpcService.HelloRequest { Name = username });
59 |
60 | db.HelloEntries.Add(new HelloEntry(Guid.NewGuid(), username, DateTime.UtcNow));
61 | await db.SaveChangesAsync();
62 |
63 | await messagePublisher.PublishAsync(new HelloMessage(response.Message));
64 |
65 | return new HelloResponse(response.Message);
66 | });
67 |
68 | using (var scope = app.Services.CreateScope())
69 | {
70 | var db = scope.ServiceProvider.GetRequiredService();
71 | db.Database.EnsureCreated(); // good only for demos 😉
72 | }
73 |
74 | app.Run();
75 |
76 | public record HelloResponse(string Greeting);
77 |
78 | public record HelloMessage(string Greeting);
79 |
80 | public record HelloEntry(Guid Id, string Username, DateTime CreatedAt);
81 |
82 | public class HelloDbContext : DbContext
83 | {
84 |
85 | #pragma warning disable CS8618 // DbSets populated by EF
86 | public HelloDbContext(DbContextOptions options) : base(options)
87 | {
88 | }
89 |
90 |
91 | public DbSet HelloEntries { get; set; }
92 | #pragma warning restore CS8618
93 |
94 | protected override void OnModelCreating(ModelBuilder modelBuilder)
95 | {
96 | modelBuilder.ApplyConfigurationsFromAssembly(GetType().Assembly);
97 | }
98 | }
99 |
100 | public class HelloEntryConfiguration : IEntityTypeConfiguration
101 | {
102 | public void Configure(EntityTypeBuilder builder)
103 | {
104 | builder.HasKey(e => e.Id);
105 | }
106 | }
--------------------------------------------------------------------------------
/ExploringDistributedTracingWithAspNet.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.26124.0
5 | MinimumVisualStudioVersion = 15.0.26124.0
6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{213FE490-5DFB-4628-B321-B638B56D7C27}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebClient", "src\WebClient\WebClient.csproj", "{C9F069A4-6092-4E35-840C-7F65AB0EDA36}"
9 | EndProject
10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApi", "src\WebApi\WebApi.csproj", "{67F991AA-C822-4F27-A26C-E2F0F3A5AE3C}"
11 | EndProject
12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GrpcService", "src\GrpcService\GrpcService.csproj", "{C4D80C25-39B2-4AC6-8FA3-D342E1205BA9}"
13 | EndProject
14 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Worker", "src\Worker\Worker.csproj", "{693B347E-4BF1-4DCB-A5FC-8546D4E96ADE}"
15 | EndProject
16 | Global
17 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
18 | Debug|Any CPU = Debug|Any CPU
19 | Debug|x64 = Debug|x64
20 | Debug|x86 = Debug|x86
21 | Release|Any CPU = Release|Any CPU
22 | Release|x64 = Release|x64
23 | Release|x86 = Release|x86
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
29 | {C9F069A4-6092-4E35-840C-7F65AB0EDA36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
30 | {C9F069A4-6092-4E35-840C-7F65AB0EDA36}.Debug|Any CPU.Build.0 = Debug|Any CPU
31 | {C9F069A4-6092-4E35-840C-7F65AB0EDA36}.Debug|x64.ActiveCfg = Debug|Any CPU
32 | {C9F069A4-6092-4E35-840C-7F65AB0EDA36}.Debug|x64.Build.0 = Debug|Any CPU
33 | {C9F069A4-6092-4E35-840C-7F65AB0EDA36}.Debug|x86.ActiveCfg = Debug|Any CPU
34 | {C9F069A4-6092-4E35-840C-7F65AB0EDA36}.Debug|x86.Build.0 = Debug|Any CPU
35 | {C9F069A4-6092-4E35-840C-7F65AB0EDA36}.Release|Any CPU.ActiveCfg = Release|Any CPU
36 | {C9F069A4-6092-4E35-840C-7F65AB0EDA36}.Release|Any CPU.Build.0 = Release|Any CPU
37 | {C9F069A4-6092-4E35-840C-7F65AB0EDA36}.Release|x64.ActiveCfg = Release|Any CPU
38 | {C9F069A4-6092-4E35-840C-7F65AB0EDA36}.Release|x64.Build.0 = Release|Any CPU
39 | {C9F069A4-6092-4E35-840C-7F65AB0EDA36}.Release|x86.ActiveCfg = Release|Any CPU
40 | {C9F069A4-6092-4E35-840C-7F65AB0EDA36}.Release|x86.Build.0 = Release|Any CPU
41 | {67F991AA-C822-4F27-A26C-E2F0F3A5AE3C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
42 | {67F991AA-C822-4F27-A26C-E2F0F3A5AE3C}.Debug|Any CPU.Build.0 = Debug|Any CPU
43 | {67F991AA-C822-4F27-A26C-E2F0F3A5AE3C}.Debug|x64.ActiveCfg = Debug|Any CPU
44 | {67F991AA-C822-4F27-A26C-E2F0F3A5AE3C}.Debug|x64.Build.0 = Debug|Any CPU
45 | {67F991AA-C822-4F27-A26C-E2F0F3A5AE3C}.Debug|x86.ActiveCfg = Debug|Any CPU
46 | {67F991AA-C822-4F27-A26C-E2F0F3A5AE3C}.Debug|x86.Build.0 = Debug|Any CPU
47 | {67F991AA-C822-4F27-A26C-E2F0F3A5AE3C}.Release|Any CPU.ActiveCfg = Release|Any CPU
48 | {67F991AA-C822-4F27-A26C-E2F0F3A5AE3C}.Release|Any CPU.Build.0 = Release|Any CPU
49 | {67F991AA-C822-4F27-A26C-E2F0F3A5AE3C}.Release|x64.ActiveCfg = Release|Any CPU
50 | {67F991AA-C822-4F27-A26C-E2F0F3A5AE3C}.Release|x64.Build.0 = Release|Any CPU
51 | {67F991AA-C822-4F27-A26C-E2F0F3A5AE3C}.Release|x86.ActiveCfg = Release|Any CPU
52 | {67F991AA-C822-4F27-A26C-E2F0F3A5AE3C}.Release|x86.Build.0 = Release|Any CPU
53 | {C4D80C25-39B2-4AC6-8FA3-D342E1205BA9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
54 | {C4D80C25-39B2-4AC6-8FA3-D342E1205BA9}.Debug|Any CPU.Build.0 = Debug|Any CPU
55 | {C4D80C25-39B2-4AC6-8FA3-D342E1205BA9}.Debug|x64.ActiveCfg = Debug|Any CPU
56 | {C4D80C25-39B2-4AC6-8FA3-D342E1205BA9}.Debug|x64.Build.0 = Debug|Any CPU
57 | {C4D80C25-39B2-4AC6-8FA3-D342E1205BA9}.Debug|x86.ActiveCfg = Debug|Any CPU
58 | {C4D80C25-39B2-4AC6-8FA3-D342E1205BA9}.Debug|x86.Build.0 = Debug|Any CPU
59 | {C4D80C25-39B2-4AC6-8FA3-D342E1205BA9}.Release|Any CPU.ActiveCfg = Release|Any CPU
60 | {C4D80C25-39B2-4AC6-8FA3-D342E1205BA9}.Release|Any CPU.Build.0 = Release|Any CPU
61 | {C4D80C25-39B2-4AC6-8FA3-D342E1205BA9}.Release|x64.ActiveCfg = Release|Any CPU
62 | {C4D80C25-39B2-4AC6-8FA3-D342E1205BA9}.Release|x64.Build.0 = Release|Any CPU
63 | {C4D80C25-39B2-4AC6-8FA3-D342E1205BA9}.Release|x86.ActiveCfg = Release|Any CPU
64 | {C4D80C25-39B2-4AC6-8FA3-D342E1205BA9}.Release|x86.Build.0 = Release|Any CPU
65 | {693B347E-4BF1-4DCB-A5FC-8546D4E96ADE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
66 | {693B347E-4BF1-4DCB-A5FC-8546D4E96ADE}.Debug|Any CPU.Build.0 = Debug|Any CPU
67 | {693B347E-4BF1-4DCB-A5FC-8546D4E96ADE}.Debug|x64.ActiveCfg = Debug|Any CPU
68 | {693B347E-4BF1-4DCB-A5FC-8546D4E96ADE}.Debug|x64.Build.0 = Debug|Any CPU
69 | {693B347E-4BF1-4DCB-A5FC-8546D4E96ADE}.Debug|x86.ActiveCfg = Debug|Any CPU
70 | {693B347E-4BF1-4DCB-A5FC-8546D4E96ADE}.Debug|x86.Build.0 = Debug|Any CPU
71 | {693B347E-4BF1-4DCB-A5FC-8546D4E96ADE}.Release|Any CPU.ActiveCfg = Release|Any CPU
72 | {693B347E-4BF1-4DCB-A5FC-8546D4E96ADE}.Release|Any CPU.Build.0 = Release|Any CPU
73 | {693B347E-4BF1-4DCB-A5FC-8546D4E96ADE}.Release|x64.ActiveCfg = Release|Any CPU
74 | {693B347E-4BF1-4DCB-A5FC-8546D4E96ADE}.Release|x64.Build.0 = Release|Any CPU
75 | {693B347E-4BF1-4DCB-A5FC-8546D4E96ADE}.Release|x86.ActiveCfg = Release|Any CPU
76 | {693B347E-4BF1-4DCB-A5FC-8546D4E96ADE}.Release|x86.Build.0 = Release|Any CPU
77 | EndGlobalSection
78 | GlobalSection(NestedProjects) = preSolution
79 | {C9F069A4-6092-4E35-840C-7F65AB0EDA36} = {213FE490-5DFB-4628-B321-B638B56D7C27}
80 | {67F991AA-C822-4F27-A26C-E2F0F3A5AE3C} = {213FE490-5DFB-4628-B321-B638B56D7C27}
81 | {C4D80C25-39B2-4AC6-8FA3-D342E1205BA9} = {213FE490-5DFB-4628-B321-B638B56D7C27}
82 | {693B347E-4BF1-4DCB-A5FC-8546D4E96ADE} = {213FE490-5DFB-4628-B321-B638B56D7C27}
83 | EndGlobalSection
84 | EndGlobal
85 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.suo
8 | *.user
9 | *.userosscache
10 | *.sln.docstates
11 |
12 | # User-specific files (MonoDevelop/Xamarin Studio)
13 | *.userprefs
14 |
15 | # Build results
16 | [Dd]ebug/
17 | [Dd]ebugPublic/
18 | [Rr]elease/
19 | [Rr]eleases/
20 | x64/
21 | x86/
22 | bld/
23 | [Bb]in/
24 | [Oo]bj/
25 | [Ll]og/
26 |
27 | # Visual Studio 2015/2017 cache/options directory
28 | .vs/
29 | # Uncomment if you have tasks that create the project's static files in wwwroot
30 | #wwwroot/
31 |
32 | # Visual Studio 2017 auto generated files
33 | Generated\ Files/
34 |
35 | # MSTest test Results
36 | [Tt]est[Rr]esult*/
37 | [Bb]uild[Ll]og.*
38 |
39 | # NUNIT
40 | *.VisualState.xml
41 | TestResult.xml
42 |
43 | # Build Results of an ATL Project
44 | [Dd]ebugPS/
45 | [Rr]eleasePS/
46 | dlldata.c
47 |
48 | # Benchmark Results
49 | BenchmarkDotNet.Artifacts/
50 |
51 | # .NET Core
52 | project.lock.json
53 | project.fragment.lock.json
54 | artifacts/
55 | **/Properties/launchSettings.json
56 |
57 | # StyleCop
58 | StyleCopReport.xml
59 |
60 | # Files built by Visual Studio
61 | *_i.c
62 | *_p.c
63 | *_i.h
64 | *.ilk
65 | *.meta
66 | *.obj
67 | *.iobj
68 | *.pch
69 | *.pdb
70 | *.ipdb
71 | *.pgc
72 | *.pgd
73 | *.rsp
74 | *.sbr
75 | *.tlb
76 | *.tli
77 | *.tlh
78 | *.tmp
79 | *.tmp_proj
80 | *.log
81 | *.vspscc
82 | *.vssscc
83 | .builds
84 | *.pidb
85 | *.svclog
86 | *.scc
87 |
88 | # Chutzpah Test files
89 | _Chutzpah*
90 |
91 | # Visual C++ cache files
92 | ipch/
93 | *.aps
94 | *.ncb
95 | *.opendb
96 | *.opensdf
97 | *.sdf
98 | *.cachefile
99 | *.VC.db
100 | *.VC.VC.opendb
101 |
102 | # Visual Studio profiler
103 | *.psess
104 | *.vsp
105 | *.vspx
106 | *.sap
107 |
108 | # Visual Studio Trace Files
109 | *.e2e
110 |
111 | # TFS 2012 Local Workspace
112 | $tf/
113 |
114 | # Guidance Automation Toolkit
115 | *.gpState
116 |
117 | # ReSharper is a .NET coding add-in
118 | _ReSharper*/
119 | *.[Rr]e[Ss]harper
120 | *.DotSettings.user
121 |
122 | # JustCode is a .NET coding add-in
123 | .JustCode
124 |
125 | # TeamCity is a build add-in
126 | _TeamCity*
127 |
128 | # DotCover is a Code Coverage Tool
129 | *.dotCover
130 |
131 | # AxoCover is a Code Coverage Tool
132 | .axoCover/*
133 | !.axoCover/settings.json
134 |
135 | # Visual Studio code coverage results
136 | *.coverage
137 | *.coveragexml
138 |
139 | # NCrunch
140 | _NCrunch_*
141 | .*crunch*.local.xml
142 | nCrunchTemp_*
143 |
144 | # MightyMoose
145 | *.mm.*
146 | AutoTest.Net/
147 |
148 | # Web workbench (sass)
149 | .sass-cache/
150 |
151 | # Installshield output folder
152 | [Ee]xpress/
153 |
154 | # DocProject is a documentation generator add-in
155 | DocProject/buildhelp/
156 | DocProject/Help/*.HxT
157 | DocProject/Help/*.HxC
158 | DocProject/Help/*.hhc
159 | DocProject/Help/*.hhk
160 | DocProject/Help/*.hhp
161 | DocProject/Help/Html2
162 | DocProject/Help/html
163 |
164 | # Click-Once directory
165 | publish/
166 |
167 | # Publish Web Output
168 | *.[Pp]ublish.xml
169 | *.azurePubxml
170 | # Note: Comment the next line if you want to checkin your web deploy settings,
171 | # but database connection strings (with potential passwords) will be unencrypted
172 | *.pubxml
173 | *.publishproj
174 |
175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
176 | # checkin your Azure Web App publish settings, but sensitive information contained
177 | # in these scripts will be unencrypted
178 | PublishScripts/
179 |
180 | # NuGet Packages
181 | *.nupkg
182 | # The packages folder can be ignored because of Package Restore
183 | **/[Pp]ackages/*
184 | # except build/, which is used as an MSBuild target.
185 | !**/[Pp]ackages/build/
186 | # Uncomment if necessary however generally it will be regenerated when needed
187 | #!**/[Pp]ackages/repositories.config
188 | # NuGet v3's project.json files produces more ignorable files
189 | *.nuget.props
190 | *.nuget.targets
191 |
192 | # Microsoft Azure Build Output
193 | csx/
194 | *.build.csdef
195 |
196 | # Microsoft Azure Emulator
197 | ecf/
198 | rcf/
199 |
200 | # Windows Store app package directories and files
201 | AppPackages/
202 | BundleArtifacts/
203 | Package.StoreAssociation.xml
204 | _pkginfo.txt
205 | *.appx
206 |
207 | # Visual Studio cache files
208 | # files ending in .cache can be ignored
209 | *.[Cc]ache
210 | # but keep track of directories ending in .cache
211 | !*.[Cc]ache/
212 |
213 | # Others
214 | ClientBin/
215 | ~$*
216 | *~
217 | *.dbmdl
218 | *.dbproj.schemaview
219 | *.jfm
220 | *.pfx
221 | *.publishsettings
222 | orleans.codegen.cs
223 |
224 | # Including strong name files can present a security risk
225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
226 | #*.snk
227 |
228 | # Since there are multiple workflows, uncomment next line to ignore bower_components
229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
230 | #bower_components/
231 |
232 | # RIA/Silverlight projects
233 | Generated_Code/
234 |
235 | # Backup & report files from converting an old project file
236 | # to a newer Visual Studio version. Backup files are not needed,
237 | # because we have git ;-)
238 | _UpgradeReport_Files/
239 | Backup*/
240 | UpgradeLog*.XML
241 | UpgradeLog*.htm
242 | ServiceFabricBackup/
243 | *.rptproj.bak
244 |
245 | # SQL Server files
246 | *.mdf
247 | *.ldf
248 | *.ndf
249 |
250 | # Business Intelligence projects
251 | *.rdl.data
252 | *.bim.layout
253 | *.bim_*.settings
254 | *.rptproj.rsuser
255 |
256 | # Microsoft Fakes
257 | FakesAssemblies/
258 |
259 | # GhostDoc plugin setting file
260 | *.GhostDoc.xml
261 |
262 | # Node.js Tools for Visual Studio
263 | .ntvs_analysis.dat
264 | node_modules/
265 |
266 | # Visual Studio 6 build log
267 | *.plg
268 |
269 | # Visual Studio 6 workspace options file
270 | *.opt
271 |
272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
273 | *.vbw
274 |
275 | # Visual Studio LightSwitch build output
276 | **/*.HTMLClient/GeneratedArtifacts
277 | **/*.DesktopClient/GeneratedArtifacts
278 | **/*.DesktopClient/ModelManifest.xml
279 | **/*.Server/GeneratedArtifacts
280 | **/*.Server/ModelManifest.xml
281 | _Pvt_Extensions
282 |
283 | # Paket dependency manager
284 | .paket/paket.exe
285 | paket-files/
286 |
287 | # FAKE - F# Make
288 | .fake/
289 |
290 | # JetBrains Rider
291 | .idea/
292 | *.sln.iml
293 |
294 | # CodeRush
295 | .cr/
296 |
297 | # Python Tools for Visual Studio (PTVS)
298 | __pycache__/
299 | *.pyc
300 |
301 | # Cake - Uncomment if you are using it
302 | # tools/**
303 | # !tools/packages.config
304 |
305 | # Tabs Studio
306 | *.tss
307 |
308 | # Telerik's JustMock configuration file
309 | *.jmconfig
310 |
311 | # BizTalk build output
312 | *.btp.cs
313 | *.btm.cs
314 | *.odx.cs
315 | *.xsd.cs
316 |
317 | # OpenCover UI analysis results
318 | OpenCover/
319 |
320 | # Azure Stream Analytics local run output
321 | ASALocalRun/
322 |
323 | # MSBuild Binary and Structured Log
324 | *.binlog
325 |
326 | # NVidia Nsight GPU debugger configuration file
327 | *.nvuser
328 |
329 | # MFractors (Xamarin productivity tool) working folder
330 | .mfractor/
331 |
332 | .DS_Store
--------------------------------------------------------------------------------