-
Couldn't load subscription status.
- Fork 339
Add possibility to send telemetry events by data collectors #4622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f14cd20
096a7f1
169c936
fe8c2b3
9080351
5472fa9
d648577
69285ed
9fd6109
ecc0471
b9b1d48
bd2b7ca
e59ed11
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| #nullable enable | ||
| const Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel.MessageType.TelemetryEventMessage = "TestPlatform.TelemetryEvent" -> string! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; | ||
| using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel; | ||
| using Microsoft.VisualStudio.TestPlatform.ObjectModel; | ||
| using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; | ||
|
|
||
| namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; | ||
|
|
||
| internal class TelemetryReporter : ITelemetryReporter | ||
| { | ||
| private readonly IRequestData _requestData; | ||
| private readonly ICommunicationManager _communicationManager; | ||
| private readonly IDataSerializer _dataSerializer; | ||
|
|
||
| public TelemetryReporter(IRequestData requestData, ICommunicationManager communicationManager, IDataSerializer dataSerializer) | ||
| { | ||
| _requestData = requestData; | ||
| _communicationManager = communicationManager; | ||
| _dataSerializer = dataSerializer; | ||
| } | ||
|
|
||
| public void Report(TelemetryEvent telemetryEvent) | ||
| { | ||
| if (_requestData.IsTelemetryOptedIn) | ||
| { | ||
| string message = _dataSerializer.SerializePayload(MessageType.TelemetryEventMessage, telemetryEvent); | ||
| _communicationManager.SendRawMessage(message); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; | ||
|
|
||
| public interface ITelemetryEventsHandler | ||
| { | ||
| void HandleTelemetryEvent(TelemetryEvent telemetryEvent); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| namespace Microsoft.VisualStudio.TestPlatform.ObjectModel; | ||
|
|
||
| /// <summary> | ||
| /// Interface for extensions that choose to send telemetry events | ||
| /// </summary> | ||
| public interface ITelemetryInitializer | ||
| { | ||
| /// <summary> | ||
| /// Initializes telemetry reporter | ||
| /// </summary> | ||
| void Initialize(ITelemetryReporter telemetryReporter); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| namespace Microsoft.VisualStudio.TestPlatform.ObjectModel; | ||
|
|
||
| /// <summary> | ||
| /// Interface for extensions that choose to send telemetry events | ||
| /// </summary> | ||
| public interface ITelemetryReporter | ||
| { | ||
| /// <summary> | ||
| /// Pushes telemetry event into TP | ||
| /// </summary> | ||
| void Report(TelemetryEvent telemetryEvent); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,11 @@ | ||
| #nullable enable | ||
| Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.ITelemetryEventsHandler | ||
| Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.ITelemetryEventsHandler.HandleTelemetryEvent(Microsoft.VisualStudio.TestPlatform.ObjectModel.TelemetryEvent! telemetryEvent) -> void | ||
| Microsoft.VisualStudio.TestPlatform.ObjectModel.ITelemetryInitializer | ||
| Microsoft.VisualStudio.TestPlatform.ObjectModel.ITelemetryInitializer.Initialize(Microsoft.VisualStudio.TestPlatform.ObjectModel.ITelemetryReporter! telemetryReporter) -> void | ||
| Microsoft.VisualStudio.TestPlatform.ObjectModel.ITelemetryReporter | ||
| Microsoft.VisualStudio.TestPlatform.ObjectModel.ITelemetryReporter.Report(Microsoft.VisualStudio.TestPlatform.ObjectModel.TelemetryEvent! telemetryEvent) -> void | ||
| Microsoft.VisualStudio.TestPlatform.ObjectModel.TelemetryEvent | ||
| Microsoft.VisualStudio.TestPlatform.ObjectModel.TelemetryEvent.Name.get -> string! | ||
| Microsoft.VisualStudio.TestPlatform.ObjectModel.TelemetryEvent.Properties.get -> System.Collections.Generic.IDictionary<string!, object!>! | ||
| Microsoft.VisualStudio.TestPlatform.ObjectModel.TelemetryEvent.TelemetryEvent(string! name, System.Collections.Generic.IDictionary<string!, object!>! properties) -> void |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using System.Collections.Generic; | ||
| using System.Runtime.Serialization; | ||
|
|
||
| namespace Microsoft.VisualStudio.TestPlatform.ObjectModel; | ||
|
|
||
| public sealed class TelemetryEvent | ||
| { | ||
| /// <summary> | ||
| /// Initialize an TelemetryEvent | ||
| /// </summary> | ||
| /// <param name="name">Telemetry event name</param> | ||
| /// <param name="properties">Telemetry event properties</param> | ||
| public TelemetryEvent(string name, IDictionary<string, object> properties) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a bit generic but underneath we don't have more than that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is API used by VS telemetry |
||
| { | ||
| Name = name; | ||
| Properties = properties; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Telemetry event name. | ||
| /// </summary> | ||
| [DataMember] | ||
| public string Name { get; private set; } | ||
|
|
||
| /// <summary> | ||
| /// Telemetry event properties. | ||
| /// </summary> | ||
| [DataMember] | ||
| public IDictionary<string, object> Properties { get; private set; } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should have an option object for future extensibility but maybe we can add to the
ITelemetryReporterself if neededThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think extending API for extensions is not issue anymore.