@obtrace/browser 2.1.0 → 2.3.0
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/browser/console.js +54 -7
- package/dist/browser/errors.js +51 -17
- package/dist/browser/index.js +49 -14
- package/dist/browser_entry.bundle.js +2305 -416
- package/dist/browser_entry.bundle.js.map +4 -4
- package/dist/core/otel-web-setup.js +19 -3
- package/dist/types/browser/console.d.ts +3 -2
- package/dist/types/browser/errors.d.ts +2 -1
- package/dist/types/core/otel-web-setup.d.ts +5 -1
- package/dist/types/wrappers/frontend/react.d.ts +2 -0
- package/dist/wrappers/frontend/react.js +57 -0
- package/package.json +3 -1
|
@@ -4,6 +4,8 @@ import { BatchSpanProcessor, TraceIdRatioBasedSampler, ParentBasedSampler } from
|
|
|
4
4
|
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
|
|
5
5
|
import { MeterProvider, PeriodicExportingMetricReader } from "@opentelemetry/sdk-metrics";
|
|
6
6
|
import { OTLPMetricExporter } from "@opentelemetry/exporter-metrics-otlp-http";
|
|
7
|
+
import { LoggerProvider, BatchLogRecordProcessor } from "@opentelemetry/sdk-logs";
|
|
8
|
+
import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-http";
|
|
7
9
|
import { Resource } from "@opentelemetry/resources";
|
|
8
10
|
import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION } from "@opentelemetry/semantic-conventions";
|
|
9
11
|
import { FetchInstrumentation } from "@opentelemetry/instrumentation-fetch";
|
|
@@ -29,6 +31,7 @@ export function setupOtelWeb(config) {
|
|
|
29
31
|
...(config.projectId ? { "obtrace.project_id": config.projectId } : {}),
|
|
30
32
|
...(config.appId ? { "obtrace.app_id": config.appId } : {}),
|
|
31
33
|
...(config.env ? { "obtrace.env": config.env } : {}),
|
|
34
|
+
...(config.sessionId ? { "session.id": config.sessionId } : {}),
|
|
32
35
|
"runtime.name": "browser",
|
|
33
36
|
});
|
|
34
37
|
const traceExporter = new OTLPTraceExporter({
|
|
@@ -61,6 +64,14 @@ export function setupOtelWeb(config) {
|
|
|
61
64
|
],
|
|
62
65
|
});
|
|
63
66
|
metrics.setGlobalMeterProvider(meterProvider);
|
|
67
|
+
const logExporter = new OTLPLogExporter({
|
|
68
|
+
url: `${baseUrl}/otlp/v1/logs`,
|
|
69
|
+
headers: authHeaders,
|
|
70
|
+
});
|
|
71
|
+
const loggerProvider = new LoggerProvider({
|
|
72
|
+
resource: resource,
|
|
73
|
+
processors: [new BatchLogRecordProcessor(logExporter)],
|
|
74
|
+
});
|
|
64
75
|
const ingestPattern = new RegExp(`^${baseUrl.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`);
|
|
65
76
|
const instrumentations = [];
|
|
66
77
|
if (config.instrumentGlobalFetch !== false) {
|
|
@@ -83,8 +94,8 @@ export function setupOtelWeb(config) {
|
|
|
83
94
|
tracerProvider,
|
|
84
95
|
instrumentations,
|
|
85
96
|
});
|
|
86
|
-
const tracer = trace.getTracer("@obtrace/sdk-browser", "2.
|
|
87
|
-
const meter = metrics.getMeter("@obtrace/sdk-browser", "2.
|
|
97
|
+
const tracer = trace.getTracer("@obtrace/sdk-browser", "2.2.0");
|
|
98
|
+
const meter = metrics.getMeter("@obtrace/sdk-browser", "2.2.0");
|
|
88
99
|
const forceFlush = async () => {
|
|
89
100
|
try {
|
|
90
101
|
await tracerProvider.forceFlush();
|
|
@@ -94,11 +105,16 @@ export function setupOtelWeb(config) {
|
|
|
94
105
|
await meterProvider.forceFlush();
|
|
95
106
|
}
|
|
96
107
|
catch { }
|
|
108
|
+
try {
|
|
109
|
+
await loggerProvider.forceFlush();
|
|
110
|
+
}
|
|
111
|
+
catch { }
|
|
97
112
|
};
|
|
98
113
|
const shutdown = async () => {
|
|
99
114
|
await forceFlush();
|
|
100
115
|
await tracerProvider.shutdown();
|
|
101
116
|
await meterProvider.shutdown();
|
|
117
|
+
await loggerProvider.shutdown();
|
|
102
118
|
};
|
|
103
|
-
return { tracer, meter, shutdown, forceFlush };
|
|
119
|
+
return { tracer, meter, loggerProvider, shutdown, forceFlush };
|
|
104
120
|
}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import type
|
|
2
|
-
|
|
1
|
+
import { type Tracer } from "@opentelemetry/api";
|
|
2
|
+
import type { Logger } from "@opentelemetry/api-logs";
|
|
3
|
+
export declare function installConsoleCapture(tracer: Tracer, logger: Logger, sessionId: string): () => void;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { type Tracer } from "@opentelemetry/api";
|
|
2
|
-
|
|
2
|
+
import type { Logger } from "@opentelemetry/api-logs";
|
|
3
|
+
export declare function installBrowserErrorHooks(tracer: Tracer, logger: Logger, sessionId?: string): () => void;
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { type Tracer, type Meter } from "@opentelemetry/api";
|
|
2
|
+
import { LoggerProvider } from "@opentelemetry/sdk-logs";
|
|
2
3
|
import type { ObtraceSDKConfig } from "../shared/types";
|
|
3
4
|
export interface OtelHandles {
|
|
4
5
|
tracer: Tracer;
|
|
5
6
|
meter: Meter;
|
|
7
|
+
loggerProvider: LoggerProvider;
|
|
6
8
|
shutdown: () => Promise<void>;
|
|
7
9
|
forceFlush: () => Promise<void>;
|
|
8
10
|
}
|
|
9
|
-
export declare function setupOtelWeb(config: ObtraceSDKConfig
|
|
11
|
+
export declare function setupOtelWeb(config: ObtraceSDKConfig & {
|
|
12
|
+
sessionId?: string;
|
|
13
|
+
}): OtelHandles;
|
|
@@ -5,4 +5,6 @@ export declare function getObtrace(): BrowserSDK | null;
|
|
|
5
5
|
export declare function obtraceLog(level: "debug" | "info" | "warn" | "error" | "fatal", message: string, context?: SDKContext): void;
|
|
6
6
|
export declare function obtraceMetric(name: string, value: number, unit?: string, context?: SDKContext): void;
|
|
7
7
|
export declare function obtraceError(error: unknown, context?: SDKContext): void;
|
|
8
|
+
export declare function createObtraceErrorBoundary(React: any): any;
|
|
9
|
+
export declare function getObtraceErrorBoundary(): any;
|
|
8
10
|
export type { BrowserSDK, ObtraceSDKConfig, SDKContext };
|
|
@@ -18,3 +18,60 @@ export function obtraceMetric(name, value, unit, context) {
|
|
|
18
18
|
export function obtraceError(error, context) {
|
|
19
19
|
_sdk?.captureException(error, context);
|
|
20
20
|
}
|
|
21
|
+
let _React = null;
|
|
22
|
+
function getReact() {
|
|
23
|
+
if (_React)
|
|
24
|
+
return _React;
|
|
25
|
+
try {
|
|
26
|
+
_React = require("react");
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
try {
|
|
30
|
+
_React = globalThis.__obtrace_react;
|
|
31
|
+
}
|
|
32
|
+
catch { }
|
|
33
|
+
}
|
|
34
|
+
return _React;
|
|
35
|
+
}
|
|
36
|
+
export function createObtraceErrorBoundary(React) {
|
|
37
|
+
const Component = React.Component;
|
|
38
|
+
class ObtraceErrorBoundary extends Component {
|
|
39
|
+
constructor(props) {
|
|
40
|
+
super(props);
|
|
41
|
+
this.state = { hasError: false, error: null };
|
|
42
|
+
}
|
|
43
|
+
static getDerivedStateFromError(error) {
|
|
44
|
+
return { hasError: true, error };
|
|
45
|
+
}
|
|
46
|
+
componentDidCatch(error, errorInfo) {
|
|
47
|
+
const sdk = getObtrace();
|
|
48
|
+
if (sdk) {
|
|
49
|
+
const stack = errorInfo?.componentStack || "";
|
|
50
|
+
sdk.captureException(error, {
|
|
51
|
+
attrs: {
|
|
52
|
+
"error.type": "react.render",
|
|
53
|
+
"error.component_stack": typeof stack === "string" ? stack.slice(0, 4096) : "",
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
this.props.onError?.(error, errorInfo);
|
|
58
|
+
}
|
|
59
|
+
render() {
|
|
60
|
+
if (this.state.hasError) {
|
|
61
|
+
return this.props.fallback ?? null;
|
|
62
|
+
}
|
|
63
|
+
return this.props.children;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return ObtraceErrorBoundary;
|
|
67
|
+
}
|
|
68
|
+
let _ObtraceErrorBoundary = null;
|
|
69
|
+
export function getObtraceErrorBoundary() {
|
|
70
|
+
if (_ObtraceErrorBoundary)
|
|
71
|
+
return _ObtraceErrorBoundary;
|
|
72
|
+
const React = getReact();
|
|
73
|
+
if (!React)
|
|
74
|
+
throw new Error("React not found. Use createObtraceErrorBoundary(React) instead.");
|
|
75
|
+
_ObtraceErrorBoundary = createObtraceErrorBoundary(React);
|
|
76
|
+
return _ObtraceErrorBoundary;
|
|
77
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@obtrace/browser",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Obtrace Browser SDK with frontend wrappers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -66,6 +66,7 @@
|
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"@opentelemetry/api": "^1.9.0",
|
|
68
68
|
"@opentelemetry/context-zone": "^1.30.0",
|
|
69
|
+
"@opentelemetry/exporter-logs-otlp-http": "^0.214.0",
|
|
69
70
|
"@opentelemetry/exporter-metrics-otlp-http": "^0.57.0",
|
|
70
71
|
"@opentelemetry/exporter-trace-otlp-http": "^0.57.0",
|
|
71
72
|
"@opentelemetry/instrumentation-document-load": "^0.43.0",
|
|
@@ -73,6 +74,7 @@
|
|
|
73
74
|
"@opentelemetry/instrumentation-user-interaction": "^0.43.0",
|
|
74
75
|
"@opentelemetry/instrumentation-xml-http-request": "^0.57.0",
|
|
75
76
|
"@opentelemetry/resources": "^1.30.0",
|
|
77
|
+
"@opentelemetry/sdk-logs": "^0.214.0",
|
|
76
78
|
"@opentelemetry/sdk-metrics": "^1.30.0",
|
|
77
79
|
"@opentelemetry/sdk-trace-web": "^1.30.0",
|
|
78
80
|
"@opentelemetry/semantic-conventions": "^1.30.0",
|