forked from yurishkuro/opentracing-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHello.cs
More file actions
52 lines (47 loc) · 1.52 KB
/
Hello.cs
File metadata and controls
52 lines (47 loc) · 1.52 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
using System;
using System.Collections.Generic;
using Microsoft.Extensions.Logging;
using OpenTracing.Tutorial.Library;
namespace OpenTracing.Tutorial.Lesson01.Solution
{
internal class Hello
{
private readonly ITracer _tracer;
private readonly ILogger<Hello> _logger;
public Hello(ITracer tracer, ILoggerFactory loggerFactory)
{
_tracer = tracer;
_logger = loggerFactory.CreateLogger<Hello>();
}
public void SayHello(string helloTo)
{
var span = _tracer.BuildSpan("say-hello").Start();
span.SetTag("hello-to", helloTo);
var helloString = $"Hello, {helloTo}!";
span.Log(new Dictionary<string, object>
{
[LogFields.Event] = "string.Format",
["value"] = helloString
}
);
_logger.LogInformation(helloString);
span.Log("WriteLine");
span.Finish();
}
public static void Main(string[] args)
{
if (args.Length != 1)
{
throw new ArgumentException("Expecting one argument");
}
using (var loggerFactory = new LoggerFactory().AddConsole())
{
var helloTo = args[0];
using (var tracer = Tracing.Init("hello-world", loggerFactory))
{
new Hello(tracer, loggerFactory).SayHello(helloTo);
}
}
}
}
}