@blueking/open-telemetry 0.0.1 → 0.0.4

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.
Files changed (44) hide show
  1. package/package.json +5 -3
  2. package/playground/App.vue +0 -148
  3. package/playground/bk-ot.ts +0 -110
  4. package/playground/components/DemoLogPanel.vue +0 -89
  5. package/playground/composables/use-demo-log.ts +0 -39
  6. package/playground/index.html +0 -13
  7. package/playground/main.ts +0 -36
  8. package/playground/mock/index.ts +0 -43
  9. package/playground/pages/BlankScreenDemo.vue +0 -97
  10. package/playground/pages/BusinessDemo.vue +0 -74
  11. package/playground/pages/CustomPluginDemo.vue +0 -104
  12. package/playground/pages/ErrorDemo.vue +0 -75
  13. package/playground/pages/Home.vue +0 -133
  14. package/playground/pages/HttpDemo.vue +0 -120
  15. package/playground/pages/LongTaskDemo.vue +0 -66
  16. package/playground/pages/WebSocketDemo.vue +0 -100
  17. package/playground/router/index.ts +0 -92
  18. package/playground/style.css +0 -180
  19. package/src/browser.ts +0 -44
  20. package/src/core/config.ts +0 -327
  21. package/src/core/plugin.ts +0 -97
  22. package/src/core/processor.ts +0 -74
  23. package/src/core/route-observer.ts +0 -128
  24. package/src/core/sampling.ts +0 -64
  25. package/src/core/sdk.ts +0 -327
  26. package/src/core/url.ts +0 -66
  27. package/src/index.ts +0 -55
  28. package/src/plugins/blank-screen.ts +0 -170
  29. package/src/plugins/common.ts +0 -131
  30. package/src/plugins/csp-violation.ts +0 -74
  31. package/src/plugins/device.ts +0 -91
  32. package/src/plugins/error.ts +0 -211
  33. package/src/plugins/http-body.ts +0 -437
  34. package/src/plugins/long-task.ts +0 -99
  35. package/src/plugins/page-view.ts +0 -83
  36. package/src/plugins/route-timing.ts +0 -89
  37. package/src/plugins/session.ts +0 -127
  38. package/src/plugins/web-vitals.ts +0 -159
  39. package/src/plugins/websocket.ts +0 -179
  40. package/tsconfig.app.json +0 -27
  41. package/tsconfig.dts.json +0 -13
  42. package/tsconfig.json +0 -7
  43. package/tsconfig.node.json +0 -26
  44. package/vite.config.ts +0 -70
