-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathTelemetryTests.cs
More file actions
98 lines (81 loc) · 3.16 KB
/
TelemetryTests.cs
File metadata and controls
98 lines (81 loc) · 3.16 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
using System.Diagnostics;
using System.Reflection;
using Xunit;
namespace GitHub.Copilot.Test.Unit;
public class TelemetryTests
{
[Fact]
public void TelemetryConfig_DefaultValues_AreNull()
{
var config = new TelemetryConfig();
Assert.Null(config.OtlpEndpoint);
Assert.Null(config.FilePath);
Assert.Null(config.ExporterType);
Assert.Null(config.SourceName);
Assert.Null(config.CaptureContent);
}
[Fact]
public void TelemetryConfig_CanSetAllProperties()
{
var config = new TelemetryConfig
{
OtlpEndpoint = "http://localhost:4318",
FilePath = "/tmp/traces.json",
ExporterType = "otlp-http",
SourceName = "my-app",
CaptureContent = true
};
Assert.Equal("http://localhost:4318", config.OtlpEndpoint);
Assert.Equal("/tmp/traces.json", config.FilePath);
Assert.Equal("otlp-http", config.ExporterType);
Assert.Equal("my-app", config.SourceName);
Assert.True(config.CaptureContent);
}
[Fact]
public void CopilotClientOptions_Telemetry_DefaultsToNull()
{
var options = new CopilotClientOptions();
Assert.Null(options.Telemetry);
}
[Fact]
public void CopilotClientOptions_Clone_CopiesTelemetry()
{
var telemetry = new TelemetryConfig
{
OtlpEndpoint = "http://localhost:4318",
ExporterType = "otlp-http"
};
var options = new CopilotClientOptions { Telemetry = telemetry };
var clone = options.Clone();
Assert.Same(telemetry, clone.Telemetry);
}
[Fact]
public void TelemetryHelpers_Restores_W3C_Trace_Context()
{
using var parent = new Activity("parent");
parent.SetIdFormat(ActivityIdFormat.W3C);
parent.TraceStateString = "state=value";
parent.Start();
var traceContext = InvokeTelemetryHelper<(string? Traceparent, string? Tracestate)>("GetTraceContext");
Assert.Equal(parent.Id, traceContext.Traceparent);
Assert.Equal("state=value", traceContext.Tracestate);
parent.Stop();
using var restored = InvokeTelemetryHelper<Activity?>(
"RestoreTraceContext",
traceContext.Traceparent,
traceContext.Tracestate);
Assert.NotNull(restored);
Assert.Equal(parent.Id, restored.ParentId);
Assert.Equal("state=value", restored.TraceStateString);
Assert.Null(InvokeTelemetryHelper<Activity?>("RestoreTraceContext", "not-a-traceparent", null));
}
private static T InvokeTelemetryHelper<T>(string name, params object?[] args)
{
var helperType = typeof(CopilotClient).Assembly.GetType("GitHub.Copilot.TelemetryHelpers", throwOnError: true)!;
var method = helperType.GetMethod(name, BindingFlags.Static | BindingFlags.NonPublic)!;
return (T)method.Invoke(null, args)!;
}
}