@wisemen/vue-core-telemetry 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +125 -2
- package/package.json +11 -17
- /package/dist/{index.d.ts → index.d.mts} +0 -0
- /package/dist/{index.js → index.mjs} +0 -0
package/README.md
CHANGED
|
@@ -1,3 +1,126 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @wisemen/vue-core-telemetry
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A lightweight helper that wires Sentry error tracking and OpenTelemetry tracing into Vue applications with a single interface.
|
|
4
|
+
|
|
5
|
+
## Highlights
|
|
6
|
+
- Initialize Sentry and OpenTelemetry with one `Telemetry` instance.
|
|
7
|
+
- Capture exceptions or custom messages and enrich them with tags, extras, and user context.
|
|
8
|
+
- Ship OTLP traces with automatic Fetch/User Interaction instrumentations and custom ones via `registerAppInstrumentations`.
|
|
9
|
+
- Ship build metadata (commit, build number, environment) with every span.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pnpm i @wisemen/vue-core-telemetry
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
This package peers on Vue, so ensure the app already depends on `vue`.
|
|
18
|
+
|
|
19
|
+
## Basic usage
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
// src/plugins/telemetry.plugin.ts
|
|
23
|
+
import { Telemetry, registerAppInstrumentations } from '@wisemen/vue-core-telemetry'
|
|
24
|
+
import type { App } from 'vue'
|
|
25
|
+
|
|
26
|
+
import {
|
|
27
|
+
CURRENT_BUILD_COMMIT,
|
|
28
|
+
CURRENT_BUILD_NUMBER,
|
|
29
|
+
CURRENT_BUILD_TIMESTAMP,
|
|
30
|
+
CURRENT_ENVIRONMENT,
|
|
31
|
+
OTEL_SERVICE_NAME,
|
|
32
|
+
OTEL_TRACE_ENDPOINT,
|
|
33
|
+
SENTRY_DSN,
|
|
34
|
+
SENTRY_SAMPLE_RATE,
|
|
35
|
+
} from '@/constants/environment.constant'
|
|
36
|
+
import { oAuthClient } from '@/libs/oAuth.lib'
|
|
37
|
+
|
|
38
|
+
const telemetry = new Telemetry({
|
|
39
|
+
openTelemetry: {
|
|
40
|
+
accessTokenFn: () => oAuthClient.getAccessToken(),
|
|
41
|
+
buildNumber: CURRENT_BUILD_NUMBER,
|
|
42
|
+
buildTimestamp: CURRENT_BUILD_TIMESTAMP,
|
|
43
|
+
commitHash: CURRENT_BUILD_COMMIT,
|
|
44
|
+
environment: CURRENT_ENVIRONMENT,
|
|
45
|
+
serviceName: OTEL_SERVICE_NAME ?? 'vue-template',
|
|
46
|
+
traceEndpoint: OTEL_TRACE_ENDPOINT,
|
|
47
|
+
},
|
|
48
|
+
sentry: {
|
|
49
|
+
dsn: SENTRY_DSN,
|
|
50
|
+
sampleRate: SENTRY_SAMPLE_RATE,
|
|
51
|
+
},
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
registerAppInstrumentations() // optional: register default Fetch & User Interaction instrumentations
|
|
55
|
+
|
|
56
|
+
export const telemetryPlugin = {
|
|
57
|
+
install: async (app: App) => {
|
|
58
|
+
if (CURRENT_ENVIRONMENT === 'mock' || CURRENT_BUILD_COMMIT === 'undefined') return
|
|
59
|
+
await telemetry.init(app)
|
|
60
|
+
},
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Once initialized you can call the helper anywhere (e.g. inside error boundaries, composables, or stores) to report diagnostics:
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
telemetry.captureException(error, { feature: 'checkout' })
|
|
68
|
+
telemetry.setTags({ locale: 'en-GB' })
|
|
69
|
+
telemetry.setUser({ id: user.id, email: user.email })
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Configuration reference
|
|
73
|
+
|
|
74
|
+
The `Telemetry` constructor accepts the following options:
|
|
75
|
+
|
|
76
|
+
| Option | Description |
|
|
77
|
+
| --- | --- |
|
|
78
|
+
| `sentry?: SentryOptions` | Enables Sentry error reporting. Requires at least a `dsn`. |
|
|
79
|
+
| `openTelemetry?: OpenTelemetryOptions` | Enables OTLP trace exporting. Requires a `serviceName`, `traceEndpoint`, and `accessTokenFn`. |
|
|
80
|
+
|
|
81
|
+
### `SentryOptions`
|
|
82
|
+
|
|
83
|
+
| Property | Type | Notes |
|
|
84
|
+
| --- | --- | --- |
|
|
85
|
+
| `dsn` | `string` | Required DSN for your Sentry project. |
|
|
86
|
+
| `enabled` | `boolean` | Default `true`. Skip initialization when `false`. |
|
|
87
|
+
| `debug` | `boolean` | Logs verbose warnings in development. |
|
|
88
|
+
| `environment` | `string` | Defaults to `"production"`. |
|
|
89
|
+
| `sampleRate` | `number` | Event sampling rate (`1.0` = 100%). |
|
|
90
|
+
| `enableReplays` | `boolean` | Enables session replays. |
|
|
91
|
+
| `replaysSessionSampleRate` | `number` | Default `0.1`. |
|
|
92
|
+
| `replaysOnErrorSampleRate` | `number` | Default `1`. |
|
|
93
|
+
|
|
94
|
+
### `OpenTelemetryOptions`
|
|
95
|
+
|
|
96
|
+
| Property | Type | Notes |
|
|
97
|
+
| --- | --- | --- |
|
|
98
|
+
| `accessTokenFn` | `() => Promise<string>` | Must resolve to a valid bearer token for the OTLP endpoint. Called before every batch export. |
|
|
99
|
+
| `traceEndpoint` | `string` | URL of the OTLP/HTTP trace collector. Required to enable tracing. |
|
|
100
|
+
| `serviceName` | `string` | Telemetry service identifier (e.g. app name). |
|
|
101
|
+
| `environment`, `buildNumber`, `buildTimestamp`, `commitHash`, `serviceVersion` | `string` | Optional metadata that is attached to every span. |
|
|
102
|
+
| `debug` | `boolean` | Emits logs while initializing. |
|
|
103
|
+
| `enabled` | `boolean` | Disable tracing entirely when set to `false`. |
|
|
104
|
+
|
|
105
|
+
## Registering additional instrumentations
|
|
106
|
+
|
|
107
|
+
The helper exports `registerAppInstrumentations` which registers sensible defaults (Fetch + User Interaction). Pass extra instrumentations if your application needs to instrument other libraries:
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
import { registerAppInstrumentations } from '@wisemen/vue-core-telemetry'
|
|
111
|
+
import { DocumentLoadInstrumentation } from '@opentelemetry/instrumentation-document-load'
|
|
112
|
+
|
|
113
|
+
registerAppInstrumentations([
|
|
114
|
+
new DocumentLoadInstrumentation(),
|
|
115
|
+
])
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## API surface
|
|
119
|
+
|
|
120
|
+
- `telemetry.init(app)` – bootstraps Sentry and/or OpenTelemetry using the provided options.
|
|
121
|
+
- `captureException(error, context?)` – forwards errors to Sentry, optionally with structured context.
|
|
122
|
+
- `captureMessage(message, level?)` – log arbitrary messages with a Sentry severity level.
|
|
123
|
+
- `setExtra(key, value)` / `setTag(key, value)` / `setTags(record)` / `setUser(user)` – enrich subsequent events with extra fields.
|
|
124
|
+
- `registerAppInstrumentations(instrumentations?)` – helper for OpenTelemetry instrumentation setup (also exported separately).
|
|
125
|
+
|
|
126
|
+
Refer to the [`vue-project-template`](https://github.com/wisemen-digital/vue-project-template) for a fully wired example plugin and environment setup.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wisemen/vue-core-telemetry",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.3",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -9,22 +9,14 @@
|
|
|
9
9
|
"sideEffects": false,
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
12
|
-
"types": "./dist/index.d.
|
|
13
|
-
"import": "./dist/index.mjs"
|
|
14
|
-
"require": "./dist/index.cjs"
|
|
12
|
+
"types": "./dist/index.d.mts",
|
|
13
|
+
"import": "./dist/index.mjs"
|
|
15
14
|
}
|
|
16
15
|
},
|
|
17
16
|
"main": "./dist/index.mjs",
|
|
18
17
|
"module": "./dist/index.mjs",
|
|
19
|
-
"types": "./dist/index.d.
|
|
20
|
-
"
|
|
21
|
-
"*": {
|
|
22
|
-
"*": [
|
|
23
|
-
"./dist/*",
|
|
24
|
-
"./dist/index.d.ts"
|
|
25
|
-
]
|
|
26
|
-
}
|
|
27
|
-
},
|
|
18
|
+
"types": "./dist/index.d.mts",
|
|
19
|
+
"typings": "./dist/index.d.mts",
|
|
28
20
|
"files": [
|
|
29
21
|
"dist"
|
|
30
22
|
],
|
|
@@ -45,11 +37,11 @@
|
|
|
45
37
|
"@sentry/vue": "10.20.0"
|
|
46
38
|
},
|
|
47
39
|
"devDependencies": {
|
|
48
|
-
"@wisemen/eslint-config-vue": "1.7.
|
|
40
|
+
"@wisemen/eslint-config-vue": "1.7.6",
|
|
49
41
|
"bumpp": "10.3.1",
|
|
50
|
-
"eslint": "9.
|
|
42
|
+
"eslint": "9.39.2",
|
|
51
43
|
"rimraf": "6.0.1",
|
|
52
|
-
"tsdown": "0.
|
|
44
|
+
"tsdown": "0.18.4",
|
|
53
45
|
"typescript": "5.9.3"
|
|
54
46
|
},
|
|
55
47
|
"scripts": {
|
|
@@ -59,6 +51,8 @@
|
|
|
59
51
|
"lint": "eslint .",
|
|
60
52
|
"lint:fix": "eslint . --fix",
|
|
61
53
|
"release": "bumpp && npm publish",
|
|
62
|
-
"type-check": "tsc --noEmit"
|
|
54
|
+
"type-check": "tsc --noEmit",
|
|
55
|
+
"pub:release": "pnpm publish --access public",
|
|
56
|
+
"pub:beta": "pnpm publish --no-git-checks --access public --tag beta"
|
|
63
57
|
}
|
|
64
58
|
}
|
|
File without changes
|
|
File without changes
|