forked from Cysharp/MagicOnion
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServiceContextTelemetryExtensions.cs
More file actions
54 lines (49 loc) · 1.93 KB
/
ServiceContextTelemetryExtensions.cs
File metadata and controls
54 lines (49 loc) · 1.93 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
using MagicOnion.Server.OpenTelemetry;
using MagicOnion.Server.Hubs;
using System.Diagnostics;
// ReSharper disable once CheckNamespace
namespace MagicOnion.Server.OpenTelemetry
{
public static class ServiceContextTelemetryExtensions
{
/// <summary>
/// Set the trace context with this service context
/// </summary>
/// <param name="context"></param>
/// <param name="activityContext"></param>
internal static void SetTraceContext(this ServiceContext context, ActivityContext activityContext)
{
context.Items[MagicOnionTelemetry.ServiceContextItemKeyTrace] = activityContext;
}
/// <summary>
/// Gets the trace context associated with this service context.
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public static ActivityContext GetTraceContext(this ServiceContext context)
{
return (ActivityContext)context.Items[MagicOnionTelemetry.ServiceContextItemKeyTrace];
}
}
public static class StreamingHubContextTelemetryExtensions
{
/// <summary>
/// Set the trace context with this streaming hub context
/// </summary>
/// <param name="context"></param>
/// <param name="activityContext"></param>
internal static void SetTraceContext(this StreamingHubContext context, ActivityContext activityContext)
{
context.Items[MagicOnionTelemetry.ServiceContextItemKeyTrace] = activityContext;
}
/// <summary>
/// Gets the trace context associated with this streaming hub context.
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public static ActivityContext GetTraceContext(this StreamingHubContext context)
{
return (ActivityContext)context.Items[MagicOnionTelemetry.ServiceContextItemKeyTrace];
}
}
}