@@ -31,5 +31,93 @@ This will enable all telemetry events from Red Hat plugins going forward.
31
31
If you want to stop sending usage data to Red Hat, you can disable it in the preferences at Tools > Red Hat Telemetry.
32
32
This will silence all telemetry events from Red Hat plugins going forward.
33
33
34
+ ## How to use from a IDEA plugin extension?
34
35
36
+ ### Dependency
37
+ Start by adding ` com.redhat.devtools.intellij.telemetry ` to the plugins section of your build.gradle, so that the dependency can be automatically downloaded and installed, when installing your extension from the Marketplace.
38
+ ``` groovy
39
+ plugins "com.redhat.devtools.intellij.telemetry:0.0.1.9"
40
+ ```
35
41
42
+ ### [ Optional] Add custom segment keys in src/main/resources/segment.properties
43
+ By default, extensions will send their data to https://app.segment.com/redhat-devtools/sources/intellij/ .
44
+ In development mode, the data is sent to https://app.segment.com/redhat-devtools/sources/intellij_test/ .
45
+ You can specify custom segment keys to connect and push usage data to https://segment.com/
46
+ ``` properties
47
+ " writeKey" : " your-segment-key-goes-here" ,
48
+ " debugWriteKey" : " your-segment-key-goes-here-for-dev-mode" ,
49
+ ```
50
+
51
+ ### Create a Telemetry singleton
52
+ You then need to create a singleton that allows you to get hold of the telemetry service.
53
+ Lazy initialisation allows late construction when things are needed.
54
+
55
+ ``` java
56
+ public class TelemetryService {
57
+
58
+ private static final TelemetryService INSTANCE = new TelemetryService ();
59
+
60
+ private final Lazy<TelemetryMessageBuilder > builder = new Lazy<> (() - > new TelemetryMessageBuilder (TelemetryService . class. getClassLoader()));
61
+
62
+ public static TelemetryMessageBuilder instance () {
63
+ return INSTANCE . builder. get();
64
+ }
65
+ }
66
+ ```
67
+ ### Send a message
68
+
69
+ To report an event you first need to get a hold on telemetry singleton and start by telling it what action you're about to build.
70
+ Good practice suggests prefixing your action by a group name that you separate with a "-".
71
+ Colons (":") cannot be used due to limitations in wooopra which won't automatically create a schema for your message in that case.
72
+ ``` java
73
+ ActionMessage telemetry = TelemetryService . instance(). action(" smurfs-find the magic cauldron" );
74
+ ```
75
+ You can then chain properties with their values to the point where you can send the message.
76
+ ``` java
77
+ telemetry
78
+ .property(" kindness" , " smurfette" )
79
+ .property(" magic" , " papa smurf" )
80
+ .send();
81
+ ```
82
+
83
+ ### Send special properties
84
+ The telemetry plugin tracks the startup and shutdown of your plugin automatically.
85
+ There's no need for you to send those messages, it's all done for you behind the scene.
86
+
87
+ Success may be used to indicate particular outcomes.
88
+ ``` java
89
+ telemetry. success(" found the magic cauldron" )
90
+ ```
91
+ Errors are passed along similarly. Error and success are both mutually exclusive.
92
+ ``` java
93
+ telemetry. error(" Gargamel was there" )
94
+ ```
95
+ A duration may be provided to indicate how long an operation took. You start by signaling when the action started.
96
+ ``` java
97
+ telemetry. started()
98
+ ```
99
+ Once the action is finished you provide the end time to the message.
100
+ ``` java
101
+ telemetry. finished(LocalDateTime . now())
102
+ ```
103
+ Not providing it won't harm, it'll done automatically for you.
104
+
105
+ ### Retrieve the anonymous User Id
106
+ Each message sends an anonymous user id along with the other payloads.
107
+ This type 4 UUID is automatically created and stored in a file at ` ~/.redhat/anonymousId `
108
+ To retrieve it you can query the class ` UserId ` .
109
+ ``` java
110
+ String userId = UserId . INSTANCE. get()
111
+ ```
112
+
113
+ ### Add a link to telemetry preferences
114
+ Telemetry provides a label that you can add to your plugin preferences panel.
115
+ ``` java
116
+ JPanel preferences = FormBuilder . createFormBuilder()
117
+ .addComponent(TelemetryPreferencesUtils . createTelemetryComponent(" Tekton Pipelines" , this :: getPanel), 1 )
118
+ .addComponentFillVertically(new JPanel (), 0 )
119
+ .getPanel();
120
+ ```
121
+ It provides a link that the user can click to get to the telemetry preferences.
122
+
123
+ ![ Consumer-preferences panel] ( images/consumer-preferences.png )
0 commit comments