@blueking/open-telemetry 0.0.26 → 0.0.27
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/dist/bk-rum.global.js +2 -2
- package/dist/bk-rum.global.js.map +1 -1
- package/dist/core/plugin.d.ts +3 -1
- package/dist/core/trace-context.d.ts +36 -0
- package/dist/index.js +528 -358
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/skills/bk-rum-otele/references/capabilities.md +2 -2
- package/skills/bk-rum-otele/references/configuration.md +1 -1
- package/skills/bk-rum-otele/references/network.md +56 -16
- package/skills/bk-rum-otele/references/production.md +2 -0
- package/skills/bk-rum-otele/references/telemetry-reference.md +11 -1
- package/skills/bk-rum-otele/references/troubleshooting.md +10 -0
package/dist/core/plugin.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { BkOTActivityEvent } from './action-activity';
|
|
2
2
|
import type { ResolvedBkOTConfig } from './config';
|
|
3
3
|
import type { BkOTSessionLifecycleEvent, BkOTUserContext, BkOTViewCommand, BkOTViewContext } from './runtime-context';
|
|
4
|
-
import type { Attributes, Span, SpanKind, TimeInput, Tracer } from '@opentelemetry/api';
|
|
4
|
+
import type { Attributes, Link, Span, SpanKind, TimeInput, Tracer } from '@opentelemetry/api';
|
|
5
5
|
import type { Instrumentation } from '@opentelemetry/instrumentation';
|
|
6
6
|
export interface BkOTPlugin {
|
|
7
7
|
enabled?: ((config: ResolvedBkOTConfig) => boolean) | boolean;
|
|
@@ -49,6 +49,8 @@ export interface BkOTStartSpanOptions {
|
|
|
49
49
|
/** 用于从历史中解析 Session/View/Action 归属;默认复用数字类型 startTime。 */
|
|
50
50
|
contextTime?: number;
|
|
51
51
|
kind?: SpanKind;
|
|
52
|
+
/** 关联其他 trace 的 Span Link;OTel 要求在创建时传入。 */
|
|
53
|
+
links?: Link[];
|
|
52
54
|
startTime?: TimeInput;
|
|
53
55
|
}
|
|
54
56
|
export declare const isPluginEnabled: (plugin: BkOTPlugin, config: ResolvedBkOTConfig) => boolean;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 被观测请求的 Trace Context 规划。
|
|
3
|
+
*
|
|
4
|
+
* 后端 APM 只解析 W3C `traceparent`,并且要求一个后端 trace 只对应一个 API 请求,因此这里不复用
|
|
5
|
+
* RUM Span 自身的 trace context,而是为每个命中白名单的请求生成独立的 trace-id/span-id,再通过
|
|
6
|
+
* Span Link 把后端 trace 关联回 RUM Span。
|
|
7
|
+
*
|
|
8
|
+
* 如果业务已经自行设置了 trace header(`traceparent`、`sentry-trace`、b3、Datadog、sw8),则完全
|
|
9
|
+
* 不注入,避免破坏业务既有的传播方式,只把已有链路建成 Link。
|
|
10
|
+
*
|
|
11
|
+
* Link 结构恒定:`context` 承载 trace-id/span-id,`attributes` 记录命中的格式与原始 header。
|
|
12
|
+
* sw8 这类无法映射为合法 OTel id 的格式会补一对占位 id,让 Link 结构保持统一。
|
|
13
|
+
*/
|
|
14
|
+
import type { Attributes, Link } from '@opentelemetry/api';
|
|
15
|
+
/** 大小写不敏感地读取一个请求 header */
|
|
16
|
+
export type BkOTHeaderReader = (name: string) => string | undefined;
|
|
17
|
+
export interface BkOTRequestTracePlan {
|
|
18
|
+
/** 关联后端 trace 的 Span Link,恒为一条 */
|
|
19
|
+
links: Link[];
|
|
20
|
+
/** 需要注入的 traceparent;业务已有 trace header 时为 undefined */
|
|
21
|
+
traceparent?: string;
|
|
22
|
+
}
|
|
23
|
+
export type BkOTUpstreamTraceFormat = 'b3' | 'b3-multi' | 'datadog' | 'sentry-trace' | 'sw8' | 'traceparent';
|
|
24
|
+
export declare const TRACEPARENT_HEADER = "traceparent";
|
|
25
|
+
interface UpstreamTrace {
|
|
26
|
+
format: BkOTUpstreamTraceFormat;
|
|
27
|
+
/** 命中格式的原始 header,原样写入 Link Attributes */
|
|
28
|
+
headers: Attributes;
|
|
29
|
+
sampled?: boolean;
|
|
30
|
+
/** 规范化后的合法 OTel id;无法映射时两者同时缺失 */
|
|
31
|
+
spanId?: string;
|
|
32
|
+
traceId?: string;
|
|
33
|
+
}
|
|
34
|
+
export declare const detectUpstreamTrace: (getHeader: BkOTHeaderReader) => UpstreamTrace | undefined;
|
|
35
|
+
export declare const planRequestTrace: (getHeader: BkOTHeaderReader) => BkOTRequestTracePlan;
|
|
36
|
+
export {};
|