@@ -1,179 +0,0 @@
1
- /*
2
- * Tencent is pleased to support the open source community by making
3
- * 蓝鲸智云PaaS平台 (BlueKing PaaS) available.
4
- *
5
- * Copyright (C) 2017-2025 Tencent. All rights reserved.
6
- *
7
- * 蓝鲸智云PaaS平台 (BlueKing PaaS) is licensed under the MIT License.
8
- *
9
- * License for 蓝鲸智云PaaS平台 (BlueKing PaaS):
10
- *
11
- * ---------------------------------------------------
12
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
13
- * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
14
- * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
15
- * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
16
- *
17
- * The above copyright notice and this permission notice shall be included in all copies or substantial portions of
18
- * the Software.
19
- *
20
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
21
- * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
23
- * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24
- * IN THE SOFTWARE.
25
- */
26
-
27
- import { SpanStatusCode } from '@opentelemetry/api';
28
- import { SeverityNumber } from '@opentelemetry/api-logs';
29
-
30
- import { shouldIgnoreUrl } from '../core/url';
31
-
32
- import type { BkOTRumConfig } from '../core/config';
33
- import type { BkOTPlugin } from '../core/plugin';
34
-
35
- const getMessageByteLength = (data: unknown): number => {
36
- if (data == null) return 0;
37
- if (typeof data === 'string') {
38
- return typeof TextEncoder === 'undefined' ? data.length : new TextEncoder().encode(data).byteLength;
39
- }
40
- if (data instanceof ArrayBuffer) return data.byteLength;
41
- if (ArrayBuffer.isView(data)) return data.byteLength;
42
- if (typeof Blob !== 'undefined' && data instanceof Blob) return data.size;
43
- return 0;
44
- };
45
-
46
- const getWebSocketAttributes = (url: string, redactUrl: (url: string) => string) => {
47
- const spanAttributes: Record<string, string> = {
48
- 'url.full': redactUrl(url),
49
- 'network.protocol.name': 'websocket',
50
- };
51
-
52
- try {
53
- const parsed = new URL(url, typeof location === 'undefined' ? 'http://localhost' : location.href);
54
- spanAttributes['server.address'] = parsed.host;
55
- } catch {
56
- /* ignore malformed URL and keep the raw, redacted URL only */
57
- }
58
-
59
- return {
60
- spanAttributes,
61
- metricAttributes: {
62
- 'network.protocol.name': 'websocket',
63
- },
64
- };
65
- };
66
-
67
- export const createWebSocketPlugin = (enabled: BkOTRumConfig['websocket']): BkOTPlugin => {
68
- let originalWebSocket: typeof WebSocket | undefined;
69
-
70
- return {
71
- name: 'websocket',
72
- enabled: Boolean(enabled),
73
- init(context) {
74
- if (typeof window === 'undefined' || typeof window.WebSocket === 'undefined') {
75
- return;
76
- }
77
-
78
- const NativeWebSocket = window.WebSocket;
79
- originalWebSocket = NativeWebSocket;
80
-
81
- const messageCounter = context.meter.createCounter('browser.websocket.message.count', {
82
- description: 'Total number of WebSocket messages observed',
83
- });
84
- const bytesCounter = context.meter.createCounter('browser.websocket.message.bytes', {
85
- unit: 'By',
86
- description: 'Total bytes transferred over WebSocket (best-effort)',
87
- });
88
- const errorCounter = context.meter.createCounter('browser.websocket.error.count', {
89
- description: 'Total number of WebSocket error events',
90
- });
91
-
92
- const PatchedWebSocket = function (this: WebSocket, url: string | URL, protocols?: string | string[]) {
93
- const urlValue = url.toString();
94
-
95
- // 用户主动 ignore 或上报 endpoint,避免回环监控
96
- if (shouldIgnoreUrl(context.config, urlValue)) {
97
- return protocols === undefined ? new NativeWebSocket(url) : new NativeWebSocket(url, protocols);
98
- }
99
-
100
- const { metricAttributes, spanAttributes } = getWebSocketAttributes(urlValue, context.config.redactUrl);
101
- // connect span 只覆盖"建立连接"阶段,避免长连接导致 span 永远不结束
102
- const connectSpan = context.startSpan('websocket.connect', spanAttributes);
103
- const startTime = performance.now();
104
- const socket = protocols === undefined ? new NativeWebSocket(url) : new NativeWebSocket(url, protocols);
105
- let connectEnded = false;
106
-
107
- const endConnectSpan = (status: 'error' | 'opened') => {
108
- if (connectEnded) return;
109
- connectEnded = true;
110
- if (status === 'error') {
111
- connectSpan.setStatus({ code: SpanStatusCode.ERROR, message: 'websocket connect failed' });
112
- }
113
- connectSpan.setAttribute('websocket.connect.duration_ms', performance.now() - startTime);
114
- connectSpan.end();
115
- };
116
-
117
- socket.addEventListener('open', () => endConnectSpan('opened'));
118
-
119
- socket.addEventListener('message', event => {
120
- messageCounter.add(1, { ...metricAttributes, 'websocket.direction': 'in' });
121
- bytesCounter.add(getMessageByteLength(event.data), {
122
- ...metricAttributes,
123
- 'websocket.direction': 'in',
124
- });
125
- });
126
-
127
- socket.addEventListener('error', () => {
128
- errorCounter.add(1, metricAttributes);
129
- endConnectSpan('error');
130
- context.emitLog({
131
- severityNumber: SeverityNumber.ERROR,
132
- severityText: 'ERROR',
133
- body: 'websocket.error',
134
- attributes: spanAttributes,
135
- });
136
- });
137
-
138
- socket.addEventListener('close', event => {
139
- endConnectSpan('opened');
140
- context.emitLog({
141
- severityNumber: SeverityNumber.INFO,
142
- severityText: 'INFO',
143
- body: 'websocket.close',
144
- attributes: {
145
- ...spanAttributes,
146
- 'websocket.close.code': event.code,
147
- 'websocket.close.reason': event.reason,
148
- 'websocket.close.was_clean': event.wasClean,
149
- },
150
- });
151
- });
152
-
153
- // 计量发送方向(无法拦截 send 的回调,所以包一层 send 方法)
154
- const originalSend = socket.send.bind(socket);
155
- socket.send = (data: ArrayBufferLike | ArrayBufferView | Blob | string) => {
156
- messageCounter.add(1, { ...metricAttributes, 'websocket.direction': 'out' });
157
- bytesCounter.add(getMessageByteLength(data), {
158
- ...metricAttributes,
159
- 'websocket.direction': 'out',
160
- });
161
- return originalSend(data);
162
- };
163
-
164
- return socket;
165
- } as unknown as typeof WebSocket;
166
-
167
- // 复制原型与静态常量(CONNECTING / OPEN / CLOSING / CLOSED 等),避免业务侧 WebSocket.OPEN 失效
168
- PatchedWebSocket.prototype = NativeWebSocket.prototype;
169
- Object.assign(PatchedWebSocket, NativeWebSocket);
170
-
171
- window.WebSocket = PatchedWebSocket;
172
- },
173
- shutdown() {
174
- if (originalWebSocket && typeof window !== 'undefined') {
175
- window.WebSocket = originalWebSocket;
176
- }
177
- },
178
- };
179
- };
package/tsconfig.app.json DELETED
@@ -1,27 +0,0 @@
1
- {
2
- "extends": "@vue/tsconfig/tsconfig.dom.json",
3
- "compilerOptions": {
4
- "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
5
- "types": ["vite/client"],
6
-
7
- /* Linting */
8
- "strict": true,
9
- "noUnusedLocals": true,
10
- "noUnusedParameters": true,
11
- "erasableSyntaxOnly": false,
12
- "noFallthroughCasesInSwitch": true,
13
- "noUncheckedSideEffectImports": true
14
- },
15
- "include": [
16
- "src/**/*.ts",
17
- "src/**/*.tsx",
18
- "src/**/*.d.ts",
19
- "src/**/*.vue",
20
- "playground/**/*.ts",
21
- "playground/**/*.vue",
22
- "vite.config.ts",
23
- "wikis/**/*.ts",
24
- "wikis/.vitepress/**/*.ts",
25
- "mcp/**/*.ts"
26
- ]
27
- }
package/tsconfig.dts.json DELETED
@@ -1,13 +0,0 @@
1
- {
2
- "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.vue"],
3
- "exclude": ["node_modules", "src/**/*.spec.ts"],
4
- "extends": "./tsconfig.app.json",
5
-
6
- "compilerOptions": {
7
- "declaration": true,
8
- "declarationDir": "./dist",
9
- "emitDeclarationOnly": true,
10
- "noEmit": false,
11
- "noImplicitAny": false
12
- }
13
- }
package/tsconfig.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "files": [],
3
- "references": [
4
- { "path": "./tsconfig.app.json" },
5
- { "path": "./tsconfig.node.json" }
6
- ]
7
- }
@@ -1,26 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
4
- "target": "ES2023",
5
- "lib": ["ES2023"],
6
- "module": "ESNext",
7
- "types": ["node"],
8
- "skipLibCheck": true,
9
-
10
- /* Bundler mode */
11
- "moduleResolution": "bundler",
12
- "allowImportingTsExtensions": true,
13
- "verbatimModuleSyntax": true,
14
- "moduleDetection": "force",
15
- "noEmit": true,
16
-
17
- /* Linting */
18
- "strict": true,
19
- "noUnusedLocals": true,
20
- "noUnusedParameters": true,
21
- "erasableSyntaxOnly": true,
22
- "noFallthroughCasesInSwitch": true,
23
- "noUncheckedSideEffectImports": true
24
- },
25
- "include": ["vite.config.ts", "vitest.config.ts", "src/**/*.mjs"]
26
- }
package/vite.config.ts DELETED
@@ -1,70 +0,0 @@
1
- /*
2
- * Tencent is pleased to support the open source community by making
3
- * 蓝鲸智云PaaS平台 (BlueKing PaaS) available.
4
- *
5
- * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
6
- *
7
- * 蓝鲸智云PaaS平台 (BlueKing PaaS) is licensed under the MIT License.
8
- *
9
- * License for 蓝鲸智云PaaS平台 (BlueKing PaaS):
10
- *
11
- * ---------------------------------------------------
12
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
13
- * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
14
- * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
15
- * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
16
- *
17
- * The above copyright notice and this permission notice shall be included in all copies or substantial portions of
18
- * the Software.
19
- *
20
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
21
- * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
23
- * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24
- * IN THE SOFTWARE.
25
- */
26
- import vue from '@vitejs/plugin-vue';
27
- import fs from 'fs';
28
- import path from 'path';
29
- import { defineConfig } from 'vite';
30
- import { analyzer, unstableRolldownAdapter } from 'vite-bundle-analyzer';
31
-
32
- const resolve = (dir: string) => path.resolve(__dirname, dir);
33
- const packageJson = JSON.parse(fs.readFileSync(resolve('./package.json'), 'utf-8'));
34
- const externals = Object.keys(packageJson.dependencies || {});
35
- const isExternal = (id: string) => externals.some(dep => id === dep || id.startsWith(`${dep}/`));
36
- // https://vite.dev/config/
37
- export default defineConfig(({ mode }) => {
38
- const isCdn = mode === 'cdn';
39
- const isProductionLike = mode === 'production' || isCdn;
40
-
41
- return {
42
- plugins: [vue(), mode === 'preview' ? unstableRolldownAdapter(analyzer()) : undefined].filter(Boolean),
43
- root: resolve('./playground'),
44
- build: {
45
- emptyOutDir: !isCdn,
46
- target: 'es2015',
47
- outDir: resolve('./dist'),
48
- sourcemap: isProductionLike ? 'hidden' : 'inline',
49
- lib: {
50
- entry: resolve(isCdn ? './src/browser.ts' : './src/index.ts'),
51
- name: 'BkOpenTelemetry',
52
- fileName: () => (isCdn ? 'bk-rum.global.js' : 'index.js'),
53
- formats: [isCdn ? 'iife' : 'es'],
54
- cssFileName: 'index',
55
- },
56
- minify: isProductionLike,
57
- rolldownOptions: {
58
- external: isCdn ? undefined : isExternal,
59
- output: isCdn
60
- ? {
61
- inlineDynamicImports: true,
62
- }
63
- : undefined,
64
- },
65
- },
66
- server: {
67
- allowedHosts: ['localhost', '127.0.0.1', 'appdev.woa.com'],
68
- },
69
- };
70
- });