-
-
Notifications
You must be signed in to change notification settings - Fork 295
Expand file tree
/
Copy pathProgram.cs
More file actions
60 lines (49 loc) · 1.89 KB
/
Program.cs
File metadata and controls
60 lines (49 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using OpenTelemetry;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
using Proto;
using Proto.OpenTelemetry;
using Proto.Remote;
using Proto.Remote.GrpcNet;
using Proto.Remote;
var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
Log.SetLoggerFactory(loggerFactory);
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("OpenTelemetryTracingSample"))
.AddProtoActorInstrumentation()
.AddJaegerExporter()
.Build();
var system1 = new ActorSystem().WithRemote(RemoteConfig.BindToLocalhost(12000));
var system2 = new ActorSystem().WithRemote(RemoteConfig.BindToLocalhost(12001));
await system1.Remote().StartAsync();
await system2.Remote().StartAsync();
var remoteProps = Props.FromFunc(ctx =>
{
if (ctx.Message is string msg)
{
Console.WriteLine($"[remote] received '{msg}' traceId={Activity.Current?.TraceId}");
ctx.Respond("pong");
}
return Task.CompletedTask;
}).WithTracing();
system2.Root.SpawnNamed(remoteProps, "remote");
var localProps = Props.FromFunc(async ctx =>
{
if (ctx.Message is string msg)
{
Console.WriteLine($"[local] received '{msg}' traceId={Activity.Current?.TraceId}");
var remotePid = PID.FromAddress("127.0.0.1:12001", "remote");
var res = await ctx.RequestAsync<string>(remotePid, "ping");
Console.WriteLine($"[local] got reply '{res}' traceId={Activity.Current?.TraceId}");
}
}).WithTracing();
var localPid = system1.Root.Spawn(localProps);
var tracedRoot = system1.Root.WithTracing();
using var rootActivity = new ActivitySource(Proto.OpenTelemetry.ProtoTags.ActivitySourceName).StartActivity("root");
tracedRoot.Send(localPid, "start");
Console.WriteLine("Press enter to exit");
Console.ReadLine();