4f04e9e1b5
* add metrics to host apps * merge fixes and compiles * Use ME.Console and OTel for logging to correlate * clean up * clean up for metrics * fix self-review comments * fix seq initialization * clean up for http traces and rhino 8 * use latest SDK * formatting
28 lines
850 B
C#
28 lines
850 B
C#
using System.Diagnostics;
|
|
using System.Reflection;
|
|
|
|
namespace Speckle.Connectors.Logging;
|
|
|
|
public sealed class LoggingActivityFactory : IDisposable
|
|
{
|
|
private readonly ActivitySource _activitySource =
|
|
new(Consts.TRACING_SOURCE, Consts.GetPackageVersion(Assembly.GetExecutingAssembly()));
|
|
|
|
private readonly Dictionary<string, object?> _tags = new();
|
|
|
|
public void SetTag(string key, object? value) => _tags[key] = value;
|
|
|
|
public LoggingActivity? Start(string name)
|
|
{
|
|
//If you get a MissingManifestResourceException, Likely source or name is empty string, which is no good.
|
|
var activity = _activitySource.StartActivity(name: name, kind: ActivityKind.Client, tags: _tags);
|
|
if (activity is null)
|
|
{
|
|
return null;
|
|
}
|
|
return new LoggingActivity(activity);
|
|
}
|
|
|
|
public void Dispose() => _activitySource.Dispose();
|
|
}
|