Skip to content

Commit bccbbf3

Browse files
committed
Report telemetry through Roslyn
1 parent 3c95e8c commit bccbbf3

File tree

2 files changed

+39
-38
lines changed

2 files changed

+39
-38
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Composition;
5+
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Features;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
9+
namespace Microsoft.VisualStudioCode.RazorExtension.Services;
10+
11+
[Shared]
12+
[ExportRazorStatelessLspService(typeof(RazorTelemetryReporter))]
13+
internal sealed class TelemetryReporterWrapper : RazorTelemetryReporter
14+
{
15+
[ImportingConstructor]
16+
public TelemetryReporterWrapper(VSCodeTelemetryReporter telemetryReporter)
17+
{
18+
telemetryReporter.SetTelemetryReporter(this);
19+
}
20+
21+
internal void Report(string name, IDictionary<string, object?> properties)
22+
{
23+
base.ReportEvent(name, properties.ToList());
24+
}
25+
}
Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,37 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System;
54
using System.Composition;
65
using Microsoft.CodeAnalysis.Razor.Telemetry;
6+
using Microsoft.VisualStudio.Razor.Telemetry;
7+
using Microsoft.VisualStudio.Telemetry;
78

89
namespace Microsoft.VisualStudioCode.RazorExtension.Services;
910

10-
// TODO:
11-
1211
[Shared]
12+
[Export(typeof(VSCodeTelemetryReporter))]
1313
[Export(typeof(ITelemetryReporter))]
14-
internal class VSCodeTelemetryReporter : ITelemetryReporter
14+
internal sealed class VSCodeTelemetryReporter : TelemetryReporter
1515
{
16-
public TelemetryScope BeginBlock(string name, Severity severity, TimeSpan minTimeToReport)
17-
=> TelemetryScope.Null;
18-
19-
public TelemetryScope BeginBlock(string name, Severity severity, TimeSpan minTimeToReport, Property property)
20-
=> TelemetryScope.Null;
21-
22-
public TelemetryScope BeginBlock(string name, Severity severity, TimeSpan minTimeToReport, Property property1, Property property2)
23-
=> TelemetryScope.Null;
24-
25-
public TelemetryScope BeginBlock(string name, Severity severity, TimeSpan minTimeToReport, Property property1, Property property2, Property property3)
26-
=> TelemetryScope.Null;
27-
28-
public TelemetryScope BeginBlock(string name, Severity severity, TimeSpan minTimeToReport, params ReadOnlySpan<Property> properties)
29-
=> TelemetryScope.Null;
30-
31-
public void ReportEvent(string name, Severity severity)
32-
{
33-
}
16+
private TelemetryReporterWrapper? _reporter;
3417

35-
public void ReportEvent(string name, Severity severity, Property property)
36-
{
37-
}
38-
39-
public void ReportEvent(string name, Severity severity, Property property1, Property property2)
40-
{
41-
}
18+
public override bool IsEnabled => true;
4219

43-
public void ReportEvent(string name, Severity severity, Property property1, Property property2, Property property3)
20+
internal void SetTelemetryReporter(TelemetryReporterWrapper reporter)
4421
{
22+
_reporter = reporter;
4523
}
4624

47-
public void ReportEvent(string name, Severity severity, params ReadOnlySpan<Property> properties)
48-
{
49-
}
25+
// We override any method in the base class that does actual telemetry reporting, and redirect it
26+
// through our wrapper, to the Roslyn reporter.
5027

51-
public void ReportFault(Exception exception, string? message, params object?[] @params)
28+
protected override void Report(TelemetryEvent telemetryEvent)
5229
{
30+
_reporter?.Report(telemetryEvent.Name, telemetryEvent.Properties);
5331
}
5432

55-
public TelemetryScope TrackLspRequest(string lspMethodName, string lspServerName, TimeSpan minTimeToReport, Guid correlationId)
56-
=> TelemetryScope.Null;
57-
58-
public void ReportRequestTiming(string name, string? language, TimeSpan queuedDuration, TimeSpan requestDuration, TelemetryResult result)
33+
public override void ReportMetric(AggregatingTelemetryLog.TelemetryInstrumentEvent metricEvent)
5934
{
35+
_reporter?.Report(metricEvent.Event.Name, metricEvent.Event.Properties);
6036
}
6137
}

0 commit comments

Comments
 (0)