-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBaseActivity.cs
30 lines (27 loc) · 1.09 KB
/
BaseActivity.cs
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
using AIDocumentPipeline.Shared.Observability;
using OpenTelemetry.Trace;
namespace AIDocumentPipeline.Shared;
/// <summary>
/// Defines the base class for all activity classes.
/// </summary>
/// <param name="name">The name of the activity used for observability.</param>
[ActivitySource]
public abstract class BaseActivity(string name)
{
/// <summary>
/// Defines the tracer for the activity.
/// </summary>
protected readonly Tracer Tracer = TracerProvider.Default.GetTracer(name);
/// <summary>
/// Starts a span for the activity and makes it the active span.
/// </summary>
/// <param name="name">The name of the activity span.</param>
/// <param name="context">The observability context for the activity.</param>
/// <returns>A new active span for the activity.</returns>
protected TelemetrySpan StartActiveSpan(string name, IObservabilityContext? context = default)
{
return context != default
? Tracer.StartActiveSpan(name, SpanKind.Internal, context.ExtractObservabilityContext())
: Tracer.StartActiveSpan(name);
}
}