Skip to content

Commit 1c24cfd

Browse files
pkanalmartinkuba
andauthored
docs(user-interaction): update docs to include examples of config options (#1840)
* docs(user-interaction): update docs to include examples of config options * add example to prevent span creation * fix lint * address PR comments * update link to list of events * syntax updates Co-authored-by: Martin Kuba <[email protected]> --------- Co-authored-by: Martin Kuba <[email protected]>
1 parent fb80783 commit 1c24cfd

File tree

1 file changed

+63
-0
lines changed
  • plugins/web/opentelemetry-instrumentation-user-interaction

1 file changed

+63
-0
lines changed

plugins/web/opentelemetry-instrumentation-user-interaction/README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ npm install --save @opentelemetry/instrumentation-user-interaction
2020

2121
## Usage
2222

23+
### Initialize
24+
2325
```js
2426
import { ConsoleSpanExporter, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base';
2527
import { WebTracerProvider } from '@opentelemetry/sdk-trace-web';
@@ -82,6 +84,67 @@ function getData(url) {
8284

8385
```
8486

87+
### Send spans for different events
88+
89+
By default, only `click` events are automatically instrumented. To automatically instrument other events, specify the events that should be captured for telemetry. Most [HTMLElement interface events](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement#events) are supported.
90+
91+
```js
92+
import { UserInteractionInstrumentation } from '@opentelemetry/instrumentation-user-interaction';
93+
import { registerInstrumentations } from '@opentelemetry/instrumentation';
94+
95+
// ...general opentelemetry configuration
96+
97+
registerInstrumentations({
98+
instrumentations: [
99+
new UserInteractionInstrumentation({
100+
eventNames: ['submit', 'click', 'keypress'],
101+
}),
102+
],
103+
});
104+
```
105+
106+
### Prevent spans from recording
107+
108+
```js
109+
import { UserInteractionInstrumentation } from '@opentelemetryinstrumentation-user-interaction';
110+
import { registerInstrumentations } from '@opentelemetry/instrumentation';
111+
112+
113+
// ...general opentelemetry configuration
114+
115+
registerInstrumentations({
116+
instrumentations: [
117+
new UserInteractionInstrumentation({
118+
shouldPreventSpanCreation: () => {
119+
return true;
120+
},
121+
}),
122+
],
123+
});
124+
```
125+
126+
### Add extra attributes to spans
127+
128+
To attach extra attributes to user interaction spans, provide a callback function to the `shouldPreventSpanCreation` option:
129+
130+
```js
131+
import { UserInteractionInstrumentation } from '@opentelemetryinstrumentation-user-interaction';
132+
import { registerInstrumentations } from '@opentelemetry/instrumentation';
133+
134+
// ...general opentelemetry configuration
135+
136+
registerInstrumentations({
137+
instrumentations: [
138+
new UserInteractionInstrumentation({
139+
shouldPreventSpanCreation: (event, element, span) => {
140+
span.setAttribute('target.id', element.id);
141+
// etc..
142+
}
143+
}),
144+
],
145+
});
146+
```
147+
85148
## Example Screenshots
86149

87150
![Screenshot of the running example](images/main.jpg)

0 commit comments

Comments
 (0)